23 #include <QToolButton> 25 #include <QFocusEvent> 30 , mNullValue( nullValue )
35 mClearIcon.addPixmap(
QgsApplication::getThemeIcon(
"/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
36 mClearIcon.addPixmap(
QgsApplication::getThemeIcon(
"/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );
38 connect(
this, &QLineEdit::textChanged,
this,
39 &QgsFilterLineEdit::onTextChanged );
44 mClearButtonVisible = visible;
50 if ( visible && !mSearchAction )
53 mSearchAction =
new QAction( searchIcon, QString(),
this );
54 mSearchAction->setCheckable(
false );
55 addAction( mSearchAction, QLineEdit::LeadingPosition );
57 else if ( !visible && mSearchAction )
59 mSearchAction->deleteLater();
60 mSearchAction =
nullptr;
64 void QgsFilterLineEdit::updateClearIcon()
66 bool showClear = shouldShowClear();
67 if ( showClear && !mClearAction )
69 mClearAction =
new QAction( mClearIcon, QString(),
this );
70 mClearAction->setCheckable(
false );
71 addAction( mClearAction, QLineEdit::TrailingPosition );
74 else if ( !showClear && mClearAction )
76 mClearAction->deleteLater();
77 mClearAction =
nullptr;
83 QLineEdit::focusInEvent( e );
84 if ( e->reason() == Qt::MouseFocusReason && (
isNull() || mSelectOnFocus ) )
96 setText( mNullValue );
101 setText( mDefaultValue );
109 void QgsFilterLineEdit::onTextChanged(
const QString &text )
115 setStyleSheet( QStringLiteral(
"QLineEdit { font: italic; color: gray; } %1" ).arg( mStyleSheet ) );
120 setStyleSheet( mStyleSheet );
125 void QgsFilterLineEdit::updateBusySpinner()
127 if ( !mBusySpinnerAction )
129 mBusySpinnerAction = addAction( mBusySpinnerAnimatedIcon->
icon(), QLineEdit::TrailingPosition );
131 mBusySpinnerAction->setIcon( mBusySpinnerAnimatedIcon->
icon() );
136 return mSelectOnFocus;
141 if ( mSelectOnFocus == selectOnFocus )
156 if ( showSpinner == mShowSpinner )
161 if ( !mBusySpinnerAnimatedIcon )
164 mBusySpinnerAnimatedIcon->
connectFrameChanged(
this, &QgsFilterLineEdit::updateBusySpinner );
169 removeAction( mBusySpinnerAction );
170 mBusySpinnerAction =
nullptr;
177 bool QgsFilterLineEdit::shouldShowClear()
const 179 if ( !isEnabled() || isReadOnly() || !mClearButtonVisible )
182 switch ( mClearMode )
188 return value() != mDefaultValue;
195 if ( event->type() == QEvent::ReadOnlyChange )
198 return QLineEdit::event( event );;
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.
virtual 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 cleared()
Emitted when the widget is cleared.
Animated icon is keeping an animation running if there are listeners connected to frameChanged...
QIcon icon() const
Get 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.