QGIS API Documentation  2.15.0-Master (972fc9f)
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 
30 
31 class GUI_EXPORT QgsFeatureListModel : public QAbstractProxyModel, public QgsFeatureModel
32 {
33  Q_OBJECT
34 
35  public:
36  struct FeatureInfo
37  {
38  public:
40  : isNew( false )
41  , isEdited( false )
42  {}
43 
44  bool isNew;
45  bool isEdited;
46  };
47 
48  enum Role
49  {
50  FeatureInfoRole = Qt::UserRole,
51  FeatureRole
52  };
53 
54  public:
55  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject* parent = nullptr );
56  virtual ~QgsFeatureListModel();
57 
58  virtual void setSourceModel( QgsAttributeTableFilterModel* sourceModel );
59  QgsVectorLayerCache* layerCache();
60  virtual QVariant data( const QModelIndex& index, int role ) const override;
61  virtual Qt::ItemFlags flags( const QModelIndex& index ) const override;
62 
68  void setInjectNull( bool injectNull );
69 
75  bool injectNull();
76 
77  QgsAttributeTableModel* masterModel();
78 
85  bool setDisplayExpression( const QString& expression );
86 
91  QString parserErrorString();
92 
93  QString displayExpression() const;
94  bool featureByIndex( const QModelIndex& index, QgsFeature& feat );
95  QgsFeatureId idxToFid( const QModelIndex& index ) const;
96  QModelIndex fidToIdx( const QgsFeatureId fid ) const;
97 
98  virtual QModelIndex mapToSource( const QModelIndex& proxyIndex ) const override;
99  virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const override;
100 
101  virtual QModelIndex mapToMaster( const QModelIndex& proxyIndex ) const;
102  virtual QModelIndex mapFromMaster( const QModelIndex& sourceIndex ) const;
103 
104  virtual QItemSelection mapSelectionFromMaster( const QItemSelection& selection ) const;
105  virtual QItemSelection mapSelectionToMaster( const QItemSelection& selection ) const;
106 
107  virtual QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
108  virtual QModelIndex parent( const QModelIndex& child ) const override;
109  virtual int columnCount( const QModelIndex&parent = QModelIndex() ) const override;
110  virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
111 
112  QModelIndex fidToIndex( QgsFeatureId fid ) override;
113  QModelIndexList fidToIndexList( QgsFeatureId fid );
114 
115  public slots:
116  void onBeginRemoveRows( const QModelIndex& parent, int first, int last );
117  void onEndRemoveRows( const QModelIndex& parent, int first, int last );
118  void onBeginInsertRows( const QModelIndex& parent, int first, int last );
119  void onEndInsertRows( const QModelIndex& parent, int first, int last );
120 
121  private:
122  QgsExpression* mExpression;
123  QgsAttributeTableFilterModel* mFilterModel;
124  QString mParserErrorString;
125  bool mInjectNull;
126 };
127 
129 
130 #endif // QGSATTRIBUTEEDITORMODEL_H
Class for parsing and evaluation of expressions (formerly called "search strings").
static unsigned index
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Q_DECLARE_METATYPE(QModelIndex)
This class caches features of a given QgsVectorLayer.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
typedef ItemFlags