QGIS API Documentation  2.15.0-Master (13f053b)
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 
179  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
180 
188  void sort( QString expression, Qt::SortOrder order = Qt::AscendingOrder );
189 
193  QString sortExpression() const;
194 
196  QgsMapCanvas* mapCanvas() const { return mCanvas; }
197 
198  virtual QVariant data( const QModelIndex& index, int role ) const override;
199 
200  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
201 
206  int actionColumnIndex() const;
207 
208  int columnCount( const QModelIndex &parent ) const override;
209 
215  void setAttributeTableConfig( const QgsAttributeTableConfig& config );
216 
217  protected:
224  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
225 
230  void generateListOfVisibleFeatures();
231 
236  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
237 
238  public slots:
243  void extentsChanged();
244 
245  private slots:
246  void selectionChanged();
247  void onColumnsChanged();
248 
249  private:
250  QgsFeatureIds mFilteredFeatures;
251  QgsMapCanvas* mCanvas;
252  FilterMode mFilterMode;
253  bool mSelectedOnTop;
254  QgsAttributeTableModel* mTableModel;
255 
256  QgsAttributeTableConfig mConfig;
257  QVector<int> mColumnMapping;
258 };
259 
260 #endif
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