QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
50 
51 
55  Q_PROPERTY( int featuresLimit READ featuresLimit NOTIFY featuresLimitChanged )
56 
57  public:
58 
61  {
62  FeatureTitle = Qt::UserRole + 1,
67  FoundPair
68  };
70 
72  explicit QgsQuickFeaturesListModel( QObject *parent = nullptr );
74 
76  Q_INVOKABLE QgsQuickFeatureLayerPair featureLayerPair( const int &featureId );
77 
78  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
79  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
80  QHash<int, QByteArray> roleNames() const override;
81 
86  Q_INVOKABLE void setupValueRelation( const QVariantMap &config );
87 
92  Q_INVOKABLE void populateFromLayer( QgsVectorLayer *layer );
93 
97  Q_INVOKABLE void reloadFeatures();
98 
106  Q_INVOKABLE int rowFromAttribute( const int role, const QVariant &value ) const;
107 
115  Q_INVOKABLE int keyFromAttribute( const int role, const QVariant &value ) const;
116 
118  int featuresLimit() const;
120  int featuresCount() const;
122  QString filterExpression() const;
123 
128  void setFilterExpression( const QString &filterExpression );
129 
134  void setFeatureTitleField( const QString &attribute );
135 
137  void setKeyField( const QString &attribute );
138 
139  signals:
140 
145  void featuresCountChanged( int featuresCount );
146 
148  void featuresLimitChanged( int featuresLimit );
149 
151  void filterExpressionChanged( QString filterExpression );
152 
153  private:
154 
156  void loadFeaturesFromLayer( QgsVectorLayer *layer = nullptr );
157 
159  void emptyData();
160 
162  QVariant featureTitle( const QgsQuickFeatureLayerPair &featurePair ) const;
163 
165  QString buildFilterExpression();
166 
168  QString foundPair( const QgsQuickFeatureLayerPair &feat ) const;
169 
175  QgsQuickFeatureLayerPairs mFeatures;
176 
178  const int FEATURES_LIMIT = 10000;
179 
181  QString mFilterExpression;
182 
184  QgsVectorLayer *mCurrentLayer = nullptr;
185 
187  QString mKeyField;
188 
190  QString mFeatureTitleField;
191 };
192 
193 #endif // QGSQUICKFEATURESMODEL_H
qgsvaluerelationfieldformatter.h
qgsquickfeaturelayerpair.h
QgsQuickFeaturesListModel::featuresCountChanged
void featuresCountChanged(int featuresCount)
featuresCountChanged Signal emitted when features are reloaded or layer is changed
QgsQuickFeaturesListModel::modelRoles
modelRoles
Roles for FeaturesListModel.
Definition: qgsquickfeatureslistmodel.h:61
QgsQuickFeaturesListModel::featuresLimitChanged
void featuresLimitChanged(int featuresLimit)
Signal emitted when maximum number of features that can be loaded changes.
QgsQuickFeaturesListModel::Description
@ Description
Definition: qgsquickfeatureslistmodel.h:65
QgsQuickFeatureLayerPairs
QList< QgsQuickFeatureLayerPair > QgsQuickFeatureLayerPairs
Definition: qgsquickfeaturelayerpair.h:102
QgsQuickFeaturesListModel::Feature
@ Feature
Definition: qgsquickfeatureslistmodel.h:64
QgsQuickFeaturesListModel::filterExpressionChanged
void filterExpressionChanged(QString filterExpression)
Signal emitted when filter expression has changed.
QgsQuickFeaturesListModel::~QgsQuickFeaturesListModel
~QgsQuickFeaturesListModel() override
Definition: qgsquickfeatureslistmodel.h:73
qgsvectorlayer.h
QgsQuickFeaturesListModel::KeyColumn
@ KeyColumn
secondary text in list view
Definition: qgsquickfeatureslistmodel.h:66
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsQuickFeatureLayerPair
Pair of QgsFeature and QgsVectorLayer.
Definition: qgsquickfeaturelayerpair.h:41
QgsQuickFeaturesListModel::Q_ENUM
Q_ENUM(modelRoles)
QgsQuickFeaturesListModel::FeatureId
@ FeatureId
Definition: qgsquickfeatureslistmodel.h:63
QgsQuickFeaturesListModel
List Model holding features of specific layer.
Definition: qgsquickfeatureslistmodel.h:36