QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 QgsVectorLayer *mLayer = nullptr;
79 int mAttributeIndex;
80 QString mSubstring;
81 QStringList mValues;
82 QgsFeedback *mFeedback = nullptr;
83 QMutex mFeedbackMutex;
84 bool mWasCanceled;
85};
86
88
89#endif
90
99{
100 Q_OBJECT
101
102 Q_PROPERTY( QgsVectorLayer *layer READ layer WRITE setLayer NOTIFY layerChanged )
103 Q_PROPERTY( int attributeIndex READ attributeIndex WRITE setAttributeIndex NOTIFY attributeIndexChanged )
104
105 public:
110 QgsFieldValuesLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
111
112 ~QgsFieldValuesLineEdit() override;
113
120 void setLayer( QgsVectorLayer *layer );
121
127 QgsVectorLayer *layer() const { return mLayer; }
128
135 void setAttributeIndex( int index );
136
142 int attributeIndex() const { return mAttributeIndex; }
143
144 signals:
145
151
156 void attributeIndexChanged( int index );
157
158 private slots:
159
164 void requestCompleterUpdate();
165
170 void triggerCompleterUpdate();
171
176 void updateCompleter( const QStringList &values );
177
183 void gathererThreadFinished();
184
185 private:
186 QgsVectorLayer *mLayer = nullptr;
187 int mAttributeIndex = -1;
188
190 bool mUpdateRequested = false;
191
193 QTimer mShowPopupTimer;
194
196 QgsFieldValuesLineEditValuesGatherer *mGatherer = nullptr;
197
199 QString mRequestedCompletionText;
200
202 void updateCompletionList( const QString &substring );
203};
204
205
206#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