QGIS API Documentation  master-3f58142
src/gui/attributetable/qgsattributetablefiltermodel.h
Go to the documentation of this file.
00001 /***************************************************************************
00002   QgsAttributeTableFilterModel.h - Filter Model for attribute table
00003   -------------------
00004          date                 : Feb 2009
00005          copyright            : Vita Cizek
00006          email                : weetya (at) gmail.com
00007 
00008  ***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #ifndef QGSATTRIBUTETABLEFILTERMODEL_H
00018 #define QGSATTRIBUTETABLEFILTERMODEL_H
00019 
00020 #include <QSortFilterProxyModel>
00021 #include <QModelIndex>
00022 
00023 #include "qgsvectorlayer.h" //QgsFeatureIds
00024 #include "qgsattributetablemodel.h"
00025 #include "qgsfeaturemodel.h"
00026 
00027 class QgsVectorLayerCache;
00028 class QgsMapCanvas;
00029 class QItemSelectionModel;
00030 
00031 class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
00032 {
00033     Q_OBJECT
00034 
00035   public:
00036     enum FilterMode
00037     {
00038       ShowAll,
00039       ShowSelected,
00040       ShowVisible,
00041       ShowFilteredList,
00042       ShowEdited
00043     };
00044 
00053     QgsAttributeTableFilterModel( QgsMapCanvas* canvas, QgsAttributeTableModel* sourceModel, QObject* parent = NULL );
00054 
00055     void setSourceModel( QgsAttributeTableModel* sourceModel );
00056 
00063     void setSelectedOnTop( bool selectedOnTop );
00064 
00070     bool selectedOnTop();
00071 
00078     virtual void setFilteredFeatures( QgsFeatureIds ids );
00079 
00085     void setFilterMode( FilterMode filterMode );
00086 
00092     inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
00093 
00099     inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
00100 
00106     inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
00107 
00115     QgsFeatureId rowToId( const QModelIndex& row );
00116 
00117     QModelIndex fidToIndex( QgsFeatureId fid );
00118     QModelIndexList fidToIndexList( QgsFeatureId fid );
00119 
00120     virtual QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
00121 
00122     virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;
00123 
00124   protected:
00131     bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
00132 
00137     void generateListOfVisibleFeatures();
00138 
00143     bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
00144 
00152     virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
00153 
00154   public slots:
00160     void extentsChanged();
00161 
00162   private slots:
00163     void selectionChanged();
00164 
00165   private:
00166     QgsFeatureIds mFilteredFeatures;
00167     QgsMapCanvas* mCanvas;
00168     FilterMode mFilterMode;
00169     bool mSelectedOnTop;
00170     QItemSelectionModel* mMasterSelection;
00171     QgsAttributeTableModel* mTableModel;
00172 };
00173 
00174 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines