24using namespace Qt::StringLiterals;
28QString QgsSelectByExpressionAlgorithm::name()
const
30 return u
"selectbyexpression"_s;
33QString QgsSelectByExpressionAlgorithm::displayName()
const
35 return QObject::tr(
"Select by expression" );
38QStringList QgsSelectByExpressionAlgorithm::tags()
const
40 return QObject::tr(
"select,filter,expression,field" ).split(
',' );
43QString QgsSelectByExpressionAlgorithm::group()
const
45 return QObject::tr(
"Vector selection" );
48QString QgsSelectByExpressionAlgorithm::groupId()
const
50 return u
"vectorselection"_s;
53QString QgsSelectByExpressionAlgorithm::shortDescription()
const
55 return QObject::tr(
"Selects features from a vector layer based on a QGIS expression." );
58QString QgsSelectByExpressionAlgorithm::shortHelpString()
const
61 "This algorithm creates a selection in a vector layer. The criteria for selecting "
62 "features is based on a QGIS expression.\n\n"
63 "For help with QGIS expression functions, see the inbuilt help for specific "
64 "functions which is available in the expression builder."
73QgsSelectByExpressionAlgorithm *QgsSelectByExpressionAlgorithm::createInstance()
const
75 return new QgsSelectByExpressionAlgorithm();
78void QgsSelectByExpressionAlgorithm::initAlgorithm(
const QVariantMap & )
80 QStringList methods = QStringList()
81 << QObject::tr(
"creating new selection" )
82 << QObject::tr(
"adding to current selection" )
83 << QObject::tr(
"selecting within current selection" )
84 << QObject::tr(
"removing from current selection" );
88 addParameter(
new QgsProcessingParameterEnum( u
"SELECTION_METHOD"_s, QObject::tr(
"Modify current selection by" ), methods,
false, 0 ) );
92 auto methodParam = std::make_unique<QgsProcessingParameterEnum>(
94 QObject::tr(
"Modify current selection by" ),
95 QStringList() << QObject::tr(
"creating new selection" ) << QObject::tr(
"adding to current selection" ) << QObject::tr(
"removing from current selection" ) << QObject::tr(
"selecting within current selection" ),
100 addParameter( std::move( methodParam ) );
107 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, u
"INPUT"_s, context );
113 const QString expressionString = parameterAsExpression( parameters, u
"EXPRESSION"_s, context );
115 if ( expression.hasParserError() )
122 if ( parameters.value( u
"METHOD"_s ).isValid() )
124 method =
static_cast<Qgis::SelectBehavior>( parameterAsEnum( parameters, u
"METHOD"_s, context ) );
135 mLayerId = layer->
id();
148 results.insert( u
"OUTPUT"_s, mLayerId );
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ NotAvailableInStandaloneTool
Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms wh...
@ Hidden
Parameter is hidden and should not be shown to users.
SelectBehavior
Specifies how a selection should be applied.
@ IntersectSelection
Modify current selection to include only select features which match.
@ RemoveFromSelection
Remove from current selection.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A vector layer output for processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
An expression parameter for processing algorithms.
A vector layer (with or without geometry) parameter for processing algorithms.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE void selectByExpression(const QString &expression, Qgis::SelectBehavior behavior=Qgis::SelectBehavior::SetSelection, QgsExpressionContext *context=nullptr)
Selects matching features using an expression.
QgsExpressionContextScope * createExpressionContextScope() const final
This method needs to be reimplemented in all classes which implement this interface and return an exp...