21 #include <QStringListModel>
23 #include <QHBoxLayout>
28 QCompleter *
c =
new QCompleter(
this );
29 c->setCaseSensitivity( Qt::CaseInsensitive );
30 c->setFilterMode( Qt::MatchContains );
31 c->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
33 connect(
this, &QgsFieldValuesLineEdit::textEdited,
this, &QgsFieldValuesLineEdit::requestCompleterUpdate );
34 mShowPopupTimer.setSingleShot(
true );
35 mShowPopupTimer.setInterval( 100 );
36 connect( &mShowPopupTimer, &QTimer::timeout,
this, &QgsFieldValuesLineEdit::triggerCompleterUpdate );
50 if ( mLayer ==
layer )
59 if ( mAttributeIndex == index )
62 mAttributeIndex = index;
66 void QgsFieldValuesLineEdit::requestCompleterUpdate()
68 mUpdateRequested =
true;
69 mShowPopupTimer.start();
72 void QgsFieldValuesLineEdit::triggerCompleterUpdate()
74 mShowPopupTimer.stop();
75 const QString currentText = text();
77 if ( currentText.isEmpty() )
84 updateCompletionList( currentText );
87 void QgsFieldValuesLineEdit::updateCompletionList(
const QString &text )
96 mUpdateRequested =
true;
99 mRequestedCompletionText = text;
104 mGatherer =
new QgsFieldValuesLineEditValuesGatherer( mLayer, mAttributeIndex );
105 mGatherer->setSubstring( text );
107 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::collectedValues,
this, &QgsFieldValuesLineEdit::updateCompleter );
108 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::finished,
this, &QgsFieldValuesLineEdit::gathererThreadFinished );
113 void QgsFieldValuesLineEdit::gathererThreadFinished()
115 const bool wasCanceled = mGatherer->wasCanceled();
122 const QString text = mRequestedCompletionText;
123 mRequestedCompletionText.clear();
124 updateCompletionList( text );
129 void QgsFieldValuesLineEdit::updateCompleter(
const QStringList &values )
131 mUpdateRequested =
false;
132 completer()->setModel(
new QStringListModel( values ) );
133 completer()->complete();
140 void QgsFieldValuesLineEditValuesGatherer::run()
142 mWasCanceled =
false;
143 if ( mSubstring.isEmpty() )
145 emit collectedValues( QStringList() );
152 mValues = mLayer->uniqueStringsMatching( mAttributeIndex, mSubstring, 100, mFeedback );
155 mFeedbackMutex.lock();
158 mFeedbackMutex.unlock();
160 emit collectedValues( mValues );
163 void QgsFieldValuesLineEditValuesGatherer::stop()
166 mFeedbackMutex.lock();
169 mFeedbackMutex.unlock();