QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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( nullIentifier() );
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>() == nullIentifier();
57 }
58 
59 QVariant QgsFeaturePickerModel::nullIentifier() 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:613
FID_NULL
#define FID_NULL
Definition: qgsfeatureid.h:26
QgsFeaturePickerModelBase
Definition: qgsfeaturepickermodelbase.h:30
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:470
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:327
QgsFeatureRequest::setFilterFid
QgsFeatureRequest & setFilterFid(QgsFeatureId fid)
Sets feature ID that should be fetched.
Definition: qgsfeaturerequest.cpp:103
qgsapplication.h
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
QgsFeaturePickerModelBase::sourceLayer
QgsVectorLayer sourceLayer
Definition: qgsfeaturepickermodelbase.h:47
QgsFeaturePickerModelBase::mEntries
QVector< QgsFeatureExpressionValuesGatherer::Entry > mEntries
Definition: qgsfeaturepickermodelbase.h:323
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:48
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
Definition: qgsfeature.h:55
QgsFeaturePickerModelBase::mExtraValueIndex
int mExtraValueIndex
The current index.
Definition: qgsfeaturepickermodelbase.h:330
QgsFeaturePickerModelBase::setFetchGeometry
void setFetchGeometry(bool fetchGeometry)
Defines if the geometry will be fetched.
Definition: qgsfeaturepickermodelbase.cpp:561
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25