QGIS API Documentation  3.0.2-Girona (307d082)
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  void setFilterExpression( const QString &filterExpression );
92 
97  QVariant identifierValue() const;
98 
103  void setIdentifierValue( const QVariant &identifierValue );
104 
109  QgsFeatureRequest currentFeatureRequest() const;
110 
114  bool allowNull() const;
115 
119  void setAllowNull( bool allowNull );
120 
125  QString identifierField() const;
126 
131  void setIdentifierField( const QString &identifierField );
132 
136  QModelIndex currentModelIndex() const;
137 
138  void focusOutEvent( QFocusEvent *event ) override;
139 
140  void keyPressEvent( QKeyEvent *event ) override;
141 
142  signals:
143 
147  void sourceLayerChanged();
148 
153  void displayExpressionChanged();
154 
159  void filterExpressionChanged();
160 
165  void identifierValueChanged();
166 
171  void identifierFieldChanged();
172 
176  void allowNullChanged();
177 
178  private slots:
179  void onCurrentTextChanged( const QString &text );
180  void onFilterUpdateCompleted();
181  void onLoadingChanged();
182  void onItemSelected( const QModelIndex &index );
183  void onCurrentIndexChanged( int i );
184  void onActivated( QModelIndex index );
185  void storeLineEditState();
186  void restoreLineEditState();
187  void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>() );
188 
189  private:
190  struct LineEditState
191  {
192  void store( QLineEdit *lineEdit );
193  void restore( QLineEdit *lineEdit ) const;
194 
195  QString text;
196  int selectionStart;
197  int selectionLength;
198  int cursorPosition;
199  };
200 
201  QgsFeatureFilterModel *mModel = nullptr;
202  QCompleter *mCompleter = nullptr;
203  QString mDisplayExpression;
204  QgsFilterLineEdit *mLineEdit;
205  bool mPopupRequested = false;
206  bool mIsCurrentlyEdited = false;
207  LineEditState mLineEditState;
208 };
209 
210 #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.