QGIS API Documentation 3.43.0-Master (0bee5d6404c)
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
37class GUI_EXPORT QgsAttributeTableFilterModel : public QSortFilterProxyModel, public QgsFeatureModel
38{
39 Q_OBJECT
40
41 public:
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:
298 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
299
304 void generateListOfVisibleFeatures();
305
310 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
311
312 public slots:
313
320 Q_DECL_DEPRECATED void extentsChanged();
321
328 void filterFeatures();
329
330 private slots:
331 void selectionChanged();
332 void onColumnsChanged();
333 void reloadVisible();
334 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
335 void onGeometryChanged();
336
337 private:
338 QgsFeatureIds mFilteredFeatures;
339 QgsMapCanvas *mCanvas = nullptr;
340 FilterMode mFilterMode = FilterMode::ShowAll;
341 bool mSelectedOnTop = false;
342 QgsAttributeTableModel *mTableModel = nullptr;
343
345 QVector<int> mColumnMapping;
346 QgsExpression mFilterExpression;
347 QgsExpressionContext mFilterExpressionContext;
348
349 int mapColumnToSource( int column ) const;
350 int mapColumnFromSource( int column ) const;
351
352 QTimer mReloadVisibleTimer;
353 QTimer mFilterFeaturesTimer;
354 void startTimedReloadVisible();
355 void startTimedFilterFeatures();
356};
357
358#endif
A container for configuration of the attribute table.
A proxy model for filtering an attribute table model.
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.
@ 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...
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_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