QGIS API Documentation 3.39.0-Master (be2050b798e)
Loading...
Searching...
No Matches
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
100{
101 Q_OBJECT
102
103 Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer NOTIFY layerChanged )
104 Q_PROPERTY( int attributeIndex READ attributeIndex WRITE setAttributeIndex NOTIFY attributeIndexChanged )
105
106 public:
107
112 QgsFieldValuesLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
113
114 ~QgsFieldValuesLineEdit() override;
115
122 void setLayer( QgsVectorLayer *layer );
123
129 QgsVectorLayer *layer() const { return mLayer; }
130
137 void setAttributeIndex( int index );
138
144 int attributeIndex() const { return mAttributeIndex; }
145
146 signals:
147
153
158 void attributeIndexChanged( int index );
159
160 private slots:
161
166 void requestCompleterUpdate();
167
172 void triggerCompleterUpdate();
173
178 void updateCompleter( const QStringList &values );
179
185 void gathererThreadFinished();
186
187 private:
188
189 QgsVectorLayer *mLayer = nullptr;
190 int mAttributeIndex = -1;
191
193 bool mUpdateRequested = false;
194
196 QTimer mShowPopupTimer;
197
199 QgsFieldValuesLineEditValuesGatherer *mGatherer = nullptr;
200
202 QString mRequestedCompletionText;
203
205 void updateCompletionList( const QString &substring );
206
207};
208
209
210#endif //QGSFIELDVALUESLINEEDIT_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
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.
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