24 #include <QToolButton> 26 #include <QFocusEvent> 31 , mNullValue( nullValue )
36 mClearIcon.addPixmap(
QgsApplication::getThemeIcon(
"/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
37 mClearIcon.addPixmap(
QgsApplication::getThemeIcon(
"/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );
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 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;
157 if ( mSelectOnFocus == selectOnFocus )
172 if ( showSpinner == mShowSpinner )
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 );;
218 void QgsSpinBoxLineEdit::focusInEvent( QFocusEvent *e )
220 QLineEdit::focusInEvent( e );
void valueChanged(const QString &value)
Same as textChanged() but with support for null values.
bool disconnectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Convenience function to disconnect the same style that the frame change connection was established...
void setSelectOnFocus(bool selectOnFocus)
Will select all text when this widget receives the focus.
static const double UI_SCALE_FACTOR
UI scaling factor.
void setShowSpinner(bool showSpinner)
Show a spinner icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
void showSpinnerChanged()
Show a spinner icon.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void selectOnFocusChanged()
Will select all text when this widget receives the focus.
void setShowSearchIcon(bool visible)
Define if a search icon shall be shown on the left of the image when no text is entered.
QgsFilterLineEdit(QWidget *parent=nullptr, const QString &nullValue=QString())
Constructor for QgsFilterLineEdit.
Reset value to default value (see defaultValue() )
virtual void clearValue()
Clears the widget and resets it to the null value.
bool event(QEvent *event) override
Reimplemented to enable/disable the clear action depending on read-only status.
bool selectOnFocus() const
Will select all text when this widget receives the focus.
bool showSpinner() const
Show a spinner icon.
void focusInEvent(QFocusEvent *e) override
void mouseReleaseEvent(QMouseEvent *e) override
void cleared()
Emitted when the widget is cleared.
Animated icon is keeping an animation running if there are listeners connected to frameChanged...
QIcon icon() const
Gets the icons representation in the current frame.
bool isNull() const
Determine if the current text represents null.
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
bool connectFrameChanged(const typename QtPrivate::FunctionPointer< Func1 >::Object *receiver, Func1 slot)
Connect a slot that will be notified repeatedly whenever a frame changes and which should request the...
QString value() const
Returns the text of this edit with support for handling null values.