QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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
6  email : [email protected]
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 "qgsfeaturerequest.h"
25 #include "qgis_gui.h"
26 
27 class QToolButton;
28 
29 class QgsVectorLayer;
31 class QgsAnimatedIcon;
32 class QgsFilterLineEdit;
33 
34 
44 class GUI_EXPORT QgsFeaturePickerWidget : public QWidget
45 {
46  Q_OBJECT
47 
48  Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer NOTIFY layerChanged )
49  Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
50  Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
51  Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
52  Q_PROPERTY( bool fetchGeometry READ fetchGeometry WRITE setFetchGeometry NOTIFY fetchGeometryChanged )
53  Q_PROPERTY( int fetchLimit READ fetchLimit WRITE setFetchLimit NOTIFY fetchLimitChanged )
54  Q_PROPERTY( bool showBrowserButtons READ showBrowserButtons WRITE setShowBrowserButtons NOTIFY showBrowserButtonsChanged )
55 
56  public:
57 
61  QgsFeaturePickerWidget( QWidget *parent = nullptr );
62 
66  QgsVectorLayer *layer() const;
67 
71  void setLayer( QgsVectorLayer *layer );
72 
76  void setFeature( QgsFeatureId featureId );
77 
81  QgsFeature feature() const;
82 
87  QString displayExpression() const;
88 
93  void setDisplayExpression( const QString &displayExpression );
94 
99  QString filterExpression() const;
100 
105  int nullIndex() const;
106 
111  void setFilterExpression( const QString &filterExpression );
112 
116  bool allowNull() const;
117 
121  void setAllowNull( bool allowNull );
122 
126  bool fetchGeometry() const;
127 
131  void setFetchGeometry( bool fetchGeometry );
132 
136  int fetchLimit() const;
137 
142  void setFetchLimit( int fetchLimit );
143 
147  bool showBrowserButtons() const;
148 
153  void setShowBrowserButtons( bool showBrowserButtons );
154 
155 
159  QModelIndex currentModelIndex() const;
160 
161  void focusOutEvent( QFocusEvent *event ) override;
162 
163  void keyPressEvent( QKeyEvent *event ) override;
164 
165  signals:
166 
170  void modelUpdated();
171 
175  void layerChanged();
176 
182 
188 
190  void featureChanged( const QgsFeature &feature );
191 
196 
201 
206 
209 
210  private slots:
211  void onCurrentTextChanged( const QString &text );
212  void onFilterUpdateCompleted();
213  void onLoadingChanged();
214  void onItemSelected( const QModelIndex &index );
215  void onCurrentIndexChanged( int i );
216  void onActivated( QModelIndex index );
217  void storeLineEditState();
218  void restoreLineEditState();
219  void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
220  void browseFeatures( int direction );
221 
222  private:
223  QComboBox *mComboBox;
224  QToolButton *mPreviousButton;
225  QToolButton *mNextButton;
226  QgsFeaturePickerModel *mModel = nullptr;
227  QCompleter *mCompleter = nullptr;
228  QgsFilterLineEdit *mLineEdit;
229  bool mPopupRequested = false;
230  bool mIsCurrentlyEdited = false;
231  bool mHasStoredEditState = false;
232  bool mShowBrowserButtons = false;
233 };
234 
235 
236 
237 #endif // QGSFEATURECHOOSER_H
QgsFeaturePickerWidget::filterExpressionChanged
void filterExpressionChanged()
An additional expression to further restrict the available features.
qgsfeaturerequest.h
QgsFeaturePickerWidget::layerChanged
void layerChanged()
The layer from which features should be listed.
QgsFeaturePickerWidget::showBrowserButtonsChanged
void showBrowserButtonsChanged()
Emitted when showing the browser buttons changes.
QgsFeaturePickerWidget::modelUpdated
void modelUpdated()
The underlying model has been updated.
qgsfeature.h
QgsFilterLineEdit
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
Definition: qgsfilterlineedit.h:40
QgsFeaturePickerWidget::featureChanged
void featureChanged(const QgsFeature &feature)
Sends the feature as soon as it is chosen.
QgsFeaturePickerModel
Provides a list of features based on filter conditions.
Definition: qgsfeaturepickermodel.h:32
QgsFeaturePickerWidget::displayExpressionChanged
void displayExpressionChanged()
The display expression will be used to display features as well as the the value to match the typed t...
QgsAnimatedIcon
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
Definition: qgsanimatedicon.h:31
QgsFeaturePickerWidget::fetchGeometryChanged
void fetchGeometryChanged()
Emitted when the fetching of the geometry changes.
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsFeaturePickerWidget::fetchLimitChanged
void fetchLimitChanged()
Emitted when the fetching limit for the feature request changes.
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsFeaturePickerWidget
This offers a combobox with autocompleter that allows selecting features from a layer.
Definition: qgsfeaturepickerwidget.h:45
QgsFeaturePickerWidget::allowNullChanged
void allowNullChanged()
Determines if a NULL value should be available in the list.
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28