The removeRows method of my QSortFilterProxyModel and QAbstractItemModel seem to work. The QTreeView is redrawn and shows the removed rows are missing. However my insertRow method is not updating the QTreeView, however the data structure is correct after the insert is executed.
QSortFilterProxyModel:
def insertRow(self,parent,data):
self.sourceModel().insertRow(self.mapToSource(parent),data)
def removeRows(self,row,count,parent):
self.sourceModel().removeRows(self.mapToSource(parent).row(),1,self.mapToSource(parent))
def insertRow(self,parent,data):
self.sourceModel().insertRow(self.mapToSource(parent),data)
def removeRows(self,row,count,parent):
self.sourceModel().removeRows(self.mapToSource(parent).row(),1,self.mapToSource(parent))
To copy to clipboard, switch view to plain text mode
QAbstractItemModel:
def insertRow(self,index,obj):
self.beginInsertRows(index,0,1)
# get node from index
node = self.getNode(index)
# wrap Node object around given Element
new_node = Node(obj,node)
# append new element to parent element
node._obj.append(obj)
# wrap any children with Node
for child in obj.iterchildren():
Node(child,new_node)
self.endInsertRows()
self.rowsInserted.emit(index,0,1)
return True
def insertRow(self,index,obj):
self.beginInsertRows(index,0,1)
# get node from index
node = self.getNode(index)
# wrap Node object around given Element
new_node = Node(obj,node)
# append new element to parent element
node._obj.append(obj)
# wrap any children with Node
for child in obj.iterchildren():
Node(child,new_node)
self.endInsertRows()
self.rowsInserted.emit(index,0,1)
return True
To copy to clipboard, switch view to plain text mode
Upon futher investigation I found out that the rowsInserted signal is not being propagated back through the proxy to the view. I connected it manually but it does nothing. I've tried other methods such as emitting dataChanged. Using layoutAboutToBeChanged/layoutChanged and reset result in a seg fault.
Note: The intent of insertRow is to insert a child node of the given index, only one row is required to be inserted. Is this the correct method? (Qt 4.7)
Any help appreciated.
Bookmarks