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, the order might not be kept every time." );
65 QgsOrderByExpressionAlgorithm *QgsOrderByExpressionAlgorithm::createInstance()
const 67 return new QgsOrderByExpressionAlgorithm();
72 std::unique_ptr< QgsFeatureSource > source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
76 QString expressionString = parameterAsExpression( parameters, QStringLiteral(
"EXPRESSION" ), context );
78 bool ascending = parameterAsBool( parameters, QStringLiteral(
"ASCENDING" ), context );
79 bool nullsFirst = parameterAsBool( parameters, QStringLiteral(
"NULLS_FIRST" ), context );
82 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral(
"OUTPUT" ), context, sinkId, source->fields(), source->wkbType(), source->sourceCrs() ) );
86 long count = source->featureCount();
87 double step = count > 0 ? 100.0 / count : 1;
91 request.
addOrderBy( expressionString, ascending, nullsFirst );
101 sink->addFeature( inFeature );
107 outputs.insert( QStringLiteral(
"OUTPUT" ), sinkId );
A boolean parameter for processing algorithms.
Wrapper for iterator of features from vector data provider or vector layer.
Base class for providing feedback from a processing algorithm.
An expression parameter for processing algorithms.
void setProgress(double progress)
Sets the current progress for the feedback object.
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 id, geometry and a list of field/values...
A feature sink output for processing algorithms.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Custom exception class for processing related exceptions.
bool isCanceled() const
Tells whether the operation has been canceled already.
An input feature source (such as vector layers) parameter for processing algorithms.
bool nextFeature(QgsFeature &f)
Contains information about the context in which a processing algorithm is executed.