QGIS API Documentation 4.3.0-Master (bd2f5e21fd1)
Loading...
Searching...
No Matches
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 : (C) 2009 by 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 "qgis.h"
21#include "qgis_gui.h"
23#include "qgsfeaturemodel.h"
24
25#include <QModelIndex>
26#include <QSortFilterProxyModel>
27#include <QTimer>
28
30class QgsMapCanvas;
31class QItemSelectionModel;
32
38class GUI_EXPORT QgsAttributeTableFilterModel : public QSortFilterProxyModel, public QgsFeatureModel
39{
40 Q_OBJECT
41
42 public:
50 QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
51
52#ifdef __clang__
53#pragma clang diagnostic push
54#pragma clang diagnostic ignored "-Woverloaded-virtual"
55#endif
56
63 void setSourceModel( QgsAttributeTableModel *sourceModel );
64
65#ifdef __clang__
66#pragma clang diagnostic pop
67#endif
68
76
82 bool selectedOnTop();
83
90 virtual void setFilteredFeatures( const QgsFeatureIds &ids );
91
98
105
110
115
120
126 inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
127
133 inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
134
140 inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
141
149 QgsFeatureId rowToId( const QModelIndex &row ) const;
150
151 QModelIndex fidToIndex( QgsFeatureId fid ) override;
152
153 QModelIndexList fidToIndexList( QgsFeatureId fid );
154
155 QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
156
157 inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
158
166 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
167
175 void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
176
180 QString sortExpression() const;
181
183 QgsMapCanvas *mapCanvas() const { return mCanvas; }
184
191 Q_DECL_DEPRECATED int actionColumnIndex() const SIP_DEPRECATED;
192
200 void setAttributeTableConfig( const QgsAttributeTableConfig &config, bool force SIP_PYARGREMOVE = false );
201
208 void setFilterExpression( const QgsExpression &expression, const QgsExpressionContext &context );
209
215 QString filterExpression() const { return mFilterExpression; };
216
217 signals:
218
224 void sortColumnChanged( int column, Qt::SortOrder order );
225
230
235
240 void filterError( const QString &errorMessage );
241
242 protected:
249 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
250
256
261 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
262
263 public slots:
264
271 Q_DECL_DEPRECATED void extentsChanged();
272
279 void filterFeatures();
280
281 private slots:
282 void selectionChanged();
283 void onColumnsChanged();
284 void reloadVisible();
285 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
286 void onGeometryChanged();
287
288 private:
289 QgsFeatureIds mFilteredFeatures;
290 QgsMapCanvas *mCanvas = nullptr;
292 bool mSelectedOnTop = false;
293 QgsAttributeTableModel *mTableModel = nullptr;
294
296
297 QgsExpression mFilterExpression;
298 QgsExpressionContext mFilterExpressionContext;
299
300 QTimer mReloadVisibleTimer;
301 QTimer mFilterFeaturesTimer;
302 void startTimedReloadVisible();
303 void startTimedFilterFeatures();
304};
305
306#endif
AttributeTableFilterMode
Defines how rows in attribute tables should be filtered.
Definition qgis.h:7317
@ ShowAll
Show all features.
Definition qgis.h:7318
A container for configuration of the attribute table.
QgsFeatureIds filteredFeatures() const
Gets a list of currently filtered feature ids.
Q_DECL_DEPRECATED void extentsChanged()
Is called upon every change of the visible extents on the map canvas.
QgsAttributeTableFilterModel(QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent=nullptr)
Make sure, the master model is already loaded, so the selection will get synchronized.
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
void setFilterMode(Qgis::AttributeTableFilterMode filterMode)
Set the filter mode the filter will use.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QString filterExpression() const
Returns the stored filter expression string.
void generateListOfVisibleFeatures()
Updates the list of currently visible features on the map canvas.
void disconnectFilterModeConnections()
Disconnect the connections set for the current filterMode.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Used by the sorting algorithm.
bool selectedOnTop()
Returns if selected features are currently shown on top.
void filterError(const QString &errorMessage)
Emitted when an error occurred while filtering features.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the source row will be accepted.
void connectFilterModeConnections(Qgis::AttributeTableFilterMode filterMode)
Disconnect the connections set for the new filterMode.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
void filterFeatures()
Updates the filtered features in the filter model.
virtual void setFilteredFeatures(const QgsFeatureIds &ids)
Specify a list of features, which the filter will accept.
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
Qgis::AttributeTableFilterMode filterMode()
The current filterModel.
void featuresFiltered()
Emitted when the filtering of the features has been done.
void visibleReloaded()
Emitted when the the visible features on extend are reloaded (the list is created).
void setSourceModel(QgsAttributeTableModel *sourceModel)
Set the attribute table model that backs this model.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
void setSelectedOnTop(bool selectedOnTop)
Changes the sort order of the features.
void sortColumnChanged(int column, Qt::SortOrder order)
Emitted whenever the sort column is changed.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles parsing and evaluation of expressions (formerly called "search strings").
Base class for feature models.
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
Map canvas is a class for displaying all GIS data types on a canvas.
Caches features for a given QgsVectorLayer.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_PYARGREMOVE
Definition qgis_sip.h:163
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features