QGIS API Documentation  2.99.0-Master (53aba61)
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 
38 class GUI_EXPORT QgsFeatureListModel : public QAbstractProxyModel, public QgsFeatureModel
39 {
40  Q_OBJECT
41 
42  public:
43  struct FeatureInfo
44  {
45  public:
47  : isNew( false )
48  , isEdited( false )
49  {}
50 
51  bool isNew;
52  bool isEdited;
53  };
54 
55  enum Role
56  {
57  FeatureInfoRole = Qt::UserRole,
58  FeatureRole
59  };
60 
61  public:
62  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = 0 );
63 
64  virtual void setSourceModel( QgsAttributeTableFilterModel *sourceModel );
65  QgsVectorLayerCache *layerCache();
66  virtual QVariant data( const QModelIndex &index, int role ) const override;
67  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
68 
74  void setInjectNull( bool injectNull );
75 
81  bool injectNull();
82 
83  QgsAttributeTableModel *masterModel();
84 
91  bool setDisplayExpression( const QString &expression );
92 
97  QString parserErrorString();
98 
99  QString displayExpression() const;
100  bool featureByIndex( const QModelIndex &index, QgsFeature &feat );
101  QgsFeatureId idxToFid( const QModelIndex &index ) const;
102  QModelIndex fidToIdx( const QgsFeatureId fid ) const;
103 
104  virtual QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
105  virtual QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
106 
107  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
108  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
109 
110  virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
111  virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
112 
113  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
114  virtual QModelIndex parent( const QModelIndex &child ) const override;
115  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
116  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
117 
118  QModelIndex fidToIndex( QgsFeatureId fid ) override;
119  QModelIndexList fidToIndexList( QgsFeatureId fid );
120 
121  public slots:
122  void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
123  void onEndRemoveRows( const QModelIndex &parent, int first, int last );
124  void onBeginInsertRows( const QModelIndex &parent, int first, int last );
125  void onEndInsertRows( const QModelIndex &parent, int first, int last );
126 
127  private:
128  mutable QgsExpression mDisplayExpression;
129  QgsAttributeTableFilterModel *mFilterModel = nullptr;
130  QString mParserErrorString;
131  bool mInjectNull;
132  mutable QgsExpressionContext mExpressionContext;
133  mutable QMap< QgsFeatureId, QList<QgsConditionalStyle> > mRowStylesMap;
134 };
135 
137 
138 #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:61
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