Skip to content

Commit

Permalink
Move processing algorithm configuration code to gui lib
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 9, 2018
1 parent 31d7e4b commit eb39d23
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 187 deletions.
1 change: 0 additions & 1 deletion python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatormodel.sip
%Include processing/qgsprocessingalgorithmconfigurationwidget.sip
%Include processing/qgsprocessingalgrunnertask.sip
%Include processing/qgsprocessingfeedback.sip
%Include processing/qgsprocessingprovider.sip
Expand Down
1 change: 1 addition & 0 deletions python/core/processing/qgsprocessingparameters.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ their acceptable ranges, defaults, etc.
FlagAdvanced,
FlagHidden,
FlagOptional,
FlagIsModelOutput,
};
typedef QFlags<QgsProcessingParameterDefinition::Flag> Flags;

Expand Down
24 changes: 0 additions & 24 deletions python/core/processing/qgsprocessingregistry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,6 @@ Return a list with all known parameter types.
.. versionadded:: 3.2
%End

void addAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory /Transfer/ );
%Docstring
Add a new configuration widget factory for customized algorithm configuration
widgets. Ownership is taken.

.. versionadded:: 3.2
%End

void removeAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory );
%Docstring
Remove a configuration widget factory for customized algorithm configuration
widgets.

.. versionadded:: 3.2
%End

QgsProcessingAlgorithmConfigurationWidget *algorithmConfigurationWidget( QgsProcessingAlgorithm *algorithm ) const;
%Docstring
algorithmConfigurationWidget
@param algorithm
@return
%End


signals:

void providerAdded( const QString &id );
Expand Down
2 changes: 2 additions & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@
%Include layout/qgslayoutviewtooltemporarymousepan.sip
%Include layout/qgslayoutviewtoolzoom.sip
%Include locator/qgslocatorwidget.sip
%Include processing/qgsprocessingalgorithmconfigurationwidget.sip
%Include processing/qgsprocessingalgorithmdialogbase.sip
%Include processing/qgsprocessingconfigurationwidgets.sip
%Include processing/qgsprocessingguiregistry.sip
%Include qgsadvanceddigitizingcanvasitem.sip
38 changes: 0 additions & 38 deletions python/gui/processing/qgsprocessingconfigurationwidgets.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,6 @@



class QgsProcessingConfigurationWidgets
{
%Docstring
This class is responsible for the management of processing widgets which
QGIS internally.

Standalone applications that require to show configuration widgets for processing
algorithms will need to execute the following code to have the configuration
interfaces available.

.. code-block:: python

# At startup time
QgsApplicationProcessingConfigurationWidgets.initialize()

# At exit time
QgsApplicationProcessingConfigurationWidgets.cleanup()
%End

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

static void initialize();
%Docstring
Initialize native configuration widgets.
%End

static void cleanup();
%Docstring
Cleanup native configuration widgets.
%End

private:
QgsProcessingConfigurationWidgets();
};




Expand Down
61 changes: 61 additions & 0 deletions python/gui/processing/qgsprocessingguiregistry.sip.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingguiregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsProcessingGuiRegistry
{
%Docstring
The QgsProcessingGuiRegistry is a home for widgets for processing
configuration widgets.

.. versionadded:: 3.2
%End

%TypeHeaderCode
#include "qgsprocessingguiregistry.h"
%End
public:
QgsProcessingGuiRegistry();
~QgsProcessingGuiRegistry();

void addAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory /Transfer/ );
%Docstring
Add a new configuration widget factory for customized algorithm configuration
widgets. Ownership is taken.

.. versionadded:: 3.2
%End

void removeAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory );
%Docstring
Remove a configuration widget factory for customized algorithm configuration
widgets.

.. versionadded:: 3.2
%End

QgsProcessingAlgorithmConfigurationWidget *algorithmConfigurationWidget( QgsProcessingAlgorithm *algorithm ) const;
%Docstring
algorithmConfigurationWidget
@param algorithm
@return
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/processing/qgsprocessingguiregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions python/gui/qgsgui.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Returns the global map layer action registry, used for registering map layer act
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items.
%End

static QgsProcessingGuiRegistry *processingGuiRegistry();

static void enableAutoGeometryRestore( QWidget *widget, const QString &key = QString() );
%Docstring
Register the widget to allow its position to be automatically saved and restored when open and closed.
Expand Down
12 changes: 10 additions & 2 deletions python/plugins/processing/modeler/ModelerParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
QgsProcessingOutputDefinition,
QgsSettings)

from qgis.gui import (QgsMessageBar,
from qgis.gui import (QgsGui,
QgsMessageBar,
QgsScrollArea,
QgsFilterLineEdit,
QgsHelp)
Expand Down Expand Up @@ -119,7 +120,7 @@ def setupUi(self):
line.setFrameShape(QFrame.HLine)
line.setFrameShadow(QFrame.Sunken)
self.verticalLayout.addWidget(line)
self.algorithmItem = QgsApplication.instance().processingRegistry().algorithmConfigurationWidget(self._alg)
self.algorithmItem = QgsGui.instance().processingGuiRegistry().algorithmConfigurationWidget(self._alg)
if self.configuration:
self.algorithmItem.setConfiguration(self.configuration)
self.verticalLayout.addWidget(self.algorithmItem)
Expand Down Expand Up @@ -332,6 +333,13 @@ def createAlgorithm(self):
output.setChildOutputName(dest.name())
outputs[name] = output

if dest.flags() & QgsProcessingParameterDefinition.FlagIsModelOutput:
if not name in outputs:
output = QgsProcessingModelOutput(dest.name(), dest.name())
output.setChildId(alg.childId())
output.setChildOutputName(dest.name())
outputs[dest.name()] = output

alg.setModelOutputs(outputs)

selectedOptions = self.dependenciesPanel.selectedoptions
Expand Down
10 changes: 9 additions & 1 deletion src/analysis/processing/qgsalgorithmfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ void QgsFilterAlgorithm::initAlgorithm( const QVariantMap &configuration )
const QVariantMap outputDef = output.toMap();
const QString name = QStringLiteral( "OUTPUT_%1" ).arg( outputDef.value( QStringLiteral( "name" ) ).toString() );
QgsProcessingParameterFeatureSink *outputParam = new QgsProcessingParameterFeatureSink( name, outputDef.value( QStringLiteral( "name" ) ).toString() );
outputParam->setFlags( QgsProcessingParameterDefinition::FlagHidden );
QgsProcessingParameterDefinition::Flags flags = QgsProcessingParameterDefinition::Flags();
flags |= QgsProcessingParameterDefinition::FlagHidden;
if ( outputDef.value( QStringLiteral( "isModelOutput" ) ).toBool() )
flags |= QgsProcessingParameterDefinition::FlagIsModelOutput;
outputParam->setFlags( flags );
addParameter( outputParam );
mOutputs.append( new Output( name, outputDef.value( QStringLiteral( "expression" ) ).toString() ) );
}
Expand All @@ -92,6 +96,8 @@ QVariantMap QgsFilterAlgorithm::processAlgorithm( const QVariantMap &parameters,
for ( Output *output : qgis::as_const( mOutputs ) )
{
output->sink.reset( parameterAsSink( parameters, output->name, context, output->destinationIdentifier, source->fields(), source->wkbType(), source->sourceCrs() ) );
if ( !output->sink )
return QVariantMap();
output->expression.prepare( &expressionContext );
}

Expand All @@ -115,7 +121,9 @@ QVariantMap QgsFilterAlgorithm::processAlgorithm( const QVariantMap &parameters,
for ( Output *output : qgis::as_const( mOutputs ) )
{
if ( output->expression.evaluate( &expressionContext ).toBool() )
{
output->sink->addFeature( f, QgsFeatureSink::FastInsert );
}
}

feedback->setProgress( current * step );
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsruntimeprofiler.h"
#include "qgshandlebadlayers.h"
#include "qgsprintlayout.h"
#include "qgsprocessingconfigurationwidgets.h"
#include "qgsprocessingregistry.h"
#include "qgsproject.h"
#include "qgsprojectlayergroupdialog.h"
Expand Down Expand Up @@ -1458,7 +1457,6 @@ QgisApp::~QgisApp()

// cancel request for FileOpen events
QgsApplication::setFileOpenEventReceiver( nullptr );
QgsProcessingConfigurationWidgets::cleanup();

unregisterCustomLayoutDropHandler( mLayoutQptDropHandler );

Expand Down Expand Up @@ -10497,7 +10495,6 @@ void QgisApp::initNativeProcessing()
#ifdef HAVE_3D
QgsApplication::processingRegistry()->addProvider( new Qgs3DAlgorithms( QgsApplication::processingRegistry() ) );
#endif
QgsProcessingConfigurationWidgets::initialize();
}

void QgisApp::initLayouts()
Expand Down
2 changes: 0 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ SET(QGIS_CORE_SRCS
locator/qgslocatormodel.cpp

processing/qgsprocessingalgorithm.cpp
processing/qgsprocessingalgorithmconfigurationwidget.cpp
processing/qgsprocessingalgrunnertask.cpp
processing/qgsprocessingcontext.cpp
processing/qgsprocessingfeedback.cpp
Expand Down Expand Up @@ -669,7 +668,6 @@ SET(QGIS_CORE_MOC_HDRS
locator/qgslocatorfilter.h
locator/qgslocatormodel.h

processing/qgsprocessingalgorithmconfigurationwidget.h
processing/qgsprocessingalgrunnertask.h
processing/qgsprocessingfeedback.h
processing/qgsprocessingprovider.h
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class CORE_EXPORT QgsProcessingParameterDefinition
FlagAdvanced = 1 << 1, //!< Parameter is an advanced parameter which should be hidden from users by default
FlagHidden = 1 << 2, //!< Parameter is hidden and should not be shown to users
FlagOptional = 1 << 3, //!< Parameter is optional
FlagIsModelOutput = 1 << 4, //!< Destination parameter is final output. The parameter name will be used.
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down
26 changes: 0 additions & 26 deletions src/core/processing/qgsprocessingregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "qgsprocessingregistry.h"
#include "qgsvectorfilewriter.h"
#include "qgsprocessingparametertypeimpl.h"
#include "qgsprocessingalgorithmconfigurationwidget.h"

QgsProcessingRegistry::QgsProcessingRegistry( QObject *parent SIP_TRANSFERTHIS )
: QObject( parent )
Expand Down Expand Up @@ -189,28 +188,3 @@ QList<QgsProcessingParameterType *> QgsProcessingRegistry::parameterTypes() cons
{
return mParameterTypes.values();
}

void QgsProcessingRegistry::addAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory )
{
mAlgorithmConfigurationWidgetFactories.append( factory );
}

void QgsProcessingRegistry::removeAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory )
{
mAlgorithmConfigurationWidgetFactories.removeAll( factory );
delete factory;
}

QgsProcessingAlgorithmConfigurationWidget *QgsProcessingRegistry::algorithmConfigurationWidget( QgsProcessingAlgorithm *algorithm ) const
{
for ( const auto *factory : mAlgorithmConfigurationWidgetFactories )
{
if ( factory->canCreateFor( algorithm ) )
{
return factory->create( algorithm );
}
}

return nullptr;
}

26 changes: 0 additions & 26 deletions src/core/processing/qgsprocessingregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,30 +169,6 @@ class CORE_EXPORT QgsProcessingRegistry : public QObject
*/
QList<QgsProcessingParameterType *> parameterTypes() const;

/**
* Add a new configuration widget factory for customized algorithm configuration
* widgets. Ownership is taken.
*
* \since QGIS 3.2
*/
void addAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory SIP_TRANSFER );

/**
* Remove a configuration widget factory for customized algorithm configuration
* widgets.
*
* \since QGIS 3.2
*/
void removeAlgorithmConfigurationWidgetFactory( QgsProcessingAlgorithmConfigurationWidgetFactory *factory );

/**
* @brief algorithmConfigurationWidget
* @param algorithm
* @return
*/
QgsProcessingAlgorithmConfigurationWidget *algorithmConfigurationWidget( QgsProcessingAlgorithm *algorithm ) const;


signals:

//! Emitted when a provider has been added to the registry.
Expand Down Expand Up @@ -224,8 +200,6 @@ class CORE_EXPORT QgsProcessingRegistry : public QObject
//! Hash of available parameter types by id. This object owns the pointers.
QMap<QString, QgsProcessingParameterType *> mParameterTypes;

QList <QgsProcessingAlgorithmConfigurationWidgetFactory *> mAlgorithmConfigurationWidgetFactories;

#ifdef SIP_RUN
QgsProcessingRegistry( const QgsProcessingRegistry &other );
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ SET(QGIS_GUI_SRCS
ogr/qgsnewogrconnection.cpp
ogr/qgsvectorlayersaveasdialog.cpp

processing/qgsprocessingalgorithmconfigurationwidget.cpp
processing/qgsprocessingalgorithmdialogbase.cpp
processing/qgsprocessingconfigurationwidgets.cpp
processing/qgsprocessingguiregistry.cpp

qgisinterface.cpp
qgsactionmenu.cpp
Expand Down Expand Up @@ -710,8 +712,10 @@ SET(QGIS_GUI_MOC_HDRS

locator/qgslocatorwidget.h

processing/qgsprocessingalgorithmconfigurationwidget.h
processing/qgsprocessingalgorithmdialogbase.h
processing/qgsprocessingconfigurationwidgets.h
processing/qgsprocessingguiregistry.h
)
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_MOC_HDRS ${QGIS_GUI_MOC_HDRS})

Expand Down Expand Up @@ -870,10 +874,11 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/gui/auth
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/layout
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/ogr
${CMAKE_SOURCE_DIR}/src/gui/processing
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/annotations
${CMAKE_SOURCE_DIR}/src/core/auth
Expand Down
Loading

0 comments on commit eb39d23

Please sign in to comment.