QGIS API Documentation  2.99.0-Master (585a4d3)
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 <QAbstractProxyModel>
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 QAbstractProxyModel, public QgsFeatureModel
40 {
41  Q_OBJECT
42 
43  public:
44  struct FeatureInfo
45  {
46  public:
47 
51  FeatureInfo() = default;
52 
53  bool isNew = false;
54  bool isEdited = false;
55  };
56 
57  enum Role
58  {
59  FeatureInfoRole = Qt::UserRole,
60  FeatureRole
61  };
62 
63  public:
64 
66  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
67 
68  virtual void setSourceModel( QgsAttributeTableFilterModel *sourceModel );
69  QgsVectorLayerCache *layerCache();
70  QVariant data( const QModelIndex &index, int role ) const override;
71  Qt::ItemFlags flags( const QModelIndex &index ) const override;
72 
78  void setInjectNull( bool injectNull );
79 
85  bool injectNull();
86 
87  QgsAttributeTableModel *masterModel();
88 
95  bool setDisplayExpression( const QString &expression );
96 
101  QString parserErrorString();
102 
103  QString displayExpression() const;
104  bool featureByIndex( const QModelIndex &index, QgsFeature &feat );
105  QgsFeatureId idxToFid( const QModelIndex &index ) const;
106  QModelIndex fidToIdx( const QgsFeatureId fid ) const;
107 
108  QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
109  QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
110 
111  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
112  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
113 
114  virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
115  virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
116 
117  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
118  QModelIndex parent( const QModelIndex &child ) const override;
119  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
120  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
121 
122  QModelIndex fidToIndex( QgsFeatureId fid ) override;
123  QModelIndexList fidToIndexList( QgsFeatureId fid );
124 
125  public slots:
126  void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
127  void onEndRemoveRows( const QModelIndex &parent, int first, int last );
128  void onBeginInsertRows( const QModelIndex &parent, int first, int last );
129  void onEndInsertRows( const QModelIndex &parent, int first, int last );
130 
131  private:
132  mutable QgsExpression mDisplayExpression;
133  QgsAttributeTableFilterModel *mFilterModel = nullptr;
134  QString mParserErrorString;
135  bool mInjectNull;
136  mutable QgsExpressionContext mExpressionContext;
137  mutable QMap< QgsFeatureId, QList<QgsConditionalStyle> > mRowStylesMap;
138 };
139 
141 
142 #endif // QGSATTRIBUTEEDITORMODEL_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
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.
qint64 QgsFeatureId
Definition: qgsfeature.h:37