QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgsvectorlayer.h" //QgsFeatureIds
24 #include "qgsattributetablemodel.h"
25 #include "qgsfeaturemodel.h"
26 
28 class QgsMapCanvas;
30 
35 {
36  Q_OBJECT
37 
38  public:
43  {
48  ShowEdited
49  };
50 
55  {
57  ColumnTypeActionButton
58  };
59 
65  enum Role
66  {
68  };
69 
70 
78  QgsAttributeTableFilterModel( QgsMapCanvas* canvas, QgsAttributeTableModel* sourceModel, QObject* parent = nullptr );
79 
87  void setSourceModel( QgsAttributeTableModel* sourceModel );
88 
95  void setSelectedOnTop( bool selectedOnTop );
96 
102  bool selectedOnTop();
103 
110  virtual void setFilteredFeatures( const QgsFeatureIds& ids );
111 
117  QgsFeatureIds filteredFeatures();
118 
124  void setFilterMode( FilterMode filterMode );
125 
129  FilterMode filterMode() { return mFilterMode; }
130 
136  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
137 
143  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
144 
150  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
151 
159  QgsFeatureId rowToId( const QModelIndex& row );
160 
161  QModelIndex fidToIndex( QgsFeatureId fid ) override;
162 
163  QModelIndexList fidToIndexList( QgsFeatureId fid );
164 
165  inline QModelIndex mapToMaster( const QModelIndex& proxyIndex ) const { return mapToSource( proxyIndex ); }
166 
167  inline QModelIndex mapFromMaster( const QModelIndex& sourceIndex ) const { return mapFromSource( sourceIndex ); }
168 
169  virtual QModelIndex mapToSource( const QModelIndex& proxyIndex ) const override;
170 
171  virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const override;
172 
173  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
174 
182  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
183 
191  void sort( QString expression, Qt::SortOrder order = Qt::AscendingOrder );
192 
196  QString sortExpression() const;
197 
199  QgsMapCanvas* mapCanvas() const { return mCanvas; }
200 
201  virtual QVariant data( const QModelIndex& index, int role ) const override;
202 
203  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
204 
209  int actionColumnIndex() const;
210 
211  int columnCount( const QModelIndex &parent ) const override;
212 
218  void setAttributeTableConfig( const QgsAttributeTableConfig& config );
219 
220  signals:
226  void sortColumnChanged( int column, Qt::SortOrder order );
227 
228  protected:
235  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
236 
241  void generateListOfVisibleFeatures();
242 
247  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
248 
249  public slots:
254  void extentsChanged();
255 
256  private slots:
257  void selectionChanged();
258  void onColumnsChanged();
259 
260  private:
261  QgsFeatureIds mFilteredFeatures;
262  QgsMapCanvas* mCanvas;
263  FilterMode mFilterMode;
264  bool mSelectedOnTop;
265  QgsAttributeTableModel* mTableModel;
266 
267  QgsAttributeTableConfig mConfig;
268  QVector<int> mColumnMapping;
269  int mapColumnToSource( int column ) const;
270 
271  friend class TestQgsAttributeTable;
272 
273 };
274 
275 #endif
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
static unsigned index
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual void sort(int column, Qt::SortOrder order)
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
virtual void setSourceModel(QAbstractItemModel *sourceModel)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
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:109
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
FilterMode filterMode()
The current filterModel.
FilterMode
The filter mode defines how the rows should be filtered.
virtual int columnCount(const QModelIndex &parent) const
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.
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
This is a container for configuration of the attribute table.
Represents a vector layer which manages a vector based data sets.
virtual QVariant data(const QModelIndex &index, int role) const
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
typedef ItemFlags