21#include <QStringListModel> 
   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;
 
   66void QgsFieldValuesLineEdit::requestCompleterUpdate()
 
   68  mUpdateRequested = 
true;
 
   69  mShowPopupTimer.start();
 
   72void QgsFieldValuesLineEdit::triggerCompleterUpdate()
 
   74  mShowPopupTimer.stop();
 
   75  const QString currentText = text();
 
   77  if ( currentText.isEmpty() )
 
   84  updateCompletionList( currentText );
 
   87void 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 );
 
  113void QgsFieldValuesLineEdit::gathererThreadFinished()
 
  115  const bool wasCanceled = mGatherer->wasCanceled();
 
  122    const QString text = mRequestedCompletionText;
 
  123    mRequestedCompletionText.clear();
 
  124    updateCompletionList( text );
 
  129void QgsFieldValuesLineEdit::updateCompleter( 
const QStringList &values )
 
  131  mUpdateRequested = 
false;
 
  132  completer()->setModel( 
new QStringListModel( values ) );
 
  133  completer()->complete();
 
  140void 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 );
 
  163void QgsFieldValuesLineEditValuesGatherer::stop()
 
  166  mFeedbackMutex.lock();
 
  169  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