21 #include <QStringListModel> 23 #include <QHBoxLayout> 28 QCompleter *
c =
new QCompleter(
this );
29 c->setCaseSensitivity( Qt::CaseInsensitive );
30 c->setFilterMode( Qt::MatchContains );
32 connect(
this, &QgsFieldValuesLineEdit::textEdited,
this, &QgsFieldValuesLineEdit::requestCompleterUpdate );
33 mShowPopupTimer.setSingleShot(
true );
34 mShowPopupTimer.setInterval( 100 );
35 connect( &mShowPopupTimer, &QTimer::timeout,
this, &QgsFieldValuesLineEdit::triggerCompleterUpdate );
49 if ( mLayer == layer )
58 if ( mAttributeIndex == index )
61 mAttributeIndex = index;
65 void QgsFieldValuesLineEdit::requestCompleterUpdate()
67 mUpdateRequested =
true;
68 mShowPopupTimer.start();
71 void QgsFieldValuesLineEdit::triggerCompleterUpdate()
73 mShowPopupTimer.stop();
74 QString currentText = text();
76 if ( currentText.isEmpty() )
83 updateCompletionList( currentText );
86 void QgsFieldValuesLineEdit::updateCompletionList(
const QString &text )
95 mUpdateRequested =
true;
98 mRequestedCompletionText = text;
103 mGatherer =
new QgsFieldValuesLineEditValuesGatherer( mLayer, mAttributeIndex );
104 mGatherer->setSubstring( text );
106 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::collectedValues,
this, &QgsFieldValuesLineEdit::updateCompleter );
107 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::finished,
this, &QgsFieldValuesLineEdit::gathererThreadFinished );
112 void QgsFieldValuesLineEdit::gathererThreadFinished()
114 bool wasCanceled = mGatherer->wasCanceled();
121 QString text = mRequestedCompletionText;
122 mRequestedCompletionText.clear();
123 updateCompletionList( text );
128 void QgsFieldValuesLineEdit::updateCompleter(
const QStringList &values )
130 mUpdateRequested =
false;
131 completer()->setModel(
new QStringListModel( values ) );
132 completer()->complete();
139 void QgsFieldValuesLineEditValuesGatherer::run()
141 mWasCanceled =
false;
142 if ( mSubstring.isEmpty() )
144 emit collectedValues( QStringList() );
154 mFeedbackMutex.lock();
157 mFeedbackMutex.unlock();
159 emit collectedValues( mValues );
162 void QgsFieldValuesLineEditValuesGatherer::stop()
165 mFeedbackMutex.lock();
168 mFeedbackMutex.unlock();
~QgsFieldValuesLineEdit() override
QgsVectorLayer * layer() const
Returns the layer containing the field that values will be shown from.
void setAttributeIndex(int index)
Sets the attribute index for the field containing values to show in the widget.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
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
QgsFieldValuesLineEdit(QWidget *parent=nullptr)
Constructor for QgsFieldValuesLineEdit.
QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
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.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void attributeIndexChanged(int index)
Emitted when the field associated with the widget changes.
Represents a vector layer which manages a vector based data sets.