QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgis.h"
20 
21 #include <QSortFilterProxyModel>
22 #include <QVariant>
23 #include <QItemSelectionModel>
24 
25 #include "qgsfeaturemodel.h"
26 #include "qgsfeature.h" // QgsFeatureId
27 #include "qgsexpressioncontext.h"
28 #include "qgsconditionalstyle.h"
29 #include "qgis_gui.h"
30 
34 
39 class GUI_EXPORT QgsFeatureListModel : public QSortFilterProxyModel, public QgsFeatureModel
40 {
41  Q_OBJECT
42 
43  public:
44  struct FeatureInfo
45  {
46  public:
47 
51  FeatureInfo() = default;
52 
54  bool isNew = false;
55 
57  bool isEdited = false;
58  };
59 
60  enum Role
61  {
62  FeatureInfoRole = 0x1000, // Make sure no collisions with roles on QgsAttributeTableModel
63  FeatureRole
64  };
65 
66  public:
67 
69  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
70 
71  virtual void setSourceModel( QgsAttributeTableFilterModel *sourceModel );
72 
76  QgsVectorLayerCache *layerCache();
77 
78  QVariant data( const QModelIndex &index, int role ) const override;
79  Qt::ItemFlags flags( const QModelIndex &index ) const override;
80 
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 );
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:
190  mutable QgsExpression mDisplayExpression;
191  QgsAttributeTableFilterModel *mFilterModel = nullptr;
192  QString mParserErrorString;
193  bool mInjectNull = false;
194  mutable QgsExpressionContext mExpressionContext;
195  mutable QMap< QgsFeatureId, QList<QgsConditionalStyle> > mRowStylesMap;
196  bool mSortByDisplayExpression = false;
197 };
198 
200 
201 #endif // QGSATTRIBUTEEDITORMODEL_H
Class for parsing and evaluation of expressions (formerly called "search strings").
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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...
Q_DECLARE_METATYPE(QModelIndex)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class caches features of a given QgsVectorLayer.