QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
85  void setInjectNull( bool injectNull );
86 
92  bool injectNull();
93 
94  QgsAttributeTableModel *masterModel();
95 
102  bool setDisplayExpression( const QString &expression );
103 
108  QString parserErrorString();
109 
110  QString displayExpression() const;
111  bool featureByIndex( const QModelIndex &index, QgsFeature &feat );
112 
117  QgsFeatureId idxToFid( const QModelIndex &index ) const;
118 
123  QModelIndex fidToIdx( QgsFeatureId fid ) const;
124 
125  QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
126  QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
127 
128  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
129  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
130 
131  virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
132  virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
133 
134  QModelIndex parent( const QModelIndex &child ) const override;
135  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
136  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
137 
138  QModelIndex fidToIndex( QgsFeatureId fid ) override;
139  QModelIndexList fidToIndexList( QgsFeatureId fid );
140 
146  bool sortByDisplayExpression() const;
147 
156  void setSortByDisplayExpression( bool sortByDisplayExpression );
157 
158  public slots:
159 
165  Q_DECL_DEPRECATED void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
166 
172  Q_DECL_DEPRECATED void onEndRemoveRows( const QModelIndex &parent, int first, int last );
173 
179  Q_DECL_DEPRECATED void onBeginInsertRows( const QModelIndex &parent, int first, int last );
180 
186  Q_DECL_DEPRECATED void onEndInsertRows( const QModelIndex &parent, int first, int last );
187 
188  private slots:
189 
190  void conditionalStylesChanged();
191 
192  private:
193  mutable QgsExpression mDisplayExpression;
194  QgsAttributeTableFilterModel *mFilterModel = nullptr;
195  QString mParserErrorString;
196  bool mInjectNull = false;
197  mutable QgsExpressionContext mExpressionContext;
198  mutable QMap< QgsFeatureId, QList<QgsConditionalStyle> > mRowStylesMap;
199  bool mSortByDisplayExpression = false;
200  QPointer< QgsVectorLayer > mSourceLayer;
201 };
202 
204 
205 #endif // QGSATTRIBUTEEDITORMODEL_H
Class for parsing and evaluation of expressions (formerly called "search strings").
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
This class caches features of a given QgsVectorLayer.