Skip to content
Permalink
Browse files
Add UseSelection flag to QgsProcessingContext
Indicates whether only selected features should be used in
algorithms
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent dd4f530 commit 06a20b935de482c69fd7555ddb8c81bb37b68f3c
Showing with 64 additions and 1 deletion.
  1. +29 −1 python/core/processing/qgsprocessingcontext.sip
  2. +6 −0 python/plugins/processing/tools/general.py
  3. +29 −0 src/core/processing/qgsprocessingcontext.h
@@ -26,8 +26,28 @@ class QgsProcessingContext
%End
public:

enum Flag
{
UseSelection,
};
typedef QFlags<QgsProcessingContext::Flag> Flags;


QgsProcessingContext();

QgsProcessingContext::Flags flags() const;
%Docstring
Returns any flags set in the context.
\see setFlags()
:rtype: QgsProcessingContext.Flags
%End

void setFlags( const QgsProcessingContext::Flags &flags );
%Docstring
Sets ``flags`` for the context.
\see flags()
%End

QgsProject *project() const;
%Docstring
Returns the project in which the algorithm is being executed.
@@ -58,11 +78,19 @@ class QgsProcessingContext





QFlags<QgsProcessingContext::Flag> operator|(QgsProcessingContext::Flag f1, QFlags<QgsProcessingContext::Flag> f2);






/************************************************************************
* This file has been generated automatically from *
* *
* src/core/processing/qgsprocessingcontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

@@ -41,6 +41,7 @@
from processing.core.Processing import Processing
from processing.core.parameters import ParameterSelection
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.ProcessingConfig import ProcessingConfig


def algorithmOptions(id):
@@ -102,4 +103,9 @@ def createContext():
"""
context = QgsProcessingContext()
context.setProject(QgsProject.instance())

use_selection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
if use_selection:
context.setFlags(QgsProcessingContext.UseSelection)

return context
@@ -37,8 +37,27 @@ class CORE_EXPORT QgsProcessingContext
{
public:

//! Flags that affect how processing algorithms are run
enum Flag
{
UseSelection = 1 << 0, //!< Filter to selected features when running algorithms
};
Q_DECLARE_FLAGS( Flags, Flag )

QgsProcessingContext() = default;

/**
* Returns any flags set in the context.
* \see setFlags()
*/
QgsProcessingContext::Flags flags() const { return mFlags; }

/**
* Sets \a flags for the context.
* \see flags()
*/
void setFlags( const QgsProcessingContext::Flags &flags ) { mFlags = flags; }

/**
* Returns the project in which the algorithm is being executed.
* \see setProject()
@@ -63,12 +82,22 @@ class CORE_EXPORT QgsProcessingContext

private:

QgsProcessingContext::Flags mFlags = 0;

QPointer< QgsProject > mProject;

QgsExpressionContext mExpressionContext;

};







Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingContext::Flags )

#endif // QGSPROCESSINGPARAMETERS_H


0 comments on commit 06a20b9

Please sign in to comment.