def parent(self, child): if not child.isValid(): return QtCore.QModelIndex() node = child.internalPointer() if node.row() >= 0: return self.createIndex(node.row(), 0, node.parent()) return QtCore.QModelIndex()
def index(self, row, column, parent): if not self.hasIndex(row, column, parent): return QtCore.QModelIndex() node = parent.internalPointer() if parent.isValid() else self._root if node.children: return self.createIndex(row, column, node.child(row)) else: return QtCore.QModelIndex()
def __init__(self, material_library): super(MaterialLibraryWidget, self).__init__() self._material_library = material_library self._fullPreviewWindow = FullPreviewWindow() script_dir = os.path.dirname(os.path.abspath(__file__)) ui_filepath = os.path.join(script_dir, 'materialLibrary.ui') self._ui = QtUiTools.QUiLoader().load(ui_filepath, parentWidget=self) self._layout = QtWidgets.QVBoxLayout() self.setLayout(self._layout) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.addWidget(self._ui) self._ui.filter.textChanged.connect(self._filterChanged) self._listWidget = LibraryListWidget(self) self._fullPreviewWindow._requiredWidget = self._listWidget self._ui.verticalLayout_3.insertWidget(0, self._listWidget) self._ui.treeView.clicked.connect(self._treeItemClicked) self._listWidget.clicked.connect(self._listItemClicked) self._listWidget.itemEntered.connect(self._listItemEntered) self._listWidget.viewportEntered.connect(self._listViewportEntered) self._listWidget.setMouseTracking(True) self._ui.splitter.setSizes([150, 150]) self._libraryTreeModel = LibraryTreeModel(self) # tree item height must not be less than line edit height self._ui.treeView.setModel(self._libraryTreeModel) for group, materials in material_library.material_groups: for name in materials: self._libraryTreeModel.addItem(['All', group, name], material_library.material_datas[name].preview) self._libraryTreeModel.reset() self._ui.treeView.setIndentation(self._ui.treeView.indentation() // 2) rootIndex = self._libraryTreeModel.index(0, 0, QtCore.QModelIndex()) self._treeItemClicked(rootIndex) self._ui.treeView.expand(rootIndex) self._ui.helpButton.clicked.connect(self._helpButtonClicked) self._dataModel = None self._stateLoaded = False
def columnCount(self, parent=QtCore.QModelIndex()): return 1
def rowCount(self, parent=QtCore.QModelIndex()): node = parent.internalPointer() if parent.isValid() else self._root if node is not None: return node.childCount() else: return 0