Skip to content

Commit

Permalink
[processing] Port DestinationSelectionPanel to c++
Browse files Browse the repository at this point in the history
This is basically a 1:1 port (+some fixes relating to incorrect signal
emissions and many more tests)
  • Loading branch information
nyalldawson committed Mar 16, 2020
1 parent 2b88519 commit 517aa96
Show file tree
Hide file tree
Showing 19 changed files with 1,385 additions and 147 deletions.
Expand Up @@ -107,6 +107,8 @@ You can use QgsXmlUtils.readVariant to load it from an XML document.

operator QVariant() const;

bool operator==( const QgsProcessingOutputLayerDefinition &other ) const;

};


Expand Down
@@ -0,0 +1,78 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingoutputdestinationwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProcessingLayerOutputDestinationWidget : QWidget
{
%Docstring
A widget which allows users to select the destination path for an output style Processing parameter.

.. note::

Not stable API

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsprocessingoutputdestinationwidget.h"
%End
public:

QgsProcessingLayerOutputDestinationWidget( const QgsProcessingDestinationParameter *parameter, bool defaultSelection, QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsProcessingLayerOutputDestinationWidget, associated with the specified ``parameter``.
%End

bool outputIsSkipped() const;
%Docstring
Returns ``True`` if the output is set to be skipped.
%End

void setValue( const QVariant &value );
%Docstring
Sets the ``value`` to show in the widget.
%End

QVariant value() const;
%Docstring
Returns the widgets current value.
%End

void setWidgetContext( const QgsProcessingParameterWidgetContext &context );
%Docstring
Sets the ``context`` in which the widget is shown, e.g., the
parent model algorithm, a linked map canvas, and other relevant information which allows the widget
to fine-tune its behavior.
%End

signals:

void skipOutputChanged( bool skipped );
%Docstring
Emitted whenever the "skip output" option is toggled in the widget.
%End

void destinationChanged();
%Docstring
Emitted whenever the destination value is changed in the widget.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingoutputdestinationwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
Expand Up @@ -88,6 +88,24 @@ to the user.

.. seealso:: :py:func:`setMessageBar`

.. versionadded:: 3.12
%End

void setBrowserModel( QgsBrowserGuiModel *model );
%Docstring
Sets the browser ``model`` associated with the widget. This will usually be the shared app instance of the browser model

.. seealso:: :py:func:`browserModel`

.. versionadded:: 3.14
%End

QgsBrowserGuiModel *browserModel() const;
%Docstring
Returns the browser model associated with the widget.

.. seealso:: :py:func:`setBrowserModel`

.. versionadded:: 3.12
%End

Expand Down
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -309,6 +309,7 @@
%Include auto_generated/processing/qgsprocessingmaplayercombobox.sip
%Include auto_generated/processing/qgsprocessingmodelerparameterwidget.sip
%Include auto_generated/processing/qgsprocessingmultipleselectiondialog.sip
%Include auto_generated/processing/qgsprocessingoutputdestinationwidget.sip
%Include auto_generated/processing/qgsprocessingparameterdefinitionwidget.sip
%Include auto_generated/processing/qgsprocessingrecentalgorithmlog.sip
%Include auto_generated/processing/qgsprocessingtoolboxmodel.sip
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
Expand Up @@ -37,14 +37,14 @@
QgsProcessingParameterDefinition)
from qgis.gui import (QgsMessageBar,
QgsProjectionSelectionWidget,
QgsProcessingAlgorithmDialogBase)
QgsProcessingAlgorithmDialogBase,
QgsProcessingLayerOutputDestinationWidget)

from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
from processing.gui.ParametersPanel import ParametersPanel
from processing.gui.MultipleInputPanel import MultipleInputPanel
from processing.gui.NumberInputPanel import NumberInputPanel
from processing.gui.DestinationSelectionPanel import DestinationSelectionPanel
from processing.gui.wrappers import WidgetWrapper
from processing.tools.dataobjects import createContext

Expand Down Expand Up @@ -115,7 +115,7 @@ def connectWidgetChangedSignals(self, w):
w.selectionChanged.connect(self.parametersHaveChanged)
elif isinstance(w, NumberInputPanel):
w.hasChanged.connect(self.parametersHaveChanged)
elif isinstance(w, DestinationSelectionPanel):
elif isinstance(w, QgsProcessingLayerOutputDestinationWidget):
w.destinationChanged.connect(self.parametersHaveChanged)

def parametersHaveChanged(self):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -153,7 +153,7 @@ def getParameterValues(self):
dest_project = QgsProject.instance()

widget = self.mainWidget().outputWidgets[param.name()]
value = widget.getValue()
value = widget.value()

if value and isinstance(value, QgsProcessingOutputLayerDefinition):
value.destinationProject = dest_project
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/gui/DestinationSelectionPanel.py
Expand Up @@ -69,12 +69,11 @@ class DestinationSelectionPanel(BASE, WIDGET):
skipOutputChanged = pyqtSignal(bool)
destinationChanged = pyqtSignal()

def __init__(self, parameter, alg, default_selection=False):
def __init__(self, parameter, default_selection=False):
super(DestinationSelectionPanel, self).__init__(None)
self.setupUi(self)

self.parameter = parameter
self.alg = alg
self.default_selection = default_selection
settings = QgsSettings()
self.encoding = settings.value('/Processing/encoding', 'System')
Expand Down
11 changes: 7 additions & 4 deletions python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -42,7 +42,8 @@
QgsProcessingModelAlgorithm,
QgsVectorFileWriter)
from qgis.gui import (QgsProcessingContextGenerator,
QgsProcessingParameterWidgetContext)
QgsProcessingParameterWidgetContext,
QgsProcessingLayerOutputDestinationWidget)
from qgis.utils import iface

from qgis.PyQt import uic
Expand All @@ -52,7 +53,6 @@
from qgis.PyQt.QtGui import QIcon
from osgeo import gdal

from processing.gui.DestinationSelectionPanel import DestinationSelectionPanel
from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
from processing.tools.dataobjects import createContext

Expand Down Expand Up @@ -132,6 +132,7 @@ def initWidgets(self):
widget_context.setMessageBar(self.parent.messageBar())
if isinstance(self.alg, QgsProcessingModelAlgorithm):
widget_context.setModel(self.alg)
widget_context.setBrowserModel(iface.browserModel())

# Create widgets and put them in layouts
for param in self.alg.parameterDefinitions():
Expand Down Expand Up @@ -220,7 +221,9 @@ def initWidgets(self):
continue

label = QLabel(output.description())
widget = DestinationSelectionPanel(output, self.alg)
widget = QgsProcessingLayerOutputDestinationWidget(output, False)
widget.setWidgetContext(widget_context)

self.layoutMain.insertWidget(self.layoutMain.count() - 1, label)
self.layoutMain.insertWidget(self.layoutMain.count() - 1, widget)
if isinstance(output, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)):
Expand All @@ -232,7 +235,7 @@ def skipOutputChanged(widget, checkbox, skipped):
enabled = not skipped

# Do not try to open formats that are write-only.
value = widget.getValue()
value = widget.value()
if value and isinstance(value, QgsProcessingOutputLayerDefinition) and isinstance(output, (
QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)):
filename = value.sink.staticValue()
Expand Down
Expand Up @@ -38,7 +38,10 @@
QWidget,
QTextEdit)

from qgis.gui import QgsExpressionLineEdit, QgsProjectionSelectionWidget
from qgis.gui import (QgsExpressionLineEdit,
QgsProjectionSelectionWidget,
QgsProcessingLayerOutputDestinationWidget
)
from qgis.core import (QgsApplication,
QgsSettings,
QgsProcessing,
Expand Down Expand Up @@ -68,7 +71,6 @@
QgsProcessingParameterRasterDestination,
QgsProcessingParameterVectorDestination)

from processing.gui.DestinationSelectionPanel import DestinationSelectionPanel
from processing.gui.enummodelerwidget import EnumModelerWidget
from processing.gui.matrixmodelerwidget import MatrixModelerWidget
from processing.core import parameters
Expand Down Expand Up @@ -364,7 +366,7 @@ def setupUi(self):

elif isinstance(self.param, QgsProcessingDestinationParameter):
self.verticalLayout.addWidget(QLabel(self.tr('Default value')))
self.defaultWidget = DestinationSelectionPanel(self.param, self.alg, default_selection=True)
self.defaultWidget = QgsProcessingLayerOutputDestinationWidget(self.param, defaultSelection=True)
self.verticalLayout.addWidget(self.defaultWidget)

self.verticalLayout.addSpacing(20)
Expand Down Expand Up @@ -562,29 +564,29 @@ def accept(self):
name=name,
description=self.param.description(),
type=self.param.dataType(),
defaultValue=self.defaultWidget.getValue())
defaultValue=self.defaultWidget.value())
elif (isinstance(self.param, QgsProcessingParameterFileDestination)):
self.param = QgsProcessingParameterFileDestination(
name=name,
description=self.param.description(),
fileFilter=self.param.fileFilter(),
defaultValue=self.defaultWidget.getValue())
defaultValue=self.defaultWidget.value())
elif (isinstance(self.param, QgsProcessingParameterFolderDestination)):
self.param = QgsProcessingParameterFolderDestination(
name=name,
description=self.param.description(),
defaultValue=self.defaultWidget.getValue())
defaultValue=self.defaultWidget.value())
elif (isinstance(self.param, QgsProcessingParameterRasterDestination)):
self.param = QgsProcessingParameterRasterDestination(
name=name,
description=self.param.description(),
defaultValue=self.defaultWidget.getValue())
defaultValue=self.defaultWidget.value())
elif (isinstance(self.param, QgsProcessingParameterVectorDestination)):
self.param = QgsProcessingParameterVectorDestination(
name=name,
description=self.param.description(),
type=self.param.dataType(),
defaultValue=self.defaultWidget.getValue())
defaultValue=self.defaultWidget.value())

else:
if self.paramType:
Expand Down

0 comments on commit 517aa96

Please sign in to comment.