27 , mCompleter( new QCompleter( mModel ) )
29 QHBoxLayout *layout =
new QHBoxLayout();
30 mComboBox =
new QComboBox(
this );
31 mComboBox->setEditable(
true );
32 layout->addWidget( mComboBox );
34 mPreviousButton =
new QToolButton(
this );
36 mPreviousButton->setEnabled(
false );
37 mPreviousButton->setVisible( mShowBrowserButtons );
38 layout->addWidget( mPreviousButton );
40 mNextButton =
new QToolButton(
this );
42 mNextButton->setEnabled(
false );
43 mNextButton->setVisible( mShowBrowserButtons );
44 layout->addWidget( mNextButton );
45 layout->setContentsMargins( 0, 0, 0, 0 );
49 mCompleter->setCaseSensitivity( Qt::CaseInsensitive );
50 mCompleter->setFilterMode( Qt::MatchContains );
51 mComboBox->setCompleter( mCompleter );
52 mCompleter->setWidget( mComboBox );
63 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::highlighted ),
this, &QgsFeaturePickerWidget::onItemSelected );
64 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::activated ),
this, &QgsFeaturePickerWidget::onActivated );
68 connect( mModel, &QgsFeaturePickerModel::dataChanged,
this, &QgsFeaturePickerWidget::onDataChanged );
70 connect( mComboBox,
static_cast<void( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsFeaturePickerWidget::onCurrentIndexChanged );
72 connect( mPreviousButton, &QToolButton::clicked,
this, [ = ]() {browseFeatures( -1 );} );
73 connect( mNextButton, &QToolButton::clicked,
this, [ = ]() {browseFeatures( 1 );} );
76 mLineEdit->setSelectOnFocus(
true );
77 mLineEdit->setShowClearButton(
allowNull() );
79 mComboBox->setEditable(
true );
80 mComboBox->setLineEdit( mLineEdit );
81 mComboBox->setModel( mModel );
83 connect( mLineEdit, &QgsFilterLineEdit::textEdited,
this, &QgsFeaturePickerWidget::onCurrentTextChanged );
116void QgsFeaturePickerWidget::onCurrentTextChanged(
const QString &text )
118 mIsCurrentlyEdited =
true;
119 mPopupRequested =
true;
123void QgsFeaturePickerWidget::onFilterUpdateCompleted()
125 if ( mPopupRequested )
126 mCompleter->complete();
128 mPopupRequested =
false;
131void QgsFeaturePickerWidget::onLoadingChanged()
136void QgsFeaturePickerWidget::onItemSelected(
const QModelIndex &index )
138 mComboBox->setCurrentIndex( index.row() );
141void QgsFeaturePickerWidget::onCurrentIndexChanged(
int i )
144 mIsCurrentlyEdited =
false;
146 mPreviousButton->setEnabled( i > 0 );
147 mNextButton->setEnabled( i < mComboBox->model()->rowCount() - 1 );
152 const QModelIndex modelIndex = mModel->
index( i, 0, QModelIndex() );
155 mLineEdit->setFont( mModel->
data( modelIndex, Qt::FontRole ).value<QFont>() );
156 QPalette palette = mLineEdit->palette();
157 palette.setBrush( mLineEdit->foregroundRole(), mModel->
data( modelIndex, Qt::ForegroundRole ).value<QBrush>() );
158 mLineEdit->setPalette( palette );
161void QgsFeaturePickerWidget::onActivated( QModelIndex modelIndex )
167void QgsFeaturePickerWidget::storeLineEditState()
169 if ( mIsCurrentlyEdited )
175void QgsFeaturePickerWidget::restoreLineEditState()
177 if ( mIsCurrentlyEdited )
195void QgsFeaturePickerWidget::onDataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles )
198 if ( !mIsCurrentlyEdited )
201 if ( currentIndex >= topLeft.row() && currentIndex <= bottomRight.row() )
203 const QModelIndex modelIndex = mModel->
index( currentIndex, 0, QModelIndex() );
209void QgsFeaturePickerWidget::browseFeatures(
int direction )
211 const int newIndex = std::min( std::max( 0, mComboBox->currentIndex() + direction ), mComboBox->model()->rowCount() - 1 );
212 mComboBox->setCurrentIndex( newIndex );
223 QWidget::focusOutEvent( event );
229 if ( event->key() == Qt::Key_Escape )
233 QWidget::keyReleaseEvent( event );
279 return mShowBrowserButtons;
288 mPreviousButton->setVisible( mShowBrowserButtons );
289 mNextButton->setVisible( mShowBrowserButtons );
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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 setFetchGeometry(bool fetchGeometry)
Defines if the geometry will be fetched.
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 fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
void sourceLayerChanged()
The source layer from which features will be fetched.
@ FeatureIdRole
Used to retrieve the id of a feature.
@ ValueRole
Used to retrieve the displayExpression of a feature.
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 fetchGeometryChanged()
Emitted when the fetching of the geometry changes.
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.
Provides a list of features based on filter conditions.
void setFeature(const QgsFeatureId &fid)
Set the feature to the given feature id.
void featureChanged(const QgsFeature &feature)
Emitted when the current feature changes.
QgsFeature feature() const
Returns the current feature.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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() )
bool hasStateStored() const
Returns if a state is already saved.
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.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features