QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
30 , mCompleter( new QCompleter( mModel ) )
32 mCompleter->setCaseSensitivity( Qt::CaseInsensitive );
33 mCompleter->setFilterMode( Qt::MatchContains );
35 setCompleter( mCompleter );
36 mCompleter->setWidget(
this );
46 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::highlighted ),
this, &QgsFeatureListComboBox::onItemSelected );
47 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::activated ),
this, &QgsFeatureListComboBox::onActivated );
51 connect( mModel, &QgsFeatureFilterModel::dataChanged,
this, &QgsFeatureListComboBox::onDataChanged );
53 connect(
this,
static_cast<void(
QgsFeatureListComboBox::* )(
int )
>( &QgsFeatureListComboBox::currentIndexChanged ),
this, &QgsFeatureListComboBox::onCurrentIndexChanged );
59 setLineEdit( mLineEdit );
62 connect( mLineEdit, &QgsFilterLineEdit::textEdited,
this, &QgsFeatureListComboBox::onCurrentTextChanged );
66 setToolTip( tr(
"Just start typing what you are looking for." ) );
83 for (
const QString &
field : fields )
100 void QgsFeatureListComboBox::onCurrentTextChanged(
const QString &text )
102 mIsCurrentlyEdited =
true;
103 mPopupRequested =
true;
107 void QgsFeatureListComboBox::onFilterUpdateCompleted()
109 if ( mPopupRequested )
110 mCompleter->complete();
112 mPopupRequested =
false;
115 void QgsFeatureListComboBox::onLoadingChanged()
120 void QgsFeatureListComboBox::onItemSelected(
const QModelIndex &index )
122 setCurrentIndex( index.row() );
125 void QgsFeatureListComboBox::onCurrentIndexChanged(
int i )
128 mIsCurrentlyEdited =
false;
129 const QModelIndex modelIndex = mModel->
index( i, 0, QModelIndex() );
132 mLineEdit->setFont( mModel->
data( modelIndex, Qt::FontRole ).value<QFont>() );
133 QPalette palette = mLineEdit->palette();
134 palette.setBrush( mLineEdit->foregroundRole(), mModel->
data( modelIndex, Qt::ForegroundRole ).value<QBrush>() );
135 mLineEdit->setPalette( palette );
138 void QgsFeatureListComboBox::onActivated( QModelIndex modelIndex )
144 void QgsFeatureListComboBox::storeLineEditState()
146 if ( mIsCurrentlyEdited )
152 void QgsFeatureListComboBox::restoreLineEditState()
154 if ( mIsCurrentlyEdited )
172 void QgsFeatureListComboBox::onDataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles )
175 if ( !mIsCurrentlyEdited )
178 if ( currentIndex >= topLeft.row() && currentIndex <= bottomRight.row() )
180 const QModelIndex modelIndex = mModel->
index( currentIndex, 0, QModelIndex() );
189 if ( list.isEmpty() )
212 return mModel->
index( currentIndex(), 0, QModelIndex() );
218 QComboBox::focusOutEvent( event );
224 if ( event->key() == Qt::Key_Escape )
228 QComboBox::keyReleaseEvent( event );
277 QStringList filtersAttrs;
282 if ( i >= values.count() )
291 const QString expression = filtersAttrs.join( QLatin1String(
" AND " ) );
QStringList identifierFields() const
Field name that will be used to uniquely identify the current feature.
bool isLoading() const
Indicator if the model is currently performing any feature iteration in the background.
int extraIdentifierValueIndex
void displayExpressionChanged()
The display expression will be used for.
QStringList identifierFields
A set of fields of sourceLayer that is unique and should be used to identify features.
void setCurrentFeature(const QgsFeature &feature)
Sets the current index by using the given feature.
void allowNullChanged()
Determines if a NULL value should be available in the list.
void keyPressEvent(QKeyEvent *event) override
void setFilterExpression(const QString &filterExpression)
An additional expression to further restrict the available features.
void restoreState()
Restores the current state of the line edit (selection and cursor position)
void sourceLayerChanged()
The layer from which features should be listed.
void focusOutEvent(QFocusEvent *event) override
void identifierValueChanged()
The identifier value of the currently selected feature.
@ IdentifierValuesRole
Used to retrieve the identifierValues (primary keys) of a feature.
QVariantList extraIdentifierValues
The values that identifies the current feature.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
QVariantList identifierValues
@ ClearToNull
Reset value to null.
void setSelectOnFocus(bool selectOnFocus)
Will select all text when this widget receives the focus.
void setShowSpinner(bool showSpinner)
Show a spinner icon.
@ ValueRole
Used to retrieve the displayExpression of a feature.
void setClearMode(ClearMode mode)
Sets the clear mode for the widget.
void setIdentifierFields(const QStringList &identifierFields)
The identifier field should be a unique field that can be used to identify individual features.
void currentFeatureChanged()
Emitted when the current feature in the model has changed This emitted both when the extra value chan...
void filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
Q_DECL_DEPRECATED void setIdentifierField(const QString &identifierField)
Field name that will be used to uniquely identify the current feature.
void endUpdate()
Notification that the model change is finished.
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Provides a list of features based on filter conditions. Features are fetched asynchronously.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used to display features as well as the value to match the typed text ...
bool hasStateStored() const
Returns if a state is already saved.
#define Q_NOWARN_DEPRECATED_POP
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsVectorLayer sourceLayer
void modelUpdated()
The underlying model has been updated.
QVariant data(const QModelIndex &index, int role) const override
void setIdentifierValues(const QVariantList &identifierValues)
The identifier values of the currently selected feature.
@ ClearToDefault
Reset value to default value (see defaultValue() )
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
void extraIdentifierValueIndexChanged(int index)
The index at which the extra identifier value is available within the model.
void identifierFieldsChanged()
The identifier field should be a unique field that can be used to identify individual features.
Q_DECL_DEPRECATED void setIdentifierValue(const QVariant &identifierValue)
The identifier value of the currently selected feature.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QString displayExpression
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
This offers a combobox with autocompleter that allows selecting features from a layer.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
void storeState()
Stores the current state of the line edit (selection and cursor position)
QgsFeatureRequest currentFeatureRequest() const
Shorthand for getting a feature request to query the currently selected feature.
QModelIndex currentModelIndex() const
The index of the currently selected item.
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value, QVariant::Type fieldType=QVariant::Type::Invalid)
Create an expression allowing to evaluate if a field is equal to a value.
void setAllowNull(bool allowNull)
Add a NULL entry to the list.
QSet< QgsFeatureId > QgsFeatureIds
void setSourceLayer(QgsVectorLayer *sourceLayer)
The layer from which features should be listed.
void identifierFieldChanged()
Field name that will be used to uniquely identify the current feature.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used for.
void setIdentifierFields(const QStringList &identifierFields)
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.
Represents a vector layer which manages a vector based data sets.
void currentFeatureChanged()
Emitted when the current feature changes.
void allowNullChanged()
Add a NULL entry to 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 extraIdentifierValueChanged()
Allows specifying one value that does not need to match the filter criteria but will still be availab...
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.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
QString displayExpression
void setIdentifierValuesToNull()
Sets the identifier values of the currently selected feature to NULL value(s).
void setSourceLayer(QgsVectorLayer *sourceLayer)
The source layer from which features will be fetched.
#define Q_NOWARN_DEPRECATED_PUSH
void filterExpressionChanged()
An additional expression to further restrict the available features.
void setFilterExpression(const QString &filterExpression)
An additional filter expression to apply, next to the filterValue.
void sourceLayerChanged()
The source layer from which features will be fetched.
void setFilterValue(const QString &filterValue)
This value will be used to filter the features available from this model.
QgsVectorLayer sourceLayer
void beginUpdate()
Notification that the model is about to be changed because a job was completed.
void setExtraIdentifierValueToNull() override
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void setExtraIdentifierValues(const QVariantList &extraIdentifierValues)
Allows specifying one value that does not need to match the filter criteria but will still be availab...
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.