QGIS API Documentation  2.14.0-Essen
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:
37  {
42  ShowEdited
43  };
44 
53  QgsAttributeTableFilterModel( QgsMapCanvas* canvas, QgsAttributeTableModel* sourceModel, QObject* parent = nullptr );
54 
62  void setSourceModel( QgsAttributeTableModel* sourceModel );
63 
70  void setSelectedOnTop( bool selectedOnTop );
71 
77  bool selectedOnTop();
78 
85  virtual void setFilteredFeatures( const QgsFeatureIds& ids );
86 
92  QgsFeatureIds filteredFeatures();
93 
99  void setFilterMode( FilterMode filterMode );
100 
106  FilterMode filterMode() { return mFilterMode; }
107 
113  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
114 
120  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
121 
127  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
128 
136  QgsFeatureId rowToId( const QModelIndex& row );
137 
138  QModelIndex fidToIndex( QgsFeatureId fid ) override;
139  QModelIndexList fidToIndexList( QgsFeatureId fid );
140 
141  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
142 
143  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
144 
152  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
153 
155  QgsMapCanvas* mapCanvas() const { return mCanvas; }
156 
157  protected:
164  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
165 
170  void generateListOfVisibleFeatures();
171 
176  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
177 
178  public slots:
184  void extentsChanged();
185 
186  private slots:
187  void selectionChanged();
188 
189  private:
190  QgsFeatureIds mFilteredFeatures;
191  QgsMapCanvas* mCanvas;
192  FilterMode mFilterMode;
193  bool mSelectedOnTop;
194  QgsAttributeTableModel* mTableModel;
195 };
196 
197 #endif
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
virtual void sort(int column, Qt::SortOrder order)
virtual void setSourceModel(QAbstractItemModel *sourceModel)
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
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.
This class caches features of a given QgsVectorLayer.
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.