diff --git a/plugins/extensions/pykrita/plugin/plugins/filtermanager/components/filtermanagertreemodel.py b/plugins/extensions/pykrita/plugin/plugins/filtermanager/components/filtermanagertreemodel.py --- a/plugins/extensions/pykrita/plugin/plugins/filtermanager/components/filtermanagertreemodel.py +++ b/plugins/extensions/pykrita/plugin/plugins/filtermanager/components/filtermanagertreemodel.py @@ -6,6 +6,7 @@ class FilterManagerTreeModel(QAbstractItemModel): + TYPE_COLUMN = 1 NODE_COLUMN = 3 DOCUMENT_COLUMN = 4 @@ -72,6 +73,9 @@ if role == Qt.UserRole + 2: return item.data(self.DOCUMENT_COLUMN) + if role == Qt.UserRole + 3: + return item.data(self.TYPE_COLUMN) + if role != Qt.DisplayRole and role != Qt.DecorationRole: return None diff --git a/plugins/extensions/pykrita/plugin/plugins/filtermanager/uifiltermanager.py b/plugins/extensions/pykrita/plugin/plugins/filtermanager/uifiltermanager.py --- a/plugins/extensions/pykrita/plugin/plugins/filtermanager/uifiltermanager.py +++ b/plugins/extensions/pykrita/plugin/plugins/filtermanager/uifiltermanager.py @@ -26,7 +26,7 @@ self.buttonBox.accepted.connect(self.confirmButton) self.buttonBox.rejected.connect(self.mainDialog.close) - self.documentsTreeView.setSelectionMode(QAbstractItemView.MultiSelection) + self.documentsTreeView.setSelectionMode(QAbstractItemView.SingleSelection) self.mainDialog.setWindowModality(Qt.NonModal) def initialize(self): @@ -54,16 +54,39 @@ self.mainDialog.activateWindow() def confirmButton(self): + documentsIndexes = [] + selectionModel = self.documentsTreeView.selectionModel() for index in selectionModel.selectedRows(): node = self.treeModel.data(index, Qt.UserRole + 1) documentIndex = self.treeModel.data(index, Qt.UserRole + 2) - self.applyFilterOverNode(node, self.documents[documentIndex]) + _type = self.treeModel.data(index, Qt.UserRole + 3) + + if _type == 'Document': + self.applyFilterOverDocument(self.documents[documentIndex]) + else: + self.applyFilterOverNode(node, self.documents[documentIndex]) + + documentsIndexes.append(documentIndex) + + self.refreshDocumentsProjections(set(documentsIndexes)) + + def refreshDocumentsProjections(self, indexes): + for index in indexes: + document = self.documents[index] + document.refreshProjection() def applyFilterOverNode(self, node, document): _filter = self.kritaInstance.filter(self.filterComboBox.currentText()) _filter.apply(node, 0, 0, document.width(), document.height()) + def applyFilterOverDocument(self, document): + """ This method applies the selected filter just to topLevelNodes, then + if topLevelNodes are GroupLayers, that filter will not be applied. """ + + for node in document.topLevelNodes(): + self.applyFilterOverNode(node, document) + @property def filters(self): return self._filters