QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
QgsAttributeTableFilterModel Class Reference

#include <qgsattributetablefiltermodel.h>

Inheritance diagram for QgsAttributeTableFilterModel:
Inheritance graph
[legend]

Public Types

enum  ColumnType { ColumnTypeField , ColumnTypeActionButton }
 The type of a column. More...
 
enum class  CustomRole : int { Type = static_cast< int >( QgsAttributeTableModel::CustomRole::User ) }
 The additional roles defined by this filter model. More...
 
enum  FilterMode {
  ShowAll , ShowSelected , ShowVisible , ShowFilteredList ,
  ShowEdited , ShowInvalid
}
 The filter mode defines how the rows should be filtered. More...
 

Public Slots

Q_DECL_DEPRECATED void extentsChanged ()
 Is called upon every change of the visible extents on the map canvas.
 
void filterFeatures ()
 Updates the filtered features in the filter model.
 

Signals

void featuresFiltered ()
 Emitted when the filtering of the features has been done.
 
void filterError (const QString &errorMessage)
 Emitted when an error occurred while filtering features.
 
void sortColumnChanged (int column, Qt::SortOrder order)
 Emitted whenever the sort column is changed.
 
void visibleReloaded ()
 Emitted when the the visible features on extend are reloaded (the list is created)
 

Public Member Functions

 QgsAttributeTableFilterModel (QgsMapCanvas *canvas, QgsAttributeTableModel *sourceModel, QObject *parent=nullptr)
 Make sure, the master model is already loaded, so the selection will get synchronized.
 
int actionColumnIndex () const
 Gets the index of the first column that contains an action widget.
 
int columnCount (const QModelIndex &parent) const override
 
void connectFilterModeConnections (FilterMode filterMode)
 Disconnect the connections set for the new filterMode.
 
QVariant data (const QModelIndex &index, int role) const override
 
void disconnectFilterModeConnections ()
 Disconnect the connections set for the current filterMode.
 
QModelIndex fidToIndex (QgsFeatureId fid) override
 
QModelIndexList fidToIndexList (QgsFeatureId fid)
 
QgsFeatureIds filteredFeatures ()
 Gets a list of currently filtered feature ids.
 
QString filterExpression () const
 Returns the stored filter expression string.
 
FilterMode filterMode ()
 The current filterModel.
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
QgsVectorLayerlayer () const
 Returns the layer this filter acts on.
 
QgsVectorLayerCachelayerCache () const
 Returns the layerCache this filter acts on.
 
QgsMapCanvasmapCanvas () const
 Returns the map canvas.
 
QModelIndex mapFromMaster (const QModelIndex &sourceIndex) const
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const override
 
QModelIndex mapToMaster (const QModelIndex &proxyIndex) const
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const override
 
QgsAttributeTableModelmasterModel () const
 Returns the table model this filter is using.
 
QgsFeatureId rowToId (const QModelIndex &row)
 Returns the feature id for a given model index.
 
bool selectedOnTop ()
 Returns if selected features are currently shown on top.
 
void setAttributeTableConfig (const QgsAttributeTableConfig &config, bool force=false)
 Set the attribute table configuration to control which fields are shown, in which order they are shown as well as if and where an action column is shown.
 
virtual void setFilteredFeatures (const QgsFeatureIds &ids)
 Specify a list of features, which the filter will accept.
 
void setFilterExpression (const QgsExpression &expression, const QgsExpressionContext &context)
 Set the expression and the context to be stored in case of the features need to be filtered again (like on filter or on main model data change).
 
void setFilterMode (FilterMode filterMode)
 Set the filter mode the filter will use.
 
void setSelectedOnTop (bool selectedOnTop)
 Changes the sort order of the features.
 
void setSourceModel (QgsAttributeTableModel *sourceModel)
 Set the attribute table model that backs this model.
 
void sort (const QString &expression, Qt::SortOrder order=Qt::AscendingOrder)
 Sort by the given expression using the given order.
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 Sort by the given column using the given order.
 
QString sortExpression () const
 The expression which is used to sort the attribute table.
 
- Public Member Functions inherited from QgsFeatureModel
virtual ~QgsFeatureModel ()=default
 

Protected Member Functions

bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
 Returns true if the source row will be accepted.
 
void generateListOfVisibleFeatures ()
 Updates the list of currently visible features on the map canvas.
 
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override
 Used by the sorting algorithm.
 

Detailed Description

Definition at line 36 of file qgsattributetablefiltermodel.h.

Member Enumeration Documentation

◆ ColumnType

The type of a column.

Enumerator
ColumnTypeField 

This column shows a field.

ColumnTypeActionButton 

This column shows action buttons.

Definition at line 59 of file qgsattributetablefiltermodel.h.

◆ CustomRole

The additional roles defined by this filter model.

The values of these roles start just after the roles defined by QgsAttributeTableModel so they do not conflict.

Note
Prior to QGIS 3.36 this was available as QgsAttributeTableFilterModel::Role
Since
QGIS 3.36
Enumerator
Type 

The type of a given column.

Definition at line 75 of file qgsattributetablefiltermodel.h.

◆ FilterMode

The filter mode defines how the rows should be filtered.

Enumerator
ShowAll 

Show all features.

ShowSelected 

Show only selected features.

ShowVisible 

Show only visible features (depends on the map canvas)

ShowFilteredList 

Show only features whose ids are on the filter list. {.

See also
setFilteredFeatures}
ShowEdited 

Show only features which have unsaved changes.

ShowInvalid 

Show only features not respecting constraints.

Since
QGIS 3.30

Definition at line 45 of file qgsattributetablefiltermodel.h.

Constructor & Destructor Documentation

◆ QgsAttributeTableFilterModel()

QgsAttributeTableFilterModel::QgsAttributeTableFilterModel ( QgsMapCanvas canvas,
QgsAttributeTableModel sourceModel,
QObject *  parent = nullptr 
)

Make sure, the master model is already loaded, so the selection will get synchronized.

Parameters
parentparent object (owner)
sourceModelThe QgsAttributeTableModel to use as source (mostly referred to as master model)
canvasThe mapCanvas. Used to identify the currently visible features.

Definition at line 39 of file qgsattributetablefiltermodel.cpp.

Member Function Documentation

◆ actionColumnIndex()

int QgsAttributeTableFilterModel::actionColumnIndex ( ) const

Gets the index of the first column that contains an action widget.

Returns -1 if none is defined.

Definition at line 140 of file qgsattributetablefiltermodel.cpp.

◆ columnCount()

int QgsAttributeTableFilterModel::columnCount ( const QModelIndex &  parent) const
override

Definition at line 145 of file qgsattributetablefiltermodel.cpp.

◆ connectFilterModeConnections()

void QgsAttributeTableFilterModel::connectFilterModeConnections ( QgsAttributeTableFilterModel::FilterMode  filterMode)

Disconnect the connections set for the new filterMode.

Definition at line 379 of file qgsattributetablefiltermodel.cpp.

◆ data()

QVariant QgsAttributeTableFilterModel::data ( const QModelIndex &  index,
int  role 
) const
override

Definition at line 98 of file qgsattributetablefiltermodel.cpp.

◆ disconnectFilterModeConnections()

void QgsAttributeTableFilterModel::disconnectFilterModeConnections ( )

Disconnect the connections set for the current filterMode.

Definition at line 355 of file qgsattributetablefiltermodel.cpp.

◆ extentsChanged

void QgsAttributeTableFilterModel::extentsChanged ( )
slot

Is called upon every change of the visible extents on the map canvas.

When a change is signalled, the filter is updated and invalidated if needed.

Deprecated:
QGIS 3.10.3. Made private as reloadVisible().

Definition at line 450 of file qgsattributetablefiltermodel.cpp.

◆ featuresFiltered

void QgsAttributeTableFilterModel::featuresFiltered ( )
signal

Emitted when the filtering of the features has been done.

◆ fidToIndex()

QModelIndex QgsAttributeTableFilterModel::fidToIndex ( QgsFeatureId  fid)
overridevirtual

Implements QgsFeatureModel.

Definition at line 686 of file qgsattributetablefiltermodel.cpp.

◆ fidToIndexList()

QModelIndexList QgsAttributeTableFilterModel::fidToIndexList ( QgsFeatureId  fid)

Definition at line 691 of file qgsattributetablefiltermodel.cpp.

◆ filterAcceptsRow()

bool QgsAttributeTableFilterModel::filterAcceptsRow ( int  sourceRow,
const QModelIndex &  sourceParent 
) const
overrideprotected

Returns true if the source row will be accepted.

Parameters
sourceRowrow from the source model
sourceParentparent index in the source model

Definition at line 404 of file qgsattributetablefiltermodel.cpp.

◆ filteredFeatures()

QgsFeatureIds QgsAttributeTableFilterModel::filteredFeatures ( )

Gets a list of currently filtered feature ids.

Returns
A list of feature ids

Definition at line 327 of file qgsattributetablefiltermodel.cpp.

◆ filterError

void QgsAttributeTableFilterModel::filterError ( const QString &  errorMessage)
signal

Emitted when an error occurred while filtering features.

Since
QGIS 3.18

◆ filterExpression()

QString QgsAttributeTableFilterModel::filterExpression ( ) const
inline

Returns the stored filter expression string.

Since
QGIS 3.28.0

Definition at line 264 of file qgsattributetablefiltermodel.h.

◆ filterFeatures

void QgsAttributeTableFilterModel::filterFeatures ( )
slot

Updates the filtered features in the filter model.

It is called when the data of the main table or the filter expression changed.

Since
QGIS 3.10.3

Definition at line 491 of file qgsattributetablefiltermodel.cpp.

◆ filterMode()

FilterMode QgsAttributeTableFilterModel::filterMode ( )
inline

The current filterModel.

Definition at line 158 of file qgsattributetablefiltermodel.h.

◆ flags()

Qt::ItemFlags QgsAttributeTableFilterModel::flags ( const QModelIndex &  index) const
override

Definition at line 732 of file qgsattributetablefiltermodel.cpp.

◆ generateListOfVisibleFeatures()

void QgsAttributeTableFilterModel::generateListOfVisibleFeatures ( )
protected

Updates the list of currently visible features on the map canvas.

Is called automatically when the filter mode is adjusted or the extents changed.

Definition at line 591 of file qgsattributetablefiltermodel.cpp.

◆ headerData()

QVariant QgsAttributeTableFilterModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override

Definition at line 116 of file qgsattributetablefiltermodel.cpp.

◆ layer()

QgsVectorLayer * QgsAttributeTableFilterModel::layer ( ) const
inline

Returns the layer this filter acts on.

Returns
Abovementioned layer

Definition at line 165 of file qgsattributetablefiltermodel.h.

◆ layerCache()

QgsVectorLayerCache * QgsAttributeTableFilterModel::layerCache ( ) const
inline

Returns the layerCache this filter acts on.

Returns
The layer cache

Definition at line 172 of file qgsattributetablefiltermodel.h.

◆ lessThan()

bool QgsAttributeTableFilterModel::lessThan ( const QModelIndex &  left,
const QModelIndex &  right 
) const
overrideprotected

Used by the sorting algorithm.

Compares the two model indices. Will also consider the selection state of the feature in case selected features are to be shown on top.

Definition at line 54 of file qgsattributetablefiltermodel.cpp.

◆ mapCanvas()

QgsMapCanvas * QgsAttributeTableFilterModel::mapCanvas ( ) const
inline

Returns the map canvas.

Definition at line 228 of file qgsattributetablefiltermodel.h.

◆ mapFromMaster()

QModelIndex QgsAttributeTableFilterModel::mapFromMaster ( const QModelIndex &  sourceIndex) const
inline

Definition at line 196 of file qgsattributetablefiltermodel.h.

◆ mapFromSource()

QModelIndex QgsAttributeTableFilterModel::mapFromSource ( const QModelIndex &  sourceIndex) const
override

Definition at line 717 of file qgsattributetablefiltermodel.cpp.

◆ mapToMaster()

QModelIndex QgsAttributeTableFilterModel::mapToMaster ( const QModelIndex &  proxyIndex) const

Definition at line 742 of file qgsattributetablefiltermodel.cpp.

◆ mapToSource()

QModelIndex QgsAttributeTableFilterModel::mapToSource ( const QModelIndex &  proxyIndex) const
override

Definition at line 703 of file qgsattributetablefiltermodel.cpp.

◆ masterModel()

QgsAttributeTableModel * QgsAttributeTableFilterModel::masterModel ( ) const
inline

Returns the table model this filter is using.

Returns
the table model in quesion

Definition at line 179 of file qgsattributetablefiltermodel.h.

◆ rowToId()

QgsFeatureId QgsAttributeTableFilterModel::rowToId ( const QModelIndex &  row)

Returns the feature id for a given model index.

Parameters
rowA model index of the row in question
Returns
The feature id of the feature visible in the provided row

Definition at line 681 of file qgsattributetablefiltermodel.cpp.

◆ selectedOnTop()

bool QgsAttributeTableFilterModel::selectedOnTop ( )

Returns if selected features are currently shown on top.

Returns
true if selected are shown on top

Definition at line 311 of file qgsattributetablefiltermodel.cpp.

◆ setAttributeTableConfig()

void QgsAttributeTableFilterModel::setAttributeTableConfig ( const QgsAttributeTableConfig config,
bool  force = false 
)

Set the attribute table configuration to control which fields are shown, in which order they are shown as well as if and where an action column is shown.

Parameters
configattribute table config
forcedefault false, if true the attribute table configuration will be reset even if it is not changed.

Definition at line 151 of file qgsattributetablefiltermodel.cpp.

◆ setFilteredFeatures()

void QgsAttributeTableFilterModel::setFilteredFeatures ( const QgsFeatureIds ids)
virtual

Specify a list of features, which the filter will accept.

The filter mode will automatically be adjusted to show only these features (ShowFilteredList).

Parameters
idsThe list of feature ids which will be accepted by the filter

Definition at line 316 of file qgsattributetablefiltermodel.cpp.

◆ setFilterExpression()

void QgsAttributeTableFilterModel::setFilterExpression ( const QgsExpression expression,
const QgsExpressionContext context 
)

Set the expression and the context to be stored in case of the features need to be filtered again (like on filter or on main model data change).

Since
QGIS 3.10.3

Definition at line 248 of file qgsattributetablefiltermodel.cpp.

◆ setFilterMode()

void QgsAttributeTableFilterModel::setFilterMode ( FilterMode  filterMode)

Set the filter mode the filter will use.

Parameters
filterModeSets the current mode of the filter

Definition at line 339 of file qgsattributetablefiltermodel.cpp.

◆ setSelectedOnTop()

void QgsAttributeTableFilterModel::setSelectedOnTop ( bool  selectedOnTop)

Changes the sort order of the features.

If set to true, selected features will be sorted on top, regardless of the current sort column

Parameters
selectedOnTopSpecify, if selected features should be sorted on top

Definition at line 269 of file qgsattributetablefiltermodel.cpp.

◆ setSourceModel()

void QgsAttributeTableFilterModel::setSourceModel ( QgsAttributeTableModel sourceModel)

Set the attribute table model that backs this model.

Parameters
sourceModelThe model

Definition at line 289 of file qgsattributetablefiltermodel.cpp.

◆ sort() [1/2]

void QgsAttributeTableFilterModel::sort ( const QString &  expression,
Qt::SortOrder  order = Qt::AscendingOrder 
)

Sort by the given expression using the given order.

Prefetches all the data from the layer to speed up sorting.

Parameters
expressionThe expression which should be used for sorting
orderThe order ( Qt::AscendingOrder or Qt::DescendingOrder )

Definition at line 254 of file qgsattributetablefiltermodel.cpp.

◆ sort() [2/2]

void QgsAttributeTableFilterModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
override

Sort by the given column using the given order.

Prefetches all the data from the layer to speed up sorting.

Parameters
columnThe column which should be sorted
orderThe order ( Qt::AscendingOrder or Qt::DescendingOrder )

Definition at line 81 of file qgsattributetablefiltermodel.cpp.

◆ sortColumnChanged

void QgsAttributeTableFilterModel::sortColumnChanged ( int  column,
Qt::SortOrder  order 
)
signal

Emitted whenever the sort column is changed.

Parameters
columnThe sort column
orderThe sort order

◆ sortExpression()

QString QgsAttributeTableFilterModel::sortExpression ( ) const

The expression which is used to sort the attribute table.

Definition at line 264 of file qgsattributetablefiltermodel.cpp.

◆ visibleReloaded

void QgsAttributeTableFilterModel::visibleReloaded ( )
signal

Emitted when the the visible features on extend are reloaded (the list is created)


The documentation for this class was generated from the following files: