19#include "moc_qgsfieldvalueslineedit.cpp"
22#include <QStringListModel>
29 QCompleter *
c =
new QCompleter(
this );
30 c->setCaseSensitivity( Qt::CaseInsensitive );
31 c->setFilterMode( Qt::MatchContains );
32 c->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
34 connect(
this, &QgsFieldValuesLineEdit::textEdited,
this, &QgsFieldValuesLineEdit::requestCompleterUpdate );
35 mShowPopupTimer.setSingleShot(
true );
36 mShowPopupTimer.setInterval( 100 );
37 connect( &mShowPopupTimer, &QTimer::timeout,
this, &QgsFieldValuesLineEdit::triggerCompleterUpdate );
51 if ( mLayer ==
layer )
60 if ( mAttributeIndex == index )
63 mAttributeIndex = index;
67void QgsFieldValuesLineEdit::requestCompleterUpdate()
69 mUpdateRequested =
true;
70 mShowPopupTimer.start();
73void QgsFieldValuesLineEdit::triggerCompleterUpdate()
75 mShowPopupTimer.stop();
76 const QString currentText = text();
78 if ( currentText.isEmpty() )
85 updateCompletionList( currentText );
88void QgsFieldValuesLineEdit::updateCompletionList(
const QString &text )
97 mUpdateRequested =
true;
100 mRequestedCompletionText = text;
105 mGatherer =
new QgsFieldValuesLineEditValuesGatherer( mLayer, mAttributeIndex );
106 mGatherer->setSubstring( text );
108 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::collectedValues,
this, &QgsFieldValuesLineEdit::updateCompleter );
109 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::finished,
this, &QgsFieldValuesLineEdit::gathererThreadFinished );
114void QgsFieldValuesLineEdit::gathererThreadFinished()
116 const bool wasCanceled = mGatherer->wasCanceled();
123 const QString text = mRequestedCompletionText;
124 mRequestedCompletionText.clear();
125 updateCompletionList( text );
130void QgsFieldValuesLineEdit::updateCompleter(
const QStringList &values )
132 mUpdateRequested =
false;
133 completer()->setModel(
new QStringListModel( values ) );
134 completer()->complete();
141void QgsFieldValuesLineEditValuesGatherer::run()
143 mWasCanceled =
false;
144 if ( mSubstring.isEmpty() )
146 emit collectedValues( QStringList() );
153 mValues = mLayer->uniqueStringsMatching( mAttributeIndex, mSubstring, 100, mFeedback );
156 mFeedbackMutex.lock();
159 mFeedbackMutex.unlock();
161 emit collectedValues( mValues );
164void QgsFieldValuesLineEditValuesGatherer::stop()
167 mFeedbackMutex.lock();
170 mFeedbackMutex.unlock();
Base class for feedback objects to be used for cancellation of something running in a worker thread.
void attributeIndexChanged(int index)
Emitted when the field associated with the widget changes.
~QgsFieldValuesLineEdit() override
QgsFieldValuesLineEdit(QWidget *parent=nullptr)
Constructor for QgsFieldValuesLineEdit.
void setLayer(QgsVectorLayer *layer)
Sets the layer containing the field that values will be shown from.
void layerChanged(QgsVectorLayer *layer)
Emitted when the layer associated with the widget changes.
void setAttributeIndex(int index)
Sets the attribute index for the field containing values to show in the widget.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
Represents a vector layer which manages a vector based data sets.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c