QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
6  email : [email protected]
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  ***************************************************************************/
15 #include "qgsfeaturepickermodel.h"
17 
18 #include "qgsvectorlayer.h"
19 #include "qgsconditionalstyle.h"
20 #include "qgsapplication.h"
21 #include "qgssettings.h"
22 
23 
25  : QgsFeaturePickerModelBase( parent )
26 {
27  setFetchGeometry( true );
28  setExtraIdentifierValueUnguarded( nullIdentifier() );
29 
30  connect( this, &QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged, this, [ = ]() {emit featureChanged( feature() );} );
31 }
32 
33 void QgsFeaturePickerModel::requestToReloadCurrentFeature( QgsFeatureRequest &request )
34 {
36 }
37 
38 QVariant QgsFeaturePickerModel::entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const
39 {
40  return entry.identifierFields;
41 }
42 
43 QgsFeatureExpressionValuesGatherer::Entry QgsFeaturePickerModel::createEntry( const QVariant &identifier ) const
44 {
45  QgsFeatureId fid = identifier.value<QgsFeatureId>();
46  return QgsFeatureExpressionValuesGatherer::Entry( fid, QStringLiteral( "(%1)" ).arg( fid ), sourceLayer() );
47 }
48 
49 bool QgsFeaturePickerModel::compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const
50 {
51  return a.featureId == b.featureId;
52 }
53 
54 bool QgsFeaturePickerModel::identifierIsNull( const QVariant &identifier ) const
55 {
56  return identifier.value<QgsFeatureId>() == nullIdentifier();
57 }
58 
59 QVariant QgsFeaturePickerModel::nullIdentifier() const
60 {
61  return FID_NULL;
62 }
63 
65 {
67 }
68 
70 {
72 }
73 
75 {
76  return mEntries.value( mExtraValueIndex ).feature;
77 }
78 
79 QgsFeatureExpressionValuesGatherer *QgsFeaturePickerModel::createValuesGatherer( const QgsFeatureRequest &request ) const
80 {
81  return new QgsFeatureExpressionValuesGatherer( sourceLayer(), displayExpression(), request );
82 }
83 
QgsFeaturePickerModel::featureChanged
void featureChanged(const QgsFeature &feature)
Emitted when the current feature changes.
qgsconditionalstyle.h
QgsFeaturePickerModelBase::setExtraIdentifierValue
void setExtraIdentifierValue(const QVariant &extraIdentifierValue)
Allows specifying one value that does not need to match the filter criteria but will still be availab...
Definition: qgsfeaturepickermodelbase.cpp:630
FID_NULL
#define FID_NULL
Definition: qgsfeatureid.h:29
QgsFeaturePickerModelBase
Provides a list of features based on filter conditions.
Definition: qgsfeaturepickermodelbase.h:31
QgsFeaturePickerModelBase::setExtraIdentifierValueUnguarded
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...
Definition: qgsfeaturepickermodelbase.cpp:487
QgsFeaturePickerModel::QgsFeaturePickerModel
QgsFeaturePickerModel(QObject *parent=nullptr)
Create a new QgsFeaturePickerModel, optionally specifying a parent.
Definition: qgsfeaturepickermodel.cpp:24
QgsFeaturePickerModelBase::mExtraIdentifierValue
QVariant mExtraIdentifierValue
The current identifier value.
Definition: qgsfeaturepickermodelbase.h:314
QgsFeatureRequest::setFilterFid
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
Definition: qgsfeaturerequest.cpp:98
qgsapplication.h
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:76
QgsFeaturePickerModelBase::sourceLayer
QgsVectorLayer * sourceLayer
Definition: qgsfeaturepickermodelbase.h:34
QgsFeaturePickerModelBase::mEntries
QVector< QgsFeatureExpressionValuesGatherer::Entry > mEntries
Definition: qgsfeaturepickermodelbase.h:310
qgsfeatureexpressionvaluesgatherer.h
QgsFeaturePickerModelBase::extraIdentifierValueIndexChanged
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
QgsFeaturePickerModel::setExtraIdentifierValueToNull
void setExtraIdentifierValueToNull() override
Allows specifying one value that does not need to match the filter criteria but will still be availab...
Definition: qgsfeaturepickermodel.cpp:64
QgsFeaturePickerModelBase::displayExpression
QString displayExpression
Definition: qgsfeaturepickermodelbase.h:35
qgsvectorlayer.h
QgsFeaturePickerModel::setFeature
void setFeature(const QgsFeatureId &fid)
Set the feature to the given feature id.
Definition: qgsfeaturepickermodel.cpp:69
qgsfeaturepickermodel.h
QgsFeaturePickerModel::feature
QgsFeature feature() const
Returns the current feature.
Definition: qgsfeaturepickermodel.cpp:74
qgssettings.h
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsFeaturePickerModelBase::mExtraValueIndex
int mExtraValueIndex
The current index.
Definition: qgsfeaturepickermodelbase.h:317
QgsFeaturePickerModelBase::setFetchGeometry
void setFetchGeometry(bool fetchGeometry)
Defines if the geometry will be fetched.
Definition: qgsfeaturepickermodelbase.cpp:578
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28