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() );
151 mValues = mLayer->uniqueStringsMatching( mAttributeIndex, mSubstring, 100, mFeedback );
154 mFeedbackMutex.lock();
157 mFeedbackMutex.unlock();
159 emit collectedValues( mValues );
162 void QgsFieldValuesLineEditValuesGatherer::stop()
165 mFeedbackMutex.lock();
168 mFeedbackMutex.unlock();