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