QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 currentFeatureChanged (QgsFeature feature)
 Signal emitted when current feature has changed. More...
 
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 searchExpressionChanged (QString searchExpression)
 Signal emitted when search expression has changed. More...
 

Public Member Functions

 QgsQuickFeaturesListModel (QObject *parent=nullptr)
 Create features list model. More...
 
 ~QgsQuickFeaturesListModel () override
 
Q_INVOKABLE QVariant attributeFromValue (const int role, const QVariant &value, const int requestedRole) const
 attributeFromValue finds feature with role and value, returns value for requested role More...
 
Q_INVOKABLE QVariant convertMultivalueFormat (const QVariant &multivalue, const int requestedRole=Qt::DisplayRole)
 convertMultivalueFormat converts postgres string like string to an array of variants with requested role. More...
 
QgsFeature currentFeature () const
 Gets current feature property. More...
 
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...
 
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...
 
QString searchExpression () const
 Returns search expression. More...
 
void setCurrentFeature (QgsFeature feature)
 Sets current feature property. 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 for current layer that will be used when querying for data More...
 
void setKeyField (const QString &attribute)
 Sets name of attribute used as "key" in value relation. More...
 
void setSearchExpression (const QString &searchExpression)
 setSearchExpression Sets search expression, upon setting also reloads features from current layer with new expression More...
 
Q_INVOKABLE void setupValueRelation (const QVariantMap &config)
 setupValueRelation populates model with value relation data from config More...
 

Properties

QgsFeature currentFeature
 Feature that has opened feature form. More...
 
int featuresCount
 Read only property holding true number of features in layer - not only requested features Changing search 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 searchExpression
 Search expression represents a 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 search expression is empty

Definition at line 66 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 ( )
overridedefault

Member Function Documentation

◆ attributeFromValue()

QVariant QgsQuickFeaturesListModel::attributeFromValue ( const int  role,
const QVariant &  value,
const int  requestedRole 
) const

attributeFromValue finds feature with role and value, returns value for requested role

Parameters
rolerole to find from modelRoles
valuevalue to find
requestedRolea role whose value is returned
Returns
If feature is found by role and value, method returns value for requested role. Returns empty QVariant if no feature is found. If more features match requested role and value, value for first is returned.

Definition at line 333 of file qgsquickfeatureslistmodel.cpp.

◆ convertMultivalueFormat()

QVariant QgsQuickFeaturesListModel::convertMultivalueFormat ( const QVariant &  multivalue,
const int  requestedRole = Qt::DisplayRole 
)

convertMultivalueFormat converts postgres string like string to an array of variants with requested role.

Array {1,2,3} with requested role FeatureId results in list of QVariant ints [1, 2, 3]

Parameters
multivaluestring to convert
requestedRolerole to convert keys from string, default value is Qt::DisplayRole
Returns
array of QVariants with values for requested role. If model can not find value for requested role, this key is omitted.

Definition at line 347 of file qgsquickfeatureslistmodel.cpp.

◆ currentFeature()

QgsFeature QgsQuickFeaturesListModel::currentFeature ( ) const

Gets current feature property.

Definition at line 310 of file qgsquickfeatureslistmodel.cpp.

◆ currentFeatureChanged

void QgsQuickFeaturesListModel::currentFeatureChanged ( QgsFeature  feature)
signal

Signal emitted when current feature has changed.

◆ data()

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

Definition at line 60 of file qgsquickfeatureslistmodel.cpp.

◆ featureLayerPair()

QgsQuickFeatureLayerPair QgsQuickFeaturesListModel::featureLayerPair ( const int &  featureId)

Function to get QgsQuickFeatureLayerPair by feature id.

Definition at line 362 of file qgsquickfeatureslistmodel.cpp.

◆ featuresCount()

int QgsQuickFeaturesListModel::featuresCount ( ) const

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

Definition at line 265 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 315 of file qgsquickfeatureslistmodel.cpp.

◆ featuresLimitChanged

void QgsQuickFeaturesListModel::featuresLimitChanged ( int  featuresLimit)
signal

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

◆ populateFromLayer()

void QgsQuickFeaturesListModel::populateFromLayer ( QgsVectorLayer layer)

populateFromLayer populates model with features from layer

Parameters
layerto be used

Definition at line 228 of file qgsquickfeatureslistmodel.cpp.

◆ Q_ENUM()

QgsQuickFeaturesListModel::Q_ENUM ( modelRoles  )

◆ reloadFeatures()

void QgsQuickFeaturesListModel::reloadFeatures ( )

reloadFeatures reloads features from current layer

Definition at line 237 of file qgsquickfeatureslistmodel.cpp.

◆ roleNames()

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

Definition at line 253 of file qgsquickfeatureslistmodel.cpp.

◆ rowCount()

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

Definition at line 28 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 320 of file qgsquickfeatureslistmodel.cpp.

◆ searchExpression()

QString QgsQuickFeaturesListModel::searchExpression ( ) const

Returns search expression.

Definition at line 272 of file qgsquickfeatureslistmodel.cpp.

◆ searchExpressionChanged

void QgsQuickFeaturesListModel::searchExpressionChanged ( QString  searchExpression)
signal

Signal emitted when search expression has changed.

◆ setCurrentFeature()

void QgsQuickFeaturesListModel::setCurrentFeature ( QgsFeature  feature)

Sets current feature property.

Definition at line 300 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 285 of file qgsquickfeatureslistmodel.cpp.

◆ setFilterExpression()

void QgsQuickFeaturesListModel::setFilterExpression ( const QString &  filterExpression)

setFilterExpression Sets filter expression for current layer that will be used when querying for data

Parameters
filterExpressionto be set

Definition at line 295 of file qgsquickfeatureslistmodel.cpp.

◆ setKeyField()

void QgsQuickFeaturesListModel::setKeyField ( const QString &  attribute)

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

Definition at line 290 of file qgsquickfeatureslistmodel.cpp.

◆ setSearchExpression()

void QgsQuickFeaturesListModel::setSearchExpression ( const QString &  searchExpression)

setSearchExpression Sets search expression, upon setting also reloads features from current layer with new expression

Parameters
searchExpressionQString to set, empty string represents no filter

Definition at line 277 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 204 of file qgsquickfeatureslistmodel.cpp.

Property Documentation

◆ currentFeature

QgsFeature QgsQuickFeaturesListModel::currentFeature
readwrite

Feature that has opened feature form.

This property needs to be set before opening feature form to be able to evaulate filter expressions that contain form scope.

Definition at line 1 of file qgsquickfeatureslistmodel.h.

◆ featuresCount

int QgsQuickFeaturesListModel::featuresCount
read

Read only property holding true number of features in layer - not only requested features Changing search 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.

◆ searchExpression

QString QgsQuickFeaturesListModel::searchExpression
readwrite

Search expression represents a filter used when querying for data in current layer.

Changing this property results in reloading features from current layer with new search expression.

Definition at line 1 of file qgsquickfeatureslistmodel.h.


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