22#include "moc_qgsfeaturelistcombobox.cpp"
31 , mCompleter( new QCompleter( mModel ) )
33 setMinimumContentsLength( 1 );
34 setSizeAdjustPolicy( QComboBox::SizeAdjustPolicy::AdjustToMinimumContentsLengthWithIcon );
35 mCompleter->setCaseSensitivity( Qt::CaseInsensitive );
36 mCompleter->setFilterMode( Qt::MatchContains );
38 setCompleter( mCompleter );
39 mCompleter->setWidget(
this );
49 connect( mCompleter,
static_cast<void ( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::highlighted ),
this, &QgsFeatureListComboBox::onItemSelected );
50 connect( mCompleter,
static_cast<void ( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::activated ),
this, &QgsFeatureListComboBox::onActivated );
54 connect( mModel, &QgsFeatureFilterModel::dataChanged,
this, &QgsFeatureListComboBox::onDataChanged );
56 connect(
this,
static_cast<void (
QgsFeatureListComboBox::* )(
int )
>( &QgsFeatureListComboBox::currentIndexChanged ),
this, &QgsFeatureListComboBox::onCurrentIndexChanged );
62 setLineEdit( mLineEdit );
65 connect( mLineEdit, &QgsFilterLineEdit::textEdited,
this, &QgsFeatureListComboBox::onCurrentTextChanged );
72 setToolTip( tr(
"Just start typing what you are looking for." ) );
89 for (
const QString &field : fields )
106void QgsFeatureListComboBox::onCurrentTextChanged(
const QString &text )
108 mIsCurrentlyEdited =
true;
109 mPopupRequested =
true;
113void QgsFeatureListComboBox::onFilterLineEditCleared()
120void QgsFeatureListComboBox::onFilterUpdateCompleted()
122 if ( mPopupRequested )
123 mCompleter->complete();
125 mPopupRequested =
false;
128void QgsFeatureListComboBox::onLoadingChanged()
133void QgsFeatureListComboBox::onItemSelected(
const QModelIndex &index )
135 setCurrentIndex( index.row() );
138void QgsFeatureListComboBox::onCurrentIndexChanged(
int i )
141 mIsCurrentlyEdited =
false;
142 const QModelIndex modelIndex = mModel->
index( i, 0, QModelIndex() );
145 mLineEdit->setFont( mModel->
data( modelIndex, Qt::FontRole ).value<QFont>() );
146 QPalette palette = mLineEdit->palette();
147 palette.setBrush( mLineEdit->foregroundRole(), mModel->
data( modelIndex, Qt::ForegroundRole ).value<QBrush>() );
148 mLineEdit->setPalette( palette );
151void QgsFeatureListComboBox::onActivated( QModelIndex modelIndex )
157void QgsFeatureListComboBox::storeLineEditState()
159 if ( mIsCurrentlyEdited )
165void QgsFeatureListComboBox::restoreLineEditState()
167 if ( mIsCurrentlyEdited )
185void QgsFeatureListComboBox::onDataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles )
188 if ( !mIsCurrentlyEdited )
191 if ( currentIndex >= topLeft.row() && currentIndex <= bottomRight.row() )
193 const QModelIndex modelIndex = mModel->
index( currentIndex, 0, QModelIndex() );
202 if ( list.isEmpty() )
225 return mModel->
index( currentIndex(), 0, QModelIndex() );
231 QComboBox::focusOutEvent( event );
237 if ( event->key() == Qt::Key_Escape )
241 QComboBox::keyReleaseEvent( event );
302 QStringList filtersAttrs;
307 if ( i >= values.count() )
316 const QString expression = filtersAttrs.join( QLatin1String(
" AND " ) );
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value, QMetaType::Type fieldType=QMetaType::Type::UnknownType)
Create an expression allowing to evaluate if a field is equal to a value.
Provides a list of features based on filter conditions.
void setExtraIdentifierValues(const QVariantList &extraIdentifierValues)
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void setExtraIdentifierValueToNull() override
Allows specifying one value that does not need to match the filter criteria but will still be availab...
QStringList identifierFields
A set of fields of sourceLayer that is unique and should be used to identify features.
QVariantList extraIdentifierValues
The values that identifies the current feature.
void identifierFieldsChanged()
The identifier field should be a unique field that can be used to identify individual features.
void setIdentifierFields(const QStringList &identifierFields)
The identifier field should be a unique field that can be used to identify individual features.
This offers a combobox with autocompleter that allows selecting features from a layer.
QgsVectorLayer * sourceLayer
void setIdentifierValues(const QVariantList &identifierValues)
The identifier values of the currently selected feature.
void keyPressEvent(QKeyEvent *event) override
Q_DECL_DEPRECATED void setIdentifierField(const QString &identifierField)
Field name that will be used to uniquely identify the current feature.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used to display features as well as the value to match the typed text ...
QModelIndex currentModelIndex() const
The index of the currently selected item.
void setFilterExpression(const QString &filterExpression)
An additional expression to further restrict the available features.
void setIdentifierFields(const QStringList &identifierFields)
Field name that will be used to uniquely identify the current feature.
QString displayExpression
void allowNullChanged()
Determines if a NULL value should be available in the list.
QgsFeatureListComboBox(QWidget *parent=nullptr)
Create a new QgsFeatureListComboBox, optionally specifying a parent.
void focusOutEvent(QFocusEvent *event) override
void setSourceLayer(QgsVectorLayer *sourceLayer)
The layer from which features should be listed.
void modelUpdated()
The underlying model has been updated.
QgsFeatureRequest currentFeatureRequest() const
Shorthand for getting a feature request to query the currently selected feature.
void setIdentifierValuesToNull()
Sets the identifier values of the currently selected feature to NULL value(s).
void identifierValueChanged()
The identifier value of the currently selected feature.
QVariantList identifierValues
void sourceLayerChanged()
The layer from which features should be listed.
void setCurrentFeature(const QgsFeature &feature)
Sets the current index by using the given feature.
int nullIndex() const
Returns the current index of the NULL value, or -1 if NULL values are not allowed.
void currentFeatureFoundChanged(bool found)
Emitted when the feature picker model changes its feature found state.
int fetchLimit() const
Returns the feature request fetch limit.
Q_DECL_DEPRECATED void setIdentifierValue(const QVariant &identifierValue)
The identifier value of the currently selected feature.
void currentFeatureChanged()
Emitted when the current feature changes.
QStringList identifierFields() const
Field name that will be used to uniquely identify the current feature.
void setAllowNull(bool allowNull)
Determines if a NULL value should be available in the list.
void displayExpressionChanged()
The display expression will be used to display features as well as the the value to match the typed t...
void identifierFieldChanged()
Field name that will be used to uniquely identify the current feature.
void setFetchLimit(int fetchLimit)
Defines the feature request fetch limit If set to 0, no limit is applied when fetching.
void filterExpressionChanged()
An additional expression to further restrict the available features.
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
void beginUpdate()
Notification that the model is about to be changed because a job was completed.
void setFilterValue(const QString &filterValue)
This value will be used to filter the features available from this model.
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.
void setFetchLimit(int fetchLimit)
Defines the feature request fetch limit If set to 0, no limit is applied when fetching.
void extraValueDoesNotExistChanged(bool found)
Notification whether the model has found a feature tied to the extraIdentifierValue or not.
void extraIdentifierValueChanged()
Allows specifying one value that does not need to match the filter criteria but will still be availab...
@ IdentifierValues
Used to retrieve the identifierValues (primary keys) of a feature.
@ Value
Used to retrieve the displayExpression of a feature.
void filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
void setAllowNull(bool allowNull)
Add a NULL entry to the list.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used for.
bool isLoading() const
Indicator if the model is currently performing any feature iteration in the background.
QgsVectorLayer * sourceLayer
QVariant data(const QModelIndex &index, int role) const override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
int extraIdentifierValueIndex
void sourceLayerChanged()
The source layer from which features will be fetched.
void setFilterExpression(const QString &filterExpression)
An additional filter expression to apply, next to the filterValue.
void allowNullChanged()
Add a NULL entry to the list.
void currentFeatureChanged()
Emitted when the current feature in the model has changed This emitted both when the extra value chan...
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
QString displayExpression
void endUpdate()
Notification that the model change is finished.
void displayExpressionChanged()
The display expression will be used for.
void setSourceLayer(QgsVectorLayer *sourceLayer)
The source layer from which features will be fetched.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setRequestMayBeNested(bool requestMayBeNested)
In case this request may be run nested within another already running iteration on the same connectio...
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void restoreState()
Restores the current state of the line edit (selection and cursor position)
void storeState()
Stores the current state of the line edit (selection and cursor position)
@ ClearToNull
Reset value to null.
@ ClearToDefault
Reset value to default value (see defaultValue() )
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
bool hasStateStored() const
Returns if a state is already saved.
void setSelectOnFocus(bool selectOnFocus)
Will select all text when this widget receives the focus.
void cleared()
Emitted when the widget is cleared.
void setShowSpinner(bool showSpinner)
Show a spinner icon.
void setClearMode(ClearMode mode)
Sets the clear mode for the widget.
Represents a vector layer which manages a vector based data sets.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QSet< QgsFeatureId > QgsFeatureIds