QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
53 Q_ENUM( FilterMode )
54
55
59 {
61 ColumnTypeActionButton
62 };
63 Q_ENUM( ColumnType )
64
65 // *INDENT-OFF*
66
67
78 Q_ENUM( CustomRole )
79 // *INDENT-ON*
80
81
88 QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
89
90#ifdef __clang__
91#pragma clang diagnostic push
92#pragma clang diagnostic ignored "-Woverloaded-virtual"
93#endif
94
101 void setSourceModel( QgsAttributeTableModel *sourceModel );
102
103#ifdef __clang__
104#pragma clang diagnostic pop
105#endif
106
113 void setSelectedOnTop( bool selectedOnTop );
114
120 bool selectedOnTop();
121
128 virtual void setFilteredFeatures( const QgsFeatureIds &ids );
129
135 QgsFeatureIds filteredFeatures();
136
142 void setFilterMode( FilterMode filterMode );
143
147 void disconnectFilterModeConnections();
148
152 void connectFilterModeConnections( FilterMode filterMode );
153
157 FilterMode filterMode() { return mFilterMode; }
158
164 inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
165
171 inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
172
178 inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
179
187 QgsFeatureId rowToId( const QModelIndex &row );
188
189 QModelIndex fidToIndex( QgsFeatureId fid ) override;
190
191 QModelIndexList fidToIndexList( QgsFeatureId fid );
192
193 QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
194
195 inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
196
197 QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
198
199 QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
200
201 Qt::ItemFlags flags( const QModelIndex &index ) const override;
202
210 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
211
219 void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
220
224 QString sortExpression() const;
225
227 QgsMapCanvas *mapCanvas() const { return mCanvas; }
228
229 QVariant data( const QModelIndex &index, int role ) const override;
230
231 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
232
237 int actionColumnIndex() const;
238
239 int columnCount( const QModelIndex &parent ) const override;
240
248 void setAttributeTableConfig( const QgsAttributeTableConfig &config, bool force SIP_PYARGREMOVE = false );
249
256 void setFilterExpression( const QgsExpression &expression, const QgsExpressionContext &context );
257
263 QString filterExpression() const { return mFilterExpression; };
264
265 signals:
266
272 void sortColumnChanged( int column, Qt::SortOrder order );
273
278
283
288 void filterError( const QString &errorMessage );
289
290 protected:
297 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
298
303 void generateListOfVisibleFeatures();
304
309 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
310
311 public slots:
312
319 Q_DECL_DEPRECATED void extentsChanged();
320
327 void filterFeatures();
328
329 private slots:
330 void selectionChanged();
331 void onColumnsChanged();
332 void reloadVisible();
333 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
334 void onGeometryChanged();
335
336 private:
337 QgsFeatureIds mFilteredFeatures;
338 QgsMapCanvas *mCanvas = nullptr;
339 FilterMode mFilterMode = FilterMode::ShowAll;
340 bool mSelectedOnTop = false;
341 QgsAttributeTableModel *mTableModel = nullptr;
342
344 QVector<int> mColumnMapping;
345 QgsExpression mFilterExpression;
346 QgsExpressionContext mFilterExpressionContext;
347
348 int mapColumnToSource( int column ) const;
349 int mapColumnFromSource( int column ) const;
350
351 QTimer mReloadVisibleTimer;
352 QTimer mFilterFeaturesTimer;
353 void startTimedReloadVisible();
354 void startTimedFilterFeatures();
355};
356
357#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.
@ 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