QGIS API Documentation 4.3.0-Master (16eddb2670e)
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.h"
21#include "qgis_gui.h"
23#include "qgsfeaturemodel.h"
24
25#include <QModelIndex>
26#include <QSortFilterProxyModel>
27#include <QTimer>
28
30class QgsMapCanvas;
31class QItemSelectionModel;
32
38class GUI_EXPORT QgsAttributeTableFilterModel : public QSortFilterProxyModel, public QgsFeatureModel
39{
40 Q_OBJECT
41
42 public:
51 Q_ENUM( ColumnType )
52
53 // *INDENT-OFF*
54
55
66 Q_ENUM( CustomRole )
67 // *INDENT-ON*
68
69
76 QgsAttributeTableFilterModel( QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent SIP_TRANSFERTHIS = nullptr );
77
78#ifdef __clang__
79#pragma clang diagnostic push
80#pragma clang diagnostic ignored "-Woverloaded-virtual"
81#endif
82
89 void setSourceModel( QgsAttributeTableModel *sourceModel );
90
91#ifdef __clang__
92#pragma clang diagnostic pop
93#endif
94
101 void setSelectedOnTop( bool selectedOnTop );
102
108 bool selectedOnTop();
109
116 virtual void setFilteredFeatures( const QgsFeatureIds &ids );
117
123 QgsFeatureIds filteredFeatures() const;
124
130 void setFilterMode( Qgis::AttributeTableFilterMode filterMode );
131
135 void disconnectFilterModeConnections();
136
140 void connectFilterModeConnections( Qgis::AttributeTableFilterMode filterMode );
141
146
152 inline QgsVectorLayer *layer() const { return masterModel()->layer(); }
153
159 inline QgsVectorLayerCache *layerCache() const { return masterModel()->layerCache(); }
160
166 inline QgsAttributeTableModel *masterModel() const { return mTableModel; }
167
175 QgsFeatureId rowToId( const QModelIndex &row ) const;
176
177 QModelIndex fidToIndex( QgsFeatureId fid ) override;
178
179 QModelIndexList fidToIndexList( QgsFeatureId fid );
180
181 QModelIndex mapToMaster( const QModelIndex &proxyIndex ) const;
182
183 inline QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const { return mapFromSource( sourceIndex ); }
184
185 QModelIndex mapToSource( const QModelIndex &proxyIndex ) const override;
186
187 QModelIndex mapFromSource( const QModelIndex &sourceIndex ) const override;
188
189 Qt::ItemFlags flags( const QModelIndex &index ) const override;
190
198 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
199
207 void sort( const QString &expression, Qt::SortOrder order = Qt::AscendingOrder );
208
212 QString sortExpression() const;
213
215 QgsMapCanvas *mapCanvas() const { return mCanvas; }
216
217 QVariant data( const QModelIndex &index, int role ) const override;
218
219 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
220
225 int actionColumnIndex() const;
226
227 int columnCount( const QModelIndex &parent ) const override;
228
236 void setAttributeTableConfig( const QgsAttributeTableConfig &config, bool force SIP_PYARGREMOVE = false );
237
244 void setFilterExpression( const QgsExpression &expression, const QgsExpressionContext &context );
245
251 QString filterExpression() const { return mFilterExpression; };
252
253 signals:
254
260 void sortColumnChanged( int column, Qt::SortOrder order );
261
266
271
276 void filterError( const QString &errorMessage );
277
278 protected:
285 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
286
292
297 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
298
299 public slots:
300
307 Q_DECL_DEPRECATED void extentsChanged();
308
315 void filterFeatures();
316
317 private slots:
318 void selectionChanged();
319 void onColumnsChanged();
320 void reloadVisible();
321 void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
322 void onGeometryChanged();
323
324 private:
325 QgsFeatureIds mFilteredFeatures;
326 QgsMapCanvas *mCanvas = nullptr;
328 bool mSelectedOnTop = false;
329 QgsAttributeTableModel *mTableModel = nullptr;
330
332 QVector<int> mColumnMapping;
333 QgsExpression mFilterExpression;
334 QgsExpressionContext mFilterExpressionContext;
335
336 int mapColumnToSource( int column ) const;
337 int mapColumnFromSource( int column ) const;
338
339 QTimer mReloadVisibleTimer;
340 QTimer mFilterFeaturesTimer;
341 void startTimedReloadVisible();
342 void startTimedFilterFeatures();
343};
344
345#endif
AttributeTableFilterMode
Defines how rows in attribute tables should be filtered.
Definition qgis.h:7277
@ ShowAll
Show all features.
Definition qgis.h:7278
A container for configuration of the attribute table.
A proxy model for filtering an attribute table model.
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.
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.
Qgis::AttributeTableFilterMode filterMode()
The current filterModel.
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:52
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:270
#define SIP_PYARGREMOVE
Definition qgis_sip.h:163
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:272
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features