コード例 #1
0
ファイル: dbstreemodel.py プロジェクト: spgilm/ViTables
    def insertRows(self, position=0, count=1, parent=QtCore.QModelIndex()):
        """Insert `count` rows before the given `position`.

        Inserted rows will be children of the item represented by the `parent`
        model index. This method is called during nodes population and when
        files are opened/created.

        Warning! This method is MONKEY PATCHED if the DBs Sorting plugin is
        enabled. If it is the case the working code will be in module
        vitables.plugins.dbstreesort.dbs_tree_sort

        :Parameters:

        - `position`: the position of the first row being added.
        - `count`: the number of rows being added
        - `parent`: the index of the parent item.

        :Returns: True if the row is added. Otherwise it returns False.
        """

        # Add rows to the model and update its underlaying data store
        self.layoutAboutToBeChanged.emit()
        first = position
        last = position + count - 1
        self.beginInsertRows(parent, first, last)
        node = self.nodeFromIndex(parent)
        for file_node in self.fdelta:
            self.root.insertChild(file_node, position)
        for name in self.gdelta:
            group = groupnode.GroupNode(self, node, name)
            node.insertChild(group, position)
        for name in self.ldelta:
            leaf = leafnode.LeafNode(self, node, name)
            node.insertChild(leaf, position)
        for name in self.links_delta:
            link = linknode.LinkNode(self, node, name)
            node.insertChild(link, position)
        self.dataChanged.emit(parent, parent)
        self.endInsertRows()
        self.layoutChanged.emit()

        # Report views about changes in data
        top_left = self.index(first, 0, parent)
        bottom_right = self.index(last, 0, parent)
        self.dataChanged.emit(top_left, bottom_right)

        return True
コード例 #2
0
def alphabeticalSort(self, position=0, count=1, parent=QtCore.QModelIndex()):
    """Insert `count` rows before the given row.

    This method is called during nodes population and when files are
    opened/created.

    :Parameters:

     - `position`: the position of the first row being added.
     - `count`: the number of rows being added
     - `parent`: the index of the parent item.

     :Returns: True if the row is added. Otherwise it returns False.
     """

    # Add rows to the model and update its underlaying data store
    self.layoutAboutToBeChanged.emit()
    first = position
    last = position + count - 1
    self.beginInsertRows(parent, first, last)
    node = self.nodeFromIndex(parent)
    # Children are inserted at position 0, so inserted list must
    # be reversed if we want to preserve their original order
    for file_node in sorted(self.fdelta):
        self.root.insertChild(file_node, position)
    for name in sorted(self.gdelta, reverse=True):
        group = groupnode.GroupNode(self, node, name)
        node.insertChild(group, position)
    for name in sorted(self.ldelta, reverse=True):
        leaf = leafnode.LeafNode(self, node, name)
        node.insertChild(leaf, position)
    for name in sorted(self.links_delta, reverse=True):
        link = linknode.LinkNode(self, node, name)
        node.insertChild(link, position)
    self.dataChanged.emit(parent, parent)
    self.endInsertRows()
    self.layoutChanged.emit()

    # Report views about changes in data
    top_left = self.index(first, 0, parent)
    bottom_right = self.index(last, 0, parent)
    self.dataChanged.emit(top_left, bottom_right)

    return True