23#include "moc_qgsfeaturepickerwidget.cpp"
28 , mCompleter( new QCompleter( mModel ) )
30 QHBoxLayout *layout =
new QHBoxLayout();
31 mComboBox =
new QComboBox(
this );
32 mComboBox->setEditable(
true );
33 layout->addWidget( mComboBox );
35 mPreviousButton =
new QToolButton(
this );
37 mPreviousButton->setEnabled(
false );
38 mPreviousButton->setVisible( mShowBrowserButtons );
39 layout->addWidget( mPreviousButton );
41 mNextButton =
new QToolButton(
this );
43 mNextButton->setEnabled(
false );
44 mNextButton->setVisible( mShowBrowserButtons );
45 layout->addWidget( mNextButton );
46 layout->setContentsMargins( 0, 0, 0, 0 );
50 mCompleter->setCaseSensitivity( Qt::CaseInsensitive );
51 mCompleter->setFilterMode( Qt::MatchContains );
52 mComboBox->setCompleter( mCompleter );
53 mCompleter->setWidget( mComboBox );
64 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::highlighted ),
this, &QgsFeaturePickerWidget::onItemSelected );
65 connect( mCompleter,
static_cast<void( QCompleter::* )(
const QModelIndex & )
>( &QCompleter::activated ),
this, &QgsFeaturePickerWidget::onActivated );
69 connect( mModel, &QgsFeaturePickerModel::dataChanged,
this, &QgsFeaturePickerWidget::onDataChanged );
71 connect( mComboBox,
static_cast<void( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsFeaturePickerWidget::onCurrentIndexChanged );
73 connect( mPreviousButton, &QToolButton::clicked,
this, [ = ]() {browseFeatures( -1 );} );
74 connect( mNextButton, &QToolButton::clicked,
this, [ = ]() {browseFeatures( 1 );} );
77 mLineEdit->setSelectOnFocus(
true );
78 mLineEdit->setShowClearButton(
allowNull() );
80 mComboBox->setEditable(
true );
81 mComboBox->setLineEdit( mLineEdit );
82 mComboBox->setModel( mModel );
84 connect( mLineEdit, &QgsFilterLineEdit::textEdited,
this, &QgsFeaturePickerWidget::onCurrentTextChanged );
117void QgsFeaturePickerWidget::onCurrentTextChanged(
const QString &text )
119 mIsCurrentlyEdited =
true;
120 mPopupRequested =
true;
124void QgsFeaturePickerWidget::onFilterUpdateCompleted()
126 if ( mPopupRequested )
127 mCompleter->complete();
129 mPopupRequested =
false;
132void QgsFeaturePickerWidget::onLoadingChanged()
137void QgsFeaturePickerWidget::onItemSelected(
const QModelIndex &index )
139 mComboBox->setCurrentIndex( index.row() );
142void QgsFeaturePickerWidget::onCurrentIndexChanged(
int i )
145 mIsCurrentlyEdited =
false;
147 mPreviousButton->setEnabled( i > 0 );
148 mNextButton->setEnabled( i < mComboBox->model()->rowCount() - 1 );
153 const QModelIndex modelIndex = mModel->
index( i, 0, QModelIndex() );
156 mLineEdit->setFont( mModel->
data( modelIndex, Qt::FontRole ).value<QFont>() );
157 QPalette palette = mLineEdit->palette();
158 palette.setBrush( mLineEdit->foregroundRole(), mModel->
data( modelIndex, Qt::ForegroundRole ).value<QBrush>() );
159 mLineEdit->setPalette( palette );
162void QgsFeaturePickerWidget::onActivated( QModelIndex modelIndex )
168void QgsFeaturePickerWidget::storeLineEditState()
170 if ( mIsCurrentlyEdited )
176void QgsFeaturePickerWidget::restoreLineEditState()
178 if ( mIsCurrentlyEdited )
196void QgsFeaturePickerWidget::onDataChanged(
const QModelIndex &topLeft,
const QModelIndex &bottomRight,
const QVector<int> &roles )
199 if ( !mIsCurrentlyEdited )
202 if ( currentIndex >= topLeft.row() && currentIndex <= bottomRight.row() )
204 const QModelIndex modelIndex = mModel->
index( currentIndex, 0, QModelIndex() );
210void QgsFeaturePickerWidget::browseFeatures(
int direction )
212 const int newIndex = std::min( std::max( 0, mComboBox->currentIndex() + direction ), mComboBox->model()->rowCount() - 1 );
213 mComboBox->setCurrentIndex( newIndex );
224 QWidget::focusOutEvent( event );
230 if ( event->key() == Qt::Key_Escape )
234 QWidget::keyReleaseEvent( event );
280 return mShowBrowserButtons;
289 mPreviousButton->setVisible( mShowBrowserButtons );
290 mNextButton->setVisible( mShowBrowserButtons );
static QString nullRepresentation()
Returns the string 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.
@ FeatureId
Used to retrieve the id 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 fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
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 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