QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 <QSortFilterProxyModel>
21#include <QModelIndex>
22#include <QTimer>
23
25#include "qgsfeaturemodel.h"
26#include "qgis_gui.h"
27
29class QgsMapCanvas;
30class QItemSelectionModel;
31
36class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, public QgsFeatureModel
37{
38 Q_OBJECT
39
40 public:
41
46 {
53 };
54 Q_ENUM( FilterMode )
55
56
60 {
62 ColumnTypeActionButton
63 };
64 Q_ENUM( ColumnType )
65
66
71 enum Role
72 {
74 };
75
76
84 QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
85
86#ifdef __clang__
87#pragma clang diagnostic push
88#pragma clang diagnostic ignored "-Woverloaded-virtual"
89#endif
90
98 void setSourceModel( QgsAttributeTableModel *sourceModel );
99
100#ifdef __clang__
101#pragma clang diagnostic pop
102#endif
103
110 void setSelectedOnTop( bool selectedOnTop );
111
117 bool selectedOnTop();
118
125 virtual void setFilteredFeatures( const QgsFeatureIds &ids );
126
132 QgsFeatureIds filteredFeatures();
133
139 void setFilterMode( FilterMode filterMode );
140
144 void disconnectFilterModeConnections();
145
149 void connectFilterModeConnections( FilterMode filterMode );
150
154 FilterMode filterMode() { return mFilterMode; }
155
161 inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
162
168 inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
169
175 inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
176
184 QgsFeatureId rowToId( const QModelIndex &row );
185
186 QModelIndex fidToIndex( QgsFeatureId fid ) override;
187
188 QModelIndexList fidToIndexList( QgsFeatureId fid );
189
190 inline QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const { return mapToSource( proxyIndex ); }
191
192 inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
193
194 QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
195
196 QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
197
198 Qt::ItemFlags flags( const QModelIndex &index ) const override;
199
207 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
208
216 void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
217
221 QString sortExpression() const;
222
224 QgsMapCanvas *mapCanvas() const { return mCanvas; }
225
226 QVariant data( const QModelIndex &index, int role ) const override;
227
228 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
229
234 int actionColumnIndex() const;
235
236 int columnCount( const QModelIndex &parent ) const override;
237
245 void setAttributeTableConfig( const QgsAttributeTableConfig &config, bool force SIP_PYARGREMOVE = false );
246
253 void setFilterExpression( const QgsExpression &expression, const QgsExpressionContext &context );
254
260 QString filterExpression() const { return mFilterExpression; };
261
262 signals:
263
269 void sortColumnChanged( int column, Qt::SortOrder order );
270
275
280
285 void filterError( const QString &errorMessage );
286
287 protected:
288
295 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
296
301 void generateListOfVisibleFeatures();
302
307 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
308
309 public slots:
310
317 Q_DECL_DEPRECATED void extentsChanged();
318
325 void filterFeatures();
326
327 private slots:
328 void selectionChanged();
329 void onColumnsChanged();
330 void reloadVisible();
331 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
332 void onGeometryChanged();
333
334 private:
335 QgsFeatureIds mFilteredFeatures;
336 QgsMapCanvas *mCanvas = nullptr;
337 FilterMode mFilterMode = FilterMode::ShowAll;
338 bool mSelectedOnTop = false;
339 QgsAttributeTableModel *mTableModel = nullptr;
340
342 QVector<int> mColumnMapping;
343 QgsExpression mFilterExpression;
344 QgsExpressionContext mFilterExpressionContext;
345
346 int mapColumnToSource( int column ) const;
347 int mapColumnFromSource( int column ) const;
348
349 QTimer mReloadVisibleTimer;
350 QTimer mFilterFeaturesTimer;
351 void startTimedReloadVisible();
352 void startTimedFilterFeatures();
353};
354
355#endif
This is a container for configuration of the attribute table.
FilterMode filterMode()
The current filterModel.
Role
The additional roles defined by this filter model.
QgsMapCanvas * mapCanvas() const
Returns the map canvas.
QgsVectorLayerCache * layerCache() const
Returns the layerCache this filter acts on.
QString filterExpression() const
Returns the stored filter expression string.
FilterMode
The filter mode defines how the rows should be filtered.
@ ShowFilteredList
Show only features whose ids are on the filter list. {.
@ ShowVisible
Show only visible features (depends on the map canvas)
@ ShowSelected
Show only selected features.
@ ShowInvalid
Show only features not respecting constraints (since QGIS 3.30)
@ ShowEdited
Show only features which have unsaved changes.
void filterError(const QString &errorMessage)
Emitted when an error occurred while filtering features.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
QgsAttributeTableModel * masterModel() const
Returns the table model this filter is using.
QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
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)
@ ColumnTypeField
This column shows a field.
QgsVectorLayer * layer() const
Returns the layer this filter acts on.
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...
@ UserRole
Start further roles starting from this role.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
virtual QModelIndex fidToIndex(QgsFeatureId fid)=0
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
This class caches features of a given QgsVectorLayer.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:151
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28