From 2c3edc11d6844a5d031775c6546f879666cadae4 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 27 Apr 2022 14:26:58 +0200 Subject: [PATCH 1/4] return features() instead of featureList() set visible and invisible buttons like in the original function avoid segmentation fault when connecting direct to the nmRelation.getReferencedFeatureRequest's expression - somehow it has a problem with that --- .../gui/linking_relation_editor_widget.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/linking_relation_editor/gui/linking_relation_editor_widget.py b/linking_relation_editor/gui/linking_relation_editor_widget.py index ade6ac8..56fc8ff 100644 --- a/linking_relation_editor/gui/linking_relation_editor_widget.py +++ b/linking_relation_editor/gui/linking_relation_editor_widget.py @@ -317,17 +317,17 @@ def updateUiSingleEdit(self): self.mFormViewButton.setVisible(True) self.mTableViewButton.setVisible(True) - self.mMultiEditInfoLabel.setVisible(True) + self.mMultiEditInfoLabel.setVisible(False) self.mStackedWidget.setCurrentWidget(self.mDualView) request = self.relation().getRelatedFeaturesRequest(self.feature()) - if self.nmRelation().isValid(): filters = [] for feature in self.relation().referencingLayer().getFeatures(request): - filter = self.nmRelation().getReferencedFeatureRequest(feature).filterExpression().expression() - filters.append(filter.prepend('(').append(')')) + referenced_request = self.nmRelation().getReferencedFeatureRequest(feature) + filter = referenced_request.filterExpression().expression() + filters.append('('+filter+')') nmRequest = QgsFeatureRequest() nmRequest.setFilterExpression(" OR ".join(filters)) @@ -338,8 +338,8 @@ def updateUiSingleEdit(self): self.initDualView(self.relation().referencingLayer(), request) def updateUiMultiEdit(self): - self.mFormViewButton.setVisible(True) - self.mTableViewButton.setVisible(True) + self.mFormViewButton.setVisible(False) + self.mTableViewButton.setVisible(False) self.mMultiEditInfoLabel.setVisible(True) self.mStackedWidget.setCurrentWidget(self.mMultiEditStackedWidgetPage) parentTreeWidgetItems = [] @@ -690,7 +690,7 @@ def _featureList(self): if Qgis.QGIS_VERSION_INT < 32400: return [self.feature()] else: - return self.featureList() + return self.features() def _relationEditorLinkChildManagerDialogAccepted(self): relationEditorLinkChildManagerDialog = self.sender() From 78c54e10b0c50ed8efff23701b66cb8d65b3f234 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 27 Apr 2022 16:57:01 +0200 Subject: [PATCH 2/4] avoid index loose by handling the items in reverse --- linking_relation_editor/gui/linking_child_manager_dialog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linking_relation_editor/gui/linking_child_manager_dialog.py b/linking_relation_editor/gui/linking_child_manager_dialog.py index 9c4e472..878845f 100644 --- a/linking_relation_editor/gui/linking_child_manager_dialog.py +++ b/linking_relation_editor/gui/linking_child_manager_dialog.py @@ -81,7 +81,7 @@ def __init__(self, self._actionLinkSelected = QAction(QgsApplication.getThemeIcon("/mActionArrowRight.svg"), self.tr("Link selected")) self._actionUnlinkSelected = QAction(QgsApplication.getThemeIcon("/mActionArrowLeft.svg"), - self.tr("Unlink seleted")) + self.tr("Unlink selected")) self._actionLinkAll = QAction(QgsApplication.getThemeIcon("/mActionDoubleArrowRight.svg"), self.tr("Link all")) self._actionUnlinkAll = QAction(QgsApplication.getThemeIcon("/mActionDoubleArrowLeft.svg"), @@ -255,7 +255,7 @@ def _linkSelected(self): def _unlinkSelected(self): featuresModelElements = [] - for modelIndex in self.mFeaturesListViewRight.selectedIndexes(): + for modelIndex in reversed(self.mFeaturesListViewRight.selectedIndexes()): featuresModelElements.append(self._featuresModelRight.take_item(modelIndex)) for featuresModelElement in featuresModelElements: From 13427354a9455f16f7d590ed08a7e04e3a991d94 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 27 Apr 2022 17:09:04 +0200 Subject: [PATCH 3/4] no action icon to avoid noice --- .../core/features_model.py | 2 +- linking_relation_editor/images/mNoAction.svg | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 linking_relation_editor/images/mNoAction.svg diff --git a/linking_relation_editor/core/features_model.py b/linking_relation_editor/core/features_model.py index e2fd629..9d55e0f 100644 --- a/linking_relation_editor/core/features_model.py +++ b/linking_relation_editor/core/features_model.py @@ -68,7 +68,7 @@ def display_string(self): def display_icon(self): if self._featureState == FeaturesModel.FeatureState.Unlinked or self._featureState == FeaturesModel.FeatureState.Linked: - return QIcon() + return QIcon(os.path.join(os.path.dirname(__file__), '../images/mNoAction.svg')) elif self._featureState == FeaturesModel.FeatureState.ToBeLinked: return QIcon(os.path.join(os.path.dirname(__file__), '../images/mActionToBeLinked.svg')) elif self._featureState == FeaturesModel.FeatureState.ToBeUnlinked: diff --git a/linking_relation_editor/images/mNoAction.svg b/linking_relation_editor/images/mNoAction.svg new file mode 100644 index 0000000..ec8ae53 --- /dev/null +++ b/linking_relation_editor/images/mNoAction.svg @@ -0,0 +1,55 @@ + + + + + + image/svg+xml + + + + + + + + From 6bb2f4872c7945d1c2f15de1521be115ec62a903 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 27 Apr 2022 17:37:40 +0200 Subject: [PATCH 4/4] avoid loosing index by taking all items (they dont have the correct order when selected by hand while pressing control) by passing all of em to the function and then keep the rows, sort them and delete --- .../core/features_model.py | 22 +++++++++++++++++++ .../gui/linking_child_manager_dialog.py | 17 +++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/linking_relation_editor/core/features_model.py b/linking_relation_editor/core/features_model.py index 9d55e0f..2fb1c9d 100644 --- a/linking_relation_editor/core/features_model.py +++ b/linking_relation_editor/core/features_model.py @@ -185,6 +185,28 @@ def take_item(self, return feature + def take_items(self, + indexes): + + if not indexes: + return None + features=[] + rows_to_remove = [] + for index in indexes: + row = index.row() + features.append(self._modelFeatures[row]) + rows_to_remove.append(row) + + rows_to_remove.sort(reverse=True) + for row in rows_to_remove: + self.beginRemoveRows(QModelIndex(), + row, + row+1) + del self._modelFeatures[row] + self.endRemoveRows() + + return features + def contains(self, feature_id: int): for feature in self._modelFeatures: diff --git a/linking_relation_editor/gui/linking_child_manager_dialog.py b/linking_relation_editor/gui/linking_child_manager_dialog.py index 878845f..fe19685 100644 --- a/linking_relation_editor/gui/linking_child_manager_dialog.py +++ b/linking_relation_editor/gui/linking_child_manager_dialog.py @@ -240,9 +240,9 @@ def _getAllFeatures(self): def _linkSelected(self): featuresModelElements = [] selected_indexes = self.mFeaturesListViewLeft.selectedIndexes()[:] - for model_index in reversed(selected_indexes): - source_model_index = self._featuresModelFilterLeft.mapToSource(model_index) - featuresModelElements.append(self._featuresModelLeft.take_item(source_model_index)) + source_model_indexes = [self._featuresModelFilterLeft.mapToSource(model_index) for model_index in selected_indexes] + featuresModelElements = self._featuresModelLeft.take_items(source_model_indexes) + self._featuresModelFilterLeft.invalidate() for featuresModelElement in featuresModelElements: @@ -255,8 +255,8 @@ def _linkSelected(self): def _unlinkSelected(self): featuresModelElements = [] - for modelIndex in reversed(self.mFeaturesListViewRight.selectedIndexes()): - featuresModelElements.append(self._featuresModelRight.take_item(modelIndex)) + indexes = self.mFeaturesListViewRight.selectedIndexes()[:] + featuresModelElements = self._featuresModelRight.take_items(indexes) for featuresModelElement in featuresModelElements: if featuresModelElement.feature_state() == FeaturesModel.FeatureState.ToBeLinked: @@ -269,10 +269,9 @@ def _unlinkSelected(self): def _linkAll(self): featuresModelElements = list() if self._featuresModelFilterLeft.filter_active(): - for row in reversed(range(self._featuresModelFilterLeft.rowCount())): - modelIndex = self._featuresModelFilterLeft.index(row, 0) - sourceModelIndex = self._featuresModelFilterLeft.mapToSource(modelIndex) - featuresModelElements.append(self._featuresModelLeft.take_item(sourceModelIndex)) + source_model_indexes = [self._featuresModelFilterLeft.mapToSource(self._featuresModelFilterLeft.index(row, 0)) for row in range(self._featuresModelFilterLeft.rowCount())] + featuresModelElements = self._featuresModelLeft.take_items(source_model_indexes) + else: featuresModelElements = self._featuresModelLeft.take_all_items() for featuresModelElement in featuresModelElements: