QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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  FilterMode {
  ShowAll, ShowSelected, ShowVisible, ShowFilteredList,
  ShowEdited
}
 The filter mode defines how the rows should be filtered. More...
 
enum  Role { TypeRole = QgsAttributeTableModel::UserRole }
 The additional roles defined by this filter model. More...
 

Public Slots

void extentsChanged ()
 Is called upon every change of the visible extents on the map canvas. More...
 

Signals

void sortColumnChanged (int column, Qt::SortOrder order)
 Is emitted whenever the sort column is changed. More...
 

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. More...
 
int actionColumnIndex () const
 Gets the index of the first column that contains an action widget. More...
 
int columnCount (const QModelIndex &parent) const override
 
QVariant data (const QModelIndex &index, int role) const override
 
QModelIndex fidToIndex (QgsFeatureId fid) override
 
QModelIndexList fidToIndexList (QgsFeatureId fid)
 
QgsFeatureIds filteredFeatures ()
 Gets a list of currently filtered feature ids. More...
 
FilterMode filterMode ()
 The current filterModel. More...
 
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. More...
 
QgsVectorLayerCachelayerCache () const
 Returns the layerCache this filter acts on. More...
 
QgsMapCanvasmapCanvas () const
 Returns the map canvas. More...
 
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. More...
 
QgsFeatureId rowToId (const QModelIndex &row)
 Returns the feature id for a given model index. More...
 
bool selectedOnTop ()
 Returns if selected features are currently shown on top. More...
 
void setAttributeTableConfig (const QgsAttributeTableConfig &config)
 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. More...
 
virtual void setFilteredFeatures (const QgsFeatureIds &ids)
 Specify a list of features, which the filter will accept. More...
 
void setFilterMode (FilterMode filterMode)
 Set the filter mode the filter will use. More...
 
void setSelectedOnTop (bool selectedOnTop)
 Changes the sort order of the features. More...
 
void setSourceModel (QgsAttributeTableModel *sourceModel)
 Set the attribute table model that backs this model. More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 Sort by the given column using the given order. More...
 
void sort (const QString &expression, Qt::SortOrder order=Qt::AscendingOrder)
 Sort by the given expression using the given order. More...
 
QString sortExpression () const
 The expression which is used to sort the attribute table. More...
 
- 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. More...
 
void generateListOfVisibleFeatures ()
 Updates the list of currently visible features on the map canvas. More...
 
bool lessThan (const QModelIndex &left, const QModelIndex &right) const override
 Used by the sorting algorithm. More...
 

Detailed Description

Definition at line 36 of file qgsattributetablefiltermodel.h.

Member Enumeration Documentation

The type of a column.

Enumerator
ColumnTypeField 

This column shows a field.

ColumnTypeActionButton 

This column shows action buttons.

Definition at line 58 of file qgsattributetablefiltermodel.h.

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.

Definition at line 45 of file qgsattributetablefiltermodel.h.

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.

Enumerator
TypeRole 

The type of a given column.

Definition at line 70 of file qgsattributetablefiltermodel.h.

Constructor & Destructor Documentation

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 32 of file qgsattributetablefiltermodel.cpp.

Member Function Documentation

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 119 of file qgsattributetablefiltermodel.cpp.

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

Definition at line 124 of file qgsattributetablefiltermodel.cpp.

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

Definition at line 80 of file qgsattributetablefiltermodel.cpp.

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.

Definition at line 368 of file qgsattributetablefiltermodel.cpp.

QModelIndex QgsAttributeTableFilterModel::fidToIndex ( QgsFeatureId  fid)
overridevirtual

Implements QgsFeatureModel.

Definition at line 497 of file qgsattributetablefiltermodel.cpp.

QModelIndexList QgsAttributeTableFilterModel::fidToIndexList ( QgsFeatureId  fid)

Definition at line 502 of file qgsattributetablefiltermodel.cpp.

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 323 of file qgsattributetablefiltermodel.cpp.

QgsFeatureIds QgsAttributeTableFilterModel::filteredFeatures ( )

Gets a list of currently filtered feature ids.

Returns
A list of feature ids

Definition at line 292 of file qgsattributetablefiltermodel.cpp.

FilterMode QgsAttributeTableFilterModel::filterMode ( )
inline

The current filterModel.

Definition at line 134 of file qgsattributetablefiltermodel.h.

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

Definition at line 543 of file qgsattributetablefiltermodel.cpp.

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 409 of file qgsattributetablefiltermodel.cpp.

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

Definition at line 98 of file qgsattributetablefiltermodel.cpp.

QgsVectorLayer* QgsAttributeTableFilterModel::layer ( ) const
inline

Returns the layer this filter acts on.

Returns
Abovementioned layer

Definition at line 141 of file qgsattributetablefiltermodel.h.

QgsVectorLayerCache* QgsAttributeTableFilterModel::layerCache ( ) const
inline

Returns the layerCache this filter acts on.

Returns
The layer cache

Definition at line 148 of file qgsattributetablefiltermodel.h.

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 42 of file qgsattributetablefiltermodel.cpp.

QgsMapCanvas* QgsAttributeTableFilterModel::mapCanvas ( ) const
inline

Returns the map canvas.

Definition at line 204 of file qgsattributetablefiltermodel.h.

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

Definition at line 172 of file qgsattributetablefiltermodel.h.

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

Definition at line 528 of file qgsattributetablefiltermodel.cpp.

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

Definition at line 170 of file qgsattributetablefiltermodel.h.

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

Definition at line 513 of file qgsattributetablefiltermodel.cpp.

QgsAttributeTableModel* QgsAttributeTableFilterModel::masterModel ( ) const
inline

Returns the table model this filter is using.

Returns
the table model in quesion

Definition at line 155 of file qgsattributetablefiltermodel.h.

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 492 of file qgsattributetablefiltermodel.cpp.

bool QgsAttributeTableFilterModel::selectedOnTop ( )

Returns if selected features are currently shown on top.

Returns
True if selected are shown on top

Definition at line 280 of file qgsattributetablefiltermodel.cpp.

void QgsAttributeTableFilterModel::setAttributeTableConfig ( const QgsAttributeTableConfig config)

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.

Definition at line 130 of file qgsattributetablefiltermodel.cpp.

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 285 of file qgsattributetablefiltermodel.cpp.

void QgsAttributeTableFilterModel::setFilterMode ( FilterMode  filterMode)

Set the filter mode the filter will use.

Parameters
filterModeSets the current mode of the filter

Definition at line 304 of file qgsattributetablefiltermodel.cpp.

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 241 of file qgsattributetablefiltermodel.cpp.

void QgsAttributeTableFilterModel::setSourceModel ( QgsAttributeTableModel sourceModel)

Set the attribute table model that backs this model.

Parameters
sourceModelThe model
Since
QGIS 2.0

Definition at line 258 of file qgsattributetablefiltermodel.cpp.

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 69 of file qgsattributetablefiltermodel.cpp.

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 226 of file qgsattributetablefiltermodel.cpp.

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

Is emitted whenever the sort column is changed.

Parameters
columnThe sort column
orderThe sort order
QString QgsAttributeTableFilterModel::sortExpression ( ) const

The expression which is used to sort the attribute table.

Definition at line 236 of file qgsattributetablefiltermodel.cpp.


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