QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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  const 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 
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...
int mExtraValueIndex
The current index.
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:56
#define FID_NULL
Definition: qgsfeatureid.h:29
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28