QGIS API Documentation  2.99.0-Master (cb63e82)
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 
20 #include <QAbstractProxyModel>
21 #include <QVariant>
22 #include <QItemSelectionModel>
23 
24 #include "qgsfeaturemodel.h"
25 #include "qgsfeature.h" // QgsFeatureId
26 #include "qgsexpressioncontext.h"
27 #include "qgsconditionalstyle.h"
28 #include "qgis_gui.h"
29 
33 
37 class GUI_EXPORT QgsFeatureListModel : public QAbstractProxyModel, public QgsFeatureModel
38 {
39  Q_OBJECT
40 
41  public:
42  struct FeatureInfo
43  {
44  public:
46  : isNew( false )
47  , isEdited( false )
48  {}
49 
50  bool isNew;
51  bool isEdited;
52  };
53 
54  enum Role
55  {
56  FeatureInfoRole = Qt::UserRole,
57  FeatureRole
58  };
59 
60  public:
61  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject *parent = nullptr );
62  virtual ~QgsFeatureListModel();
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
Class for parsing and evaluation of expressions (formerly called "search strings").
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
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...
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