diff --git a/qps/speclib/gui/spectralprofilecandidates.py b/qps/speclib/gui/spectralprofilecandidates.py index 435adbce..d89c12fa 100644 --- a/qps/speclib/gui/spectralprofilecandidates.py +++ b/qps/speclib/gui/spectralprofilecandidates.py @@ -60,6 +60,26 @@ def removeProfileCandidates(cls, layers: List[QgsVectorLayer], block_signal: boo cls.SHARED_SIGNALS.candidatesChanged.emit(list(changed)) return changed + @classmethod + def setProfileCandidates(cls, layer: QgsVectorLayer, candidate_fids: List[int], is_candidate: bool = True): + """ + Can be used to set or unset existing features as candidates + :param layers: + :param candidates: + :return: + """ + if isinstance(candidate_fids, int): + candidate_fids = [candidate_fids] + + old_fids = layer.customProperty(CUSTOM_PROPERTY_CANDIDATE_FIDs, []) + + if is_candidate: + new_fids = set(candidate_fids).union(set(old_fids)) + else: + new_fids = set(old_fids).difference(set(candidate_fids)) + + layer.setCustomProperty(CUSTOM_PROPERTY_CANDIDATE_FIDs, list(new_fids)) + @classmethod def addProfileCandidates(cls, project: QgsProject, diff --git a/qps/speclib/gui/spectralprofileplotmodel.py b/qps/speclib/gui/spectralprofileplotmodel.py index c8fc5994..ddbe8381 100644 --- a/qps/speclib/gui/spectralprofileplotmodel.py +++ b/qps/speclib/gui/spectralprofileplotmodel.py @@ -1410,7 +1410,7 @@ def add_dt(key: str, t0: datetime.datetime): request.setFilterExpression(filter_expression.expression()) if show_selected_only: - request.setFilterFids(selected_fids) + request.setFilterFids(selected_fids + candidate_fids) field_name = vis['field_name'] field_index = layer.fields().lookupField(field_name) diff --git a/tests/speclib/test_speclib_plotting.py b/tests/speclib/test_speclib_plotting.py index 7e9d59c0..8f85673c 100644 --- a/tests/speclib/test_speclib_plotting.py +++ b/tests/speclib/test_speclib_plotting.py @@ -28,6 +28,7 @@ SpectralProfileColorPropertyWidget from qps.speclib.gui.spectrallibraryplotwidget import SpectralLibraryPlotWidget from qps.speclib.gui.spectrallibrarywidget import SpectralLibraryWidget +from qps.speclib.gui.spectralprofilecandidates import SpectralProfileCandidates from qps.speclib.gui.spectralprofileplotmodel import copy_items, SpectralProfilePlotModel, STATS_FUNCTIONS from qps.testing import start_app, TestCase, TestObjects from qps.unitmodel import BAND_INDEX, BAND_NUMBER @@ -641,6 +642,32 @@ def test_copy_plotdataitems(self): data = QgsApplication.instance().clipboard().mimeData().text() print(data) + def test_show_selected_profiles(self): + + sl1 = TestObjects.createSpectralLibrary(n=2, n_bands=[10]) + sl2 = TestObjects.createSpectralLibrary(n=4, n_bands=[50]) + + fids1 = sl1.allFeatureIds() + fids2 = sl2.allFeatureIds() + + project = QgsProject() + project.addMapLayers([sl1, sl2]) + + C = SpectralProfileCandidates() + C.setProfileCandidates(sl1, fids1[0]) + C.setProfileCandidates(sl2, fids2[0]) + + w = SpectralLibraryWidget() + w.setProject(project) + w.actionShowProfileViewSettings.toggled.emit(True) + w.createProfileVisualization(sl1) + w.createProfileVisualization(sl2) + m: SpectralProfilePlotModel = w.plotModel() + + self.showGui(w) + w.close() + project.removeAllMapLayers() + def test_SpectralLibraryPlotWidget(self): speclib = TestObjects.createSpectralLibrary(n_bands=[-1, 12])