25 QString QgsOrderByExpressionAlgorithm::name()
const
27 return QStringLiteral(
"orderbyexpression" );
30 QString QgsOrderByExpressionAlgorithm::displayName()
const
32 return QObject::tr(
"Order by expression" );
35 QStringList QgsOrderByExpressionAlgorithm::tags()
const
37 return QObject::tr(
"orderby,sort,expression,field" ).split(
',' );
40 QString QgsOrderByExpressionAlgorithm::group()
const
42 return QObject::tr(
"Vector general" );
45 QString QgsOrderByExpressionAlgorithm::groupId()
const
47 return QStringLiteral(
"vectorgeneral" );
50 void QgsOrderByExpressionAlgorithm::initAlgorithm(
const QVariantMap & )
60 QString QgsOrderByExpressionAlgorithm::shortHelpString()
const
62 return QObject::tr(
"This algorithm sorts a vector layer according to an expression. Be careful, it might not work as expected with some providers, "
63 "the order might not be kept every time.\n\n"
64 "For help with QGIS expression functions, see the inbuilt help for specific functions "
65 "which is available in the expression builder." );
68 QgsOrderByExpressionAlgorithm *QgsOrderByExpressionAlgorithm::createInstance()
const
70 return new QgsOrderByExpressionAlgorithm();
75 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
79 const QString expressionString = parameterAsExpression( parameters, QStringLiteral(
"EXPRESSION" ), context );
81 const bool ascending = parameterAsBoolean( parameters, QStringLiteral(
"ASCENDING" ), context );
82 const bool nullsFirst = parameterAsBoolean( parameters, QStringLiteral(
"NULLS_FIRST" ), context );
85 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, sinkId, source->fields(), source->wkbType(), source->sourceCrs() ) );
89 const long count = source->featureCount();
90 const double step = count > 0 ? 100.0 / count : 1;
94 request.
addOrderBy( expressionString, ascending, nullsFirst );
104 if ( !sink->addFeature( inFeature ) )
111 outputs.insert( QStringLiteral(
"OUTPUT" ), sinkId );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & addOrderBy(const QString &expression, bool ascending=true)
Adds a new OrderByClause, appending it as the least important one.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Base class for providing feedback from a processing algorithm.
A boolean parameter for processing algorithms.
An expression parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...