QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsfeaturelistcombobox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeaturelistcombobox.h - QgsFeatureListComboBox
3  ---------------------
4  begin : 10.3.2017
5  copyright : (C) 2017 by Matthias Kuhn
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 QGSFIELDLISTCOMBOBOX_H
16 #define QGSFIELDLISTCOMBOBOX_H
17 
18 #include <QComboBox>
19 
20 #include "qgsfeature.h"
21 #include "qgsfeaturerequest.h"
22 #include "qgis_gui.h"
23 
24 class QgsVectorLayer;
26 class QgsAnimatedIcon;
27 class QgsFilterLineEdit;
28 
29 
39 class GUI_EXPORT QgsFeatureListComboBox : public QComboBox
40 {
41  Q_OBJECT
42 
43  Q_PROPERTY( QgsVectorLayer *sourceLayer READ sourceLayer WRITE setSourceLayer NOTIFY sourceLayerChanged )
44  Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
45  Q_PROPERTY( QString filterExpression READ filterExpression WRITE setFilterExpression NOTIFY filterExpressionChanged )
46  Q_PROPERTY( QVariant identifierValue READ identifierValue WRITE setIdentifierValue NOTIFY identifierValueChanged )
47  Q_PROPERTY( QVariantList identifierValues READ identifierValues WRITE setIdentifierValues NOTIFY identifierValueChanged )
48  Q_PROPERTY( QString identifierField READ identifierField WRITE setIdentifierField NOTIFY identifierFieldChanged )
49  Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
50 
51  public:
52 
56  QgsFeatureListComboBox( QWidget *parent = nullptr );
57 
61  QgsVectorLayer *sourceLayer() const;
62 
66  void setSourceLayer( QgsVectorLayer *sourceLayer );
67 
72  void setCurrentFeature( const QgsFeature &feature );
73 
78  QString displayExpression() const;
79 
84  void setDisplayExpression( const QString &displayExpression );
85 
90  QString filterExpression() const;
91 
98  int nullIndex() const;
99 
104  void setFilterExpression( const QString &filterExpression );
105 
111  Q_DECL_DEPRECATED QVariant identifierValue() const SIP_DEPRECATED;
112 
118  QVariantList identifierValues() const;
119 
120 
126  Q_DECL_DEPRECATED void setIdentifierValue( const QVariant &identifierValue ) SIP_DEPRECATED;
127 
133  void setIdentifierValues( const QVariantList &identifierValues );
134 
139  void setIdentifierValuesToNull();
140 
145  QgsFeatureRequest currentFeatureRequest() const;
146 
150  bool allowNull() const;
151 
155  void setAllowNull( bool allowNull );
156 
162  Q_DECL_DEPRECATED QString identifierField() const SIP_DEPRECATED;
163 
169  QStringList identifierFields() const;
170 
176  Q_DECL_DEPRECATED void setIdentifierField( const QString &identifierField ) SIP_DEPRECATED;
177 
183  void setIdentifierFields( const QStringList &identifierFields );
184 
188  QModelIndex currentModelIndex() const;
189 
190  void focusOutEvent( QFocusEvent *event ) override;
191 
192  void keyPressEvent( QKeyEvent *event ) override;
193 
194  signals:
195 
201  void modelUpdated();
202 
206  void sourceLayerChanged();
207 
212  void displayExpressionChanged();
213 
218  void filterExpressionChanged();
219 
224  void identifierValueChanged();
225 
230  void identifierFieldChanged();
231 
235  void allowNullChanged();
236 
241  void currentFeatureChanged();
242 
243  private slots:
244  void onCurrentTextChanged( const QString &text );
245  void onFilterUpdateCompleted();
246  void onLoadingChanged();
247  void onItemSelected( const QModelIndex &index );
248  void onCurrentIndexChanged( int i );
249  void onActivated( QModelIndex index );
250  void storeLineEditState();
251  void restoreLineEditState();
252  void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
253 
254  private:
255  QgsFeatureFilterModel *mModel = nullptr;
256  QCompleter *mCompleter = nullptr;
257  QgsFilterLineEdit *mLineEdit;
258  bool mPopupRequested = false;
259  bool mIsCurrentlyEdited = false;
260 
261  friend class TestQgsFeatureListComboBox;
262 };
263 
264 
265 
266 #endif // QGSFIELDLISTCOMBOBOX_H
qgsfeaturerequest.h
qgsfeature.h
QgsFilterLineEdit
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
Definition: qgsfilterlineedit.h:39
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsFeatureFilterModel
Provides a list of features based on filter conditions. Features are fetched asynchronously.
Definition: qgsfeaturefiltermodel.h:28
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
QgsFeatureListComboBox
This offers a combobox with autocompleter that allows selecting features from a layer.
Definition: qgsfeaturelistcombobox.h:39
QgsAnimatedIcon
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
Definition: qgsanimatedicon.h:30
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55