Skip to content
Permalink
Browse files

[FEATURE][processing] Add checkbox for each vector input layer

to control whether selected features only are to be used

Replaces the old global setting and makes it immediately obvious
to users when the selection will be respected
  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 46596c5 commit 7f687345f8544af22b4f688223713aeb98af027e
Showing with 32 additions and 9 deletions.
  1. +2 −2 python/plugins/processing/algs/qgis/Boundary.py
  2. +30 −7 python/plugins/processing/gui/wrappers.py
@@ -82,8 +82,8 @@ def processAlgorithm(self, parameters, context, feedback):
if QgsWkbTypes.hasM(input_wkb):
output_wkb = QgsWkbTypes.addM(output_wkb)

(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT_LAYER, context, '',
source.fields(), output_wkb, source.crs())
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT_LAYER, context,
source.fields(), output_wkb, source.sourceCrs())

features = source.getFeatures()
total = 100.0 / source.featureCount()
@@ -59,14 +59,16 @@
QgsProcessingParameterExpression,
QgsProcessingParameterTable,
QgsProcessingParameterTableField,
QgsProcessingParameterFeatureSource)
QgsProcessingParameterFeatureSource,
QgsProcessingFeatureSourceDefinition)

from qgis.PyQt.QtWidgets import (
QCheckBox,
QComboBox,
QDialog,
QFileDialog,
QHBoxLayout,
QVBoxLayout,
QLineEdit,
QPlainTextEdit,
QToolButton,
@@ -760,7 +762,18 @@ def createWidget(self):
btn.clicked.connect(self.selectFile)
layout.addWidget(btn)

widget.setLayout(layout)
vl = QVBoxLayout()
vl.setMargin(0)
vl.setContentsMargins(0, 0, 0, 0)
vl.setSpacing(2)
vl.addLayout(layout)

self.use_selection_checkbox = QCheckBox(self.tr('Selected features only'))
self.use_selection_checkbox.setChecked(False)
self.use_selection_checkbox.setEnabled(False)
vl.addWidget(self.use_selection_checkbox)

widget.setLayout(vl)

filters = QgsMapLayerProxyModel.Filters()
if QgsProcessingParameterDefinition.TypeVectorAny in self.param.dataTypes():
@@ -775,6 +788,8 @@ def createWidget(self):
try:
if iface.activeLayer().type() == QgsMapLayer.VectorLayer:
self.combo.setLayer(iface.activeLayer())
self.use_selection_checkbox.setEnabled(iface.activeLayer().selectedFeatureCount() > 0)

except:
pass

@@ -787,8 +802,7 @@ def createWidget(self):
self.combo.setFilters(filters)
self.combo.setExcludedProviders(['grass'])

self.combo.currentIndexChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
self.combo.currentTextChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
self.combo.layerChanged.connect(self.layerChanged)
return widget

elif self.dialogType == DIALOG_BATCH:
@@ -818,6 +832,14 @@ def createWidget(self):
widget.setLayout(layout)
return widget

def layerChanged(self, layer):
if not layer or layer.type() != QgsMapLayer.VectorLayer or layer.selectedFeatureCount() == 0:
self.use_selection_checkbox.setChecked(False)
self.use_selection_checkbox.setEnabled(False)
else:
self.use_selection_checkbox.setEnabled(True)
self.widgetValueHasChanged.emit(self)

def selectFile(self):
filename, selected_filter = self.getFileName(self.combo.currentText())
if filename:
@@ -840,14 +862,15 @@ def setValue(self, value):

def value(self):
if self.dialogType == DIALOG_STANDARD:
use_selected_features = self.use_selection_checkbox.isChecked()
try:
layer = self.combo.currentLayer()
if layer:
return layer.id()
return QgsProcessingFeatureSourceDefinition(layer.id(), use_selected_features)
else:
return self.combo.currentText()
return QgsProcessingFeatureSourceDefinition(self.combo.currentText(), use_selected_features)
except:
return self.combo.currentText()
return QgsProcessingFeatureSourceDefinition(self.combo.currentText(), use_selected_features)
elif self.dialogType == DIALOG_BATCH:
return self.widget.value()
else:

0 comments on commit 7f68734

Please sign in to comment.
You can’t perform that action at this time.