QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Public Types | Signals | Public Member Functions | Properties | List of all members
QgsQuickFeaturesListModel Class Reference

List Model holding features of specific layer. More...

#include <qgsquickfeatureslistmodel.h>

Inheritance diagram for QgsQuickFeaturesListModel:
Inheritance graph
[legend]

Public Types

enum  modelRoles {
  FeatureTitle = Qt::UserRole + 1, FeatureId, Feature, Description,
  KeyColumn, FoundPair
}
 Roles for FeaturesListModel. More...
 

Signals

void featuresCountChanged (int featuresCount)
 featuresCountChanged Signal emitted when features are reloaded or layer is changed More...
 
void featuresLimitChanged (int featuresLimit)
 Signal emitted when maximum number of features that can be loaded changes. More...
 
void filterExpressionChanged (QString filterExpression)
 Signal emitted when filter expression has changed. More...
 

Public Member Functions

 QgsQuickFeaturesListModel (QObject *parent=nullptr)
 Create features list model. More...
 
 ~QgsQuickFeaturesListModel () override
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
Q_INVOKABLE QgsQuickFeatureLayerPair featureLayerPair (const int &featureId)
 Function to get QgsQuickFeatureLayerPair by feature id. More...
 
int featuresCount () const
 Returns number of features in layer, not number of loaded features. More...
 
int featuresLimit () const
 Returns maximum amount of features that can be queried from layer. More...
 
QString filterExpression () const
 Returns filter expression, empty string represents no filter. More...
 
Q_INVOKABLE int keyFromAttribute (const int role, const QVariant &value) const
 keyFromAttribute finds feature with requested role and value, returns keycolumn More...
 
Q_INVOKABLE void populateFromLayer (QgsVectorLayer *layer)
 populateFromLayer populates model with features from layer More...
 
 Q_ENUM (modelRoles)
 
Q_INVOKABLE void reloadFeatures ()
 reloadFeatures reloads features from current layer More...
 
QHash< int, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
Q_INVOKABLE int rowFromAttribute (const int role, const QVariant &value) const
 rowFromAttribute finds feature with requested role and value, returns its row More...
 
void setFeatureTitleField (const QString &attribute)
 setFeatureTitleField Sets name of attribute that will be used for FeatureTitle and Qt::DisplayRole More...
 
void setFilterExpression (const QString &filterExpression)
 setFilterExpression Sets filter expression, upon setting also reloads features from current layer with new filter More...
 
void setKeyField (const QString &attribute)
 Sets name of attribute used as "key" in value relation. More...
 
Q_INVOKABLE void setupValueRelation (const QVariantMap &config)
 setupValueRelation populates model with value relation data from config More...
 

Properties

int featuresCount
 Read only property holding true number of features in layer - not only requested features Changing filter expression does not result in changing this number. More...
 
int featuresLimit
 Property limiting maximum number of features queried from layer Read only property. More...
 
QString filterExpression
 Filter Expression represents filter used when querying for data in current layer. More...
 

Detailed Description

List Model holding features of specific layer.

Model allows searching by any string or number attribute.

Note
QML Type: FeaturesListModel
Since
QGIS 3.16

Definition at line 35 of file qgsquickfeatureslistmodel.h.

Member Enumeration Documentation

◆ modelRoles

Roles for FeaturesListModel.

Enumerator
FeatureTitle 
FeatureId 
Feature 
Description 
KeyColumn 

secondary text in list view

FoundPair 

key in value relation

pair of attribute and its value by which the feature was found, empty if mFilterExpression is empty

Definition at line 60 of file qgsquickfeatureslistmodel.h.

Constructor & Destructor Documentation

◆ QgsQuickFeaturesListModel()

QgsQuickFeaturesListModel::QgsQuickFeaturesListModel ( QObject *  parent = nullptr)
explicit

Create features list model.

Definition at line 20 of file qgsquickfeatureslistmodel.cpp.

◆ ~QgsQuickFeaturesListModel()

QgsQuickFeaturesListModel::~QgsQuickFeaturesListModel ( )
inlineoverride

Definition at line 73 of file qgsquickfeatureslistmodel.h.

Member Function Documentation

◆ data()

QVariant QgsQuickFeaturesListModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Definition at line 58 of file qgsquickfeatureslistmodel.cpp.

◆ featureLayerPair()

QgsQuickFeatureLayerPair QgsQuickFeaturesListModel::featureLayerPair ( const int &  featureId)

Function to get QgsQuickFeatureLayerPair by feature id.

Definition at line 270 of file qgsquickfeatureslistmodel.cpp.

◆ featuresCount()

int QgsQuickFeaturesListModel::featuresCount ( ) const

Returns number of features in layer, not number of loaded features.

Definition at line 208 of file qgsquickfeatureslistmodel.cpp.

◆ featuresCountChanged

void QgsQuickFeaturesListModel::featuresCountChanged ( int  featuresCount)
signal

featuresCountChanged Signal emitted when features are reloaded or layer is changed

Parameters
featuresCountnumber of features in layer, not number of loaded features

◆ featuresLimit()

int QgsQuickFeaturesListModel::featuresLimit ( ) const

Returns maximum amount of features that can be queried from layer.

Definition at line 238 of file qgsquickfeatureslistmodel.cpp.

◆ featuresLimitChanged

void QgsQuickFeaturesListModel::featuresLimitChanged ( int  featuresLimit)
signal

Signal emitted when maximum number of features that can be loaded changes.

◆ filterExpression()

QString QgsQuickFeaturesListModel::filterExpression ( ) const

Returns filter expression, empty string represents no filter.

Definition at line 215 of file qgsquickfeatureslistmodel.cpp.

◆ filterExpressionChanged

void QgsQuickFeaturesListModel::filterExpressionChanged ( QString  filterExpression)
signal

Signal emitted when filter expression has changed.

◆ keyFromAttribute()

int QgsQuickFeaturesListModel::keyFromAttribute ( const int  role,
const QVariant &  value 
) const

keyFromAttribute finds feature with requested role and value, returns keycolumn

Parameters
rolerole to find from modelRoles
valuevalue to find
Returns
KeyColumn role for found feature, returns -1 if no feature is found. If more features match requested role and value, KeyColumn for first is returned.

Definition at line 256 of file qgsquickfeatureslistmodel.cpp.

◆ populateFromLayer()

void QgsQuickFeaturesListModel::populateFromLayer ( QgsVectorLayer layer)

populateFromLayer populates model with features from layer

Parameters
layerto be used

Definition at line 173 of file qgsquickfeatureslistmodel.cpp.

◆ Q_ENUM()

QgsQuickFeaturesListModel::Q_ENUM ( modelRoles  )

◆ reloadFeatures()

void QgsQuickFeaturesListModel::reloadFeatures ( )

reloadFeatures reloads features from current layer

Definition at line 182 of file qgsquickfeatureslistmodel.cpp.

◆ roleNames()

QHash< int, QByteArray > QgsQuickFeaturesListModel::roleNames ( ) const
override

Definition at line 196 of file qgsquickfeatureslistmodel.cpp.

◆ rowCount()

int QgsQuickFeaturesListModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 26 of file qgsquickfeatureslistmodel.cpp.

◆ rowFromAttribute()

int QgsQuickFeaturesListModel::rowFromAttribute ( const int  role,
const QVariant &  value 
) const

rowFromAttribute finds feature with requested role and value, returns its row

Parameters
roleto find from modelRoles
valueto find
Returns
Row index for found feature, returns -1 if no feature is found. If more features match requested role and value, index of first is returned.

Definition at line 243 of file qgsquickfeatureslistmodel.cpp.

◆ setFeatureTitleField()

void QgsQuickFeaturesListModel::setFeatureTitleField ( const QString &  attribute)

setFeatureTitleField Sets name of attribute that will be used for FeatureTitle and Qt::DisplayRole

Parameters
attributeName of attribute to use. If empty, displayExpression will be used.

Definition at line 228 of file qgsquickfeatureslistmodel.cpp.

◆ setFilterExpression()

void QgsQuickFeaturesListModel::setFilterExpression ( const QString &  filterExpression)

setFilterExpression Sets filter expression, upon setting also reloads features from current layer with new filter

Parameters
filterExpressionQString to set, empty string represents no filter

Definition at line 220 of file qgsquickfeatureslistmodel.cpp.

◆ setKeyField()

void QgsQuickFeaturesListModel::setKeyField ( const QString &  attribute)

Sets name of attribute used as "key" in value relation.

Definition at line 233 of file qgsquickfeatureslistmodel.cpp.

◆ setupValueRelation()

void QgsQuickFeaturesListModel::setupValueRelation ( const QVariantMap &  config)

setupValueRelation populates model with value relation data from config

Parameters
configto be used

Definition at line 152 of file qgsquickfeatureslistmodel.cpp.

Property Documentation

◆ featuresCount

int QgsQuickFeaturesListModel::featuresCount
read

Read only property holding true number of features in layer - not only requested features Changing filter expression does not result in changing this number.

Definition at line 1 of file qgsquickfeatureslistmodel.h.

◆ featuresLimit

int QgsQuickFeaturesListModel::featuresLimit
read

Property limiting maximum number of features queried from layer Read only property.

Definition at line 1 of file qgsquickfeatureslistmodel.h.

◆ filterExpression

QString QgsQuickFeaturesListModel::filterExpression
readwrite

Filter Expression represents filter used when querying for data in current layer.

String and numerical attributes are compared with filterExpression

Definition at line 1 of file qgsquickfeatureslistmodel.h.


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