15#ifndef QGSFEATUREEXPRESSIONVALUESGATHERER_H
16#define QGSFEATUREEXPRESSIONVALUESGATHERER_H
38class QgsFeatureExpressionValuesGatherer :
public QThread
50 QgsFeatureExpressionValuesGatherer(
54 , mDisplayExpression( displayExpression.isEmpty() ? layer->
displayExpression() : displayExpression )
57 , mIdentifierFields( identifierFields )
60 QgsFeatureExpressionValuesGatherer(
62 const QString &displayExpression = QString(),
63 const QString &orderExpression = QString(),
65 const QStringList &identifierFields = QStringList()
68 , mDisplayExpression( displayExpression.isEmpty() ? layer->
displayExpression() : displayExpression )
69 , mOrderExpression( orderExpression.isEmpty() ? displayExpression.isEmpty() ? layer->
displayExpression() : displayExpression : orderExpression )
72 , mIdentifierFields( identifierFields )
79 Entry(
const QVariantList &_identifierFields,
const QString &_value,
const QString &_orderValue,
const QgsFeature &_feature )
80 : identifierFields( _identifierFields )
83 , orderValue( _orderValue )
87 Entry(
const QVariantList &_identifierFields,
const QString &_value,
const QgsFeature &_feature )
88 : identifierFields( _identifierFields )
95 : featureId( _featureId )
100 QVariantList identifierFields;
106 bool operator()(
const Entry &lhs,
const Entry &rhs )
const;
113 mWasCanceled =
false;
117 mDisplayExpression.prepare( &mExpressionContext );
118 mOrderExpression.prepare( &mExpressionContext );
121 QList<int> attributeIndexes;
122 for (
auto it = mIdentifierFields.constBegin(); it != mIdentifierFields.constEnd(); ++it )
123 attributeIndexes << mSource->fields().indexOf( *it );
127 mExpressionContext.setFeature( feature );
128 QVariantList attributes;
129 for (
const int idx : attributeIndexes )
132 const QString expressionValue = mDisplayExpression.evaluate( &mExpressionContext ).toString();
133 const QString orderValue = mOrderExpression.evaluate( &mExpressionContext ).toString();
135 mEntries.append( Entry( attributes, expressionValue, orderValue, feature ) );
137 const QMutexLocker locker( &mCancelMutex );
146 const QMutexLocker locker( &mCancelMutex );
151 bool wasCanceled()
const
153 const QMutexLocker locker( &mCancelMutex );
157 QVector<Entry> entries()
const {
return mEntries; }
164 QVariant data()
const {
return mData; }
169 void setData(
const QVariant &data ) { mData = data; }
172 QVector<Entry> mEntries;
175 std::unique_ptr<QgsVectorLayerFeatureSource> mSource;
180 bool mWasCanceled =
false;
181 mutable QMutex mCancelMutex;
182 QStringList mIdentifierFields;
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Container of fields for a vector layer.
Partial snapshot of vector layer's state (only the members necessary for access to features).
Represents a vector layer which manages a vector based dataset.
QString displayExpression
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features