Esempio n. 1
0
    def update(self, index: QModelIndex):
        if not index.isValid():
            return QVariant()
        if self.hasChildren(index):
            self.beginRemoveRows(index, 0, max(self.rowCount(index) - 1, 0))
            self.removeRows(0, self.rowCount(index), index)
            self.endRemoveRows()
            self.rowsRemoved.emit(index, 0, max(self.rowCount(index) - 1, 0))
            self.dataChanged.emit(
                index,
                index.child(
                    self.rowCount(index) - 1,
                    self.columnCount(index) - 1))

        self.objByIndex(index).populate()
        if self.hasChildren(index):
            self.beginInsertRows(index, 0, max(self.rowCount(index) - 1, 0))
            self.endInsertRows()
            self.rowsInserted.emit(index, 0, max(self.rowCount(index) - 1, 0))
            self.dataChanged.emit(
                index,
                index.child(
                    self.rowCount(index) - 1,
                    self.columnCount(index) - 1))
        else:
            self.dataChanged.emit(index, index)
        return True
Esempio n. 2
0
 def leafs(self, searchedIndex: QModelIndex) -> QModelIndexList:
     leafs = QModelIndexList()
     if searchedIndex.isValid():
         childCount = searchedIndex.model().columnCount(searchedIndex)
         for i in range(childCount):
             leafs += self.searchLeafs(searchedIndex.child(0, i))
     return leafs
Esempio n. 3
0
    def setData(self, index: QModelIndex, value: QVariant, role: int = None):
        if not index.isValid():
            return False
        item = index.internalPointer()

        if role == Qt.CheckStateRole:
            childrenCount = item.childrenCount()
            if childrenCount:
                for i in range(childrenCount):
                    self.setData(index.child(i, 0), value, role = role)
            else:
                item.selected = bool(value)
            self.dataChanged.emit(index, index, [Qt.CheckStateRole])

            # recalculate parents
            p = index
            while True:
                p = p.parent()
                if p.isValid():
                    self.dataChanged.emit(p, p, [Qt.CheckStateRole])
                else:
                    break

            # success
            return True

        if role == Qt.EditRole:
            assert index.column() == TaskTreeColumn.FileName
            item.setNameByUser(value)
            self.dataChanged.emit(index, index, [Qt.DisplayRole])
            return True

        return False
Esempio n. 4
0
    def setData(self, index: QModelIndex, value: QVariant, role: int = None):
        if not index.isValid():
            return False
        item = index.internalPointer()

        if role == Qt.CheckStateRole:
            childrenCount = item.childrenCount()
            if childrenCount:
                for i in range(childrenCount):
                    self.setData(index.child(i, 0), value, role=role)
            else:
                item.selected = bool(value)
            self.dataChanged.emit(index, index, [Qt.CheckStateRole])

            # recalculate parents
            p = index
            while True:
                p = p.parent()
                if p.isValid():
                    self.dataChanged.emit(p, p, [Qt.CheckStateRole])
                else:
                    break

            # success
            return True

        if role == Qt.EditRole:
            assert index.column() == TaskTreeColumn.FileName
            item.setNameByUser(value)
            self.dataChanged.emit(index, index, [Qt.DisplayRole])
            return True

        return False
Esempio n. 5
0
 def searchLeafs(self, currentIndex: QModelIndex) -> QModelIndexList:
     res = QModelIndexList()
     if currentIndex.isValid():
         childCount = currentIndex.model().columnCount(currentIndex)
         if childCount:
             for i in range(childCount):
                 res += self.searchLeafs(currentIndex.child(0, i))
         else:
             res.push_back(currentIndex)
     return res
Esempio n. 6
0
 def findLeaf(self, currentIndex: QModelIndex, sectionIndex: int,
              currentLeafIndex: int) -> QModelIndex:
     if currentIndex.isValid():
         childCount = currentIndex.model().columnCount(currentIndex)
         if childCount:
             for i in range(childCount):
                 res, currentLeafIndex = self.findLeaf(
                     currentIndex.child(0, i), sectionIndex,
                     currentLeafIndex)
                 if res.isValid():
                     return res, currentLeafIndex
         else:
             currentLeafIndex += 1
             if currentLeafIndex == sectionIndex:
                 return currentIndex, currentLeafIndex
     return QModelIndex(), currentLeafIndex
Esempio n. 7
0
 def onRowsInserted(self, parent: QModelIndex, first: int, last: int):
     index = parent.child(last, 0)
     self.setCurrentIndex(index)
     QTimer.singleShot(100, self.updateUndoRedoActs)