QGIS API Documentation  3.13.0-Master (788156190c)
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]gis.ch
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 
106  void setFilterExpression( const QString &filterExpression );
107 
113  Q_DECL_DEPRECATED QVariant identifierValue() const SIP_DEPRECATED;
114 
120  QVariantList identifierValues() const;
121 
122 
128  Q_DECL_DEPRECATED void setIdentifierValue( const QVariant &identifierValue ) SIP_DEPRECATED;
129 
135  void setIdentifierValues( const QVariantList &identifierValues );
136 
141  void setIdentifierValuesToNull();
142 
147  QgsFeatureRequest currentFeatureRequest() const;
148 
152  bool allowNull() const;
153 
157  void setAllowNull( bool allowNull );
158 
164  Q_DECL_DEPRECATED QString identifierField() const SIP_DEPRECATED;
165 
171  QStringList identifierFields() const;
172 
178  Q_DECL_DEPRECATED void setIdentifierField( const QString &identifierField ) SIP_DEPRECATED;
179 
185  void setIdentifierFields( const QStringList &identifierFields );
186 
190  QModelIndex currentModelIndex() const;
191 
192  void focusOutEvent( QFocusEvent *event ) override;
193 
194  void keyPressEvent( QKeyEvent *event ) override;
195 
196  signals:
197 
203  void modelUpdated();
204 
208  void sourceLayerChanged();
209 
214  void displayExpressionChanged();
215 
220  void filterExpressionChanged();
221 
226  void identifierValueChanged();
227 
232  void identifierFieldChanged();
233 
237  void allowNullChanged();
238 
239  private slots:
240  void onCurrentTextChanged( const QString &text );
241  void onFilterUpdateCompleted();
242  void onLoadingChanged();
243  void onItemSelected( const QModelIndex &index );
244  void onCurrentIndexChanged( int i );
245  void onActivated( QModelIndex index );
246  void storeLineEditState();
247  void restoreLineEditState();
248  void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
249 
250  private:
251  struct LineEditState
252  {
253  void store( QLineEdit *lineEdit );
254  void restore( QLineEdit *lineEdit ) const;
255 
256  QString text;
257  int selectionStart;
258  int selectionLength;
259  int cursorPosition;
260  };
261 
262  QgsFeatureFilterModel *mModel = nullptr;
263  QCompleter *mCompleter = nullptr;
264  QgsFilterLineEdit *mLineEdit;
265  bool mPopupRequested = false;
266  bool mIsCurrentlyEdited = false;
267  bool mHasStoredEditState = false;
268  LineEditState mLineEditState;
269 
270  friend class TestQgsFeatureListComboBox;
271 };
272 
273 
274 
275 #endif // QGSFIELDLISTCOMBOBOX_H
qgsfeaturerequest.h
qgsfeature.h
QgsFilterLineEdit
Definition: qgsfilterlineedit.h:39
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsFeatureFilterModel
Definition: qgsfeaturefiltermodel.h:31
QgsFeatureRequest
Definition: qgsfeaturerequest.h:72
QgsFeatureListComboBox
Definition: qgsfeaturelistcombobox.h:39
QgsAnimatedIcon
Definition: qgsanimatedicon.h:30
QgsVectorLayer
Definition: qgsvectorlayer.h:386
QgsFeature
Definition: qgsfeature.h:55