Skip to content

Commit 06a20b9

Browse files
committed
Add UseSelection flag to QgsProcessingContext
Indicates whether only selected features should be used in algorithms
1 parent dd4f530 commit 06a20b9

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

python/core/processing/qgsprocessingcontext.sip

+29-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,28 @@ class QgsProcessingContext
2626
%End
2727
public:
2828

29+
enum Flag
30+
{
31+
UseSelection,
32+
};
33+
typedef QFlags<QgsProcessingContext::Flag> Flags;
34+
35+
2936
QgsProcessingContext();
3037

38+
QgsProcessingContext::Flags flags() const;
39+
%Docstring
40+
Returns any flags set in the context.
41+
\see setFlags()
42+
:rtype: QgsProcessingContext.Flags
43+
%End
44+
45+
void setFlags( const QgsProcessingContext::Flags &flags );
46+
%Docstring
47+
Sets ``flags`` for the context.
48+
\see flags()
49+
%End
50+
3151
QgsProject *project() const;
3252
%Docstring
3353
Returns the project in which the algorithm is being executed.
@@ -58,11 +78,19 @@ class QgsProcessingContext
5878

5979

6080

81+
82+
83+
QFlags<QgsProcessingContext::Flag> operator|(QgsProcessingContext::Flag f1, QFlags<QgsProcessingContext::Flag> f2);
84+
85+
86+
87+
88+
89+
6190
/************************************************************************
6291
* This file has been generated automatically from *
6392
* *
6493
* src/core/processing/qgsprocessingcontext.h *
6594
* *
6695
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
6796
************************************************************************/
68-

python/plugins/processing/tools/general.py

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from processing.core.Processing import Processing
4242
from processing.core.parameters import ParameterSelection
4343
from processing.gui.Postprocessing import handleAlgorithmResults
44+
from processing.core.ProcessingConfig import ProcessingConfig
4445

4546

4647
def algorithmOptions(id):
@@ -102,4 +103,9 @@ def createContext():
102103
"""
103104
context = QgsProcessingContext()
104105
context.setProject(QgsProject.instance())
106+
107+
use_selection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
108+
if use_selection:
109+
context.setFlags(QgsProcessingContext.UseSelection)
110+
105111
return context

src/core/processing/qgsprocessingcontext.h

+29
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,27 @@ class CORE_EXPORT QgsProcessingContext
3737
{
3838
public:
3939

40+
//! Flags that affect how processing algorithms are run
41+
enum Flag
42+
{
43+
UseSelection = 1 << 0, //!< Filter to selected features when running algorithms
44+
};
45+
Q_DECLARE_FLAGS( Flags, Flag )
46+
4047
QgsProcessingContext() = default;
4148

49+
/**
50+
* Returns any flags set in the context.
51+
* \see setFlags()
52+
*/
53+
QgsProcessingContext::Flags flags() const { return mFlags; }
54+
55+
/**
56+
* Sets \a flags for the context.
57+
* \see flags()
58+
*/
59+
void setFlags( const QgsProcessingContext::Flags &flags ) { mFlags = flags; }
60+
4261
/**
4362
* Returns the project in which the algorithm is being executed.
4463
* \see setProject()
@@ -63,12 +82,22 @@ class CORE_EXPORT QgsProcessingContext
6382

6483
private:
6584

85+
QgsProcessingContext::Flags mFlags = 0;
86+
6687
QPointer< QgsProject > mProject;
6788

6889
QgsExpressionContext mExpressionContext;
6990

7091
};
7192

93+
94+
95+
96+
97+
98+
99+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingContext::Flags )
100+
72101
#endif // QGSPROCESSINGPARAMETERS_H
73102

74103

0 commit comments

Comments
 (0)