QGIS API Documentation  2.99.0-Master (bdf46d7)
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 #include "qgis_gui.h"
26 
28 class QgsMapCanvas;
29 class QItemSelectionModel;
30 
34 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
35 {
36  Q_OBJECT
37 
38  public:
39 
44  {
49  ShowEdited
50  };
51 
56  {
58  ColumnTypeActionButton
59  };
60 
66  enum Role
67  {
69  };
70 
71 
79  QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent = nullptr );
80 
88  void setSourceModel( QgsAttributeTableModel *sourceModel );
89 
96  void setSelectedOnTop( bool selectedOnTop );
97 
103  bool selectedOnTop();
104 
111  virtual void setFilteredFeatures( const QgsFeatureIds &ids );
112 
118  QgsFeatureIds filteredFeatures();
119 
125  void setFilterMode( FilterMode filterMode );
126 
130  FilterMode filterMode() { return mFilterMode; }
131 
137  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
138 
144  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
145 
151  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
152 
160  QgsFeatureId rowToId( const QModelIndex &row );
161 
162  QModelIndex fidToIndex( QgsFeatureId fid ) override;
163 
164  QModelIndexList fidToIndexList( QgsFeatureId fid );
165 
166  inline QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const { return mapToSource( proxyIndex ); }
167 
168  inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
169 
170  virtual QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
171 
172  virtual QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
173 
174  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
175 
183  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
184 
192  void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
193 
197  QString sortExpression() const;
198 
200  QgsMapCanvas *mapCanvas() const { return mCanvas; }
201 
202  virtual QVariant data( const QModelIndex &index, int role ) const override;
203 
204  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
205 
210  int actionColumnIndex() const;
211 
212  int columnCount( const QModelIndex &parent ) const override;
213 
219  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
220 
221  signals:
222 
228  void sortColumnChanged( int column, Qt::SortOrder order );
229 
230  protected:
231 
238  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
239 
244  void generateListOfVisibleFeatures();
245 
250  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
251 
252  public slots:
253 
258  void extentsChanged();
259 
260  private slots:
261  void selectionChanged();
262  void onColumnsChanged();
263 
264  private:
265  QgsFeatureIds mFilteredFeatures;
266  QgsMapCanvas *mCanvas = nullptr;
267  FilterMode mFilterMode;
268  bool mSelectedOnTop;
269  QgsAttributeTableModel *mTableModel = nullptr;
270 
271  QgsAttributeTableConfig mConfig;
272  QVector<int> mColumnMapping;
273  int mapColumnToSource( int column ) const;
274 
275 };
276 
277 #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:517
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:72
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:37
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