QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsfeaturelistmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeaturelistmodel.h
3  ---------------------
4  begin : February 2013
5  copyright : (C) 2013 by Matthias Kuhn
6  email : matthias at opengis dot ch
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 #ifndef QGSATTRIBUTEEDITORMODEL_H
16 #define QGSATTRIBUTEEDITORMODEL_H
17 
18 #include "qgsexpression.h"
19 
20 #include <QSortFilterProxyModel>
21 #include <QVariant>
22 #include <QItemSelectionModel>
23 
24 #include "qgsfeaturemodel.h"
25 #include "qgsfeature.h" // QgsFeatureId
26 #include "qgsexpressioncontext.h"
27 #include "qgsconditionalstyle.h"
28 #include "qgis_gui.h"
29 
33 
38 class GUI_EXPORT QgsFeatureListModel : public QSortFilterProxyModel, public QgsFeatureModel
39 {
40  Q_OBJECT
41 
42  public:
43  struct FeatureInfo
44  {
45  public:
46 
50  FeatureInfo() = default;
51 
53  bool isNew = false;
54 
56  bool isEdited = false;
57  };
58 
59  enum Role
60  {
61  FeatureInfoRole = 0x1000, // Make sure no collisions with roles on QgsAttributeTableModel
62  FeatureRole
63  };
64 
65  public:
66 
68  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
69 
70  virtual void setSourceModel( QgsAttributeTableFilterModel *sourceModel );
71 
75  QgsVectorLayerCache *layerCache();
76 
77  QVariant data( const QModelIndex &index, int role ) const override;
78  Qt::ItemFlags flags( const QModelIndex &index ) const override;
79 
86  void setInjectNull( bool injectNull );
87 
93  bool injectNull();
94 
95  QgsAttributeTableModel *masterModel();
96 
103  bool setDisplayExpression( const QString &expression );
104 
109  QString parserErrorString();
110 
111  QString displayExpression() const;
112  bool featureByIndex( const QModelIndex &index, QgsFeature &feat );
113 
118  QgsFeatureId idxToFid( const QModelIndex &index ) const;
119 
124  QModelIndex fidToIdx( QgsFeatureId fid ) const;
125 
126  QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
127  QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
128 
129  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
130  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
131 
132  virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
133  virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
134 
135  QModelIndex parent( const QModelIndex &child ) const override;
136  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
137  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
138 
139  QModelIndex fidToIndex( QgsFeatureId fid ) override;
140  QModelIndexList fidToIndexList( QgsFeatureId fid );
141 
147  bool sortByDisplayExpression() const;
148 
157  void setSortByDisplayExpression( bool sortByDisplayExpression, Qt::SortOrder order = Qt::AscendingOrder );
158 
159  public slots:
160 
166  Q_DECL_DEPRECATED void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
167 
173  Q_DECL_DEPRECATED void onEndRemoveRows( const QModelIndex &parent, int first, int last );
174 
180  Q_DECL_DEPRECATED void onBeginInsertRows( const QModelIndex &parent, int first, int last );
181 
187  Q_DECL_DEPRECATED void onEndInsertRows( const QModelIndex &parent, int first, int last );
188 
189  private slots:
190 
191  void conditionalStylesChanged();
192 
193  private:
194  mutable QgsExpression mDisplayExpression;
195  QgsAttributeTableFilterModel *mFilterModel = nullptr;
196  QString mParserErrorString;
197  bool mInjectNull = false;
198  mutable QgsExpressionContext mExpressionContext;
199  mutable QMap< QgsFeatureId, QList<QgsConditionalStyle> > mRowStylesMap;
200  bool mSortByDisplayExpression = false;
201  QPointer< QgsVectorLayer > mSourceLayer;
202 };
203 
205 
206 #endif // QGSATTRIBUTEEDITORMODEL_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
qgsconditionalstyle.h
QgsVectorLayerCache
This class caches features of a given QgsVectorLayer.
Definition: qgsvectorlayercache.h:46
QgsFeatureModel::fidToIndex
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
qgsexpression.h
qgsfeature.h
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
qgsexpressioncontext.h
QgsAttributeTableModel
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Definition: qgsattributetablemodel.h:50
QgsFeatureListModel::FeatureInfo
Definition: qgsfeaturelistmodel.h:44
QgsFeatureModel
Definition: qgsfeaturemodel.h:27
QgsFeatureListModel::FeatureInfo::FeatureInfo
FeatureInfo()=default
Constructor for FeatureInfo.
qgsfeaturemodel.h
QgsFeatureListModel::Role
Role
Definition: qgsfeaturelistmodel.h:60
QgsAttributeTableFilterModel
Definition: qgsattributetablefiltermodel.h:36
QgsFeatureListModel
Definition: qgsfeaturelistmodel.h:39
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28