QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
21 : QAbstractListModel( parent ),
22 mCurrentLayer( nullptr )
30 if ( parent.isValid() )
33 return mFeatures.count();
40 if ( !mFeatureTitleField.isEmpty() )
43 if ( !title.isEmpty() )
48 context.setFeature( featurePair.
feature() );
50 title = expr.evaluate( &context ).toString();
52 if ( title.isEmpty() )
60 int row = index.row();
61 if ( row < 0 || row >= mFeatures.count() )
64 if ( !index.isValid() )
73 case Feature:
return QVariant::fromValue<QgsFeature>( pair.
feature() );
77 case Qt::DisplayRole:
return featureTitle( pair );
85 if ( mFilterExpression.isEmpty() )
94 if ( attrValue.toLower().indexOf( mFilterExpression.toLower() ) != -1 )
100 QString QgsQuickFeaturesListModel::buildFilterExpression()
102 if ( mFilterExpression.isEmpty() || !mCurrentLayer )
106 QStringList expressionParts;
108 bool filterExpressionIsNumeric;
109 int filterInt = mFilterExpression.toInt( &filterExpressionIsNumeric );
110 Q_UNUSED( filterInt );
116 else if (
field.
type() == QVariant::String )
120 QString expression = QStringLiteral(
"(%1)" ).arg( expressionParts.join( QLatin1String(
" ) OR ( " ) ) );
125 void QgsQuickFeaturesListModel::loadFeaturesFromLayer(
QgsVectorLayer *layer )
127 if ( layer && layer->
isValid() )
128 mCurrentLayer = layer;
136 if ( !mFilterExpression.isEmpty() )
164 setKeyField( fields.
field( config.value( QStringLiteral(
"Key" ) ).toString() ).name() );
167 loadFeaturesFromLayer( layer );
178 loadFeaturesFromLayer( layer );
184 loadFeaturesFromLayer();
187 void QgsQuickFeaturesListModel::emptyData()
190 mCurrentLayer =
nullptr;
192 mFeatureTitleField.clear();
193 mFilterExpression.clear();
198 QHash<int, QByteArray>
roleNames = QAbstractListModel::roleNames();
217 return mFilterExpression;
225 loadFeaturesFromLayer();
230 mFeatureTitleField = attribute;
235 mKeyField = attribute;
240 return FEATURES_LIMIT;
245 for (
int i = 0; i < mFeatures.count(); ++i )
247 QVariant d =
data( index( i, 0 ), role );
258 for (
int i = 0; i < mFeatures.count(); ++i )
260 QVariant d =
data( index( i, 0 ), role );
274 if ( i.feature().id() == featureId )
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void featuresCountChanged(int featuresCount)
featuresCountChanged Signal emitted when features are reloaded or layer is changed
void setKeyField(const QString &attribute)
Sets name of attribute used as "key" in value relation.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Container of fields for a vector layer.
void setFilterExpression(const QString &filterExpression)
setFilterExpression Sets filter expression, upon setting also reloads features from current layer wit...
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QString filterExpression
Filter Expression represents filter used when querying for data in current layer.
int featuresLimit
Property limiting maximum number of features queried from layer Read only property.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsQuickFeaturesListModel(QObject *parent=nullptr)
Create features list model.
Q_GADGET QgsVectorLayer * layer
Vector layer to which the feature belongs.
Q_INVOKABLE int keyFromAttribute(const int role, const QVariant &value) const
keyFromAttribute finds feature with requested role and value, returns keycolumn
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void filterExpressionChanged(QString filterExpression)
Signal emitted when filter expression has changed.
QgsFeature feature
Feature that belongs to layer.
Q_INVOKABLE QgsQuickFeatureLayerPair featureLayerPair(const int &featureId)
Function to get QgsQuickFeatureLayerPair by feature id.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
bool nextFeature(QgsFeature &f)
@ KeyColumn
secondary text in list view
Q_INVOKABLE void reloadFeatures()
reloadFeatures reloads features from current layer
Represents a vector layer which manages a vector based data sets.
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
int featuresCount
Read only property holding true number of features in layer - not only requested features Changing fi...
Q_INVOKABLE void setupValueRelation(const QVariantMap &config)
setupValueRelation populates model with value relation data from config
Pair of QgsFeature and QgsVectorLayer.
@ FoundPair
key in value relation
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Class for parsing and evaluation of expressions (formerly called "search strings").
QString displayExpression
Wrapper for iterator of features from vector data provider or vector layer.
Q_INVOKABLE void populateFromLayer(QgsVectorLayer *layer)
populateFromLayer populates model with features from layer
Q_INVOKABLE int rowFromAttribute(const int role, const QVariant &value) const
rowFromAttribute finds feature with requested role and value, returns its row
QHash< int, QByteArray > roleNames() const override
void setFeatureTitleField(const QString &attribute)
setFeatureTitleField Sets name of attribute that will be used for FeatureTitle and Qt::DisplayRole
Encapsulate a field in an attribute table or data source.