QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
29 class QItemSelectionModel;
30 
31 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
32 {
33  Q_OBJECT
34 
35  public:
37  {
42  ShowEdited
43  };
44 
53  QgsAttributeTableFilterModel( QgsMapCanvas* canvas, QgsAttributeTableModel* sourceModel, QObject* parent = 0 );
54 
55  void setSourceModel( QgsAttributeTableModel* sourceModel );
56 
63  void setSelectedOnTop( bool selectedOnTop );
64 
70  bool selectedOnTop();
71 
78  virtual void setFilteredFeatures( QgsFeatureIds ids );
79 
80  QgsFeatureIds filteredFeatures();
81 
87  void setFilterMode( FilterMode filterMode );
88 
89  FilterMode filterMode() { return mFilterMode; }
90 
96  inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
97 
103  inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
104 
110  inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
111 
119  QgsFeatureId rowToId( const QModelIndex& row );
120 
121  QModelIndex fidToIndex( QgsFeatureId fid ) override;
122  QModelIndexList fidToIndexList( QgsFeatureId fid );
123 
124  virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
125 
126  virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
127 
128  protected:
135  bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
136 
141  void generateListOfVisibleFeatures();
142 
147  bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
148 
156  virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
157 
158  public slots:
164  void extentsChanged();
165 
166  private slots:
167  void selectionChanged();
168 
169  private:
170  QgsFeatureIds mFilteredFeatures;
171  QgsMapCanvas* mCanvas;
172  FilterMode mFilterMode;
173  bool mSelectedOnTop;
174  QgsAttributeTableModel* mTableModel;
175 };
176 
177 #endif