QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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_gui.h"
22#include "qgsfeaturemodel.h"
23
24#include <QModelIndex>
25#include <QSortFilterProxyModel>
26#include <QTimer>
27
29class QgsMapCanvas;
30class QItemSelectionModel;
31
37class GUI_EXPORT QgsAttributeTableFilterModel : public QSortFilterProxyModel, public QgsFeatureModel
38{
39 Q_OBJECT
40
41 public:
42
55 Q_ENUM( FilterMode )
56
57
65 Q_ENUM( ColumnType )
66
67 // *INDENT-OFF*
68
69
80 Q_ENUM( CustomRole )
81 // *INDENT-ON*
82
83
90 QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
91
92#ifdef __clang__
93#pragma clang diagnostic push
94#pragma clang diagnostic ignored "-Woverloaded-virtual"
95#endif
96
103 void setSourceModel( QgsAttributeTableModel *sourceModel );
104
105#ifdef __clang__
106#pragma clang diagnostic pop
107#endif
108
115 void setSelectedOnTop( bool selectedOnTop );
116
122 bool selectedOnTop();
123
130 virtual void setFilteredFeatures( const QgsFeatureIds &ids );
131
137 QgsFeatureIds filteredFeatures();
138
144 void setFilterMode( FilterMode filterMode );
145
149 void disconnectFilterModeConnections();
150
154 void connectFilterModeConnections( FilterMode filterMode );
155
159 FilterMode filterMode() { return mFilterMode; }
160
166 inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
167
173 inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
174
180 inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
181
189 QgsFeatureId rowToId( const QModelIndex &row );
190
191 QModelIndex fidToIndex( QgsFeatureId fid ) override;
192
193 QModelIndexList fidToIndexList( QgsFeatureId fid );
194
195 QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
196
197 inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
198
199 QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
200
201 QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
202
203 Qt::ItemFlags flags( const QModelIndex &index ) const override;
204
212 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
213
221 void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
222
226 QString sortExpression() const;
227
229 QgsMapCanvas *mapCanvas() const { return mCanvas; }
230
231 QVariant data( const QModelIndex &index, int role ) const override;
232
233 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
234
239 int actionColumnIndex() const;
240
241 int columnCount( const QModelIndex &parent ) const override;
242
250 void setAttributeTableConfig( const QgsAttributeTableConfig &config, bool force SIP_PYARGREMOVE = false );
251
258 void setFilterExpression( const QgsExpression &expression, const QgsExpressionContext &context );
259
265 QString filterExpression() const { return mFilterExpression; };
266
267 signals:
268
274 void sortColumnChanged( int column, Qt::SortOrder order );
275
280
285
290 void filterError( const QString &errorMessage );
291
292 protected:
293
300 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
301
307
312 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
313
314 public slots:
315
322 Q_DECL_DEPRECATED void extentsChanged();
323
330 void filterFeatures();
331
332 private slots:
333 void selectionChanged();
334 void onColumnsChanged();
335 void reloadVisible();
336 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
337 void onGeometryChanged();
338
339 private:
340 QgsFeatureIds mFilteredFeatures;
341 QgsMapCanvas *mCanvas = nullptr;
342 FilterMode mFilterMode = FilterMode::ShowAll;
343 bool mSelectedOnTop = false;
344 QgsAttributeTableModel *mTableModel = nullptr;
345
347 QVector<int> mColumnMapping;
348 QgsExpression mFilterExpression;
349 QgsExpressionContext mFilterExpressionContext;
350
351 int mapColumnToSource( int column ) const;
352 int mapColumnFromSource( int column ) const;
353
354 QTimer mReloadVisibleTimer;
355 QTimer mFilterFeaturesTimer;
356 void startTimedReloadVisible();
357 void startTimedFilterFeatures();
358};
359
360#endif
A container for configuration of the attribute table.
A proxy model for filtering an attribute table model.
FilterMode filterMode()
The current filterModel.
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
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.
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.
CustomRole
The additional roles defined by this filter model.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Used by the sorting algorithm.
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.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Returns true if the source row will be accepted.
QModelIndex mapFromMaster(const QModelIndex &sourceIndex) const
void filterFeatures()
Updates the filtered features in the filter model.
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).
@ ColumnTypeActionButton
This column shows action buttons.
@ 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:268
#define SIP_PYARGREMOVE
Definition qgis_sip.h:159
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features