QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsfeaturepickerwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfeaturepickerwidget.h - QgsFeaturePickerWidget
3 ---------------------
4 begin : 03.04.2020
5 copyright : (C) 2020 by Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSFEATURECHOOSER_H
16#define QGSFEATURECHOOSER_H
17
18#include <QWidget>
19#include <QComboBox>
20#include <QLineEdit>
21#include <QCompleter>
22
23#include "qgsfeature.h"
24#include "qgis_gui.h"
25
26class QToolButton;
27
28class QgsVectorLayer;
30class QgsAnimatedIcon;
32
33
43class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
44{
45 Q_OBJECT
46
47 Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer NOTIFY layerChanged )
48 Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
49 Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
50 Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
51 Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
52 Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
53 Q_PROPERTY( bool showBrowserButtons READ showBrowserButtons WRITE setShowBrowserButtons NOTIFY showBrowserButtonsChanged )
54
55 public:
56
60 QgsFeaturePickerWidget( QWidget *parent = nullptr );
61
65 QgsVectorLayer *layer() const;
66
70 void setLayer( QgsVectorLayer *layer );
71
75 void setFeature( QgsFeatureId featureId );
76
80 QgsFeature feature() const;
81
86 QString displayExpression() const;
87
92 void setDisplayExpression( const QString &displayExpression );
93
98 QString filterExpression() const;
99
104 int nullIndex() const;
105
110 void setFilterExpression( const QString &filterExpression );
111
115 bool allowNull() const;
116
120 void setAllowNull( bool allowNull );
121
125 bool fetchGeometry() const;
126
130 void setFetchGeometry( bool fetchGeometry );
131
135 int fetchLimit() const;
136
141 void setFetchLimit( int fetchLimit );
142
146 bool showBrowserButtons() const;
147
152 void setShowBrowserButtons( bool showBrowserButtons );
153
154
158 QModelIndex currentModelIndex() const;
159
160 void focusOutEvent( QFocusEvent *event ) override;
161
162 void keyPressEvent( QKeyEvent *event ) override;
163
164 signals:
165
170
175
181
187
189 void featureChanged( const QgsFeature &feature );
190
195
200
205
208
209 private slots:
210 void onCurrentTextChanged( const QString &text );
211 void onFilterUpdateCompleted();
212 void onLoadingChanged();
213 void onItemSelected( const QModelIndex &index );
214 void onCurrentIndexChanged( int i );
215 void onActivated( QModelIndex index );
216 void storeLineEditState();
217 void restoreLineEditState();
218 void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
219 void browseFeatures( int direction );
220
221 private:
222 QComboBox *mComboBox;
223 QToolButton *mPreviousButton;
224 QToolButton *mNextButton;
225 QgsFeaturePickerModel *mModel = nullptr;
226 QCompleter *mCompleter = nullptr;
227 QgsFilterLineEdit *mLineEdit;
228 bool mPopupRequested = false;
229 bool mIsCurrentlyEdited = false;
230 bool mHasStoredEditState = false;
231 bool mShowBrowserButtons = false;
232};
233
234
235
236#endif // QGSFEATURECHOOSER_H
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
Provides a list of features based on filter conditions.
This offers a combobox with autocompleter that allows selecting features from a layer.
void allowNullChanged()
Determines if a NULL value should be available in the list.
void filterExpressionChanged()
An additional expression to further restrict the available features.
void displayExpressionChanged()
The display expression will be used to display features as well as the the value to match the typed t...
void layerChanged()
The layer from which features should be listed.
void modelUpdated()
The underlying model has been updated.
void showBrowserButtonsChanged()
Emitted when showing the browser buttons changes.
void fetchGeometryChanged()
Emitted when the fetching of the geometry changes.
void featureChanged(const QgsFeature &feature)
Sends the feature as soon as it is chosen.
void fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
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
Definition: qgsfeatureid.h:28