diff -r d75dfc0d10f2 -r 9c21b2746218 WebBrowser/Bookmarks/BookmarksModel.py --- a/WebBrowser/Bookmarks/BookmarksModel.py Thu Mar 23 18:58:56 2017 +0100 +++ b/WebBrowser/Bookmarks/BookmarksModel.py Thu Mar 23 19:06:13 2017 +0100 @@ -109,7 +109,7 @@ idx = self.nodeIndex(node) self.dataChanged.emit(idx, idx) - def removeRows(self, row, count, parent=QModelIndex()): + def removeRows(self, row, count, parent=None): """ Public method to remove bookmarks from the model. @@ -118,6 +118,9 @@ @param parent index of the parent bookmark node (QModelIndex) @return flag indicating successful removal (boolean) """ + if parent is None: + parent = QModelIndex() + if row < 0 or count <= 0 or row + count > self.rowCount(parent): return False @@ -202,25 +205,31 @@ return None - def columnCount(self, parent=QModelIndex()): + def columnCount(self, parent=None): """ Public method to get the number of columns. @param parent index of parent (QModelIndex) @return number of columns (integer) """ + if parent is None: + parent = QModelIndex() + if parent.column() > 0: return 0 else: return len(self.__headers) - def rowCount(self, parent=QModelIndex()): + def rowCount(self, parent=None): """ Public method to determine the number of rows. @param parent index of parent (QModelIndex) @return number of rows (integer) """ + if parent is None: + parent = QModelIndex() + if parent.column() > 0: return 0 @@ -230,7 +239,7 @@ itm = parent.internalPointer() return len(itm.children()) - def index(self, row, column, parent=QModelIndex()): + def index(self, row, column, parent=None): """ Public method to get a model index for a node cell. @@ -239,6 +248,9 @@ @param parent index of the parent (QModelIndex) @return index (QModelIndex) """ + if parent is None: + parent = QModelIndex() + if row < 0 or column < 0 or \ row >= self.rowCount(parent) or column >= self.columnCount(parent): return QModelIndex() @@ -246,13 +258,16 @@ parentNode = self.node(parent) return self.createIndex(row, column, parentNode.children()[row]) - def parent(self, index=QModelIndex()): + def parent(self, index=None): """ Public method to get the index of the parent node. @param index index of the child node (QModelIndex) @return index of the parent node (QModelIndex) """ + if index is None: + index = QModelIndex() + if not index.isValid(): return QModelIndex() @@ -271,13 +286,16 @@ parentRow = grandParentNode.children().index(parentNode) return self.createIndex(parentRow, 0, parentNode) - def hasChildren(self, parent=QModelIndex()): + def hasChildren(self, parent=None): """ Public method to check, if a parent node has some children. @param parent index of the parent node (QModelIndex) @return flag indicating the presence of children (boolean) """ + if parent is None: + parent = QModelIndex() + if not parent.isValid(): return True