23#include <QStringListModel>
26#include "moc_qgsfieldvalueslineedit.cpp"
31 QCompleter *
c =
new QCompleter(
this );
32 c->setCaseSensitivity( Qt::CaseInsensitive );
33 c->setFilterMode( Qt::MatchContains );
34 c->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
36 connect(
this, &QgsFieldValuesLineEdit::textEdited,
this, &QgsFieldValuesLineEdit::requestCompleterUpdate );
37 mShowPopupTimer.setSingleShot(
true );
38 mShowPopupTimer.setInterval( 100 );
39 connect( &mShowPopupTimer, &QTimer::timeout,
this, &QgsFieldValuesLineEdit::triggerCompleterUpdate );
53 if ( mLayer ==
layer )
62 if ( mAttributeIndex == index )
65 mAttributeIndex = index;
69void QgsFieldValuesLineEdit::requestCompleterUpdate()
71 mUpdateRequested =
true;
72 mShowPopupTimer.start();
75void QgsFieldValuesLineEdit::triggerCompleterUpdate()
77 mShowPopupTimer.stop();
78 const QString currentText = text();
80 if ( currentText.isEmpty() )
87 updateCompletionList( currentText );
90void QgsFieldValuesLineEdit::updateCompletionList(
const QString &text )
99 mUpdateRequested =
true;
102 mRequestedCompletionText = text;
107 mGatherer =
new QgsFieldValuesLineEditValuesGatherer( mLayer, mAttributeIndex );
108 mGatherer->setSubstring( text );
110 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::collectedValues,
this, &QgsFieldValuesLineEdit::updateCompleter );
111 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::finished,
this, &QgsFieldValuesLineEdit::gathererThreadFinished );
116void QgsFieldValuesLineEdit::gathererThreadFinished()
118 const bool wasCanceled = mGatherer->wasCanceled();
125 const QString text = mRequestedCompletionText;
126 mRequestedCompletionText.clear();
127 updateCompletionList( text );
132void QgsFieldValuesLineEdit::updateCompleter(
const QStringList &values )
134 mUpdateRequested =
false;
135 completer()->setModel(
new QStringListModel( values ) );
136 completer()->complete();
143void QgsFieldValuesLineEditValuesGatherer::run()
145 mWasCanceled =
false;
146 if ( mSubstring.isEmpty() )
148 emit collectedValues( QStringList() );
155 mValues = mLayer->uniqueStringsMatching( mAttributeIndex, mSubstring, 100, mFeedback );
158 mFeedbackMutex.lock();
161 mFeedbackMutex.unlock();
163 emit collectedValues( mValues );
166void QgsFieldValuesLineEditValuesGatherer::stop()
169 mFeedbackMutex.lock();
172 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.
QgsFilterLineEdit(QWidget *parent=nullptr, const QString &nullValue=QString())
Constructor for QgsFilterLineEdit.
Represents a vector layer which manages a vector based dataset.
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