30 , mCompleter( new QCompleter( mModel ) )
32 mCompleter->setCaseSensitivity( Qt::CaseInsensitive );
33 mCompleter->setFilterMode( Qt::MatchContains );
34 setCompleter( mCompleter );
35 mCompleter->setWidget(
this );
45 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::highlighted ),
this, &QgsFeatureListComboBox::onItemSelected );
46 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::activated ),
this, &QgsFeatureListComboBox::onActivated );
50 connect( mModel, &QgsFeatureFilterModel::dataChanged,
this, &QgsFeatureListComboBox::onDataChanged );
52 connect(
this,
static_cast<void(
QgsFeatureListComboBox::* )(
int )
>( &QgsFeatureListComboBox::currentIndexChanged ),
this, &QgsFeatureListComboBox::onCurrentIndexChanged );
59 setLineEdit( mLineEdit );
62 connect( mLineEdit, &QgsFilterLineEdit::textEdited,
this, &QgsFeatureListComboBox::onCurrentTextChanged );
64 setToolTip( tr(
"Just start typing what you are looking for." ) );
87 void QgsFeatureListComboBox::onCurrentTextChanged(
const QString &text )
89 mIsCurrentlyEdited =
true;
90 mPopupRequested =
true;
94 void QgsFeatureListComboBox::onFilterUpdateCompleted()
96 if ( mPopupRequested )
97 mCompleter->complete();
99 mPopupRequested =
false;
102 void QgsFeatureListComboBox::onLoadingChanged()
107 void QgsFeatureListComboBox::onItemSelected(
const QModelIndex &index )
109 setCurrentIndex( index.row() );
112 void QgsFeatureListComboBox::onCurrentIndexChanged(
int i )
114 if ( !mHasStoredEditState )
115 mIsCurrentlyEdited =
false;
116 QModelIndex modelIndex = mModel->
index( i, 0, QModelIndex() );
119 mLineEdit->setFont( mModel->
data( modelIndex, Qt::FontRole ).value<QFont>() );
120 QPalette palette = mLineEdit->palette();
121 palette.setBrush( mLineEdit->foregroundRole(), mModel->
data( modelIndex, Qt::ForegroundRole ).value<QBrush>() );
122 mLineEdit->setPalette( palette );
125 void QgsFeatureListComboBox::onActivated( QModelIndex modelIndex )
131 void QgsFeatureListComboBox::storeLineEditState()
133 if ( mIsCurrentlyEdited )
135 mHasStoredEditState =
true;
136 mLineEditState.store( mLineEdit );
140 void QgsFeatureListComboBox::restoreLineEditState()
142 if ( mIsCurrentlyEdited )
144 mHasStoredEditState =
false;
145 mLineEditState.restore( mLineEdit );
161 void QgsFeatureListComboBox::onDataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles )
164 if ( !mIsCurrentlyEdited )
167 if ( currentIndex >= topLeft.row() && currentIndex <= bottomRight.row() )
169 QModelIndex modelIndex = mModel->
index( currentIndex, 0, QModelIndex() );
193 QComboBox::focusOutEvent( event );
199 if ( event->key() == Qt::Key_Escape )
203 QComboBox::keyReleaseEvent( event );
244 void QgsFeatureListComboBox::LineEditState::store( QLineEdit *lineEdit )
246 text = lineEdit->text();
247 selectionStart = lineEdit->selectionStart();
248 selectionLength = lineEdit->selectedText().length();
249 cursorPosition = lineEdit->cursorPosition();
253 void QgsFeatureListComboBox::LineEditState::restore( QLineEdit *lineEdit )
const 255 lineEdit->setText( text );
256 lineEdit->setCursorPosition( cursorPosition );
257 if ( selectionStart > -1 )
258 lineEdit->setSelection( selectionStart, selectionLength );
void setIdentifierValue(const QVariant &identifierValue)
The identifier value of the currently selected feature.
Provides a list of features based on filter conditions.
This offers a combobox with autocompleter that allows selecting features from a layer.
QSet< QgsFeatureId > QgsFeatureIds
void setSelectOnFocus(bool selectOnFocus)
Will select all text when this widget receives the focus.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
void beginUpdate()
Notification that the model is about to be changed because a job was completed.
QString displayExpression
Used to retrieve the displayExpression of a feature.
void identifierFieldChanged()
Field name that will be used to uniquely identify the current feature.
int nullIndex() const
Returns the current index of the NULL value, or -1 if NULL values are not allowed.
void setFilterExpression(const QString &filterExpression)
An additional filter expression to apply, next to the filterValue.
void setShowSpinner(bool showSpinner)
Show a spinner icon.
QString displayExpression() const
The display expression will be used to display features as well as the value to match the typed text ...
void displayExpressionChanged()
The display expression will be used to display features as well as the the value to match the typed t...
void filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
void setSourceLayer(QgsVectorLayer *sourceLayer)
The layer from which features should be listed.
void filterExpressionChanged()
An additional expression to further restrict the available features.
QString identifierField() const
Field name that will be used to uniquely identify the current feature.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
void identifierFieldChanged()
The identifier field should be a unique field that can be used to identify individual features...
QgsFeatureRequest currentFeatureRequest() const
Shorthand for getting a feature request to query the currently selected feature.
void setAllowNull(bool allowNull)
Determines if a NULL value should be available in the list.
QgsFeatureListComboBox(QWidget *parent=nullptr)
Create a new QgsFeatureListComboBox, optionally specifying a parent.
void setFilterValue(const QString &filterValue)
This value will be used to filter the features available from this model.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QString identifierField
A field of sourceLayer that is unique and should be used to identify features.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QVariant extraIdentifierValue
The value that identifies the current feature.
void identifierValueChanged()
The identifier value of the currently selected feature.
QModelIndex currentModelIndex() const
The index of the currently selected item.
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
void allowNullChanged()
Add a NULL entry to the list.
bool allowNull() const
Determines if a NULL value should be available in the list.
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.
void endUpdate()
Notification that the model change is finished.
void extraIdentifierValueChanged()
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void setIdentifierField(const QString &identifierField)
The identifier field should be a unique field that can be used to identify individual features...
void setSourceLayer(QgsVectorLayer *sourceLayer)
The source layer from which features will be fetched.
void setFilterExpression(const QString &filterExpression)
An additional expression to further restrict the available features.
void sourceLayerChanged()
The source layer from which features will be fetched.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
void allowNullChanged()
Determines if a NULL value should be available in the list.
int extraIdentifierValueIndex
void keyPressEvent(QKeyEvent *event) override
void setExtraIdentifierValue(const QVariant &extraIdentifierValue)
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void sourceLayerChanged()
The layer from which features should be listed.
QString filterExpression() const
An additional expression to further restrict the available features.
void focusOutEvent(QFocusEvent *event) override
QVariant data(const QModelIndex &index, int role) const override
void setAllowNull(bool allowNull)
Add a NULL entry to the list.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required...
Used to retrieve the identifierValue (primary key) of a feature.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used for.
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
Represents a vector layer which manages a vector based data sets.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used to display features as well as the value to match the typed text ...
QgsVectorLayer sourceLayer
void modelUpdated()
The underlying model has been updated.
void setIdentifierField(const QString &identifierField)
Field name that will be used to uniquely identify the current feature.
QgsVectorLayer * sourceLayer() const
The layer from which features should be listed.
void displayExpressionChanged()
The display expression will be used for.
QVariant identifierValue() const
The identifier value of the currently selected feature.