QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
16 #include <QHBoxLayout>
17 #include <QToolButton>
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 );
116 void QgsFeaturePickerWidget::onCurrentTextChanged(
const QString &text )
118 mIsCurrentlyEdited =
true;
119 mPopupRequested =
true;
123 void QgsFeaturePickerWidget::onFilterUpdateCompleted()
125 if ( mPopupRequested )
126 mCompleter->complete();
128 mPopupRequested =
false;
131 void QgsFeaturePickerWidget::onLoadingChanged()
136 void QgsFeaturePickerWidget::onItemSelected(
const QModelIndex &index )
138 mComboBox->setCurrentIndex( index.row() );
141 void 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 );
161 void QgsFeaturePickerWidget::onActivated( QModelIndex modelIndex )
167 void QgsFeaturePickerWidget::storeLineEditState()
169 if ( mIsCurrentlyEdited )
175 void QgsFeaturePickerWidget::restoreLineEditState()
177 if ( mIsCurrentlyEdited )
195 void 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() );
209 void 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 );
void featureChanged(const QgsFeature &feature)
Emitted when the current feature changes.
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.
void restoreState()
Restores the current state of the line edit (selection and cursor position)
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
@ ClearToNull
Reset value to null.
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 filterJobCompleted()
Indicates that a filter job has been completed and new data may be available.
Provides a list of features based on filter conditions. Features are fetched asynchronously.
void endUpdate()
Notification that the model change is finished.
void isLoadingChanged()
Indicator if the model is currently performing any feature iteration in the background.
bool hasStateStored() const
Returns if a state is already saved.
QgsVectorLayer sourceLayer
QVariant data(const QModelIndex &index, int role) const override
@ 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 fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QString displayExpression
void storeState()
Stores the current state of the line edit (selection and cursor position)
void setAllowNull(bool allowNull)
Add a NULL entry to the list.
void setDisplayExpression(const QString &displayExpression)
The display expression will be used for.
void setFeature(const QgsFeatureId &fid)
Set the feature to the given feature id.
Represents a vector layer which manages a vector based data sets.
QgsFeature feature() const
Returns the current feature.
void allowNullChanged()
Add a NULL entry to the list.
void fetchGeometryChanged()
Emitted when the fetching of the geometry changes.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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 setSourceLayer(QgsVectorLayer *sourceLayer)
The source layer from which features will be fetched.
@ FeatureIdRole
Used to retrieve the id of a feature.
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.
void beginUpdate()
Notification that the model is about to be changed because a job was completed.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
void filterExpressionChanged()
An additional filter expression to apply, next to the filterValue.