QGIS API Documentation  2.99.0-Master (8ec3eaf)
qgsattributetablefiltermodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  QgsAttributeTableFilterModel.h - Filter Model for attribute table
3  -------------------
4  date : Feb 2009
5  copyright : Vita Cizek
6  email : weetya (at) gmail.com
7 
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSATTRIBUTETABLEFILTERMODEL_H
18 #define QGSATTRIBUTETABLEFILTERMODEL_H
19 
20 #include <QSortFilterProxyModel>
21 #include <QModelIndex>
22 
23 #include "qgsattributetablemodel.h"
24 #include "qgsfeaturemodel.h"
25 
27 class QgsMapCanvas;
28 class QItemSelectionModel;
29 
33 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
34 {
35  Q_OBJECT
36 
37  public:
38 
43  {
48  ShowEdited
49  };
50 
55  {
57  ColumnTypeActionButton
58  };
59 
65  enum Role
66  {
68  };
69 
70 
78  QgsAttributeTableFilterModel( QgsMapCanvas* canvas, QgsAttributeTableModel* sourceModel, QObject* parent = nullptr );
79 
87  void setSourceModel( QgsAttributeTableModel* sourceModel );
88 
95  void setSelectedOnTop( bool selectedOnTop );
96 
102  bool selectedOnTop();
103 
110  virtual void setFilteredFeatures( const QgsFeatureIds& ids );
111 
117  QgsFeatureIds filteredFeatures();
118 
124  void setFilterMode( FilterMode filterMode );
125 
129  FilterMode filterMode() { return mFilterMode; }
130 
136  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
137 
143  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
144 
150  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
151 
159  QgsFeatureId rowToId( const QModelIndex& row );
160 
161  QModelIndex fidToIndex( QgsFeatureId fid ) override;
162 
163  QModelIndexList fidToIndexList( QgsFeatureId fid );
164 
165  inline QModelIndex mapToMaster( const QModelIndex& proxyIndex ) const { return mapToSource( proxyIndex ); }
166 
167  inline QModelIndex mapFromMaster( const QModelIndex& sourceIndex ) const { return mapFromSource( sourceIndex ); }
168 
169  virtual QModelIndex mapToSource( const QModelIndex& proxyIndex ) const override;
170 
171  virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const override;
172 
173  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
174 
182  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
183 
191  void sort( const QString& expression, Qt::SortOrder order = Qt::AscendingOrder );
192 
196  QString sortExpression() const;
197 
199  QgsMapCanvas* mapCanvas() const { return mCanvas; }
200 
201  virtual QVariant data( const QModelIndex& index, int role ) const override;
202 
203  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
204 
209  int actionColumnIndex() const;
210 
211  int columnCount( const QModelIndex &parent ) const override;
212 
218  void setAttributeTableConfig( const QgsAttributeTableConfig& config );
219 
220  signals:
221 
227  void sortColumnChanged( int column, Qt::SortOrder order );
228 
229  protected:
230 
237  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
238 
243  void generateListOfVisibleFeatures();
244 
249  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
250 
251  public slots:
252 
257  void extentsChanged();
258 
259  private slots:
260  void selectionChanged();
261  void onColumnsChanged();
262 
263  private:
264  QgsFeatureIds mFilteredFeatures;
265  QgsMapCanvas* mCanvas;
266  FilterMode mFilterMode;
267  bool mSelectedOnTop;
268  QgsAttributeTableModel* mTableModel;
269 
270  QgsAttributeTableConfig mConfig;
271  QVector<int> mColumnMapping;
272  int mapColumnToSource( int column ) const;
273 
274 };
275 
276 #endif
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
static unsigned index
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
Role
The additional roles defined by this filter model.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Show only visible features (depends on the map canvas)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:106
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
FilterMode filterMode()
The current filterModel.
FilterMode
The filter mode defines how the rows should be filtered.
This class caches features of a given QgsVectorLayer.
Show only features whose ids are on the filter list. {.
Start further roles starting from this role.
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
qint64 QgsFeatureId
Definition: qgsfeature.h:32
This is a container for configuration of the attribute table.
Represents a vector layer which manages a vector based data sets.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const