QGIS API Documentation  2.99.0-Master (7d4f81d)
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  virtual ~QgsFeatureListModel();
64 
65  virtual void setSourceModel( QgsAttributeTableFilterModel *sourceModel );
66  QgsVectorLayerCache *layerCache();
67  virtual QVariant data( const QModelIndex &index, int role ) const override;
68  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
69 
75  void setInjectNull( bool injectNull );
76 
82  bool injectNull();
83 
84  QgsAttributeTableModel *masterModel();
85 
92  bool setDisplayExpression( const QString &expression );
93 
98  QString parserErrorString();
99 
100  QString displayExpression() const;
101  bool featureByIndex( const QModelIndex &index, QgsFeature &feat );
102  QgsFeatureId idxToFid( const QModelIndex &index ) const;
103  QModelIndex fidToIdx( const QgsFeatureId fid ) const;
104 
105  virtual QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
106  virtual QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
107 
108  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
109  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
110 
111  virtual QItemSelection mapSelectionFromMaster( const QItemSelection &selection ) const;
112  virtual QItemSelection mapSelectionToMaster( const QItemSelection &selection ) const;
113 
114  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
115  virtual QModelIndex parent( const QModelIndex &child ) const override;
116  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
117  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
118 
119  QModelIndex fidToIndex( QgsFeatureId fid ) override;
120  QModelIndexList fidToIndexList( QgsFeatureId fid );
121 
122  public slots:
123  void onBeginRemoveRows( const QModelIndex &parent, int first, int last );
124  void onEndRemoveRows( const QModelIndex &parent, int first, int last );
125  void onBeginInsertRows( const QModelIndex &parent, int first, int last );
126  void onEndInsertRows( const QModelIndex &parent, int first, int last );
127 
128  private:
129  mutable QgsExpression mDisplayExpression;
130  QgsAttributeTableFilterModel *mFilterModel = nullptr;
131  QString mParserErrorString;
132  bool mInjectNull;
133  mutable QgsExpressionContext mExpressionContext;
134  mutable QMap< QgsFeatureId, QList<QgsConditionalStyle> > mRowStylesMap;
135 };
136 
138 
139 #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