QGIS API Documentation 3.38.0-Grenoble (exported)
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 <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
54 Q_ENUM( FilterMode )
55
56
60 {
62 ColumnTypeActionButton
63 };
64 Q_ENUM( ColumnType )
65
66 // *INDENT-OFF*
67
68
79 Q_ENUM( CustomRole )
80 // *INDENT-ON*
81
82
89 QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
90
91#ifdef __clang__
92#pragma clang diagnostic push
93#pragma clang diagnostic ignored "-Woverloaded-virtual"
94#endif
95
102 void setSourceModel( QgsAttributeTableModel *sourceModel );
103
104#ifdef __clang__
105#pragma clang diagnostic pop
106#endif
107
114 void setSelectedOnTop( bool selectedOnTop );
115
121 bool selectedOnTop();
122
129 virtual void setFilteredFeatures( const QgsFeatureIds &ids );
130
136 QgsFeatureIds filteredFeatures();
137
143 void setFilterMode( FilterMode filterMode );
144
148 void disconnectFilterModeConnections();
149
153 void connectFilterModeConnections( FilterMode filterMode );
154
158 FilterMode filterMode() { return mFilterMode; }
159
165 inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
166
172 inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
173
179 inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
180
188 QgsFeatureId rowToId( const QModelIndex &row );
189
190 QModelIndex fidToIndex( QgsFeatureId fid ) override;
191
192 QModelIndexList fidToIndexList( QgsFeatureId fid );
193
194 QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
195
196 inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
197
198 QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
199
200 QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
201
202 Qt::ItemFlags flags( const QModelIndex &index ) const override;
203
211 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
212
220 void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
221
225 QString sortExpression() const;
226
228 QgsMapCanvas *mapCanvas() const { return mCanvas; }
229
230 QVariant data( const QModelIndex &index, int role ) const override;
231
232 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
233
238 int actionColumnIndex() const;
239
240 int columnCount( const QModelIndex &parent ) const override;
241
249 void setAttributeTableConfig( const QgsAttributeTableConfig &config, bool force SIP_PYARGREMOVE = false );
250
257 void setFilterExpression( const QgsExpression &expression, const QgsExpressionContext &context );
258
264 QString filterExpression() const { return mFilterExpression; };
265
266 signals:
267
273 void sortColumnChanged( int column, Qt::SortOrder order );
274
279
284
289 void filterError( const QString &errorMessage );
290
291 protected:
292
299 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
300
305 void generateListOfVisibleFeatures();
306
311 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
312
313 public slots:
314
321 Q_DECL_DEPRECATED void extentsChanged();
322
329 void filterFeatures();
330
331 private slots:
332 void selectionChanged();
333 void onColumnsChanged();
334 void reloadVisible();
335 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
336 void onGeometryChanged();
337
338 private:
339 QgsFeatureIds mFilteredFeatures;
340 QgsMapCanvas *mCanvas = nullptr;
341 FilterMode mFilterMode = FilterMode::ShowAll;
342 bool mSelectedOnTop = false;
343 QgsAttributeTableModel *mTableModel = nullptr;
344
346 QVector<int> mColumnMapping;
347 QgsExpression mFilterExpression;
348 QgsExpressionContext mFilterExpressionContext;
349
350 int mapColumnToSource( int column ) const;
351 int mapColumnFromSource( int column ) const;
352
353 QTimer mReloadVisibleTimer;
354 QTimer mFilterFeaturesTimer;
355 void startTimedReloadVisible();
356 void startTimedFilterFeatures();
357};
358
359#endif
This is a container for configuration of the attribute table.
FilterMode filterMode()
The current filterModel.
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.
CustomRole
The additional roles defined by this filter model.
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.
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...
@ User
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.
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_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_PYARGREMOVE
Definition qgis_sip.h:151
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features