24 #include <QToolButton>
26 #include <QFocusEvent>
31 , mNullValue( nullValue )
39 connect(
this, &QLineEdit::textChanged,
this,
40 &QgsFilterLineEdit::onTextChanged );
45 mClearButtonVisible = visible;
51 if ( visible && !mSearchAction )
54 mSearchAction =
new QAction( searchIcon, QString(),
this );
55 mSearchAction->setCheckable(
false );
56 addAction( mSearchAction, QLineEdit::LeadingPosition );
58 else if ( !visible && mSearchAction )
60 mSearchAction->deleteLater();
61 mSearchAction =
nullptr;
65 void QgsFilterLineEdit::updateClearIcon()
67 const bool showClear = shouldShowClear();
68 if ( showClear && !mClearAction )
70 mClearAction =
new QAction( mClearIcon, QString(),
this );
71 mClearAction->setCheckable(
false );
72 addAction( mClearAction, QLineEdit::TrailingPosition );
75 else if ( !showClear && mClearAction )
82 removeAction( mClearAction );
83 mClearAction->deleteLater();
84 mClearAction =
nullptr;
90 QLineEdit::focusInEvent( e );
91 if ( e->reason() == Qt::MouseFocusReason && (
isNull() || mSelectOnFocus ) )
93 mWaitingForMouseRelease =
true;
99 QLineEdit::mouseReleaseEvent( e );
100 if ( mWaitingForMouseRelease )
102 mWaitingForMouseRelease =
false;
109 switch ( mClearMode )
112 setText( mNullValue );
117 setText( mDefaultValue );
125 void QgsFilterLineEdit::onTextChanged(
const QString &text )
131 setStyleSheet( QStringLiteral(
"QLineEdit { font: italic; color: gray; } %1" ).arg( mStyleSheet ) );
136 setStyleSheet( mStyleSheet );
141 void QgsFilterLineEdit::updateBusySpinner()
143 if ( !mBusySpinnerAction )
145 mBusySpinnerAction = addAction( mBusySpinnerAnimatedIcon->
icon(), QLineEdit::TrailingPosition );
147 mBusySpinnerAction->setIcon( mBusySpinnerAnimatedIcon->
icon() );
152 return mSelectOnFocus;
177 if ( !mBusySpinnerAnimatedIcon )
180 mBusySpinnerAnimatedIcon->
connectFrameChanged(
this, &QgsFilterLineEdit::updateBusySpinner );
185 removeAction( mBusySpinnerAction );
186 mBusySpinnerAction =
nullptr;
193 bool QgsFilterLineEdit::shouldShowClear()
const
195 if ( !isEnabled() || isReadOnly() || !mClearButtonVisible )
198 switch ( mClearMode )
204 return value() != mDefaultValue;
211 if (
event->type() == QEvent::ReadOnlyChange ||
event->type() == QEvent::EnabledChange )
214 return QLineEdit::event(
event );
219 mLineEditState.text = text();
220 mLineEditState.selectionStart = selectionStart();
221 mLineEditState.selectionLength = selectedText().length();
222 mLineEditState.cursorPosition = cursorPosition();
223 mLineEditState.hasStateStored =
true;
228 setText( mLineEditState.text );
229 setCursorPosition( mLineEditState.cursorPosition );
230 if ( mLineEditState.selectionStart > -1 )
231 setSelection( mLineEditState.selectionStart, mLineEditState.selectionLength );
232 mLineEditState.hasStateStored =
false;
236 void QgsSpinBoxLineEdit::focusInEvent( QFocusEvent *e )