QGIS API Documentation  3.0.2-Girona (307d082)
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 : (C) 2009 by 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  Q_ENUM( FilterMode )
54 
55 
59  {
61  ColumnTypeActionButton
62  };
63  Q_ENUM( ColumnType )
64 
65 
70  enum Role
71  {
73  };
74 
75 
83  QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
84 
92  void setSourceModel( QgsAttributeTableModel *sourceModel );
93 
100  void setSelectedOnTop( bool selectedOnTop );
101 
107  bool selectedOnTop();
108 
115  virtual void setFilteredFeatures( const QgsFeatureIds &ids );
116 
122  QgsFeatureIds filteredFeatures();
123 
129  void setFilterMode( FilterMode filterMode );
130 
134  FilterMode filterMode() { return mFilterMode; }
135 
141  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
142 
148  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
149 
155  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
156 
164  QgsFeatureId rowToId( const QModelIndex &row );
165 
166  QModelIndex fidToIndex( QgsFeatureId fid ) override;
167 
168  QModelIndexList fidToIndexList( QgsFeatureId fid );
169 
170  inline QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const { return mapToSource( proxyIndex ); }
171 
172  inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
173 
174  QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
175 
176  QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
177 
178  Qt::ItemFlags flags( const QModelIndex &index ) const override;
179 
187  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
188 
196  void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
197 
201  QString sortExpression() const;
202 
204  QgsMapCanvas *mapCanvas() const { return mCanvas; }
205 
206  QVariant data( const QModelIndex &index, int role ) const override;
207 
208  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
209 
214  int actionColumnIndex() const;
215 
216  int columnCount( const QModelIndex &parent ) const override;
217 
223  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
224 
225  signals:
226 
232  void sortColumnChanged( int column, Qt::SortOrder order );
233 
234  protected:
235 
242  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
243 
248  void generateListOfVisibleFeatures();
249 
254  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
255 
256  public slots:
257 
262  void extentsChanged();
263 
264  private slots:
265  void selectionChanged();
266  void onColumnsChanged();
267 
268  private:
269  QgsFeatureIds mFilteredFeatures;
270  QgsMapCanvas *mCanvas = nullptr;
271  FilterMode mFilterMode;
272  bool mSelectedOnTop;
273  QgsAttributeTableModel *mTableModel = nullptr;
274 
275  QgsAttributeTableConfig mConfig;
276  QVector<int> mColumnMapping;
277  int mapColumnToSource( int column ) const;
278 
279 };
280 
281 #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