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