Skip to content
Permalink
Browse files

Move processing algorithm configuration code to gui lib

  • Loading branch information
m-kuhn committed Apr 9, 2018
1 parent 31d7e4b commit eb39d2379c130218182f2f7e66ce3772428d02c0
@@ -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
@@ -168,6 +168,7 @@ their acceptable ranges, defaults, etc.
FlagAdvanced,
FlagHidden,
FlagOptional,
FlagIsModelOutput,
};
typedef QFlags<QgsProcessingParameterDefinition::Flag> Flags;

@@ -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 );
@@ -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
@@ -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();
};




@@ -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 *
************************************************************************/
@@ -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.
@@ -53,7 +53,8 @@
QgsProcessingOutputDefinition,
QgsSettings)

from qgis.gui import (QgsMessageBar,
from qgis.gui import (QgsGui,
QgsMessageBar,
QgsScrollArea,
QgsFilterLineEdit,
QgsHelp)
@@ -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)
@@ -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
@@ -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() ) );
}
@@ -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 );
}

@@ -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 );
@@ -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"
@@ -1458,7 +1457,6 @@ QgisApp::~QgisApp()

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

unregisterCustomLayoutDropHandler( mLayoutQptDropHandler );

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

void QgisApp::initLayouts()
@@ -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
@@ -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
@@ -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 )

@@ -18,7 +18,6 @@
#include "qgsprocessingregistry.h"
#include "qgsvectorfilewriter.h"
#include "qgsprocessingparametertypeimpl.h"
#include "qgsprocessingalgorithmconfigurationwidget.h"

QgsProcessingRegistry::QgsProcessingRegistry( QObject *parent SIP_TRANSFERTHIS )
: QObject( parent )
@@ -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;
}

@@ -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.
@@ -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
@@ -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
@@ -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})

@@ -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

0 comments on commit eb39d23

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