20 #include <QStringListModel> 22 #include <QHBoxLayout> 27 QCompleter *
c =
new QCompleter(
this );
28 c->setCaseSensitivity( Qt::CaseInsensitive );
29 c->setFilterMode( Qt::MatchContains );
31 connect(
this, &QgsFieldValuesLineEdit::textEdited,
this, &QgsFieldValuesLineEdit::requestCompleterUpdate );
32 mShowPopupTimer.setSingleShot(
true );
33 mShowPopupTimer.setInterval( 100 );
34 connect( &mShowPopupTimer, &QTimer::timeout,
this, &QgsFieldValuesLineEdit::triggerCompleterUpdate );
48 if ( mLayer == layer )
57 if ( mAttributeIndex == index )
60 mAttributeIndex = index;
64 void QgsFieldValuesLineEdit::requestCompleterUpdate()
66 mUpdateRequested =
true;
67 mShowPopupTimer.start();
70 void QgsFieldValuesLineEdit::triggerCompleterUpdate()
72 mShowPopupTimer.stop();
73 QString currentText = text();
75 if ( currentText.isEmpty() )
82 updateCompletionList( currentText );
85 void QgsFieldValuesLineEdit::updateCompletionList(
const QString &text )
94 mUpdateRequested =
true;
97 mRequestedCompletionText = text;
102 mGatherer =
new QgsFieldValuesLineEditValuesGatherer( mLayer, mAttributeIndex );
103 mGatherer->setSubstring( text );
105 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::collectedValues,
this, &QgsFieldValuesLineEdit::updateCompleter );
106 connect( mGatherer, &QgsFieldValuesLineEditValuesGatherer::finished,
this, &QgsFieldValuesLineEdit::gathererThreadFinished );
111 void QgsFieldValuesLineEdit::gathererThreadFinished()
113 bool wasCanceled = mGatherer->wasCanceled();
120 QString text = mRequestedCompletionText;
121 mRequestedCompletionText.clear();
122 updateCompletionList( text );
127 void QgsFieldValuesLineEdit::updateCompleter(
const QStringList &values )
129 mUpdateRequested =
false;
130 completer()->setModel(
new QStringListModel( values ) );
131 completer()->complete();
~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.
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.
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.