QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsquickfeatureslistmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsquickfeatureslistmodel.h
3  ---------------------------
4  Date : Sep 2020
5  Copyright : (C) 2020 by Tomas Mizera
6  Email : tomas.mizera2 at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSQUICKFEATURESMODEL_H
17 #define QGSQUICKFEATURESMODEL_H
18 
19 #include <QAbstractListModel>
20 
21 #include "qgsvectorlayer.h"
24 
35 class QUICK_EXPORT QgsQuickFeaturesListModel : public QAbstractListModel
36 {
37  Q_OBJECT
38 
43  Q_PROPERTY( int featuresCount READ featuresCount NOTIFY featuresCountChanged )
44 
45 
49  Q_PROPERTY( QString searchExpression READ searchExpression WRITE setSearchExpression NOTIFY searchExpressionChanged )
50 
51 
55  Q_PROPERTY( int featuresLimit READ featuresLimit NOTIFY featuresLimitChanged )
56 
57 
61  Q_PROPERTY( QgsFeature currentFeature READ currentFeature WRITE setCurrentFeature NOTIFY currentFeatureChanged )
62 
63  public:
64 
67  {
68  FeatureTitle = Qt::UserRole + 1,
73  FoundPair
74  };
76 
78  explicit QgsQuickFeaturesListModel( QObject *parent = nullptr );
80 
82  Q_INVOKABLE QgsQuickFeatureLayerPair featureLayerPair( const int &featureId );
83 
84  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
85  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
86  QHash<int, QByteArray> roleNames() const override;
87 
92  Q_INVOKABLE void setupValueRelation( const QVariantMap &config );
93 
98  Q_INVOKABLE void populateFromLayer( QgsVectorLayer *layer );
99 
103  Q_INVOKABLE void reloadFeatures();
104 
112  Q_INVOKABLE int rowFromAttribute( const int role, const QVariant &value ) const;
113 
122  Q_INVOKABLE QVariant attributeFromValue( const int role, const QVariant &value, const int requestedRole ) const;
123 
131  Q_INVOKABLE QVariant convertMultivalueFormat( const QVariant &multivalue, const int requestedRole = Qt::DisplayRole );
132 
134  int featuresLimit() const;
136  int featuresCount() const;
138  QString searchExpression() const;
139 
144  void setSearchExpression( const QString &searchExpression );
145 
150  void setFeatureTitleField( const QString &attribute );
151 
153  void setKeyField( const QString &attribute );
154 
159  void setFilterExpression( const QString &filterExpression );
160 
162  void setCurrentFeature( QgsFeature feature );
163 
165  QgsFeature currentFeature() const;
166 
167  signals:
168 
173  void featuresCountChanged( int featuresCount );
174 
176  void featuresLimitChanged( int featuresLimit );
177 
179  void searchExpressionChanged( QString searchExpression );
180 
183 
184  private:
185 
187  void setupFeatureRequest( QgsFeatureRequest &request );
188 
190  void loadFeaturesFromLayer( QgsVectorLayer *layer = nullptr );
191 
193  void emptyData();
194 
196  QVariant featureTitle( const QgsQuickFeatureLayerPair &featurePair ) const;
197 
199  QString buildSearchExpression();
200 
202  QString foundPair( const QgsQuickFeatureLayerPair &feat ) const;
203 
209  QgsQuickFeatureLayerPairs mFeatures;
210 
212  const int FEATURES_LIMIT = 10000;
213 
215  QString mSearchExpression;
216 
218  QString mFilterExpression;
219 
221  QgsVectorLayer *mCurrentLayer = nullptr;
222 
224  QgsFeature mCurrentFeature;
225 
227  QString mKeyField;
228 
230  QString mFeatureTitleField;
231 };
232 
233 #endif // QGSQUICKFEATURESMODEL_H
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
Pair of QgsFeature and QgsVectorLayer.
List Model holding features of specific layer.
~QgsQuickFeaturesListModel() override
void currentFeatureChanged(QgsFeature feature)
Signal emitted when current feature has changed.
void featuresLimitChanged(int featuresLimit)
Signal emitted when maximum number of features that can be loaded changes.
void featuresCountChanged(int featuresCount)
featuresCountChanged Signal emitted when features are reloaded or layer is changed
modelRoles
Roles for FeaturesListModel.
@ KeyColumn
secondary text in list view
void searchExpressionChanged(QString searchExpression)
Signal emitted when search expression has changed.
Represents a vector layer which manages a vector based data sets.
QList< QgsQuickFeatureLayerPair > QgsQuickFeatureLayerPairs