QGIS API Documentation  2.99.0-Master (9fdd060)
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 
36 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
37 {
38  Q_OBJECT
39 
40  public:
41 
46  {
51  ShowEdited
52  };
53 
58  {
60  ColumnTypeActionButton
61  };
62 
68  enum Role
69  {
71  };
72 
73 
81  QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = 0 );
82 
90  void setSourceModel( QgsAttributeTableModel *sourceModel );
91 
98  void setSelectedOnTop( bool selectedOnTop );
99 
105  bool selectedOnTop();
106 
113  virtual void setFilteredFeatures( const QgsFeatureIds &ids );
114 
120  QgsFeatureIds filteredFeatures();
121 
127  void setFilterMode( FilterMode filterMode );
128 
132  FilterMode filterMode() { return mFilterMode; }
133 
139  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
140 
146  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
147 
153  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
154 
162  QgsFeatureId rowToId( const QModelIndex &row );
163 
164  QModelIndex fidToIndex( QgsFeatureId fid ) override;
165 
166  QModelIndexList fidToIndexList( QgsFeatureId fid );
167 
168  inline QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const { return mapToSource( proxyIndex ); }
169 
170  inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
171 
172  virtual QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
173 
174  virtual QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
175 
176  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
177 
185  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
186 
194  void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
195 
199  QString sortExpression() const;
200 
202  QgsMapCanvas *mapCanvas() const { return mCanvas; }
203 
204  virtual QVariant data( const QModelIndex &index, int role ) const override;
205 
206  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
207 
212  int actionColumnIndex() const;
213 
214  int columnCount( const QModelIndex &parent ) const override;
215 
221  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
222 
223  signals:
224 
230  void sortColumnChanged( int column, Qt::SortOrder order );
231 
232  protected:
233 
240  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
241 
246  void generateListOfVisibleFeatures();
247 
252  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
253 
254  public slots:
255 
260  void extentsChanged();
261 
262  private slots:
263  void selectionChanged();
264  void onColumnsChanged();
265 
266  private:
267  QgsFeatureIds mFilteredFeatures;
268  QgsMapCanvas *mCanvas = nullptr;
269  FilterMode mFilterMode;
270  bool mSelectedOnTop;
271  QgsAttributeTableModel *mTableModel = nullptr;
272 
273  QgsAttributeTableConfig mConfig;
274  QVector<int> mColumnMapping;
275  int mapColumnToSource( int column ) const;
276 
277 };
278 
279 #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:46
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
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:74
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