QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 <QModelIndex>
22 
23 #include "qgsattributetablemodel.h"
24 #include "qgsfeaturemodel.h"
25 #include "qgis_gui.h"
26 
28 class QgsMapCanvas;
29 class QItemSelectionModel;
30 
35 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
36 {
37  Q_OBJECT
38 
39  public:
40 
45  {
50  ShowEdited
51  };
52  Q_ENUM( FilterMode )
53 
54 
58  {
60  ColumnTypeActionButton
61  };
62  Q_ENUM( ColumnType )
63 
64 
69  enum Role
70  {
72  };
73 
74 
82  QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
83 
91  void setSourceModel( QgsAttributeTableModel *sourceModel );
92 
99  void setSelectedOnTop( bool selectedOnTop );
100 
106  bool selectedOnTop();
107 
114  virtual void setFilteredFeatures( const QgsFeatureIds &ids );
115 
121  QgsFeatureIds filteredFeatures();
122 
128  void setFilterMode( FilterMode filterMode );
129 
133  FilterMode filterMode() { return mFilterMode; }
134 
140  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
141 
147  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
148 
154  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
155 
163  QgsFeatureId rowToId( const QModelIndex &row );
164 
165  QModelIndex fidToIndex( QgsFeatureId fid ) override;
166 
167  QModelIndexList fidToIndexList( QgsFeatureId fid );
168 
169  inline QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const { return mapToSource( proxyIndex ); }
170 
171  inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
172 
173  QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
174 
175  QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
176 
177  Qt::ItemFlags flags( const QModelIndex &index ) const override;
178 
186  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
187 
195  void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
196 
200  QString sortExpression() const;
201 
203  QgsMapCanvas *mapCanvas() const { return mCanvas; }
204 
205  QVariant data( const QModelIndex &index, int role ) const override;
206 
207  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
208 
213  int actionColumnIndex() const;
214 
215  int columnCount( const QModelIndex &parent ) const override;
216 
222  void setAttributeTableConfig( const QgsAttributeTableConfig &config );
223 
224  signals:
225 
231  void sortColumnChanged( int column, Qt::SortOrder order );
232 
233  protected:
234 
241  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
242 
247  void generateListOfVisibleFeatures();
248 
253  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
254 
255  public slots:
256 
261  void extentsChanged();
262 
263  private slots:
264  void selectionChanged();
265  void onColumnsChanged();
266 
267  private:
268  QgsFeatureIds mFilteredFeatures;
269  QgsMapCanvas *mCanvas = nullptr;
270  FilterMode mFilterMode = FilterMode::ShowAll;
271  bool mSelectedOnTop = false;
272  QgsAttributeTableModel *mTableModel = nullptr;
273 
274  QgsAttributeTableConfig mConfig;
275  QVector<int> mColumnMapping;
276  int mapColumnToSource( int column ) const;
277  int mapColumnFromSource( int column ) const;
278 
279 };
280 
281 #endif
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
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:75
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.
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