QGIS API Documentation  2.99.0-Master (0a63d1f)
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 "qgis_gui.h"
27 
31 
35 class GUI_EXPORT QgsFeatureListModel : public QAbstractProxyModel, public QgsFeatureModel
36 {
37  Q_OBJECT
38 
39  public:
40  struct FeatureInfo
41  {
42  public:
44  : isNew( false )
45  , isEdited( false )
46  {}
47 
48  bool isNew;
49  bool isEdited;
50  };
51 
52  enum Role
53  {
54  FeatureInfoRole = Qt::UserRole,
55  FeatureRole
56  };
57 
58  public:
59  explicit QgsFeatureListModel( QgsAttributeTableFilterModel *sourceModel, QObject* parent = nullptr );
60  virtual ~QgsFeatureListModel();
61 
62  virtual void setSourceModel( QgsAttributeTableFilterModel* sourceModel );
63  QgsVectorLayerCache* layerCache();
64  virtual QVariant data( const QModelIndex& index, int role ) const override;
65  virtual Qt::ItemFlags flags( const QModelIndex& index ) const override;
66 
72  void setInjectNull( bool injectNull );
73 
79  bool injectNull();
80 
81  QgsAttributeTableModel* masterModel();
82 
89  bool setDisplayExpression( const QString& expression );
90 
95  QString parserErrorString();
96 
97  QString displayExpression() const;
98  bool featureByIndex( const QModelIndex& index, QgsFeature& feat );
99  QgsFeatureId idxToFid( const QModelIndex& index ) const;
100  QModelIndex fidToIdx( const QgsFeatureId fid ) const;
101 
102  virtual QModelIndex mapToSource( const QModelIndex& proxyIndex ) const override;
103  virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const override;
104 
105  virtual QModelIndex mapToMaster( const QModelIndex& proxyIndex ) const;
106  virtual QModelIndex mapFromMaster( const QModelIndex& sourceIndex ) const;
107 
108  virtual QItemSelection mapSelectionFromMaster( const QItemSelection& selection ) const;
109  virtual QItemSelection mapSelectionToMaster( const QItemSelection& selection ) const;
110 
111  virtual QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override;
112  virtual QModelIndex parent( const QModelIndex& child ) const override;
113  virtual int columnCount( const QModelIndex&parent = QModelIndex() ) const override;
114  virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
115 
116  QModelIndex fidToIndex( QgsFeatureId fid ) override;
117  QModelIndexList fidToIndexList( QgsFeatureId fid );
118 
119  public slots:
120  void onBeginRemoveRows( const QModelIndex& parent, int first, int last );
121  void onEndRemoveRows( const QModelIndex& parent, int first, int last );
122  void onBeginInsertRows( const QModelIndex& parent, int first, int last );
123  void onEndInsertRows( const QModelIndex& parent, int first, int last );
124 
125  private:
126  QgsExpression* mExpression;
127  QgsAttributeTableFilterModel* mFilterModel;
128  QString mParserErrorString;
129  bool mInjectNull;
130 };
131 
133 
134 #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:136
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:33