QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsfeaturelistmodel.h
Go to the documentation of this file.
1 #ifndef QGSATTRIBUTEEDITORMODEL_H
2 #define QGSATTRIBUTEEDITORMODEL_H
3 
4 #include <qgsexpression.h>
5 
6 #include <QAbstractProxyModel>
7 #include <QVariant>
8 #include <QItemSelectionModel>
9 
10 #include "qgsfeaturemodel.h"
11 #include "qgsfeature.h" // QgsFeatureId
12 
16 
17 class GUI_EXPORT QgsFeatureListModel : public QAbstractProxyModel, public QgsFeatureModel
18 {
19  Q_OBJECT
20 
21  public:
22  struct FeatureInfo
23  {
24  public:
26  : isNew( false )
27  , isEdited( false )
28  {}
29 
30  bool isNew;
31  bool isEdited;
32  };
33 
34  enum Role
35  {
36  FeatureInfoRole = Qt::UserRole,
37  FeatureRole
38  };
39 
40  public:
41  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject* parent = 0 );
42  virtual ~QgsFeatureListModel();
43 
44  virtual void setSourceModel( QgsAttributeTableFilterModel* sourceModel );
45  QgsVectorLayerCache* layerCache();
46  virtual QVariant data( const QModelIndex& index, int role ) const override;
47  virtual Qt::ItemFlags flags( const QModelIndex& index ) const override;
48 
49  QgsAttributeTableModel* masterModel();
50 
57  bool setDisplayExpression( const QString expression );
58 
63  QString parserErrorString();
64 
65  QString displayExpression() const;
66  bool featureByIndex( const QModelIndex& index, QgsFeature& feat );
67  QgsFeatureId idxToFid( const QModelIndex& index ) const;
68  QModelIndex fidToIdx( const QgsFeatureId fid ) const;
69 
70  virtual QModelIndex mapToSource( const QModelIndex& proxyIndex ) const override;
71  virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const override;
72 
73  virtual QModelIndex mapToMaster( const QModelIndex& proxyIndex ) const;
74  virtual QModelIndex mapFromMaster( const QModelIndex& sourceIndex ) const;
75 
76  virtual QItemSelection mapSelectionFromMaster( const QItemSelection& selection ) const;
77  virtual QItemSelection mapSelectionToMaster( const QItemSelection& selection ) const;
78 
79  virtual QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
80  virtual QModelIndex parent( const QModelIndex& child ) const override;
81  virtual int columnCount( const QModelIndex&parent = QModelIndex() ) const override;
82  virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
83 
84  QModelIndex fidToIndex( QgsFeatureId fid ) override;
85  QModelIndexList fidToIndexList( QgsFeatureId fid );
86 
87  public slots:
88  void onBeginRemoveRows( const QModelIndex& parent, int first, int last );
89  void onEndRemoveRows( const QModelIndex& parent, int first, int last );
90  void onBeginInsertRows( const QModelIndex& parent, int first, int last );
91  void onEndInsertRows( const QModelIndex& parent, int first, int last );
92 
93  private:
94  QgsExpression* mExpression;
95  QgsAttributeTableFilterModel* mFilterModel;
96  QString mParserErrorString;
97 };
98 
100 
101 #endif // QGSATTRIBUTEEDITORMODEL_H