QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsfeaturepickermodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeaturepickermodel.cpp - QgsFeaturePickerModel
3 ---------------------
4 begin : 03.04.2020
5 copyright : (C) 2020 by Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
16#include "moc_qgsfeaturepickermodel.cpp"
18
19#include "qgsvectorlayer.h"
20#include "qgsconditionalstyle.h"
21#include "qgsapplication.h"
22#include "qgssettings.h"
23
24
27{
28 setFetchGeometry( true );
29 setExtraIdentifierValueUnguarded( nullIdentifier() );
30
31 connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [this]() {emit featureChanged( feature() );} );
32}
33
34void QgsFeaturePickerModel::requestToReloadCurrentFeature( QgsFeatureRequest &request )
35{
37}
38
39QVariant QgsFeaturePickerModel::entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const
40{
41 return entry.identifierFields;
42}
43
44QgsFeatureExpressionValuesGatherer::Entry QgsFeaturePickerModel::createEntry( const QVariant &identifier ) const
45{
46 const QgsFeatureId fid = identifier.value<QgsFeatureId>();
47 return QgsFeatureExpressionValuesGatherer::Entry( fid, QStringLiteral( "(%1)" ).arg( fid ), sourceLayer() );
48}
49
50bool QgsFeaturePickerModel::compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const
51{
52 return a.featureId == b.featureId;
53}
54
55bool QgsFeaturePickerModel::identifierIsNull( const QVariant &identifier ) const
56{
57 return identifier.value<QgsFeatureId>() == nullIdentifier();
58}
59
60QVariant QgsFeaturePickerModel::nullIdentifier() const
61{
62 return FID_NULL;
63}
64
69
74
76{
77 return mEntries.value( mExtraValueIndex ).feature;
78}
79
80QgsFeatureExpressionValuesGatherer *QgsFeaturePickerModel::createValuesGatherer( const QgsFeatureRequest &request ) const
81{
82 return new QgsFeatureExpressionValuesGatherer( sourceLayer(), displayExpression(), request );
83}
84
Provides a list of features based on filter conditions.
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
void setExtraIdentifierValue(const QVariant &extraIdentifierValue)
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void setFetchGeometry(bool fetchGeometry)
Defines if the geometry will be fetched.
void setExtraIdentifierValueUnguarded(const QVariant &identifierValue)
This will set the identifier value to be set in the model even if it doesn't exist currently in the d...
QVariant mExtraIdentifierValue
The current identifier value.
QVector< QgsFeatureExpressionValuesGatherer::Entry > mEntries
QgsFeaturePickerModel(QObject *parent=nullptr)
Create a new QgsFeaturePickerModel, optionally specifying a parent.
void setFeature(const QgsFeatureId &fid)
Set the feature to the given feature id.
void featureChanged(const QgsFeature &feature)
Emitted when the current feature changes.
void setExtraIdentifierValueToNull() override
Allows specifying one value that does not need to match the filter criteria but will still be availab...
QgsFeature feature() const
Returns the current feature.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets the feature ID that should be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
#define FID_NULL
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features