QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsfeaturelistcombobox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldlistcombobox.h - QgsFieldListComboBox
3 
4  ---------------------
5  begin : 10.3.2017
6  copyright : (C) 2017 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSFIELDLISTCOMBOBOX_H
17 #define QGSFIELDLISTCOMBOBOX_H
18 
19 #include <QComboBox>
20 
21 #include "qgsfeature.h"
22 #include "qgsfeaturerequest.h"
23 #include "qgis_gui.h"
24 
25 class QgsVectorLayer;
27 class QgsAnimatedIcon;
28 class QgsFilterLineEdit;
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( QString identifierField READ identifierField WRITE setIdentifierField NOTIFY identifierFieldChanged )
48  Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull NOTIFY allowNullChanged )
49 
50  public:
51 
55  QgsFeatureListComboBox( QWidget *parent = nullptr );
56 
60  QgsVectorLayer *sourceLayer() const;
61 
65  void setSourceLayer( QgsVectorLayer *sourceLayer );
66 
71  QString displayExpression() const;
72 
77  void setDisplayExpression( const QString &displayExpression );
78 
83  QString filterExpression() const;
84 
91  int nullIndex() const;
92 
99  void setFilterExpression( const QString &filterExpression );
100 
105  QVariant identifierValue() const;
106 
111  void setIdentifierValue( const QVariant &identifierValue );
112 
117  QgsFeatureRequest currentFeatureRequest() const;
118 
122  bool allowNull() const;
123 
127  void setAllowNull( bool allowNull );
128 
133  QString identifierField() const;
134 
139  void setIdentifierField( const QString &identifierField );
140 
144  QModelIndex currentModelIndex() const;
145 
146  void focusOutEvent( QFocusEvent *event ) override;
147 
148  void keyPressEvent( QKeyEvent *event ) override;
149 
150  signals:
151 
157  void modelUpdated();
158 
162  void sourceLayerChanged();
163 
168  void displayExpressionChanged();
169 
174  void filterExpressionChanged();
175 
180  void identifierValueChanged();
181 
186  void identifierFieldChanged();
187 
191  void allowNullChanged();
192 
193  private slots:
194  void onCurrentTextChanged( const QString &text );
195  void onFilterUpdateCompleted();
196  void onLoadingChanged();
197  void onItemSelected( const QModelIndex &index );
198  void onCurrentIndexChanged( int i );
199  void onActivated( QModelIndex index );
200  void storeLineEditState();
201  void restoreLineEditState();
202  void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
203 
204  private:
205  struct LineEditState
206  {
207  void store( QLineEdit *lineEdit );
208  void restore( QLineEdit *lineEdit ) const;
209 
210  QString text;
211  int selectionStart;
212  int selectionLength;
213  int cursorPosition;
214  };
215 
216  QgsFeatureFilterModel *mModel = nullptr;
217  QCompleter *mCompleter = nullptr;
218  QString mDisplayExpression;
219  QgsFilterLineEdit *mLineEdit;
220  bool mPopupRequested = false;
221  bool mIsCurrentlyEdited = false;
222  LineEditState mLineEditState;
223 };
224 
225 #endif // QGSFIELDLISTCOMBOBOX_H
Provides a list of features based on filter conditions.
This offers a combobox with autocompleter that allows selecting features from a layer.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QLineEdit subclass with built in support for clearing the widget&#39;s value and handling custom null val...
Animated icon is keeping an animation running if there are listeners connected to frameChanged...
Represents a vector layer which manages a vector based data sets.