QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
33class QgsVectorLayer;
34
35
36#ifndef SIP_RUN
37
38// just internal guff - definitely not for exposing to public API!
40
45class 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
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
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A line edit with an autocompleter which takes unique values from a vector layer's fields.
void attributeIndexChanged(int index)
Emitted when the field associated with the widget changes.
void layerChanged(QgsVectorLayer *layer)
Emitted when the layer associated with the widget changes.
int attributeIndex() const
Returns the attribute index for the field containing values shown in the widget.
QgsVectorLayer * layer() const
Returns the layer containing the field that values will be shown from.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A QWidget subclass for creating widgets which float outside of the normal Qt layout system.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53