QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsfieldvalueslineedit.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldvalueslineedit.h
3  -----------------------
4  Date : 20-08-2016
5  Copyright : (C) 2016 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
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 QGSFIELDVALUESLINEEDIT_H
16 #define QGSFIELDVALUESLINEEDIT_H
17 
18 #include "qgsfilterlineedit.h"
19 #include "qgis_sip.h"
20 #include "qgsfeedback.h"
21 
22 #include <QStringListModel>
23 #include <QTreeView>
24 #include <QFocusEvent>
25 #include <QHeaderView>
26 #include <QTimer>
27 #include <QThread>
28 #include <QMutex>
29 
30 #include "qgis_gui.h"
31 
32 class QgsFloatingWidget;
33 class QgsVectorLayer;
34 
35 
36 #ifndef SIP_RUN
37 
38 // just internal guff - definitely not for exposing to public API!
40 
45 class QgsFieldValuesLineEditValuesGatherer: public QThread
46 {
47  Q_OBJECT
48 
49  public:
50  QgsFieldValuesLineEditValuesGatherer( QgsVectorLayer *layer, int attributeIndex )
51  : mLayer( layer )
52  , mAttributeIndex( attributeIndex )
53  , mWasCanceled( false )
54  {}
55 
59  void setSubstring( const QString &string ) { mSubstring = string; }
60 
61  void run() override;
62 
64  void stop();
65 
67  bool wasCanceled() const { return mWasCanceled; }
68 
69  signals:
70 
75  void collectedValues( const QStringList &values );
76 
77  private:
78 
79  QgsVectorLayer *mLayer = nullptr;
80  int mAttributeIndex;
81  QString mSubstring;
82  QStringList mValues;
83  QgsFeedback *mFeedback = nullptr;
84  QMutex mFeedbackMutex;
85  bool mWasCanceled;
86 };
87 
89 
90 #endif
91 
101 {
102  Q_OBJECT
103 
104  Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer NOTIFY layerChanged )
105  Q_PROPERTY( int attributeIndex READ attributeIndex WRITE setAttributeIndex NOTIFY attributeIndexChanged )
106 
107  public:
108 
113  QgsFieldValuesLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
114 
115  ~QgsFieldValuesLineEdit() override;
116 
123  void setLayer( QgsVectorLayer *layer );
124 
130  QgsVectorLayer *layer() const { return mLayer; }
131 
138  void setAttributeIndex( int index );
139 
145  int attributeIndex() const { return mAttributeIndex; }
146 
147  signals:
148 
153  void layerChanged( QgsVectorLayer *layer );
154 
159  void attributeIndexChanged( int index );
160 
161  private slots:
162 
167  void requestCompleterUpdate();
168 
173  void triggerCompleterUpdate();
174 
179  void updateCompleter( const QStringList &values );
180 
186  void gathererThreadFinished();
187 
188  private:
189 
190  QgsVectorLayer *mLayer = nullptr;
191  int mAttributeIndex = -1;
192 
194  bool mUpdateRequested = false;
195 
197  QTimer mShowPopupTimer;
198 
200  QgsFieldValuesLineEditValuesGatherer *mGatherer = nullptr;
201 
203  QString mRequestedCompletionText;
204 
206  void updateCompletionList( const QString &substring );
207 
208 };
209 
210 
211 #endif //QGSFIELDVALUESLINEEDIT_H
QgsFieldValuesLineEdit::attributeIndex
int attributeIndex() const
Returns the attribute index for the field containing values shown in the widget.
Definition: qgsfieldvalueslineedit.h:145
qgsfilterlineedit.h
QgsFilterLineEdit
Definition: qgsfilterlineedit.h:39
QgsFeedback
Definition: qgsfeedback.h:43
QgsFieldValuesLineEdit
Definition: qgsfieldvalueslineedit.h:100
qgis_sip.h
QgsFloatingWidget
Definition: qgsfloatingwidget.h:33
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgsfeedback.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53