mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
[processing] Initial work on porting base GUI classes to c++
- Add abstract base class for Processing widget wrappers to c++ - Add wrapper factory interface to c++ - Make QgsProcessingGuiRegistry also register widget wrapper factories, and be responsible for creation of new c++ processing widget wrapper instances - Start on private c++ implementation of boolean widget wrapper, including unit tests
This commit is contained in:
parent
bb9117075d
commit
644ef6a752
@ -10,13 +10,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class QgsProcessingGuiRegistry
|
class QgsProcessingGuiRegistry
|
||||||
{
|
{
|
||||||
%Docstring
|
%Docstring
|
||||||
The QgsProcessingGuiRegistry is a home for widgets for processing
|
The QgsProcessingGuiRegistry is a home for widgets for processing
|
||||||
configuration widgets.
|
configuration widgets.
|
||||||
|
|
||||||
|
QgsProcessingGuiRegistry is not usually directly created, but rather accessed through
|
||||||
|
:py:func:`QgsGui.processingGuiRegistry()`
|
||||||
|
|
||||||
.. versionadded:: 3.2
|
.. versionadded:: 3.2
|
||||||
%End
|
%End
|
||||||
|
|
||||||
@ -55,6 +57,41 @@ next to parameter widgets. Most algorithms do not have a configuration widget
|
|||||||
and in this case, None will be returned.
|
and in this case, None will be returned.
|
||||||
|
|
||||||
.. versionadded:: 3.2
|
.. versionadded:: 3.2
|
||||||
|
%End
|
||||||
|
|
||||||
|
bool addParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory /Transfer/ );
|
||||||
|
%Docstring
|
||||||
|
Adds a parameter widget ``factory`` to the registry. Ownership of ``factory`` is transferred to the registry.
|
||||||
|
|
||||||
|
Returns true if the factory was successfully added, or false if the factory could not be added. Each
|
||||||
|
factory must return a unique value for QgsProcessingParameterWidgetFactoryInterface.parameterType(),
|
||||||
|
and attempting to add a new factory with a duplicate type will result in failure.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`removeParameterWidgetFactory`
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createParameterWidgetWrapper`
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
void removeParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory );
|
||||||
|
%Docstring
|
||||||
|
Removes a parameter widget ``factory`` from the registry. The factory will be deleted.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`addParameterWidgetFactory`
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *createParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) /Factory/;
|
||||||
|
%Docstring
|
||||||
|
Creates a new parameter widget wrapper for the given ``parameter``. The ``type`` argument
|
||||||
|
dictates the type of dialog the wrapper should be created for. The caller takes ownership
|
||||||
|
of the returned wrapper.
|
||||||
|
|
||||||
|
If no factory is registered which handles the given ``parameter``, a None will be returned.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`addParameterWidgetFactory`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,194 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* This file has been generated automatically from *
|
||||||
|
* *
|
||||||
|
* src/gui/processing/qgsprocessingwidgetwrapper.h *
|
||||||
|
* *
|
||||||
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class QgsAbstractProcessingParameterWidgetWrapper : QObject
|
||||||
|
{
|
||||||
|
%Docstring
|
||||||
|
|
||||||
|
A widget wrapper for Processing parameter value widgets.
|
||||||
|
|
||||||
|
Widget wrappers are used to create widgets for individual Processing parameters, and
|
||||||
|
handle retrieving and setting the current value for those parameters.
|
||||||
|
|
||||||
|
Widget wrappers can be created for different dialog types, allowing different
|
||||||
|
appearance and behavior of widgets depending on whether they are being created for
|
||||||
|
use in a standard algorithm dialog, a batch processing dialog, or a modeler dialog.
|
||||||
|
|
||||||
|
Individual widget wrappers are not usually created directly, instead they are
|
||||||
|
constructed through the central registry, via calls to
|
||||||
|
QgsGui.processingGuiRegistry()->createParameterWidgetWrapper().
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
%TypeHeaderCode
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
|
%End
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum WidgetType
|
||||||
|
{
|
||||||
|
Standard,
|
||||||
|
Batch,
|
||||||
|
Modeler,
|
||||||
|
};
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter = 0,
|
||||||
|
WidgetType type = Standard, QObject *parent /TransferThis/ = 0 );
|
||||||
|
%Docstring
|
||||||
|
Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified
|
||||||
|
``parameter`` definition and dialog ``type``.
|
||||||
|
%End
|
||||||
|
|
||||||
|
WidgetType type() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the dialog type for which widgets and labels will be created by this wrapper.
|
||||||
|
%End
|
||||||
|
|
||||||
|
QWidget *createWrappedWidget( const QgsProcessingContext &context ) /Factory/;
|
||||||
|
%Docstring
|
||||||
|
Creates and return a new wrapped widget which allows customization of the parameter's value.
|
||||||
|
|
||||||
|
The caller takes ownership of the returned widget. The wrapped widget can be retrieved at a later
|
||||||
|
stage by calling wrappedWidget().
|
||||||
|
|
||||||
|
The supplied ``context`` is used while initializing the widget to the parameter's default value.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createWrappedLabel`
|
||||||
|
%End
|
||||||
|
|
||||||
|
QLabel *createWrappedLabel() /Factory/;
|
||||||
|
%Docstring
|
||||||
|
Creates and returns a new label to accompany widgets created by the wrapper.
|
||||||
|
|
||||||
|
The caller takes ownership of the returned label. Some parameter type and dialog type
|
||||||
|
combinations will return None for this method. If None is returned, then no
|
||||||
|
label should be shown for the parameter's widget (i.e. the label is embedded inside the
|
||||||
|
widget itself).
|
||||||
|
|
||||||
|
The wrapped label can be retrieved at a later stage by calling wrappedLabel().
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createWrappedWidget`
|
||||||
|
%End
|
||||||
|
|
||||||
|
QWidget *wrappedWidget();
|
||||||
|
%Docstring
|
||||||
|
Returns the current wrapped widget, if any.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createWrappedWidget`
|
||||||
|
%End
|
||||||
|
|
||||||
|
QLabel *wrappedLabel();
|
||||||
|
%Docstring
|
||||||
|
Returns the current wrapped label, if any.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createWrappedLabel`
|
||||||
|
%End
|
||||||
|
|
||||||
|
const QgsProcessingParameterDefinition *parameterDefinition() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the parameter definition associated with this wrapper.
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual void setWidgetValue( const QVariant &value, const QgsProcessingContext &context ) = 0;
|
||||||
|
%Docstring
|
||||||
|
Sets the current ``value`` for the parameter.
|
||||||
|
|
||||||
|
The ``context`` argument is used to specify the wider Processing context which the
|
||||||
|
current value is associated with.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`value`
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual QVariant value() const = 0;
|
||||||
|
%Docstring
|
||||||
|
Returns the current value of the parameter.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`setWidgetValue`
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
|
||||||
|
%Docstring
|
||||||
|
Called after all wrappers have been created within a particular dialog or context,
|
||||||
|
allowing the wrapper to connect to the wrappers of other, related parameters.
|
||||||
|
%End
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual QWidget *createWidget() = 0 /Factory/;
|
||||||
|
%Docstring
|
||||||
|
Creates a new widget which allows customization of the parameter's value.
|
||||||
|
|
||||||
|
The caller takes ownership of the returned widget.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createLabel`
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual QLabel *createLabel() /Factory/;
|
||||||
|
%Docstring
|
||||||
|
Creates a new label to accompany widgets created by the wrapper.
|
||||||
|
|
||||||
|
The caller takes ownership of the returned label. Some parameter type and dialog type
|
||||||
|
combinations will return None for this method. If None is returned, then no
|
||||||
|
label should be shown for the parameter's widget (i.e. the label is embedded inside the
|
||||||
|
widget itself).
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`createWidget`
|
||||||
|
%End
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QgsProcessingParameterWidgetFactoryInterface
|
||||||
|
{
|
||||||
|
%Docstring
|
||||||
|
|
||||||
|
An interface for Processing widget wrapper factories.
|
||||||
|
|
||||||
|
Widget wrapper factories allow creation of QgsAbstractProcessingParameterWidgetWrapper objects.
|
||||||
|
They are centrally managed by :py:class:`QgsProcessingGuiRegistry`. Usually, individual factories
|
||||||
|
are not directly utilized, rather the QgsGui.processingGuiRegistry()->createParameterWidgetWrapper()
|
||||||
|
method is used to create widget wrappers.
|
||||||
|
|
||||||
|
.. versionadded:: 3.4
|
||||||
|
%End
|
||||||
|
|
||||||
|
%TypeHeaderCode
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
|
%End
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~QgsProcessingParameterWidgetFactoryInterface();
|
||||||
|
|
||||||
|
virtual QString parameterType() const = 0;
|
||||||
|
%Docstring
|
||||||
|
Returns the type string for the parameter type the factory is associated with.
|
||||||
|
%End
|
||||||
|
|
||||||
|
virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) = 0 /Factory/;
|
||||||
|
%Docstring
|
||||||
|
Creates a new widget wrapper for the specified ``parameter`` definition.
|
||||||
|
|
||||||
|
The ``type`` argument indicates the dialog type to create a wrapper for.
|
||||||
|
%End
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/************************************************************************
|
||||||
|
* This file has been generated automatically from *
|
||||||
|
* *
|
||||||
|
* src/gui/processing/qgsprocessingwidgetwrapper.h *
|
||||||
|
* *
|
||||||
|
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
|
||||||
|
************************************************************************/
|
@ -319,4 +319,5 @@
|
|||||||
%Include auto_generated/processing/qgsprocessingrecentalgorithmlog.sip
|
%Include auto_generated/processing/qgsprocessingrecentalgorithmlog.sip
|
||||||
%Include auto_generated/processing/qgsprocessingtoolboxmodel.sip
|
%Include auto_generated/processing/qgsprocessingtoolboxmodel.sip
|
||||||
%Include auto_generated/processing/qgsprocessingtoolboxtreeview.sip
|
%Include auto_generated/processing/qgsprocessingtoolboxtreeview.sip
|
||||||
|
%Include auto_generated/processing/qgsprocessingwidgetwrapper.sip
|
||||||
%Include auto_generated/qgsadvanceddigitizingcanvasitem.sip
|
%Include auto_generated/qgsadvanceddigitizingcanvasitem.sip
|
||||||
|
@ -43,12 +43,12 @@ class RasterOptionsWidgetWrapper(WidgetWrapper):
|
|||||||
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
|
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
|
||||||
for desc, val in options:
|
for desc, val in options:
|
||||||
widget.addItem(desc, val)
|
widget.addItem(desc, val)
|
||||||
widget.setEditText(self.param.defaultValue() or '')
|
widget.setEditText(self.parameterDefinition().defaultValue() or '')
|
||||||
return widget
|
return widget
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
widget = QLineEdit()
|
widget = QLineEdit()
|
||||||
if self.param.defaultValue():
|
if self.parameterDefinition().defaultValue():
|
||||||
widget.setText(self.param.defaultValue())
|
widget.setText(self.parameterDefinition().defaultValue())
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
return QgsRasterFormatSaveOptionsWidget()
|
return QgsRasterFormatSaveOptionsWidget()
|
||||||
|
@ -513,7 +513,7 @@ class FieldsMappingWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.parentLayerParameter():
|
if wrapper.param.name() == self.parameterDefinition().parentLayerParameter():
|
||||||
if wrapper.value():
|
if wrapper.value():
|
||||||
self.setLayer(wrapper.value())
|
self.setLayer(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
||||||
|
@ -181,13 +181,13 @@ class HeatmapPixelSizeWidgetWrapper(WidgetWrapper):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.parent_layer:
|
if wrapper.parameterDefinition().name() == self.param.parent_layer:
|
||||||
self.setSource(wrapper.value())
|
self.setSource(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
||||||
elif wrapper.param.name() == self.param.radius_param:
|
elif wrapper.parameterDefinition().name() == self.param.radius_param:
|
||||||
self.setRadius(wrapper.value())
|
self.setRadius(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.radiusChanged)
|
wrapper.widgetValueHasChanged.connect(self.radiusChanged)
|
||||||
elif wrapper.param.name() == self.param.radius_field_param:
|
elif wrapper.parameterDefinition().name() == self.param.radius_field_param:
|
||||||
self.setSource(wrapper.value())
|
self.setSource(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.radiusFieldChanged)
|
wrapper.widgetValueHasChanged.connect(self.radiusFieldChanged)
|
||||||
|
|
||||||
|
@ -223,30 +223,30 @@ class ExpressionWidgetWrapper(WidgetWrapper):
|
|||||||
for lyr in layers:
|
for lyr in layers:
|
||||||
for n in range(lyr.bandCount()):
|
for n in range(lyr.bandCount()):
|
||||||
options[lyr.name()] = '{:s}@{:d}'.format(lyr.name(), n + 1)
|
options[lyr.name()] = '{:s}@{:d}'.format(lyr.name(), n + 1)
|
||||||
self.widget.setList(options)
|
self.widget().setList(options)
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
pass # TODO
|
pass # TODO
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
return self.widget.setText(value)
|
return self.widget().setText(value)
|
||||||
else:
|
else:
|
||||||
self.widget.setValue(value)
|
self.widget().setValue(value)
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.dialogType in DIALOG_STANDARD:
|
if self.dialogType in DIALOG_STANDARD:
|
||||||
return self.widget.value()
|
return self.widget().value()
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
return self.widget.text()
|
return self.widget().text()
|
||||||
else:
|
else:
|
||||||
return self.widget.value()
|
return self.widget().value()
|
||||||
|
|
||||||
|
|
||||||
class LayersListWidgetWrapper(WidgetWrapper):
|
class LayersListWidgetWrapper(WidgetWrapper):
|
||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType == DIALOG_BATCH:
|
if self.dialogType == DIALOG_BATCH:
|
||||||
widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
|
widget = BatchInputSelectionPanel(self.parameterDefinition(), self.row, self.col, self.dialog)
|
||||||
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
@ -272,7 +272,7 @@ class LayersListWidgetWrapper(WidgetWrapper):
|
|||||||
return self.widget.getText()
|
return self.widget.getText()
|
||||||
else:
|
else:
|
||||||
options = self._getOptions()
|
options = self._getOptions()
|
||||||
values = [options[i] for i in self.widget.selectedoptions]
|
values = [options[i] for i in self.widget().selectedoptions]
|
||||||
if len(values) == 0 and not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if len(values) == 0 and not self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
return values
|
return values
|
||||||
|
@ -98,14 +98,23 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
|||||||
if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
||||||
continue
|
continue
|
||||||
if not param.isDestination():
|
if not param.isDestination():
|
||||||
|
try:
|
||||||
wrapper = self.mainWidget().wrappers[param.name()]
|
wrapper = self.mainWidget().wrappers[param.name()]
|
||||||
value = None
|
except KeyError:
|
||||||
if wrapper.widget is not None:
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
widget = wrapper.wrappedWidget()
|
||||||
|
except AttributeError:
|
||||||
|
widget = wrapper.widget
|
||||||
|
if widget is None:
|
||||||
|
continue
|
||||||
|
|
||||||
value = wrapper.value()
|
value = wrapper.value()
|
||||||
parameters[param.name()] = value
|
parameters[param.name()] = value
|
||||||
|
|
||||||
if not param.checkValueIsAcceptable(value):
|
if not param.checkValueIsAcceptable(value):
|
||||||
raise AlgorithmDialogBase.InvalidParameterValue(param, wrapper.widget)
|
raise AlgorithmDialogBase.InvalidParameterValue(param, widget)
|
||||||
else:
|
else:
|
||||||
dest_project = None
|
dest_project = None
|
||||||
if not param.flags() & QgsProcessingParameterDefinition.FlagHidden and \
|
if not param.flags() & QgsProcessingParameterDefinition.FlagHidden and \
|
||||||
|
@ -36,7 +36,7 @@ from qgis.core import (Qgis,
|
|||||||
QgsApplication,
|
QgsApplication,
|
||||||
QgsSettings,
|
QgsSettings,
|
||||||
QgsProcessingParameterDefinition)
|
QgsProcessingParameterDefinition)
|
||||||
from qgis.gui import QgsMessageBar
|
from qgis.gui import QgsAbstractProcessingParameterWidgetWrapper
|
||||||
|
|
||||||
from processing.gui.wrappers import WidgetWrapperFactory
|
from processing.gui.wrappers import WidgetWrapperFactory
|
||||||
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
|
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
|
||||||
@ -232,14 +232,23 @@ class BatchPanel(BASE, WIDGET):
|
|||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
json.dump(toSave, f)
|
json.dump(toSave, f)
|
||||||
|
|
||||||
def setCellWrapper(self, row, column, wrapper):
|
def setCellWrapper(self, row, column, wrapper, context):
|
||||||
self.wrappers[row][column] = wrapper
|
self.wrappers[row][column] = wrapper
|
||||||
self.tblParameters.setCellWidget(row, column, wrapper.widget)
|
|
||||||
|
is_cpp_wrapper = issubclass(wrapper.__class__, QgsAbstractProcessingParameterWidgetWrapper)
|
||||||
|
if is_cpp_wrapper:
|
||||||
|
widget = wrapper.createWrappedWidget(context)
|
||||||
|
else:
|
||||||
|
widget = wrapper.widget
|
||||||
|
|
||||||
|
self.tblParameters.setCellWidget(row, column, widget)
|
||||||
|
|
||||||
def addRow(self):
|
def addRow(self):
|
||||||
self.wrappers.append([None] * self.tblParameters.columnCount())
|
self.wrappers.append([None] * self.tblParameters.columnCount())
|
||||||
self.tblParameters.setRowCount(self.tblParameters.rowCount() + 1)
|
self.tblParameters.setRowCount(self.tblParameters.rowCount() + 1)
|
||||||
|
|
||||||
|
context = dataobjects.createContext()
|
||||||
|
|
||||||
wrappers = {}
|
wrappers = {}
|
||||||
row = self.tblParameters.rowCount() - 1
|
row = self.tblParameters.rowCount() - 1
|
||||||
column = 0
|
column = 0
|
||||||
@ -249,7 +258,7 @@ class BatchPanel(BASE, WIDGET):
|
|||||||
|
|
||||||
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
|
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent, row, column)
|
||||||
wrappers[param.name()] = wrapper
|
wrappers[param.name()] = wrapper
|
||||||
self.setCellWrapper(row, column, wrapper)
|
self.setCellWrapper(row, column, wrapper, context)
|
||||||
column += 1
|
column += 1
|
||||||
|
|
||||||
for out in self.alg.destinationParameterDefinitions():
|
for out in self.alg.destinationParameterDefinitions():
|
||||||
|
@ -44,6 +44,9 @@ from qgis.core import (QgsProcessingParameterDefinition,
|
|||||||
QgsProcessingParameterFeatureSink,
|
QgsProcessingParameterFeatureSink,
|
||||||
QgsProcessingParameterVectorDestination,
|
QgsProcessingParameterVectorDestination,
|
||||||
QgsProject)
|
QgsProject)
|
||||||
|
from qgis.gui import (QgsGui,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper)
|
||||||
|
|
||||||
from qgis.PyQt import uic
|
from qgis.PyQt import uic
|
||||||
from qgis.PyQt.QtCore import QCoreApplication, Qt
|
from qgis.PyQt.QtCore import QCoreApplication, Qt
|
||||||
from qgis.PyQt.QtWidgets import (QWidget, QHBoxLayout, QToolButton,
|
from qgis.PyQt.QtWidgets import (QWidget, QHBoxLayout, QToolButton,
|
||||||
@ -52,7 +55,7 @@ from qgis.PyQt.QtGui import QIcon
|
|||||||
|
|
||||||
from processing.gui.DestinationSelectionPanel import DestinationSelectionPanel
|
from processing.gui.DestinationSelectionPanel import DestinationSelectionPanel
|
||||||
from processing.gui.wrappers import WidgetWrapperFactory
|
from processing.gui.wrappers import WidgetWrapperFactory
|
||||||
|
from processing.tools.dataobjects import createContext
|
||||||
|
|
||||||
pluginPath = os.path.split(os.path.dirname(__file__))[0]\
|
pluginPath = os.path.split(os.path.dirname(__file__))[0]\
|
||||||
|
|
||||||
@ -91,7 +94,10 @@ class ParametersPanel(BASE, WIDGET):
|
|||||||
|
|
||||||
def layerRegistryChanged(self, layers):
|
def layerRegistryChanged(self, layers):
|
||||||
for wrapper in list(self.wrappers.values()):
|
for wrapper in list(self.wrappers.values()):
|
||||||
|
try:
|
||||||
wrapper.refresh()
|
wrapper.refresh()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def formatParameterTooltip(self, parameter):
|
def formatParameterTooltip(self, parameter):
|
||||||
return '<p><b>{}</b></p><p>{}</p>'.format(
|
return '<p><b>{}</b></p><p>{}</p>'.format(
|
||||||
@ -100,6 +106,8 @@ class ParametersPanel(BASE, WIDGET):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def initWidgets(self):
|
def initWidgets(self):
|
||||||
|
context = createContext()
|
||||||
|
|
||||||
# If there are advanced parameters — show corresponding groupbox
|
# If there are advanced parameters — show corresponding groupbox
|
||||||
for param in self.alg.parameterDefinitions():
|
for param in self.alg.parameterDefinitions():
|
||||||
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
||||||
@ -115,9 +123,16 @@ class ParametersPanel(BASE, WIDGET):
|
|||||||
else:
|
else:
|
||||||
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent)
|
wrapper = WidgetWrapperFactory.create_wrapper(param, self.parent)
|
||||||
self.wrappers[param.name()] = wrapper
|
self.wrappers[param.name()] = wrapper
|
||||||
|
is_cpp_wrapper = issubclass(wrapper.__class__, QgsAbstractProcessingParameterWidgetWrapper)
|
||||||
|
if is_cpp_wrapper:
|
||||||
|
widget = wrapper.createWrappedWidget(context)
|
||||||
|
else:
|
||||||
widget = wrapper.widget
|
widget = wrapper.widget
|
||||||
|
|
||||||
if widget is not None:
|
if widget is not None:
|
||||||
|
if not is_cpp_wrapper:
|
||||||
|
widget.setToolTip(param.toolTip())
|
||||||
|
|
||||||
if isinstance(param, QgsProcessingParameterFeatureSource):
|
if isinstance(param, QgsProcessingParameterFeatureSource):
|
||||||
layout = QHBoxLayout()
|
layout = QHBoxLayout()
|
||||||
layout.setSpacing(6)
|
layout.setSpacing(6)
|
||||||
@ -136,15 +151,19 @@ class ParametersPanel(BASE, WIDGET):
|
|||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
|
|
||||||
widget.setToolTip(param.toolTip())
|
label = None
|
||||||
|
if is_cpp_wrapper:
|
||||||
|
label = wrapper.createWrappedLabel()
|
||||||
|
else:
|
||||||
|
label = wrapper.label
|
||||||
|
|
||||||
if wrapper.label is not None:
|
if label is not None:
|
||||||
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
||||||
self.layoutAdvanced.addWidget(wrapper.label)
|
self.layoutAdvanced.addWidget(label)
|
||||||
else:
|
else:
|
||||||
self.layoutMain.insertWidget(
|
self.layoutMain.insertWidget(
|
||||||
self.layoutMain.count() - 2, wrapper.label)
|
self.layoutMain.count() - 2, label)
|
||||||
else:
|
elif not is_cpp_wrapper:
|
||||||
desc = param.description()
|
desc = param.description()
|
||||||
if isinstance(param, QgsProcessingParameterExtent):
|
if isinstance(param, QgsProcessingParameterExtent):
|
||||||
desc += self.tr(' (xmin, xmax, ymin, ymax)')
|
desc += self.tr(' (xmin, xmax, ymin, ymax)')
|
||||||
@ -188,6 +207,7 @@ class ParametersPanel(BASE, WIDGET):
|
|||||||
wrapper.postInitialize(list(self.wrappers.values()))
|
wrapper.postInitialize(list(self.wrappers.values()))
|
||||||
|
|
||||||
def setParameters(self, parameters):
|
def setParameters(self, parameters):
|
||||||
|
context = createContext()
|
||||||
for param in self.alg.parameterDefinitions():
|
for param in self.alg.parameterDefinitions():
|
||||||
if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
||||||
continue
|
continue
|
||||||
@ -196,8 +216,10 @@ class ParametersPanel(BASE, WIDGET):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if not param.isDestination():
|
if not param.isDestination():
|
||||||
|
value = parameters[param.name()]
|
||||||
|
|
||||||
wrapper = self.wrappers[param.name()]
|
wrapper = self.wrappers[param.name()]
|
||||||
wrapper.setValue(parameters[param.name()])
|
wrapper.setWidgetValue(value, context)
|
||||||
else:
|
else:
|
||||||
dest_widget = self.outputWidgets[param.name()]
|
dest_widget = self.outputWidgets[param.name()]
|
||||||
dest_widget.setValue(parameters[param.name()])
|
dest_widget.setValue(parameters[param.name()])
|
||||||
|
@ -94,6 +94,7 @@ from qgis.PyQt.QtWidgets import (
|
|||||||
QWidget,
|
QWidget,
|
||||||
)
|
)
|
||||||
from qgis.gui import (
|
from qgis.gui import (
|
||||||
|
QgsGui,
|
||||||
QgsExpressionLineEdit,
|
QgsExpressionLineEdit,
|
||||||
QgsExpressionBuilderDialog,
|
QgsExpressionBuilderDialog,
|
||||||
QgsFieldComboBox,
|
QgsFieldComboBox,
|
||||||
@ -102,6 +103,7 @@ from qgis.gui import (
|
|||||||
QgsMapLayerComboBox,
|
QgsMapLayerComboBox,
|
||||||
QgsProjectionSelectionWidget,
|
QgsProjectionSelectionWidget,
|
||||||
QgsRasterBandComboBox,
|
QgsRasterBandComboBox,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper
|
||||||
)
|
)
|
||||||
from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant, Qt
|
from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant, Qt
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
@ -122,9 +124,9 @@ from processing.gui.ParameterGuiUtils import getFileFilter
|
|||||||
|
|
||||||
from processing.tools import dataobjects
|
from processing.tools import dataobjects
|
||||||
|
|
||||||
DIALOG_STANDARD = 'standard'
|
DIALOG_STANDARD = QgsAbstractProcessingParameterWidgetWrapper.Standard
|
||||||
DIALOG_BATCH = 'batch'
|
DIALOG_BATCH = QgsAbstractProcessingParameterWidgetWrapper.Batch
|
||||||
DIALOG_MODELER = 'modeler'
|
DIALOG_MODELER = QgsAbstractProcessingParameterWidgetWrapper.Modeler
|
||||||
|
|
||||||
|
|
||||||
class InvalidParameterValue(Exception):
|
class InvalidParameterValue(Exception):
|
||||||
@ -144,18 +146,19 @@ def getExtendedLayerName(layer):
|
|||||||
return layer.name()
|
return layer.name()
|
||||||
|
|
||||||
|
|
||||||
class WidgetWrapper(QObject):
|
class WidgetWrapper(QgsAbstractProcessingParameterWidgetWrapper):
|
||||||
widgetValueHasChanged = pyqtSignal(object)
|
widgetValueHasChanged = pyqtSignal(object)
|
||||||
|
|
||||||
NOT_SET_OPTION = '~~~~!!!!NOT SET!!!!~~~~~~~'
|
NOT_SET_OPTION = '~~~~!!!!NOT SET!!!!~~~~~~~'
|
||||||
|
|
||||||
def __init__(self, param, dialog, row=0, col=0, **kwargs):
|
def __init__(self, param, dialog, row=0, col=0, **kwargs):
|
||||||
QObject.__init__(self)
|
self.dialogType = dialogTypes.get(dialog.__class__.__name__, QgsAbstractProcessingParameterWidgetWrapper.Standard)
|
||||||
|
super().__init__(param, self.dialogType)
|
||||||
self.param = param
|
self.param = param
|
||||||
self.dialog = dialog
|
self.dialog = dialog
|
||||||
self.row = row
|
self.row = row
|
||||||
self.col = col
|
self.col = col
|
||||||
self.dialogType = dialogTypes.get(dialog.__class__.__name__, DIALOG_STANDARD)
|
|
||||||
self.widget = self.createWidget(**kwargs)
|
self.widget = self.createWidget(**kwargs)
|
||||||
self.label = self.createLabel()
|
self.label = self.createLabel()
|
||||||
if param.defaultValue() is not None:
|
if param.defaultValue() is not None:
|
||||||
@ -183,21 +186,24 @@ class WidgetWrapper(QObject):
|
|||||||
def createLabel(self):
|
def createLabel(self):
|
||||||
if self.dialogType == DIALOG_BATCH:
|
if self.dialogType == DIALOG_BATCH:
|
||||||
return None
|
return None
|
||||||
desc = self.param.description()
|
desc = self.parameterDefinition().description()
|
||||||
if isinstance(self.param, QgsProcessingParameterExtent):
|
if isinstance(self.parameterDefinition(), QgsProcessingParameterExtent):
|
||||||
desc += self.tr(' (xmin, xmax, ymin, ymax)')
|
desc += self.tr(' (xmin, xmax, ymin, ymax)')
|
||||||
if isinstance(self.param, QgsProcessingParameterPoint):
|
if isinstance(self.parameterDefinition(), QgsProcessingParameterPoint):
|
||||||
desc += self.tr(' (x, y)')
|
desc += self.tr(' (x, y)')
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
desc += self.tr(' [optional]')
|
desc += self.tr(' [optional]')
|
||||||
|
|
||||||
label = QLabel(desc)
|
label = QLabel(desc)
|
||||||
label.setToolTip(self.param.name())
|
label.setToolTip(self.parameterDefinition().name())
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def setWidgetValue(self, value, context):
|
||||||
|
self.setValue(value)
|
||||||
|
|
||||||
def setComboValue(self, value, combobox=None):
|
def setComboValue(self, value, combobox=None):
|
||||||
if combobox is None:
|
if combobox is None:
|
||||||
combobox = self.widget
|
combobox = self.widget
|
||||||
@ -219,12 +225,6 @@ class WidgetWrapper(QObject):
|
|||||||
else:
|
else:
|
||||||
combobox.setCurrentIndex(0)
|
combobox.setCurrentIndex(0)
|
||||||
|
|
||||||
def value(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def postInitialize(self, wrappers):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ class WidgetWrapper(QObject):
|
|||||||
|
|
||||||
# TODO: should use selectedFilter argument for default file format
|
# TODO: should use selectedFilter argument for default file format
|
||||||
filename, selected_filter = QFileDialog.getOpenFileName(self.widget, self.tr('Select File'),
|
filename, selected_filter = QFileDialog.getOpenFileName(self.widget, self.tr('Select File'),
|
||||||
path, getFileFilter(self.param))
|
path, getFileFilter(self.parameterDefinition()))
|
||||||
if filename:
|
if filename:
|
||||||
settings.setValue('/Processing/LastInputPath',
|
settings.setValue('/Processing/LastInputPath',
|
||||||
os.path.dirname(str(filename)))
|
os.path.dirname(str(filename)))
|
||||||
@ -331,19 +331,19 @@ class CrsWidgetWrapper(WidgetWrapper):
|
|||||||
QgsProcessingOutputMapLayer])
|
QgsProcessingOutputMapLayer])
|
||||||
for l in layers:
|
for l in layers:
|
||||||
self.combo.addItem("Crs of layer " + self.dialog.resolveValueDescription(l), l)
|
self.combo.addItem("Crs of layer " + self.dialog.resolveValueDescription(l), l)
|
||||||
if self.param.defaultValue():
|
if self.parameterDefinition().defaultValue():
|
||||||
self.combo.setEditText(self.param.defaultValue())
|
self.combo.setEditText(self.parameterDefinition().defaultValue())
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
widget = QgsProjectionSelectionWidget()
|
widget = QgsProjectionSelectionWidget()
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
|
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
|
||||||
|
|
||||||
if self.param.defaultValue():
|
if self.parameterDefinition().defaultValue():
|
||||||
if self.param.defaultValue() == 'ProjectCrs':
|
if self.parameterDefinition().defaultValue() == 'ProjectCrs':
|
||||||
crs = QgsProject.instance().crs()
|
crs = QgsProject.instance().crs()
|
||||||
else:
|
else:
|
||||||
crs = QgsCoordinateReferenceSystem(self.param.defaultValue())
|
crs = QgsCoordinateReferenceSystem(self.parameterDefinition().defaultValue())
|
||||||
widget.setCrs(crs)
|
widget.setCrs(crs)
|
||||||
else:
|
else:
|
||||||
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
|
widget.setOptionVisible(QgsProjectionSelectionWidget.CrsNotSet, True)
|
||||||
@ -387,12 +387,12 @@ class ExtentWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
return ExtentSelectionPanel(self.dialog, self.param)
|
return ExtentSelectionPanel(self.dialog, self.parameterDefinition())
|
||||||
else:
|
else:
|
||||||
widget = QComboBox()
|
widget = QComboBox()
|
||||||
widget.setEditable(True)
|
widget.setEditable(True)
|
||||||
extents = self.dialog.getAvailableValuesOfType(QgsProcessingParameterExtent, (QgsProcessingOutputString))
|
extents = self.dialog.getAvailableValuesOfType(QgsProcessingParameterExtent, (QgsProcessingOutputString))
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
widget.addItem(self.USE_MIN_COVERING_EXTENT, None)
|
widget.addItem(self.USE_MIN_COVERING_EXTENT, None)
|
||||||
layers = self.dialog.getAvailableValuesOfType([QgsProcessingParameterFeatureSource,
|
layers = self.dialog.getAvailableValuesOfType([QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterRasterLayer,
|
QgsProcessingParameterRasterLayer,
|
||||||
@ -404,8 +404,8 @@ class ExtentWidgetWrapper(WidgetWrapper):
|
|||||||
widget.addItem(self.dialog.resolveValueDescription(ex), ex)
|
widget.addItem(self.dialog.resolveValueDescription(ex), ex)
|
||||||
for l in layers:
|
for l in layers:
|
||||||
widget.addItem("Extent of " + self.dialog.resolveValueDescription(l), l)
|
widget.addItem("Extent of " + self.dialog.resolveValueDescription(l), l)
|
||||||
if not self.param.defaultValue():
|
if not self.parameterDefinition().defaultValue():
|
||||||
widget.setEditText(self.param.defaultValue())
|
widget.setEditText(self.parameterDefinition().defaultValue())
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
@ -433,7 +433,7 @@ class ExtentWidgetWrapper(WidgetWrapper):
|
|||||||
float(token)
|
float(token)
|
||||||
except:
|
except:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
elif self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
elif self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
s = None
|
s = None
|
||||||
else:
|
else:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
@ -446,14 +446,14 @@ class PointWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
return PointSelectionPanel(self.dialog, self.param.defaultValue())
|
return PointSelectionPanel(self.dialog, self.parameterDefinition().defaultValue())
|
||||||
else:
|
else:
|
||||||
item = QComboBox()
|
item = QComboBox()
|
||||||
item.setEditable(True)
|
item.setEditable(True)
|
||||||
points = self.dialog.getAvailableValuesOfType((QgsProcessingParameterPoint, QgsProcessingParameterString), (QgsProcessingOutputString))
|
points = self.dialog.getAvailableValuesOfType((QgsProcessingParameterPoint, QgsProcessingParameterString), (QgsProcessingOutputString))
|
||||||
for p in points:
|
for p in points:
|
||||||
item.addItem(self.dialog.resolveValueDescription(p), p)
|
item.addItem(self.dialog.resolveValueDescription(p), p)
|
||||||
item.setEditText(str(self.param.defaultValue()))
|
item.setEditText(str(self.parameterDefinition().defaultValue()))
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
@ -481,7 +481,7 @@ class PointWidgetWrapper(WidgetWrapper):
|
|||||||
float(token)
|
float(token)
|
||||||
except:
|
except:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
elif self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
elif self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
s = None
|
s = None
|
||||||
else:
|
else:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
@ -494,15 +494,15 @@ class FileWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
return FileSelectionPanel(self.param.behavior() == QgsProcessingParameterFile.Folder,
|
return FileSelectionPanel(self.parameterDefinition().behavior() == QgsProcessingParameterFile.Folder,
|
||||||
self.param.extension())
|
self.parameterDefinition().extension())
|
||||||
else:
|
else:
|
||||||
self.combo = QComboBox()
|
self.combo = QComboBox()
|
||||||
self.combo.setEditable(True)
|
self.combo.setEditable(True)
|
||||||
files = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, (QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
|
files = self.dialog.getAvailableValuesOfType(QgsProcessingParameterFile, (QgsProcessingOutputRasterLayer, QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
|
||||||
for f in files:
|
for f in files:
|
||||||
self.combo.addItem(self.dialog.resolveValueDescription(f), f)
|
self.combo.addItem(self.dialog.resolveValueDescription(f), f)
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.setEditText("")
|
self.combo.setEditText("")
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
layout = QHBoxLayout()
|
layout = QHBoxLayout()
|
||||||
@ -527,9 +527,9 @@ class FileWidgetWrapper(WidgetWrapper):
|
|||||||
else:
|
else:
|
||||||
path = ''
|
path = ''
|
||||||
|
|
||||||
if self.param.extension():
|
if self.parameterDefinition().extension():
|
||||||
filter = self.tr('{} files').format(
|
filter = self.tr('{} files').format(
|
||||||
self.param.extension().upper()) + ' (*.' + self.param.extension() + self.tr(
|
self.parameterDefinition().extension().upper()) + ' (*.' + self.parameterDefinition().extension() + self.tr(
|
||||||
');;All files (*.*)')
|
');;All files (*.*)')
|
||||||
else:
|
else:
|
||||||
filter = self.tr('All files (*.*)')
|
filter = self.tr('All files (*.*)')
|
||||||
@ -560,7 +560,7 @@ class FixedTableWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
return FixedTablePanel(self.param)
|
return FixedTablePanel(self.parameterDefinition())
|
||||||
else:
|
else:
|
||||||
self.combobox = QComboBox()
|
self.combobox = QComboBox()
|
||||||
values = self.dialog.getAvailableValuesOfType(QgsProcessingParameterMatrix)
|
values = self.dialog.getAvailableValuesOfType(QgsProcessingParameterMatrix)
|
||||||
@ -584,14 +584,14 @@ class FixedTableWidgetWrapper(WidgetWrapper):
|
|||||||
class MultipleLayerWidgetWrapper(WidgetWrapper):
|
class MultipleLayerWidgetWrapper(WidgetWrapper):
|
||||||
|
|
||||||
def _getOptions(self):
|
def _getOptions(self):
|
||||||
if self.param.layerType() == QgsProcessing.TypeVectorAnyGeometry:
|
if self.parameterDefinition().layerType() == QgsProcessing.TypeVectorAnyGeometry:
|
||||||
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
QgsProcessingParameterMultipleLayers),
|
QgsProcessingParameterMultipleLayers),
|
||||||
[QgsProcessingOutputVectorLayer,
|
[QgsProcessingOutputVectorLayer,
|
||||||
QgsProcessingOutputMapLayer,
|
QgsProcessingOutputMapLayer,
|
||||||
QgsProcessingOutputMultipleLayers])
|
QgsProcessingOutputMultipleLayers])
|
||||||
elif self.param.layerType() == QgsProcessing.TypeVector:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeVector:
|
||||||
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
QgsProcessingParameterMultipleLayers),
|
QgsProcessingParameterMultipleLayers),
|
||||||
@ -599,7 +599,7 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
QgsProcessingOutputMapLayer,
|
QgsProcessingOutputMapLayer,
|
||||||
QgsProcessingOutputMultipleLayers],
|
QgsProcessingOutputMultipleLayers],
|
||||||
[QgsProcessing.TypeVector])
|
[QgsProcessing.TypeVector])
|
||||||
elif self.param.layerType() == QgsProcessing.TypeVectorPoint:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeVectorPoint:
|
||||||
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
QgsProcessingParameterMultipleLayers),
|
QgsProcessingParameterMultipleLayers),
|
||||||
@ -608,7 +608,7 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
QgsProcessingOutputMultipleLayers],
|
QgsProcessingOutputMultipleLayers],
|
||||||
[QgsProcessing.TypeVectorPoint,
|
[QgsProcessing.TypeVectorPoint,
|
||||||
QgsProcessing.TypeVectorAnyGeometry])
|
QgsProcessing.TypeVectorAnyGeometry])
|
||||||
elif self.param.layerType() == QgsProcessing.TypeVectorLine:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeVectorLine:
|
||||||
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
QgsProcessingParameterMultipleLayers),
|
QgsProcessingParameterMultipleLayers),
|
||||||
@ -617,7 +617,7 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
QgsProcessingOutputMultipleLayers],
|
QgsProcessingOutputMultipleLayers],
|
||||||
[QgsProcessing.TypeVectorLine,
|
[QgsProcessing.TypeVectorLine,
|
||||||
QgsProcessing.TypeVectorAnyGeometry])
|
QgsProcessing.TypeVectorAnyGeometry])
|
||||||
elif self.param.layerType() == QgsProcessing.TypeVectorPolygon:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeVectorPolygon:
|
||||||
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
QgsProcessingParameterMultipleLayers),
|
QgsProcessingParameterMultipleLayers),
|
||||||
@ -626,13 +626,13 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
QgsProcessingOutputMultipleLayers],
|
QgsProcessingOutputMultipleLayers],
|
||||||
[QgsProcessing.TypeVectorPolygon,
|
[QgsProcessing.TypeVectorPolygon,
|
||||||
QgsProcessing.TypeVectorAnyGeometry])
|
QgsProcessing.TypeVectorAnyGeometry])
|
||||||
elif self.param.layerType() == QgsProcessing.TypeRaster:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
|
||||||
options = self.dialog.getAvailableValuesOfType(
|
options = self.dialog.getAvailableValuesOfType(
|
||||||
(QgsProcessingParameterRasterLayer, QgsProcessingParameterMultipleLayers),
|
(QgsProcessingParameterRasterLayer, QgsProcessingParameterMultipleLayers),
|
||||||
[QgsProcessingOutputRasterLayer,
|
[QgsProcessingOutputRasterLayer,
|
||||||
QgsProcessingOutputMapLayer,
|
QgsProcessingOutputMapLayer,
|
||||||
QgsProcessingOutputMultipleLayers])
|
QgsProcessingOutputMultipleLayers])
|
||||||
elif self.param.layerType() == QgsProcessing.TypeVector:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeVector:
|
||||||
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
options = self.dialog.getAvailableValuesOfType((QgsProcessingParameterFeatureSource,
|
||||||
QgsProcessingParameterVectorLayer,
|
QgsProcessingParameterVectorLayer,
|
||||||
QgsProcessingParameterMultipleLayers),
|
QgsProcessingParameterMultipleLayers),
|
||||||
@ -645,40 +645,40 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
if self.param.layerType() == QgsProcessing.TypeFile:
|
if self.parameterDefinition().layerType() == QgsProcessing.TypeFile:
|
||||||
return MultipleInputPanel(datatype=QgsProcessing.TypeFile)
|
return MultipleInputPanel(datatype=QgsProcessing.TypeFile)
|
||||||
else:
|
else:
|
||||||
if self.param.layerType() == QgsProcessing.TypeRaster:
|
if self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
|
||||||
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
|
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
|
||||||
elif self.param.layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
|
elif self.parameterDefinition().layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
||||||
elif self.param.layerType() == QgsProcessing.TypeMapLayer:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
||||||
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
|
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
|
||||||
else:
|
else:
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()],
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.parameterDefinition().layerType()],
|
||||||
False)
|
False)
|
||||||
opts = [getExtendedLayerName(opt) for opt in options]
|
opts = [getExtendedLayerName(opt) for opt in options]
|
||||||
return MultipleInputPanel(opts, datatype=self.param.layerType())
|
return MultipleInputPanel(opts, datatype=self.parameterDefinition().layerType())
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
|
widget = BatchInputSelectionPanel(self.parameterDefinition(), self.row, self.col, self.dialog)
|
||||||
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
options = [self.dialog.resolveValueDescription(opt) for opt in self._getOptions()]
|
options = [self.dialog.resolveValueDescription(opt) for opt in self._getOptions()]
|
||||||
return MultipleInputPanel(options, datatype=self.param.layerType())
|
return MultipleInputPanel(options, datatype=self.parameterDefinition().layerType())
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
if self.param.layerType() != QgsProcessing.TypeFile:
|
if self.parameterDefinition().layerType() != QgsProcessing.TypeFile:
|
||||||
if self.param.layerType() == QgsProcessing.TypeRaster:
|
if self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
|
||||||
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
|
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
|
||||||
elif self.param.layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
|
elif self.parameterDefinition().layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
||||||
elif self.param.layerType() == QgsProcessing.TypeMapLayer:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
||||||
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
|
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
|
||||||
else:
|
else:
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()],
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.parameterDefinition().layerType()],
|
||||||
False)
|
False)
|
||||||
opts = [getExtendedLayerName(opt) for opt in options]
|
opts = [getExtendedLayerName(opt) for opt in options]
|
||||||
self.widget.updateForOptions(opts)
|
self.widget.updateForOptions(opts)
|
||||||
@ -710,18 +710,18 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
if self.param.layerType() == QgsProcessing.TypeFile:
|
if self.parameterDefinition().layerType() == QgsProcessing.TypeFile:
|
||||||
return self.param.setValue(self.widget.selectedoptions)
|
return self.parameterDefinition().setValue(self.widget.selectedoptions)
|
||||||
else:
|
else:
|
||||||
if self.param.layerType() == QgsProcessing.TypeRaster:
|
if self.parameterDefinition().layerType() == QgsProcessing.TypeRaster:
|
||||||
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
|
options = QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False)
|
||||||
elif self.param.layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
|
elif self.parameterDefinition().layerType() in (QgsProcessing.TypeVectorAnyGeometry, QgsProcessing.TypeVector):
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
||||||
elif self.param.layerType() == QgsProcessing.TypeMapLayer:
|
elif self.parameterDefinition().layerType() == QgsProcessing.TypeMapLayer:
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [], False)
|
||||||
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
|
options.extend(QgsProcessingUtils.compatibleRasterLayers(QgsProject.instance(), False))
|
||||||
else:
|
else:
|
||||||
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.param.layerType()],
|
options = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance(), [self.parameterDefinition().layerType()],
|
||||||
False)
|
False)
|
||||||
return [options[i] if isinstance(i, int) else i for i in self.widget.selectedoptions]
|
return [options[i] if isinstance(i, int) else i for i in self.widget.selectedoptions]
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
@ -730,7 +730,7 @@ class MultipleLayerWidgetWrapper(WidgetWrapper):
|
|||||||
options = self._getOptions()
|
options = self._getOptions()
|
||||||
values = [options[i] if isinstance(i, int) else QgsProcessingModelChildParameterSource.fromStaticValue(i)
|
values = [options[i] if isinstance(i, int) else QgsProcessingModelChildParameterSource.fromStaticValue(i)
|
||||||
for i in self.widget.selectedoptions]
|
for i in self.widget.selectedoptions]
|
||||||
if len(values) == 0 and not self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if len(values) == 0 and not self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@ -739,11 +739,11 @@ class NumberWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
widget = NumberInputPanel(self.param)
|
widget = NumberInputPanel(self.parameterDefinition())
|
||||||
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
return ModelerNumberInputPanel(self.param, self.dialog)
|
return ModelerNumberInputPanel(self.parameterDefinition(), self.dialog)
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
if value is None or value == NULL:
|
if value is None or value == NULL:
|
||||||
@ -755,9 +755,9 @@ class NumberWidgetWrapper(WidgetWrapper):
|
|||||||
return self.widget.getValue()
|
return self.widget.getValue()
|
||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH) and self.param.isDynamic():
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH) and self.parameterDefinition().isDynamic():
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.dynamicLayerParameterName():
|
if wrapper.parameterDefinition().name() == self.parameterDefinition().dynamicLayerParameterName():
|
||||||
self.widget.setDynamicLayer(wrapper.value())
|
self.widget.setDynamicLayer(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
||||||
break
|
break
|
||||||
@ -770,11 +770,11 @@ class DistanceWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
widget = DistanceInputPanel(self.param)
|
widget = DistanceInputPanel(self.parameterDefinition())
|
||||||
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
return ModelerNumberInputPanel(self.param, self.dialog)
|
return ModelerNumberInputPanel(self.parameterDefinition(), self.dialog)
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
if value is None or value == NULL:
|
if value is None or value == NULL:
|
||||||
@ -788,10 +788,10 @@ class DistanceWidgetWrapper(WidgetWrapper):
|
|||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.dynamicLayerParameterName():
|
if wrapper.parameterDefinition().name() == self.parameterDefinition().dynamicLayerParameterName():
|
||||||
self.widget.setDynamicLayer(wrapper.value())
|
self.widget.setDynamicLayer(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.dynamicLayerChanged)
|
wrapper.widgetValueHasChanged.connect(self.dynamicLayerChanged)
|
||||||
if wrapper.param.name() == self.param.parentParameterName():
|
if wrapper.parameterDefinition().name() == self.parameterDefinition().parentParameterName():
|
||||||
self.widget.setUnitParameterValue(wrapper.value())
|
self.widget.setUnitParameterValue(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentParameterChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentParameterChanged)
|
||||||
|
|
||||||
@ -806,7 +806,7 @@ class RangeWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
widget = RangePanel(self.param)
|
widget = RangePanel(self.parameterDefinition())
|
||||||
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.hasChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
#else:
|
#else:
|
||||||
@ -851,7 +851,7 @@ class MapLayerWidgetWrapper(WidgetWrapper):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.setAllowEmptyLayer(True)
|
self.combo.setAllowEmptyLayer(True)
|
||||||
self.combo.setLayer(None)
|
self.combo.setLayer(None)
|
||||||
|
|
||||||
@ -859,14 +859,14 @@ class MapLayerWidgetWrapper(WidgetWrapper):
|
|||||||
self.combo.currentTextChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
self.combo.currentTextChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
|
widget = BatchInputSelectionPanel(self.parameterDefinition(), self.row, self.col, self.dialog)
|
||||||
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
self.combo = QComboBox()
|
self.combo = QComboBox()
|
||||||
layers = self.getAvailableLayers()
|
layers = self.getAvailableLayers()
|
||||||
self.combo.setEditable(True)
|
self.combo.setEditable(True)
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
|
self.combo.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
|
||||||
for layer in layers:
|
for layer in layers:
|
||||||
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
|
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
|
||||||
@ -949,7 +949,7 @@ class MapLayerWidgetWrapper(WidgetWrapper):
|
|||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
if not bool(v):
|
if not bool(v):
|
||||||
return self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
else:
|
else:
|
||||||
return os.path.exists(v)
|
return os.path.exists(v)
|
||||||
|
|
||||||
@ -969,7 +969,7 @@ class RasterWidgetWrapper(MapLayerWidgetWrapper):
|
|||||||
def selectFile(self):
|
def selectFile(self):
|
||||||
filename, selected_filter = self.getFileName(self.combo.currentText())
|
filename, selected_filter = self.getFileName(self.combo.currentText())
|
||||||
if filename:
|
if filename:
|
||||||
filename = dataobjects.getRasterSublayer(filename, self.param)
|
filename = dataobjects.getRasterSublayer(filename, self.parameterDefinition())
|
||||||
if isinstance(self.combo, QgsMapLayerComboBox):
|
if isinstance(self.combo, QgsMapLayerComboBox):
|
||||||
items = self.combo.additionalItems()
|
items = self.combo.additionalItems()
|
||||||
items.append(filename)
|
items.append(filename)
|
||||||
@ -987,23 +987,23 @@ class EnumWidgetWrapper(WidgetWrapper):
|
|||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
self._useCheckBoxes = useCheckBoxes
|
self._useCheckBoxes = useCheckBoxes
|
||||||
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
|
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
|
||||||
return CheckboxesPanel(options=self.param.options(),
|
return CheckboxesPanel(options=self.parameterDefinition().options(),
|
||||||
multiple=self.param.allowMultiple(),
|
multiple=self.parameterDefinition().allowMultiple(),
|
||||||
columns=columns)
|
columns=columns)
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
return MultipleInputPanel(options=self.param.options())
|
return MultipleInputPanel(options=self.parameterDefinition().options())
|
||||||
else:
|
else:
|
||||||
widget = QComboBox()
|
widget = QComboBox()
|
||||||
for i, option in enumerate(self.param.options()):
|
for i, option in enumerate(self.parameterDefinition().options()):
|
||||||
widget.addItem(option, i)
|
widget.addItem(option, i)
|
||||||
if self.param.defaultValue():
|
if self.parameterDefinition().defaultValue():
|
||||||
widget.setCurrentIndex(widget.findData(self.param.defaultValue()))
|
widget.setCurrentIndex(widget.findData(self.parameterDefinition().defaultValue()))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
self.combobox = QComboBox()
|
self.combobox = QComboBox()
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combobox.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
|
self.combobox.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
|
||||||
for i, option in enumerate(self.param.options()):
|
for i, option in enumerate(self.parameterDefinition().options()):
|
||||||
self.combobox.addItem(option, i)
|
self.combobox.addItem(option, i)
|
||||||
values = self.dialog.getAvailableValuesOfType(QgsProcessingParameterEnum)
|
values = self.dialog.getAvailableValuesOfType(QgsProcessingParameterEnum)
|
||||||
for v in values:
|
for v in values:
|
||||||
@ -1018,7 +1018,7 @@ class EnumWidgetWrapper(WidgetWrapper):
|
|||||||
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
|
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
|
||||||
self.widget.setValue(value)
|
self.widget.setValue(value)
|
||||||
return
|
return
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
self.widget.setSelectedItems(value)
|
self.widget.setSelectedItems(value)
|
||||||
else:
|
else:
|
||||||
self.widget.setCurrentIndex(self.widget.findData(value))
|
self.widget.setCurrentIndex(self.widget.findData(value))
|
||||||
@ -1029,7 +1029,7 @@ class EnumWidgetWrapper(WidgetWrapper):
|
|||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
|
if self._useCheckBoxes and not self.dialogType == DIALOG_BATCH:
|
||||||
return self.widget.value()
|
return self.widget.value()
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
return self.widget.selectedoptions
|
return self.widget.selectedoptions
|
||||||
else:
|
else:
|
||||||
return self.widget.currentData()
|
return self.widget.currentData()
|
||||||
@ -1071,13 +1071,13 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
|
|||||||
widget.setLayout(vl)
|
widget.setLayout(vl)
|
||||||
|
|
||||||
filters = QgsMapLayerProxyModel.Filters()
|
filters = QgsMapLayerProxyModel.Filters()
|
||||||
if QgsProcessing.TypeVectorAnyGeometry in self.param.dataTypes() or len(self.param.dataTypes()) == 0:
|
if QgsProcessing.TypeVectorAnyGeometry in self.parameterDefinition().dataTypes() or len(self.parameterDefinition().dataTypes()) == 0:
|
||||||
filters = QgsMapLayerProxyModel.HasGeometry
|
filters = QgsMapLayerProxyModel.HasGeometry
|
||||||
if QgsProcessing.TypeVectorPoint in self.param.dataTypes():
|
if QgsProcessing.TypeVectorPoint in self.parameterDefinition().dataTypes():
|
||||||
filters |= QgsMapLayerProxyModel.PointLayer
|
filters |= QgsMapLayerProxyModel.PointLayer
|
||||||
if QgsProcessing.TypeVectorLine in self.param.dataTypes():
|
if QgsProcessing.TypeVectorLine in self.parameterDefinition().dataTypes():
|
||||||
filters |= QgsMapLayerProxyModel.LineLayer
|
filters |= QgsMapLayerProxyModel.LineLayer
|
||||||
if QgsProcessing.TypeVectorPolygon in self.param.dataTypes():
|
if QgsProcessing.TypeVectorPolygon in self.parameterDefinition().dataTypes():
|
||||||
filters |= QgsMapLayerProxyModel.PolygonLayer
|
filters |= QgsMapLayerProxyModel.PolygonLayer
|
||||||
if not filters:
|
if not filters:
|
||||||
filters = QgsMapLayerProxyModel.VectorLayer
|
filters = QgsMapLayerProxyModel.VectorLayer
|
||||||
@ -1097,7 +1097,7 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
|
|||||||
self.combo.setFilters(filters)
|
self.combo.setFilters(filters)
|
||||||
self.combo.setExcludedProviders(['grass'])
|
self.combo.setExcludedProviders(['grass'])
|
||||||
|
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.setAllowEmptyLayer(True)
|
self.combo.setAllowEmptyLayer(True)
|
||||||
self.combo.setLayer(None)
|
self.combo.setLayer(None)
|
||||||
|
|
||||||
@ -1105,18 +1105,18 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
|
|||||||
return widget
|
return widget
|
||||||
|
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
|
widget = BatchInputSelectionPanel(self.parameterDefinition(), self.row, self.col, self.dialog)
|
||||||
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
self.combo = QComboBox()
|
self.combo = QComboBox()
|
||||||
layers = self.dialog.getAvailableValuesOfType(
|
layers = self.dialog.getAvailableValuesOfType(
|
||||||
(QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer),
|
(QgsProcessingParameterFeatureSource, QgsProcessingParameterVectorLayer),
|
||||||
(QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputString, QgsProcessingOutputFile), self.param.dataTypes())
|
(QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputString, QgsProcessingOutputFile), self.parameterDefinition().dataTypes())
|
||||||
self.combo.setEditable(True)
|
self.combo.setEditable(True)
|
||||||
for layer in layers:
|
for layer in layers:
|
||||||
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
|
self.combo.addItem(self.dialog.resolveValueDescription(layer), layer)
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.setEditText("")
|
self.combo.setEditText("")
|
||||||
|
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
@ -1144,7 +1144,7 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
|
|||||||
def selectFile(self):
|
def selectFile(self):
|
||||||
filename, selected_filter = self.getFileName(self.combo.currentText())
|
filename, selected_filter = self.getFileName(self.combo.currentText())
|
||||||
if filename:
|
if filename:
|
||||||
filename = dataobjects.getRasterSublayer(filename, self.param)
|
filename = dataobjects.getRasterSublayer(filename, self.parameterDefinition())
|
||||||
if isinstance(self.combo, QgsMapLayerComboBox):
|
if isinstance(self.combo, QgsMapLayerComboBox):
|
||||||
items = self.combo.additionalItems()
|
items = self.combo.additionalItems()
|
||||||
items.append(filename)
|
items.append(filename)
|
||||||
@ -1208,7 +1208,7 @@ class FeatureSourceWidgetWrapper(WidgetWrapper):
|
|||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
if not bool(v):
|
if not bool(v):
|
||||||
return self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
else:
|
else:
|
||||||
return os.path.exists(v)
|
return os.path.exists(v)
|
||||||
|
|
||||||
@ -1222,7 +1222,7 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
if self.param.multiLine():
|
if self.parameterDefinition().multiLine():
|
||||||
widget = QPlainTextEdit()
|
widget = QPlainTextEdit()
|
||||||
else:
|
else:
|
||||||
self._lineedit = QLineEdit()
|
self._lineedit = QLineEdit()
|
||||||
@ -1238,7 +1238,7 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
QgsProcessingParameterField, QgsProcessingParameterExpression],
|
QgsProcessingParameterField, QgsProcessingParameterExpression],
|
||||||
[QgsProcessingOutputString, QgsProcessingOutputFile])
|
[QgsProcessingOutputString, QgsProcessingOutputFile])
|
||||||
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
|
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
|
||||||
if self.param.multiLine():
|
if self.parameterDefinition().multiLine():
|
||||||
widget = MultilineTextPanel(options)
|
widget = MultilineTextPanel(options)
|
||||||
else:
|
else:
|
||||||
widget = QComboBox()
|
widget = QComboBox()
|
||||||
@ -1267,7 +1267,7 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
if self.param.multiLine():
|
if self.parameterDefinition().multiLine():
|
||||||
self.widget.setPlainText(value)
|
self.widget.setPlainText(value)
|
||||||
else:
|
else:
|
||||||
self._lineedit.setText(value)
|
self._lineedit.setText(value)
|
||||||
@ -1276,14 +1276,14 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
self.widget.setText(value)
|
self.widget.setText(value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.param.multiLine():
|
if self.parameterDefinition().multiLine():
|
||||||
self.widget.setValue(value)
|
self.widget.setValue(value)
|
||||||
else:
|
else:
|
||||||
self.setComboValue(value)
|
self.setComboValue(value)
|
||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.dialogType in DIALOG_STANDARD:
|
if self.dialogType in DIALOG_STANDARD:
|
||||||
if self.param.multiLine():
|
if self.parameterDefinition().multiLine():
|
||||||
text = self.widget.toPlainText()
|
text = self.widget.toPlainText()
|
||||||
else:
|
else:
|
||||||
text = self._lineedit.text()
|
text = self._lineedit.text()
|
||||||
@ -1293,12 +1293,12 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
return self.widget.text()
|
return self.widget.text()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.param.multiLine():
|
if self.parameterDefinition().multiLine():
|
||||||
value = self.widget.getValue()
|
value = self.widget.getValue()
|
||||||
option = self.widget.getOption()
|
option = self.widget.getOption()
|
||||||
if option == MultilineTextPanel.USE_TEXT:
|
if option == MultilineTextPanel.USE_TEXT:
|
||||||
if value == '':
|
if value == '':
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
raise InvalidParameterValue()
|
raise InvalidParameterValue()
|
||||||
@ -1308,7 +1308,7 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
return value
|
return value
|
||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return bool(v) or self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
|
|
||||||
return self.comboValue(validator)
|
return self.comboValue(validator)
|
||||||
|
|
||||||
@ -1321,12 +1321,12 @@ class ExpressionWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.parentLayerParameterName():
|
if self.parameterDefinition().parentLayerParameterName():
|
||||||
widget = QgsFieldExpressionWidget()
|
widget = QgsFieldExpressionWidget()
|
||||||
else:
|
else:
|
||||||
widget = QgsExpressionLineEdit()
|
widget = QgsExpressionLineEdit()
|
||||||
if self.param.defaultValue():
|
if self.parameterDefinition().defaultValue():
|
||||||
widget.setExpression(self.param.defaultValue())
|
widget.setExpression(self.parameterDefinition().defaultValue())
|
||||||
else:
|
else:
|
||||||
strings = self.dialog.getAvailableValuesOfType(
|
strings = self.dialog.getAvailableValuesOfType(
|
||||||
[QgsProcessingParameterExpression, QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterDistance],
|
[QgsProcessingParameterExpression, QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterDistance],
|
||||||
@ -1336,12 +1336,12 @@ class ExpressionWidgetWrapper(WidgetWrapper):
|
|||||||
widget.setEditable(True)
|
widget.setEditable(True)
|
||||||
for desc, val in options:
|
for desc, val in options:
|
||||||
widget.addItem(desc, val)
|
widget.addItem(desc, val)
|
||||||
widget.setEditText(self.param.defaultValue() or "")
|
widget.setEditText(self.parameterDefinition().defaultValue() or "")
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.parentLayerParameterName():
|
if wrapper.parameterDefinition().name() == self.parameterDefinition().parentLayerParameterName():
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
self.setLayer(wrapper.value())
|
self.setLayer(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentLayerChanged)
|
||||||
@ -1374,7 +1374,7 @@ class ExpressionWidgetWrapper(WidgetWrapper):
|
|||||||
return self.widget.expression()
|
return self.widget.expression()
|
||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return bool(v) or self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
|
|
||||||
return self.comboValue(validator)
|
return self.comboValue(validator)
|
||||||
|
|
||||||
@ -1403,13 +1403,13 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
|
|||||||
self.combo.setShowCrs(True)
|
self.combo.setShowCrs(True)
|
||||||
|
|
||||||
filters = QgsMapLayerProxyModel.Filters()
|
filters = QgsMapLayerProxyModel.Filters()
|
||||||
if QgsProcessing.TypeVectorAnyGeometry in self.param.dataTypes() or len(self.param.dataTypes()) == 0:
|
if QgsProcessing.TypeVectorAnyGeometry in self.parameterDefinition().dataTypes() or len(self.parameterDefinition().dataTypes()) == 0:
|
||||||
filters = QgsMapLayerProxyModel.HasGeometry
|
filters = QgsMapLayerProxyModel.HasGeometry
|
||||||
if QgsProcessing.TypeVectorPoint in self.param.dataTypes():
|
if QgsProcessing.TypeVectorPoint in self.parameterDefinition().dataTypes():
|
||||||
filters |= QgsMapLayerProxyModel.PointLayer
|
filters |= QgsMapLayerProxyModel.PointLayer
|
||||||
if QgsProcessing.TypeVectorLine in self.param.dataTypes():
|
if QgsProcessing.TypeVectorLine in self.parameterDefinition().dataTypes():
|
||||||
filters |= QgsMapLayerProxyModel.LineLayer
|
filters |= QgsMapLayerProxyModel.LineLayer
|
||||||
if QgsProcessing.TypeVectorPolygon in self.param.dataTypes():
|
if QgsProcessing.TypeVectorPolygon in self.parameterDefinition().dataTypes():
|
||||||
filters |= QgsMapLayerProxyModel.PolygonLayer
|
filters |= QgsMapLayerProxyModel.PolygonLayer
|
||||||
if not filters:
|
if not filters:
|
||||||
filters = QgsMapLayerProxyModel.VectorLayer
|
filters = QgsMapLayerProxyModel.VectorLayer
|
||||||
@ -1424,7 +1424,7 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.setAllowEmptyLayer(True)
|
self.combo.setAllowEmptyLayer(True)
|
||||||
self.combo.setLayer(None)
|
self.combo.setLayer(None)
|
||||||
|
|
||||||
@ -1433,7 +1433,7 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
|
|||||||
return widget
|
return widget
|
||||||
|
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
widget = BatchInputSelectionPanel(self.param, self.row, self.col, self.dialog)
|
widget = BatchInputSelectionPanel(self.parameterDefinition(), self.row, self.col, self.dialog)
|
||||||
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.valueChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
@ -1441,7 +1441,7 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
|
|||||||
self.combo.setEditable(True)
|
self.combo.setEditable(True)
|
||||||
tables = self.dialog.getAvailableValuesOfType((QgsProcessingParameterVectorLayer, QgsProcessingParameterString),
|
tables = self.dialog.getAvailableValuesOfType((QgsProcessingParameterVectorLayer, QgsProcessingParameterString),
|
||||||
(QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
|
(QgsProcessingOutputVectorLayer, QgsProcessingOutputMapLayer, QgsProcessingOutputFile, QgsProcessingOutputString))
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
self.combo.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
|
self.combo.addItem(self.NOT_SELECTED, self.NOT_SET_OPTION)
|
||||||
for table in tables:
|
for table in tables:
|
||||||
self.combo.addItem(self.dialog.resolveValueDescription(table), table)
|
self.combo.addItem(self.dialog.resolveValueDescription(table), table)
|
||||||
@ -1463,7 +1463,7 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
|
|||||||
def selectFile(self):
|
def selectFile(self):
|
||||||
filename, selected_filter = self.getFileName(self.combo.currentText())
|
filename, selected_filter = self.getFileName(self.combo.currentText())
|
||||||
if filename:
|
if filename:
|
||||||
filename = dataobjects.getRasterSublayer(filename, self.param)
|
filename = dataobjects.getRasterSublayer(filename, self.parameterDefinition())
|
||||||
if isinstance(self.combo, QgsMapLayerComboBox):
|
if isinstance(self.combo, QgsMapLayerComboBox):
|
||||||
items = self.combo.additionalItems()
|
items = self.combo.additionalItems()
|
||||||
items.append(filename)
|
items.append(filename)
|
||||||
@ -1516,7 +1516,7 @@ class VectorLayerWidgetWrapper(WidgetWrapper):
|
|||||||
return self.widget.value()
|
return self.widget.value()
|
||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return bool(v) or self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
|
|
||||||
return self.comboValue(validator, combobox=self.combo)
|
return self.comboValue(validator, combobox=self.combo)
|
||||||
|
|
||||||
@ -1532,17 +1532,17 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
|||||||
self._layer = None
|
self._layer = None
|
||||||
|
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
return MultipleInputPanel(options=[])
|
return MultipleInputPanel(options=[])
|
||||||
else:
|
else:
|
||||||
widget = QgsFieldComboBox()
|
widget = QgsFieldComboBox()
|
||||||
widget.setAllowEmptyFieldName(self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
|
widget.setAllowEmptyFieldName(self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional)
|
||||||
widget.fieldChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.fieldChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
if self.param.dataType() == QgsProcessingParameterField.Numeric:
|
if self.parameterDefinition().dataType() == QgsProcessingParameterField.Numeric:
|
||||||
widget.setFilters(QgsFieldProxyModel.Numeric)
|
widget.setFilters(QgsFieldProxyModel.Numeric)
|
||||||
elif self.param.dataType() == QgsProcessingParameterField.String:
|
elif self.parameterDefinition().dataType() == QgsProcessingParameterField.String:
|
||||||
widget.setFilters(QgsFieldProxyModel.String)
|
widget.setFilters(QgsFieldProxyModel.String)
|
||||||
elif self.param.dataType() == QgsProcessingParameterField.DateTime:
|
elif self.parameterDefinition().dataType() == QgsProcessingParameterField.DateTime:
|
||||||
widget.setFilters(QgsFieldProxyModel.Date | QgsFieldProxyModel.Time)
|
widget.setFilters(QgsFieldProxyModel.Date | QgsFieldProxyModel.Time)
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
@ -1550,7 +1550,7 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
|||||||
widget.setEditable(True)
|
widget.setEditable(True)
|
||||||
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterField, QgsProcessingParameterString],
|
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterField, QgsProcessingParameterString],
|
||||||
[QgsProcessingOutputString])
|
[QgsProcessingOutputString])
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
widget.addItem(self.NOT_SET, self.NOT_SET_OPTION)
|
widget.addItem(self.NOT_SET, self.NOT_SET_OPTION)
|
||||||
for f in fields:
|
for f in fields:
|
||||||
widget.addItem(self.dialog.resolveValueDescription(f), f)
|
widget.addItem(self.dialog.resolveValueDescription(f), f)
|
||||||
@ -1561,7 +1561,7 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.parentLayerParameterName():
|
if wrapper.parameterDefinition().name() == self.parameterDefinition().parentLayerParameterName():
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
self.setLayer(wrapper.value())
|
self.setLayer(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentValueChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentValueChanged)
|
||||||
@ -1579,24 +1579,24 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
|||||||
self.refreshItems()
|
self.refreshItems()
|
||||||
|
|
||||||
def refreshItems(self):
|
def refreshItems(self):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
self.widget.updateForOptions(self.getFields())
|
self.widget.updateForOptions(self.getFields())
|
||||||
else:
|
else:
|
||||||
self.widget.setLayer(self._layer)
|
self.widget.setLayer(self._layer)
|
||||||
self.widget.setCurrentIndex(0)
|
self.widget.setCurrentIndex(0)
|
||||||
if self.param.defaultValue() is not None:
|
if self.parameterDefinition().defaultValue() is not None:
|
||||||
self.setValue(self.param.defaultValue())
|
self.setValue(self.parameterDefinition().defaultValue())
|
||||||
|
|
||||||
def getFields(self):
|
def getFields(self):
|
||||||
if self._layer is None:
|
if self._layer is None:
|
||||||
return []
|
return []
|
||||||
fieldTypes = []
|
fieldTypes = []
|
||||||
if self.param.dataType() == QgsProcessingParameterField.String:
|
if self.parameterDefinition().dataType() == QgsProcessingParameterField.String:
|
||||||
fieldTypes = [QVariant.String]
|
fieldTypes = [QVariant.String]
|
||||||
elif self.param.dataType() == QgsProcessingParameterField.Numeric:
|
elif self.parameterDefinition().dataType() == QgsProcessingParameterField.Numeric:
|
||||||
fieldTypes = [QVariant.Int, QVariant.Double, QVariant.LongLong,
|
fieldTypes = [QVariant.Int, QVariant.Double, QVariant.LongLong,
|
||||||
QVariant.UInt, QVariant.ULongLong]
|
QVariant.UInt, QVariant.ULongLong]
|
||||||
elif self.param.dataType() == QgsProcessingParameterField.DateTime:
|
elif self.parameterDefinition().dataType() == QgsProcessingParameterField.DateTime:
|
||||||
fieldTypes = [QVariant.Date, QVariant.Time, QVariant.DateTime]
|
fieldTypes = [QVariant.Date, QVariant.Time, QVariant.DateTime]
|
||||||
|
|
||||||
fieldNames = []
|
fieldNames = []
|
||||||
@ -1610,7 +1610,7 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
options = self.widget.options
|
options = self.widget.options
|
||||||
selected = []
|
selected = []
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
@ -1632,16 +1632,16 @@ class TableFieldWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
return [self.widget.options[i] for i in self.widget.selectedoptions]
|
return [self.widget.options[i] for i in self.widget.selectedoptions]
|
||||||
else:
|
else:
|
||||||
f = self.widget.currentField()
|
f = self.widget.currentField()
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional and not f:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional and not f:
|
||||||
return None
|
return None
|
||||||
return f
|
return f
|
||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return bool(v) or self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
|
|
||||||
return self.comboValue(validator)
|
return self.comboValue(validator)
|
||||||
|
|
||||||
@ -1657,10 +1657,10 @@ class BandWidgetWrapper(WidgetWrapper):
|
|||||||
self._layer = None
|
self._layer = None
|
||||||
|
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
return MultipleInputPanel(options=[])
|
return MultipleInputPanel(options=[])
|
||||||
widget = QgsRasterBandComboBox()
|
widget = QgsRasterBandComboBox()
|
||||||
widget.setShowNotSetOption(self.param.flags() & QgsProcessingParameterDefinition.FlagOptional)
|
widget.setShowNotSetOption(self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional)
|
||||||
widget.bandChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
widget.bandChanged.connect(lambda: self.widgetValueHasChanged.emit(self))
|
||||||
return widget
|
return widget
|
||||||
else:
|
else:
|
||||||
@ -1668,7 +1668,7 @@ class BandWidgetWrapper(WidgetWrapper):
|
|||||||
widget.setEditable(True)
|
widget.setEditable(True)
|
||||||
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterBand, QgsProcessingParameterDistance, QgsProcessingParameterNumber],
|
fields = self.dialog.getAvailableValuesOfType([QgsProcessingParameterBand, QgsProcessingParameterDistance, QgsProcessingParameterNumber],
|
||||||
[QgsProcessingOutputNumber])
|
[QgsProcessingOutputNumber])
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional:
|
||||||
widget.addItem(self.NOT_SET, self.NOT_SET_OPTION)
|
widget.addItem(self.NOT_SET, self.NOT_SET_OPTION)
|
||||||
for f in fields:
|
for f in fields:
|
||||||
widget.addItem(self.dialog.resolveValueDescription(f), f)
|
widget.addItem(self.dialog.resolveValueDescription(f), f)
|
||||||
@ -1676,7 +1676,7 @@ class BandWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self.param.parentLayerParameterName():
|
if wrapper.parameterDefinition().name() == self.parameterDefinition().parentLayerParameterName():
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
self.setLayer(wrapper.value())
|
self.setLayer(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.parentValueChanged)
|
wrapper.widgetValueHasChanged.connect(self.parentValueChanged)
|
||||||
@ -1719,7 +1719,7 @@ class BandWidgetWrapper(WidgetWrapper):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
options = self.widget.options
|
options = self.widget.options
|
||||||
selected = []
|
selected = []
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
@ -1739,7 +1739,7 @@ class BandWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def value(self):
|
def value(self):
|
||||||
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
|
||||||
if self.param.allowMultiple():
|
if self.parameterDefinition().allowMultiple():
|
||||||
bands = []
|
bands = []
|
||||||
for i in self.widget.selectedoptions:
|
for i in self.widget.selectedoptions:
|
||||||
match = re.search('(?:\A|[^0-9])([0-9]+)(?:\Z|[^0-9]|)', self.widget.options[i])
|
match = re.search('(?:\A|[^0-9])([0-9]+)(?:\Z|[^0-9]|)', self.widget.options[i])
|
||||||
@ -1748,12 +1748,12 @@ class BandWidgetWrapper(WidgetWrapper):
|
|||||||
return bands
|
return bands
|
||||||
else:
|
else:
|
||||||
f = self.widget.currentBand()
|
f = self.widget.currentBand()
|
||||||
if self.param.flags() & QgsProcessingParameterDefinition.FlagOptional and not f:
|
if self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional and not f:
|
||||||
return None
|
return None
|
||||||
return f
|
return f
|
||||||
else:
|
else:
|
||||||
def validator(v):
|
def validator(v):
|
||||||
return bool(v) or self.param.flags() & QgsProcessingParameterDefinition.FlagOptional
|
return bool(v) or self.parameterDefinition().flags() & QgsProcessingParameterDefinition.FlagOptional
|
||||||
|
|
||||||
return self.comboValue(validator)
|
return self.comboValue(validator)
|
||||||
|
|
||||||
@ -1770,6 +1770,14 @@ class WidgetWrapperFactory:
|
|||||||
if param.metadata().get('widget_wrapper', None) is not None:
|
if param.metadata().get('widget_wrapper', None) is not None:
|
||||||
return WidgetWrapperFactory.create_wrapper_from_metadata(param, dialog, row, col)
|
return WidgetWrapperFactory.create_wrapper_from_metadata(param, dialog, row, col)
|
||||||
else:
|
else:
|
||||||
|
# try from c++ registry first
|
||||||
|
dialog_type = dialogTypes.get(dialog.__class__.__name__,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper.Standard)
|
||||||
|
wrapper = QgsGui.processingGuiRegistry().createParameterWidgetWrapper(param, dialog_type)
|
||||||
|
if wrapper is not None:
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
# fallback to Python registry
|
||||||
return WidgetWrapperFactory.create_wrapper_from_class(param, dialog, row, col)
|
return WidgetWrapperFactory.create_wrapper_from_class(param, dialog, row, col)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -89,7 +89,7 @@ class SchemaWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self._connection_param:
|
if wrapper.parameterDefinition().name() == self._connection_param:
|
||||||
self.connection_wrapper = wrapper
|
self.connection_wrapper = wrapper
|
||||||
self.setConnection(wrapper.value())
|
self.setConnection(wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.connectionChanged)
|
wrapper.widgetValueHasChanged.connect(self.connectionChanged)
|
||||||
@ -161,7 +161,7 @@ class TableWidgetWrapper(WidgetWrapper):
|
|||||||
|
|
||||||
def postInitialize(self, wrappers):
|
def postInitialize(self, wrappers):
|
||||||
for wrapper in wrappers:
|
for wrapper in wrappers:
|
||||||
if wrapper.param.name() == self._schema_param:
|
if wrapper.parameterDefinition().name() == self._schema_param:
|
||||||
self.schema_wrapper = wrapper
|
self.schema_wrapper = wrapper
|
||||||
self.setSchema(wrapper.database(), wrapper.value())
|
self.setSchema(wrapper.database(), wrapper.value())
|
||||||
wrapper.widgetValueHasChanged.connect(self.schemaChanged)
|
wrapper.widgetValueHasChanged.connect(self.schemaChanged)
|
||||||
|
@ -200,6 +200,8 @@ SET(QGIS_GUI_SRCS
|
|||||||
processing/qgsprocessingrecentalgorithmlog.cpp
|
processing/qgsprocessingrecentalgorithmlog.cpp
|
||||||
processing/qgsprocessingtoolboxmodel.cpp
|
processing/qgsprocessingtoolboxmodel.cpp
|
||||||
processing/qgsprocessingtoolboxtreeview.cpp
|
processing/qgsprocessingtoolboxtreeview.cpp
|
||||||
|
processing/qgsprocessingwidgetwrapper.cpp
|
||||||
|
processing/qgsprocessingwidgetwrapperimpl.cpp
|
||||||
|
|
||||||
qgisinterface.cpp
|
qgisinterface.cpp
|
||||||
qgsactionmenu.cpp
|
qgsactionmenu.cpp
|
||||||
@ -726,6 +728,8 @@ SET(QGIS_GUI_MOC_HDRS
|
|||||||
processing/qgsprocessingrecentalgorithmlog.h
|
processing/qgsprocessingrecentalgorithmlog.h
|
||||||
processing/qgsprocessingtoolboxmodel.h
|
processing/qgsprocessingtoolboxmodel.h
|
||||||
processing/qgsprocessingtoolboxtreeview.h
|
processing/qgsprocessingtoolboxtreeview.h
|
||||||
|
processing/qgsprocessingwidgetwrapper.h
|
||||||
|
processing/qgsprocessingwidgetwrapperimpl.h
|
||||||
)
|
)
|
||||||
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_MOC_HDRS ${QGIS_GUI_MOC_HDRS})
|
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_MOC_HDRS ${QGIS_GUI_MOC_HDRS})
|
||||||
|
|
||||||
|
@ -18,17 +18,26 @@
|
|||||||
#include "qgsprocessingguiregistry.h"
|
#include "qgsprocessingguiregistry.h"
|
||||||
#include "qgsprocessingalgorithmconfigurationwidget.h"
|
#include "qgsprocessingalgorithmconfigurationwidget.h"
|
||||||
#include "qgsprocessingconfigurationwidgets.h"
|
#include "qgsprocessingconfigurationwidgets.h"
|
||||||
|
#include "qgsprocessingwidgetwrapperimpl.h"
|
||||||
|
#include "qgsprocessingparameters.h"
|
||||||
#include "qgis.h"
|
#include "qgis.h"
|
||||||
|
#include "qgslogger.h"
|
||||||
|
|
||||||
QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
|
QgsProcessingGuiRegistry::QgsProcessingGuiRegistry()
|
||||||
{
|
{
|
||||||
addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
|
addAlgorithmConfigurationWidgetFactory( new QgsFilterAlgorithmConfigurationWidgetFactory() );
|
||||||
|
|
||||||
|
addParameterWidgetFactory( new QgsProcessingBooleanWidgetWrapper() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry()
|
QgsProcessingGuiRegistry::~QgsProcessingGuiRegistry()
|
||||||
{
|
{
|
||||||
for ( QgsProcessingAlgorithmConfigurationWidgetFactory *factory : qgis::as_const( mAlgorithmConfigurationWidgetFactories ) )
|
const QList< QgsProcessingAlgorithmConfigurationWidgetFactory * > factories = mAlgorithmConfigurationWidgetFactories;
|
||||||
|
for ( QgsProcessingAlgorithmConfigurationWidgetFactory *factory : factories )
|
||||||
removeAlgorithmConfigurationWidgetFactory( factory );
|
removeAlgorithmConfigurationWidgetFactory( factory );
|
||||||
|
const QMap< QString, QgsProcessingParameterWidgetFactoryInterface * > paramFactories = mParameterWidgetFactories;
|
||||||
|
for ( auto it = paramFactories.constBegin(); it != paramFactories.constEnd(); ++it )
|
||||||
|
removeParameterWidgetFactory( it.value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsProcessingGuiRegistry::addAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory )
|
void QgsProcessingGuiRegistry::addAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory )
|
||||||
@ -54,3 +63,44 @@ QgsProcessingAlgorithmConfigurationWidget *QgsProcessingGuiRegistry::algorithmCo
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsProcessingGuiRegistry::addParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory )
|
||||||
|
{
|
||||||
|
if ( !factory )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( mParameterWidgetFactories.contains( factory->parameterType() ) )
|
||||||
|
{
|
||||||
|
QgsLogger::warning( QStringLiteral( "Duplicate parameter factory for %1 registered" ).arg( factory->parameterType() ) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mParameterWidgetFactories.insert( factory->parameterType(), factory );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsProcessingGuiRegistry::removeParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory )
|
||||||
|
{
|
||||||
|
if ( !factory )
|
||||||
|
return;
|
||||||
|
|
||||||
|
mParameterWidgetFactories.remove( factory->parameterType() );
|
||||||
|
delete factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingGuiRegistry::createParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type )
|
||||||
|
{
|
||||||
|
// TODO - support modeler type
|
||||||
|
if ( type == QgsAbstractProcessingParameterWidgetWrapper::Modeler )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if ( !parameter )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
const QString parameterType = parameter->type();
|
||||||
|
if ( !mParameterWidgetFactories.contains( parameterType ) )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return mParameterWidgetFactories.value( parameterType )->createWidgetWrapper( parameter, type );
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
|
|
||||||
#include "qgis_gui.h"
|
#include "qgis_gui.h"
|
||||||
#include "qgis_sip.h"
|
#include "qgis_sip.h"
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
class QgsProcessingAlgorithm;
|
class QgsProcessingAlgorithm;
|
||||||
class QgsProcessingAlgorithmConfigurationWidget;
|
class QgsProcessingAlgorithmConfigurationWidget;
|
||||||
@ -31,6 +32,9 @@ class QgsProcessingAlgorithmConfigurationWidgetFactory;
|
|||||||
* The QgsProcessingGuiRegistry is a home for widgets for processing
|
* The QgsProcessingGuiRegistry is a home for widgets for processing
|
||||||
* configuration widgets.
|
* configuration widgets.
|
||||||
*
|
*
|
||||||
|
* QgsProcessingGuiRegistry is not usually directly created, but rather accessed through
|
||||||
|
* QgsGui::processingGuiRegistry().
|
||||||
|
*
|
||||||
* \ingroup gui
|
* \ingroup gui
|
||||||
* \since QGIS 3.2
|
* \since QGIS 3.2
|
||||||
*/
|
*/
|
||||||
@ -70,9 +74,44 @@ class GUI_EXPORT QgsProcessingGuiRegistry
|
|||||||
*/
|
*/
|
||||||
QgsProcessingAlgorithmConfigurationWidget *algorithmConfigurationWidget( const QgsProcessingAlgorithm *algorithm ) const;
|
QgsProcessingAlgorithmConfigurationWidget *algorithmConfigurationWidget( const QgsProcessingAlgorithm *algorithm ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a parameter widget \a factory to the registry. Ownership of \a factory is transferred to the registry.
|
||||||
|
*
|
||||||
|
* Returns true if the factory was successfully added, or false if the factory could not be added. Each
|
||||||
|
* factory must return a unique value for QgsProcessingParameterWidgetFactoryInterface::parameterType(),
|
||||||
|
* and attempting to add a new factory with a duplicate type will result in failure.
|
||||||
|
*
|
||||||
|
* \see removeParameterWidgetFactory()
|
||||||
|
* \see createParameterWidgetWrapper()
|
||||||
|
*
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
bool addParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory SIP_TRANSFER );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a parameter widget \a factory from the registry. The factory will be deleted.
|
||||||
|
*
|
||||||
|
* \see addParameterWidgetFactory()
|
||||||
|
*
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
void removeParameterWidgetFactory( QgsProcessingParameterWidgetFactoryInterface *factory );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new parameter widget wrapper for the given \a parameter. The \a type argument
|
||||||
|
* dictates the type of dialog the wrapper should be created for. The caller takes ownership
|
||||||
|
* of the returned wrapper.
|
||||||
|
*
|
||||||
|
* If no factory is registered which handles the given \a parameter, a nullptr will be returned.
|
||||||
|
*
|
||||||
|
* \see addParameterWidgetFactory()
|
||||||
|
*/
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *createParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) SIP_FACTORY;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QList <QgsProcessingAlgorithmConfigurationWidgetFactory *> mAlgorithmConfigurationWidgetFactories;
|
QList <QgsProcessingAlgorithmConfigurationWidgetFactory *> mAlgorithmConfigurationWidgetFactories;
|
||||||
|
QMap< QString, QgsProcessingParameterWidgetFactoryInterface *> mParameterWidgetFactories;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QGSPROCESSINGGUIREGISTRY_H
|
#endif // QGSPROCESSINGGUIREGISTRY_H
|
||||||
|
92
src/gui/processing/qgsprocessingwidgetwrapper.cpp
Normal file
92
src/gui/processing/qgsprocessingwidgetwrapper.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsprocessingwidgetwrapper.cpp
|
||||||
|
---------------------
|
||||||
|
begin : August 2018
|
||||||
|
copyright : (C) 2018 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
|
#include "qgsprocessingparameters.h"
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper::QgsAbstractProcessingParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type, QObject *parent )
|
||||||
|
: QObject( parent )
|
||||||
|
, mType( type )
|
||||||
|
, mParameterDefinition( parameter )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper::WidgetType QgsAbstractProcessingParameterWidgetWrapper::type() const
|
||||||
|
{
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *QgsAbstractProcessingParameterWidgetWrapper::createWrappedWidget( const QgsProcessingContext &context )
|
||||||
|
{
|
||||||
|
if ( mWidget )
|
||||||
|
return mWidget;
|
||||||
|
|
||||||
|
mWidget = createWidget();
|
||||||
|
setWidgetValue( mParameterDefinition->defaultValue(), context );
|
||||||
|
|
||||||
|
return mWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *QgsAbstractProcessingParameterWidgetWrapper::createWrappedLabel()
|
||||||
|
{
|
||||||
|
if ( mLabel )
|
||||||
|
return mLabel;
|
||||||
|
|
||||||
|
mLabel = createLabel();
|
||||||
|
return mLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *QgsAbstractProcessingParameterWidgetWrapper::wrappedWidget()
|
||||||
|
{
|
||||||
|
return mWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *QgsAbstractProcessingParameterWidgetWrapper::wrappedLabel()
|
||||||
|
{
|
||||||
|
return mLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QgsProcessingParameterDefinition *QgsAbstractProcessingParameterWidgetWrapper::parameterDefinition() const
|
||||||
|
{
|
||||||
|
return mParameterDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *QgsAbstractProcessingParameterWidgetWrapper::createLabel()
|
||||||
|
{
|
||||||
|
switch ( mType )
|
||||||
|
{
|
||||||
|
case Batch:
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
case Standard:
|
||||||
|
case Modeler:
|
||||||
|
{
|
||||||
|
std::unique_ptr< QLabel > label = qgis::make_unique< QLabel >( mParameterDefinition->description() );
|
||||||
|
label->setToolTip( mParameterDefinition->name() );
|
||||||
|
return label.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsAbstractProcessingParameterWidgetWrapper::postInitialize( const QList<QgsAbstractProcessingParameterWidgetWrapper *> & )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
212
src/gui/processing/qgsprocessingwidgetwrapper.h
Normal file
212
src/gui/processing/qgsprocessingwidgetwrapper.h
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsprocessingwidgetwrapper.h
|
||||||
|
---------------------
|
||||||
|
begin : August 2018
|
||||||
|
copyright : (C) 2018 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QGSPROCESSINGWIDGETWRAPPER_H
|
||||||
|
#define QGSPROCESSINGWIDGETWRAPPER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
#include "qgis_gui.h"
|
||||||
|
#include "qgis_sip.h"
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
class QgsProcessingParameterDefinition;
|
||||||
|
class QgsProcessingContext;
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class QgsAbstractProcessingParameterWidgetWrapper
|
||||||
|
*
|
||||||
|
* A widget wrapper for Processing parameter value widgets.
|
||||||
|
*
|
||||||
|
* Widget wrappers are used to create widgets for individual Processing parameters, and
|
||||||
|
* handle retrieving and setting the current value for those parameters.
|
||||||
|
*
|
||||||
|
* Widget wrappers can be created for different dialog types, allowing different
|
||||||
|
* appearance and behavior of widgets depending on whether they are being created for
|
||||||
|
* use in a standard algorithm dialog, a batch processing dialog, or a modeler dialog.
|
||||||
|
*
|
||||||
|
* Individual widget wrappers are not usually created directly, instead they are
|
||||||
|
* constructed through the central registry, via calls to
|
||||||
|
* QgsGui::processingGuiRegistry()->createParameterWidgetWrapper().
|
||||||
|
*
|
||||||
|
* \ingroup gui
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
class GUI_EXPORT QgsAbstractProcessingParameterWidgetWrapper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Types of dialogs the widgets can be created for
|
||||||
|
enum WidgetType
|
||||||
|
{
|
||||||
|
Standard, //!< Standard algorithm dialog
|
||||||
|
Batch, //!< Batch processing dialog
|
||||||
|
Modeler, //!< Modeler dialog
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for QgsAbstractProcessingParameterWidgetWrapper, for the specified
|
||||||
|
* \a parameter definition and dialog \a type.
|
||||||
|
*/
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
|
||||||
|
WidgetType type = Standard, QObject *parent SIP_TRANSFERTHIS = nullptr );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the dialog type for which widgets and labels will be created by this wrapper.
|
||||||
|
*/
|
||||||
|
WidgetType type() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and return a new wrapped widget which allows customization of the parameter's value.
|
||||||
|
*
|
||||||
|
* The caller takes ownership of the returned widget. The wrapped widget can be retrieved at a later
|
||||||
|
* stage by calling wrappedWidget().
|
||||||
|
*
|
||||||
|
* The supplied \a context is used while initializing the widget to the parameter's default value.
|
||||||
|
*
|
||||||
|
* \see createWrappedLabel()
|
||||||
|
*/
|
||||||
|
QWidget *createWrappedWidget( const QgsProcessingContext &context ) SIP_FACTORY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a new label to accompany widgets created by the wrapper.
|
||||||
|
*
|
||||||
|
* The caller takes ownership of the returned label. Some parameter type and dialog type
|
||||||
|
* combinations will return nullptr for this method. If nullptr is returned, then no
|
||||||
|
* label should be shown for the parameter's widget (i.e. the label is embedded inside the
|
||||||
|
* widget itself).
|
||||||
|
*
|
||||||
|
* The wrapped label can be retrieved at a later stage by calling wrappedLabel().
|
||||||
|
*
|
||||||
|
* \see createWrappedWidget()
|
||||||
|
*/
|
||||||
|
QLabel *createWrappedLabel() SIP_FACTORY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current wrapped widget, if any.
|
||||||
|
* \see createWrappedWidget()
|
||||||
|
*/
|
||||||
|
QWidget *wrappedWidget();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current wrapped label, if any.
|
||||||
|
* \see createWrappedLabel()
|
||||||
|
*/
|
||||||
|
QLabel *wrappedLabel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the parameter definition associated with this wrapper.
|
||||||
|
*/
|
||||||
|
const QgsProcessingParameterDefinition *parameterDefinition() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current \a value for the parameter.
|
||||||
|
*
|
||||||
|
* The \a context argument is used to specify the wider Processing context which the
|
||||||
|
* current value is associated with.
|
||||||
|
*
|
||||||
|
* \see value()
|
||||||
|
*/
|
||||||
|
virtual void setWidgetValue( const QVariant &value, const QgsProcessingContext &context ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current value of the parameter.
|
||||||
|
*
|
||||||
|
* \see setWidgetValue()
|
||||||
|
*/
|
||||||
|
virtual QVariant value() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after all wrappers have been created within a particular dialog or context,
|
||||||
|
* allowing the wrapper to connect to the wrappers of other, related parameters.
|
||||||
|
*/
|
||||||
|
virtual void postInitialize( const QList< QgsAbstractProcessingParameterWidgetWrapper * > &wrappers );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new widget which allows customization of the parameter's value.
|
||||||
|
*
|
||||||
|
* The caller takes ownership of the returned widget.
|
||||||
|
*
|
||||||
|
* \see createLabel()
|
||||||
|
*/
|
||||||
|
virtual QWidget *createWidget() = 0 SIP_FACTORY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new label to accompany widgets created by the wrapper.
|
||||||
|
*
|
||||||
|
* The caller takes ownership of the returned label. Some parameter type and dialog type
|
||||||
|
* combinations will return nullptr for this method. If nullptr is returned, then no
|
||||||
|
* label should be shown for the parameter's widget (i.e. the label is embedded inside the
|
||||||
|
* widget itself).
|
||||||
|
*
|
||||||
|
* \see createWidget()
|
||||||
|
*/
|
||||||
|
virtual QLabel *createLabel() SIP_FACTORY;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
WidgetType mType = Standard;
|
||||||
|
const QgsProcessingParameterDefinition *mParameterDefinition = nullptr;
|
||||||
|
|
||||||
|
QPointer< QWidget > mWidget;
|
||||||
|
QPointer< QLabel > mLabel;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class QgsProcessingParameterWidgetFactoryInterface
|
||||||
|
*
|
||||||
|
* An interface for Processing widget wrapper factories.
|
||||||
|
*
|
||||||
|
* Widget wrapper factories allow creation of QgsAbstractProcessingParameterWidgetWrapper objects.
|
||||||
|
* They are centrally managed by QgsProcessingGuiRegistry. Usually, individual factories
|
||||||
|
* are not directly utilized, rather the QgsGui::processingGuiRegistry()->createParameterWidgetWrapper()
|
||||||
|
* method is used to create widget wrappers.
|
||||||
|
*
|
||||||
|
* \ingroup gui
|
||||||
|
* \since QGIS 3.4
|
||||||
|
*/
|
||||||
|
class GUI_EXPORT QgsProcessingParameterWidgetFactoryInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual ~QgsProcessingParameterWidgetFactoryInterface() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type string for the parameter type the factory is associated with.
|
||||||
|
*/
|
||||||
|
virtual QString parameterType() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new widget wrapper for the specified \a parameter definition.
|
||||||
|
*
|
||||||
|
* The \a type argument indicates the dialog type to create a wrapper for.
|
||||||
|
*/
|
||||||
|
virtual QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) = 0 SIP_FACTORY;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QGSPROCESSINGWIDGETWRAPPER_H
|
117
src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Normal file
117
src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsprocessingwidgetwrapperimpl.cpp
|
||||||
|
---------------------
|
||||||
|
begin : August 2018
|
||||||
|
copyright : (C) 2018 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "qgsprocessingwidgetwrapperimpl.h"
|
||||||
|
#include "qgsprocessingparameters.h"
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
///@cond PRIVATE
|
||||||
|
|
||||||
|
//
|
||||||
|
// QgsProcessingBooleanWidgetWrapper
|
||||||
|
//
|
||||||
|
|
||||||
|
QgsProcessingBooleanWidgetWrapper::QgsProcessingBooleanWidgetWrapper( const QgsProcessingParameterDefinition *parameter, WidgetType type, QWidget *parent )
|
||||||
|
: QgsAbstractProcessingParameterWidgetWrapper( parameter, type, parent )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *QgsProcessingBooleanWidgetWrapper::createWidget()
|
||||||
|
{
|
||||||
|
switch ( type() )
|
||||||
|
{
|
||||||
|
case Standard:
|
||||||
|
{
|
||||||
|
QString description = parameterDefinition()->description();
|
||||||
|
if ( parameterDefinition()->flags() & QgsProcessingParameterDefinition::FlagOptional )
|
||||||
|
description = QObject::tr( "%1 [optional]" ).arg( description );
|
||||||
|
|
||||||
|
mCheckBox = new QCheckBox( description );
|
||||||
|
mCheckBox->setToolTip( parameterDefinition()->toolTip() );
|
||||||
|
return mCheckBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
case Batch:
|
||||||
|
{
|
||||||
|
mComboBox = new QComboBox();
|
||||||
|
mComboBox->addItem( tr( "Yes" ), true );
|
||||||
|
mComboBox->addItem( tr( "No" ), false );
|
||||||
|
mComboBox->setToolTip( parameterDefinition()->toolTip() );
|
||||||
|
return mComboBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *QgsProcessingBooleanWidgetWrapper::createLabel()
|
||||||
|
{
|
||||||
|
// avoid creating labels in standard dialogs
|
||||||
|
if ( type() == QgsAbstractProcessingParameterWidgetWrapper::Standard )
|
||||||
|
return nullptr;
|
||||||
|
else
|
||||||
|
return QgsAbstractProcessingParameterWidgetWrapper::createLabel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsProcessingBooleanWidgetWrapper::setWidgetValue( const QVariant &value, const QgsProcessingContext &context )
|
||||||
|
{
|
||||||
|
switch ( type() )
|
||||||
|
{
|
||||||
|
case Standard:
|
||||||
|
{
|
||||||
|
const bool v = QgsProcessingParameters::parameterAsBool( parameterDefinition(), value, context );
|
||||||
|
mCheckBox->setChecked( v );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Batch:
|
||||||
|
{
|
||||||
|
const bool v = QgsProcessingParameters::parameterAsBool( parameterDefinition(), value, context );
|
||||||
|
mComboBox->setCurrentIndex( mComboBox->findData( v ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant QgsProcessingBooleanWidgetWrapper::value() const
|
||||||
|
{
|
||||||
|
switch ( type() )
|
||||||
|
{
|
||||||
|
case Standard:
|
||||||
|
return mCheckBox->isChecked();
|
||||||
|
|
||||||
|
case Batch:
|
||||||
|
return mComboBox->currentData();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QgsProcessingBooleanWidgetWrapper::parameterType() const
|
||||||
|
{
|
||||||
|
return QStringLiteral( "boolean" );
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingBooleanWidgetWrapper::createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type )
|
||||||
|
{
|
||||||
|
return new QgsProcessingBooleanWidgetWrapper( parameter, type );
|
||||||
|
}
|
||||||
|
|
||||||
|
///@endcond PRIVATE
|
55
src/gui/processing/qgsprocessingwidgetwrapperimpl.h
Normal file
55
src/gui/processing/qgsprocessingwidgetwrapperimpl.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsprocessingwidgetwrapperimpl.h
|
||||||
|
---------------------
|
||||||
|
begin : August 2018
|
||||||
|
copyright : (C) 2018 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QGSPROCESSINGWIDGETWRAPPERIMPL_H
|
||||||
|
#define QGSPROCESSINGWIDGETWRAPPERIMPL_H
|
||||||
|
|
||||||
|
#define SIP_NO_FILE
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
|
|
||||||
|
class QCheckBox;
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
|
///@cond PRIVATE
|
||||||
|
|
||||||
|
class GUI_EXPORT QgsProcessingBooleanWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper, public QgsProcessingParameterWidgetFactoryInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
QgsProcessingBooleanWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper::WidgetType type = Standard, QWidget *parent = nullptr );
|
||||||
|
|
||||||
|
// QgsProcessingParameterWidgetFactoryInterface
|
||||||
|
QString parameterType() const override;
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) override;
|
||||||
|
|
||||||
|
// QgsProcessingParameterWidgetWrapper interface
|
||||||
|
QWidget *createWidget() override SIP_FACTORY;
|
||||||
|
QLabel *createLabel() override SIP_FACTORY;
|
||||||
|
void setWidgetValue( const QVariant &value, const QgsProcessingContext &context ) override;
|
||||||
|
QVariant value() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QCheckBox *mCheckBox = nullptr;
|
||||||
|
QComboBox *mComboBox = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
///@endcond PRIVATE
|
||||||
|
|
||||||
|
#endif // QGSPROCESSINGWIDGETWRAPPERIMPL_H
|
52
src/gui/processing/qgsprocessingwidgetwrapperimpl.h.bom
Normal file
52
src/gui/processing/qgsprocessingwidgetwrapperimpl.h.bom
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgsprocessingwidgetwrapperimpl.h
|
||||||
|
---------------------
|
||||||
|
begin : August 2018
|
||||||
|
copyright : (C) 2018 by Nyall Dawson
|
||||||
|
email : nyall dot dawson at gmail dot com
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef QGSPROCESSINGWIDGETWRAPPERIMPL_H
|
||||||
|
#define QGSPROCESSINGWIDGETWRAPPERIMPL_H
|
||||||
|
|
||||||
|
#define SIP_NO_FILE
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
|
|
||||||
|
class QCheckBox;
|
||||||
|
|
||||||
|
class QgsProcessingBooleanWidgetWrapper : public QgsProcessingParameterWidgetWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
QgsProcessingBooleanWidgetWrapper( const QgsProcessingParameterDefinition *parameter, QgsProcessingParameterWidgetWrapper::WidgetType type, QWidget *parent = nullptr );
|
||||||
|
void setValue( const QVariant &value ) override;
|
||||||
|
QVariant value() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QCheckBox *mCheckBox = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QgsProcessingBooleanWidgetFactory : public QgsProcessingParameterWidgetFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
QString parameterType() const override;
|
||||||
|
QgsProcessingParameterWidgetWrapper *createWidget( const QgsProcessingParameterDefinition *parameter, QgsProcessingParameterWidgetWrapper::WidgetType type ) override;
|
||||||
|
QLabel *createLabel( const QgsProcessingParameterDefinition *parameter, QgsProcessingParameterWidgetWrapper::WidgetType type ) override;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // QGSPROCESSINGWIDGETWRAPPERIMPL_H
|
@ -16,14 +16,97 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
#include "qgstest.h"
|
#include "qgstest.h"
|
||||||
#include "qgsgui.h"
|
#include "qgsgui.h"
|
||||||
#include "qgsprocessingguiregistry.h"
|
#include "qgsprocessingguiregistry.h"
|
||||||
#include "qgsprocessingregistry.h"
|
#include "qgsprocessingregistry.h"
|
||||||
#include "qgsprocessingalgorithmconfigurationwidget.h"
|
#include "qgsprocessingalgorithmconfigurationwidget.h"
|
||||||
|
#include "qgsprocessingwidgetwrapper.h"
|
||||||
|
#include "qgsprocessingwidgetwrapperimpl.h"
|
||||||
#include "qgsnativealgorithms.h"
|
#include "qgsnativealgorithms.h"
|
||||||
#include "qgsxmlutils.h"
|
#include "qgsxmlutils.h"
|
||||||
|
|
||||||
|
class TestParamType : public QgsProcessingParameterDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
TestParamType( const QString &type, const QString &name, const QVariant &defaultValue = QVariant() )
|
||||||
|
: QgsProcessingParameterDefinition( name, name, defaultValue )
|
||||||
|
, mType( type )
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString mType;
|
||||||
|
|
||||||
|
QgsProcessingParameterDefinition *clone() const override
|
||||||
|
{
|
||||||
|
return new TestParamType( mType, name() );
|
||||||
|
}
|
||||||
|
|
||||||
|
QString type() const override { return mType; }
|
||||||
|
QString valueAsPythonString( const QVariant &, QgsProcessingContext & ) const override { return QString(); }
|
||||||
|
QString asScriptCode() const override { return QString(); }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestWidgetWrapper : public QgsAbstractProcessingParameterWidgetWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
TestWidgetWrapper( const QgsProcessingParameterDefinition *parameter = nullptr,
|
||||||
|
WidgetType type = Standard )
|
||||||
|
: QgsAbstractProcessingParameterWidgetWrapper( parameter, type )
|
||||||
|
{}
|
||||||
|
|
||||||
|
QWidget *createWidget() override
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLabel *createLabel() override
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWidgetValue( const QVariant &, const QgsProcessingContext & ) override
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant value() const override
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestWidgetFactory : public QgsProcessingParameterWidgetFactoryInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TestWidgetFactory( const QString &type )
|
||||||
|
: type( type )
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString type;
|
||||||
|
|
||||||
|
QString parameterType() const override
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *createWidgetWrapper( const QgsProcessingParameterDefinition *parameter,
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper::WidgetType type ) override
|
||||||
|
{
|
||||||
|
return new TestWidgetWrapper( parameter, type );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class TestProcessingGui : public QObject
|
class TestProcessingGui : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -37,6 +120,9 @@ class TestProcessingGui : public QObject
|
|||||||
void cleanup();// will be called after every testfunction.
|
void cleanup();// will be called after every testfunction.
|
||||||
void testSetGetConfig();
|
void testSetGetConfig();
|
||||||
void testFilterAlgorithmConfig();
|
void testFilterAlgorithmConfig();
|
||||||
|
void testWrapperFactoryRegistry();
|
||||||
|
void testWrapperGeneral();
|
||||||
|
void testBooleanWrapper();
|
||||||
};
|
};
|
||||||
|
|
||||||
void TestProcessingGui::initTestCase()
|
void TestProcessingGui::initTestCase()
|
||||||
@ -110,5 +196,122 @@ void TestProcessingGui::testFilterAlgorithmConfig()
|
|||||||
QCOMPARE( configDoc.toString(), configControlDoc.toString() );
|
QCOMPARE( configDoc.toString(), configControlDoc.toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestProcessingGui::testWrapperFactoryRegistry()
|
||||||
|
{
|
||||||
|
QgsProcessingGuiRegistry registry;
|
||||||
|
|
||||||
|
TestParamType numParam( QStringLiteral( "num" ), QStringLiteral( "num" ) );
|
||||||
|
TestParamType stringParam( QStringLiteral( "str" ), QStringLiteral( "str" ) );
|
||||||
|
|
||||||
|
QVERIFY( !registry.createParameterWidgetWrapper( &numParam, QgsAbstractProcessingParameterWidgetWrapper::Standard ) );
|
||||||
|
|
||||||
|
TestWidgetFactory *factory = new TestWidgetFactory( QStringLiteral( "str" ) );
|
||||||
|
QVERIFY( registry.addParameterWidgetFactory( factory ) );
|
||||||
|
|
||||||
|
// duplicate type not allowed
|
||||||
|
TestWidgetFactory *factory2 = new TestWidgetFactory( QStringLiteral( "str" ) );
|
||||||
|
QVERIFY( !registry.addParameterWidgetFactory( factory2 ) );
|
||||||
|
delete factory2;
|
||||||
|
|
||||||
|
QgsAbstractProcessingParameterWidgetWrapper *wrapper = registry.createParameterWidgetWrapper( &numParam, QgsAbstractProcessingParameterWidgetWrapper::Standard );
|
||||||
|
QVERIFY( !wrapper );
|
||||||
|
wrapper = registry.createParameterWidgetWrapper( &stringParam, QgsAbstractProcessingParameterWidgetWrapper::Standard );
|
||||||
|
QVERIFY( wrapper );
|
||||||
|
QCOMPARE( wrapper->parameterDefinition()->type(), QStringLiteral( "str" ) );
|
||||||
|
delete wrapper;
|
||||||
|
|
||||||
|
TestWidgetFactory *factory3 = new TestWidgetFactory( QStringLiteral( "num" ) );
|
||||||
|
QVERIFY( registry.addParameterWidgetFactory( factory3 ) );
|
||||||
|
|
||||||
|
wrapper = registry.createParameterWidgetWrapper( &numParam, QgsAbstractProcessingParameterWidgetWrapper::Standard );
|
||||||
|
QVERIFY( wrapper );
|
||||||
|
QCOMPARE( wrapper->parameterDefinition()->type(), QStringLiteral( "num" ) );
|
||||||
|
delete wrapper;
|
||||||
|
|
||||||
|
// removing
|
||||||
|
registry.removeParameterWidgetFactory( nullptr );
|
||||||
|
TestWidgetFactory *factory4 = new TestWidgetFactory( QStringLiteral( "xxxx" ) );
|
||||||
|
registry.removeParameterWidgetFactory( factory4 );
|
||||||
|
registry.removeParameterWidgetFactory( factory );
|
||||||
|
wrapper = registry.createParameterWidgetWrapper( &stringParam, QgsAbstractProcessingParameterWidgetWrapper::Standard );
|
||||||
|
QVERIFY( !wrapper );
|
||||||
|
|
||||||
|
wrapper = registry.createParameterWidgetWrapper( &numParam, QgsAbstractProcessingParameterWidgetWrapper::Standard );
|
||||||
|
QVERIFY( wrapper );
|
||||||
|
QCOMPARE( wrapper->parameterDefinition()->type(), QStringLiteral( "num" ) );
|
||||||
|
delete wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestProcessingGui::testWrapperGeneral()
|
||||||
|
{
|
||||||
|
TestParamType param( QStringLiteral( "boolean" ), QStringLiteral( "bool" ) );
|
||||||
|
QgsProcessingBooleanWidgetWrapper wrapper( ¶m );
|
||||||
|
QCOMPARE( wrapper.type(), QgsAbstractProcessingParameterWidgetWrapper::Standard );
|
||||||
|
QgsProcessingBooleanWidgetWrapper wrapper2( ¶m, QgsAbstractProcessingParameterWidgetWrapper::Batch );
|
||||||
|
QCOMPARE( wrapper2.type(), QgsAbstractProcessingParameterWidgetWrapper::Batch );
|
||||||
|
|
||||||
|
QCOMPARE( wrapper2.parameterDefinition()->name(), QStringLiteral( "bool" ) );
|
||||||
|
|
||||||
|
QgsProcessingContext context;
|
||||||
|
QVERIFY( !wrapper2.wrappedWidget() );
|
||||||
|
QWidget *w = wrapper2.createWrappedWidget( context );
|
||||||
|
QVERIFY( w );
|
||||||
|
QCOMPARE( wrapper2.wrappedWidget(), w );
|
||||||
|
delete w;
|
||||||
|
QVERIFY( !wrapper2.wrappedLabel() );
|
||||||
|
QLabel *l = wrapper2.createWrappedLabel();
|
||||||
|
QCOMPARE( wrapper2.wrappedLabel(), l );
|
||||||
|
delete l;
|
||||||
|
|
||||||
|
// check that created widget starts with default value
|
||||||
|
param = TestParamType( QStringLiteral( "boolean" ), QStringLiteral( "bool" ), true );
|
||||||
|
QgsProcessingBooleanWidgetWrapper trueDefault( ¶m );
|
||||||
|
w = trueDefault.createWrappedWidget( context );
|
||||||
|
QVERIFY( trueDefault.value().toBool() );
|
||||||
|
delete w;
|
||||||
|
param = TestParamType( QStringLiteral( "boolean" ), QStringLiteral( "bool" ), false );
|
||||||
|
QgsProcessingBooleanWidgetWrapper falseDefault( ¶m );
|
||||||
|
w = falseDefault.createWrappedWidget( context );
|
||||||
|
QVERIFY( !falseDefault.value().toBool() );
|
||||||
|
delete w;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestProcessingGui::testBooleanWrapper()
|
||||||
|
{
|
||||||
|
TestParamType param( QStringLiteral( "boolean" ), QStringLiteral( "bool" ) );
|
||||||
|
|
||||||
|
// standard wrapper
|
||||||
|
QgsProcessingBooleanWidgetWrapper wrapper( ¶m );
|
||||||
|
|
||||||
|
QgsProcessingContext context;
|
||||||
|
QWidget *w = wrapper.createWrappedWidget( context );
|
||||||
|
wrapper.setWidgetValue( true, context );
|
||||||
|
QVERIFY( wrapper.value().toBool() );
|
||||||
|
QVERIFY( static_cast< QCheckBox * >( wrapper.wrappedWidget() )->isChecked() );
|
||||||
|
wrapper.setWidgetValue( false, context );
|
||||||
|
QVERIFY( !wrapper.value().toBool() );
|
||||||
|
QVERIFY( !static_cast< QCheckBox * >( wrapper.wrappedWidget() )->isChecked() );
|
||||||
|
|
||||||
|
// should be no label in standard mode
|
||||||
|
QVERIFY( !wrapper.createWrappedLabel() );
|
||||||
|
QCOMPARE( static_cast< QCheckBox * >( wrapper.wrappedWidget() )->text(), QStringLiteral( "bool" ) );
|
||||||
|
delete w;
|
||||||
|
|
||||||
|
// batch wrapper
|
||||||
|
QgsProcessingBooleanWidgetWrapper wrapperB( ¶m, QgsAbstractProcessingParameterWidgetWrapper::Batch );
|
||||||
|
|
||||||
|
w = wrapperB.createWrappedWidget( context );
|
||||||
|
wrapperB.setWidgetValue( true, context );
|
||||||
|
QVERIFY( wrapperB.value().toBool() );
|
||||||
|
QVERIFY( static_cast< QComboBox * >( wrapperB.wrappedWidget() )->currentData().toBool() );
|
||||||
|
wrapperB.setWidgetValue( false, context );
|
||||||
|
QVERIFY( !wrapperB.value().toBool() );
|
||||||
|
QVERIFY( !static_cast< QComboBox * >( wrapperB.wrappedWidget() )->currentData().toBool() );
|
||||||
|
|
||||||
|
// should be no label in batch mode
|
||||||
|
QVERIFY( !wrapperB.createWrappedLabel() );
|
||||||
|
delete w;
|
||||||
|
}
|
||||||
|
|
||||||
QGSTEST_MAIN( TestProcessingGui )
|
QGSTEST_MAIN( TestProcessingGui )
|
||||||
#include "testprocessinggui.moc"
|
#include "testprocessinggui.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user