--- a/Helpviewer/Bookmarks/BookmarksModel.py Thu Mar 23 18:58:56 2017 +0100 +++ b/Helpviewer/Bookmarks/BookmarksModel.py Thu Mar 23 19:06:13 2017 +0100 @@ -108,7 +108,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. @@ -117,6 +117,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 @@ -198,25 +201,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 @@ -226,7 +235,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. @@ -235,6 +244,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() @@ -242,14 +254,14 @@ 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 not index.isValid(): + if index is None or not index.isValid(): return QModelIndex() itemNode = self.node(index) @@ -267,14 +279,14 @@ 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 not parent.isValid(): + if parent is None or not parent.isValid(): return True from .BookmarkNode import BookmarkNode