Skip to content

Commit

Permalink
Add UseSelection flag to QgsProcessingContext
Browse files Browse the repository at this point in the history
Indicates whether only selected features should be used in
algorithms
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent dd4f530 commit 06a20b9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
30 changes: 29 additions & 1 deletion python/core/processing/qgsprocessingcontext.sip
Expand Up @@ -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.
Expand Down Expand Up @@ -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 *
************************************************************************/

6 changes: 6 additions & 0 deletions python/plugins/processing/tools/general.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
29 changes: 29 additions & 0 deletions src/core/processing/qgsprocessingcontext.h
Expand Up @@ -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()
Expand All @@ -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


Expand Down

0 comments on commit 06a20b9

Please sign in to comment.