QGIS API Documentation
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 
32 {
33  Q_OBJECT
34 
35  public:
40  {
45  ShowEdited
46  };
47 
52  {
54  ColumnTypeActionButton
55  };
56 
62  enum Role
63  {
65  };
66 
67 
75  QgsAttributeTableFilterModel( QgsMapCanvas* canvas, QgsAttributeTableModel* sourceModel, QObject* parent = nullptr );
76 
84  void setSourceModel( QgsAttributeTableModel* sourceModel );
85 
92  void setSelectedOnTop( bool selectedOnTop );
93 
99  bool selectedOnTop();
100 
107  virtual void setFilteredFeatures( const QgsFeatureIds& ids );
108 
114  QgsFeatureIds filteredFeatures();
115 
121  void setFilterMode( FilterMode filterMode );
122 
126  FilterMode filterMode() { return mFilterMode; }
127 
133  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
134 
140  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
141 
147  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
148 
156  QgsFeatureId rowToId( const QModelIndex& row );
157 
158  QModelIndex fidToIndex( QgsFeatureId fid ) override;
159 
160  QModelIndexList fidToIndexList( QgsFeatureId fid );
161 
162  inline QModelIndex mapToMaster( const QModelIndex& proxyIndex ) const { return mapToSource( proxyIndex ); }
163 
164  inline QModelIndex mapFromMaster( const QModelIndex& sourceIndex ) const { return mapFromSource( sourceIndex ); }
165 
166  virtual QModelIndex mapToSource( const QModelIndex& proxyIndex ) const override;
167 
168  virtual QModelIndex mapFromSource( const QModelIndex& sourceIndex ) const override;
169 
170  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
171 
172  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
173 
181  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
182 
184  QgsMapCanvas* mapCanvas() const { return mCanvas; }
185 
186  virtual QVariant data( const QModelIndex& index, int role ) const override;
187 
188  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
189 
194  int actionColumnIndex() const;
195 
196  int columnCount( const QModelIndex &parent ) const override;
197 
203  void setAttributeTableConfig( const QgsAttributeTableConfig& config );
204 
205  protected:
212  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
213 
218  void generateListOfVisibleFeatures();
219 
224  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
225 
226  public slots:
231  void extentsChanged();
232 
233  private slots:
234  void selectionChanged();
235  void onColumnsChanged();
236 
237  private:
238  QgsFeatureIds mFilteredFeatures;
239  QgsMapCanvas* mCanvas;
240  FilterMode mFilterMode;
241  bool mSelectedOnTop;
242  QgsAttributeTableModel* mTableModel;
243 
244  QgsAttributeTableConfig mConfig;
245  QVector<int> mColumnMapping;
246 };
247 
248 #endif
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
static unsigned index
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual void sort(int column, Qt::SortOrder order)
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:108
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
FilterMode filterMode()
The current filterModel.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
FilterMode
The filter mode defines how the rows should be filtered.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
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
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
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
typedef ItemFlags