QGIS API Documentation  2.99.0-Master (009e47e)
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 "qgis.h"
22 #include <QModelIndex>
23 
24 #include "qgsattributetablemodel.h"
25 #include "qgsfeaturemodel.h"
26 #include "qgis_gui.h"
27 
29 class QgsMapCanvas;
30 class QItemSelectionModel;
31 
35 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
36 {
37  Q_OBJECT
38 
39  public:
40 
45  {
50  ShowEdited
51  };
52 
57  {
59  ColumnTypeActionButton
60  };
61 
67  enum Role
68  {
70  };
71 
72 
80  QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = 0 );
81 
89  void setSourceModel( QgsAttributeTableModel *sourceModel );
90 
97  void setSelectedOnTop( bool selectedOnTop );
98 
104  bool selectedOnTop();
105 
112  virtual void setFilteredFeatures( const QgsFeatureIds &ids );
113 
119  QgsFeatureIds filteredFeatures();
120 
126  void setFilterMode( FilterMode filterMode );
127 
131  FilterMode filterMode() { return mFilterMode; }
132 
138  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
139 
145  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
146 
152  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
153 
161  QgsFeatureId rowToId( const QModelIndex &row );
162 
163  QModelIndex fidToIndex( QgsFeatureId fid ) override;
164 
165  QModelIndexList fidToIndexList( QgsFeatureId fid );
166 
167  inline QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const { return mapToSource( proxyIndex ); }
168 
169  inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
170 
171  virtual QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
172 
173  virtual QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
174 
175  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
176 
184  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
185 
193  void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
194 
198  QString sortExpression() const;
199 
201  QgsMapCanvas *mapCanvas() const { return mCanvas; }
202 
203  virtual QVariant data( const QModelIndex &index, int role ) const override;
204 
205  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
206 
211  int actionColumnIndex() const;
212 
213  int columnCount( const QModelIndex &parent ) const override;
214 
220  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
221 
222  signals:
223 
229  void sortColumnChanged( int column, Qt::SortOrder order );
230 
231  protected:
232 
239  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
240 
245  void generateListOfVisibleFeatures();
246 
251  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
252 
253  public slots:
254 
259  void extentsChanged();
260 
261  private slots:
262  void selectionChanged();
263  void onColumnsChanged();
264 
265  private:
266  QgsFeatureIds mFilteredFeatures;
267  QgsMapCanvas *mCanvas = nullptr;
268  FilterMode mFilterMode;
269  bool mSelectedOnTop;
270  QgsAttributeTableModel *mTableModel = nullptr;
271 
272  QgsAttributeTableConfig mConfig;
273  QVector<int> mColumnMapping;
274  int mapColumnToSource( int column ) const;
275 
276 };
277 
278 #endif
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:519
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:73
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