From c6c63a06224dbe13c6db79bc0fda2127a5b30591 Mon Sep 17 00:00:00 2001 From: ghtmtt Date: Thu, 23 Jun 2022 08:52:21 +0200 Subject: [PATCH] fix the item selection of the plots --- DataPlotly/core/plot_factory.py | 8 +++---- DataPlotly/gui/plot_settings_widget.py | 30 +++++++++++--------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/DataPlotly/core/plot_factory.py b/DataPlotly/core/plot_factory.py index 3b725dd1..8e3f834c 100644 --- a/DataPlotly/core/plot_factory.py +++ b/DataPlotly/core/plot_factory.py @@ -485,13 +485,11 @@ def js_callback(_): dds["type"] = data.points[0].data.type featureIds = []; - featureIdsTernary = []; data.points.forEach(function(pt){ - featureIds.push(parseInt(pt.id)) - featureIdsTernary.push(parseInt(pt.pointNumber)) + featureIds.push(pt.x) dds["id"] = featureIds - dds["tid"] = featureIdsTernary + dds["field"] = pt.data.customdata[0] }) //console.log(dds) window.status = JSON.stringify(dds) @@ -511,6 +509,8 @@ def js_callback(_): if(data.points[i].data.type == 'scatter'){ dd["uid"] = data.points[i].data.uid dd["type"] = data.points[i].data.type + dd["field"] = data.points[i].data.customdata[0] + dd["id"] = data.points[i].x data.points.forEach(function(pt){ dd["fid"] = pt.id diff --git a/DataPlotly/gui/plot_settings_widget.py b/DataPlotly/gui/plot_settings_widget.py index 7d5780cf..3638407a 100644 --- a/DataPlotly/gui/plot_settings_widget.py +++ b/DataPlotly/gui/plot_settings_widget.py @@ -55,7 +55,6 @@ from qgis.core import ( Qgis, QgsNetworkAccessManager, - QgsFeatureRequest, QgsMapLayerProxyModel, QgsProject, QgsFileUtils, @@ -475,37 +474,34 @@ def getJSmessage(self, status): # if a selection event is performed if dic['mode'] == 'selection': - if dic['type'] == 'scatter': - self.layer_combo.currentLayer().selectByIds(dic['id']) - else: - self.layer_combo.currentLayer().selectByIds(dic['tid']) + exp = """ {} IN {} """.format(dic['field'], dic['id']) + exp = exp.replace('[', '(').replace(']', ')') + # select the features from the layer by expression + self.layer_combo.currentLayer().selectByExpression(exp) # if a clicking event is performed depending on the plot type elif dic["mode"] == 'clicking': if dic['type'] == 'scatter': - self.layer_combo.currentLayer().selectByIds([dic['fidd']]) + exp = """ {} = '{}' """.format(dic['field'], dic['id']) + # select the features from the layer by expression + self.layer_combo.currentLayer().selectByExpression(exp) elif dic["type"] == 'pie': exp = """ "{}" = '{}' """.format(dic['field'], dic['label']) - # set the iterator with the expression as filter in feature request - request = QgsFeatureRequest().setFilterExpression(exp) - it = self.layer_combo.currentLayer().getFeatures(request) - self.layer_combo.currentLayer().selectByIds([f.id() for f in it]) + # select the features from the layer by expression + self.layer_combo.currentLayer().selectByExpression(exp) elif dic["type"] == 'histogram': vmin = dic['id'] - dic['bin_step'] / 2 vmax = dic['id'] + dic['bin_step'] / 2 exp = """ "{}" <= {} AND "{}" > {} """.format(dic['field'], vmax, dic['field'], vmin) - request = QgsFeatureRequest().setFilterExpression(exp) - it = self.layer_combo.currentLayer().getFeatures(request) - self.layer_combo.currentLayer().selectByIds([f.id() for f in it]) + # select the features from the layer by expression + self.layer_combo.currentLayer().selectByExpression(exp) elif dic["type"] == 'scatterternary': self.layer_combo.currentLayer().selectByIds([dic['fid']]) else: # build the expression from the js dic (customdata) exp = """ "{}" = '{}' """.format(dic['field'], dic['id']) - # set the iterator with the expression as filter in feature request - request = QgsFeatureRequest().setFilterExpression(exp) - it = self.layer_combo.currentLayer().getFeatures(request) - self.layer_combo.currentLayer().selectByIds([f.id() for f in it]) + # select the features from the layer by expression + self.layer_combo.currentLayer().selectByExpression(exp) # print(exp) except: # pylint: disable=bare-except # noqa: F401 pass