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 )
81 removeAction( mClearAction );
82 mClearAction->deleteLater();
83 mClearAction =
nullptr;
89 QLineEdit::focusInEvent( e );
90 if ( e->reason() == Qt::MouseFocusReason && (
isNull() || mSelectOnFocus ) )
102 setText( mNullValue );
107 setText( mDefaultValue );
115 void QgsFilterLineEdit::onTextChanged(
const QString &text )
121 setStyleSheet( QStringLiteral(
"QLineEdit { font: italic; color: gray; } %1" ).arg( mStyleSheet ) );
126 setStyleSheet( mStyleSheet );
131 void QgsFilterLineEdit::updateBusySpinner()
133 if ( !mBusySpinnerAction )
135 mBusySpinnerAction = addAction( mBusySpinnerAnimatedIcon->
icon(), QLineEdit::TrailingPosition );
137 mBusySpinnerAction->setIcon( mBusySpinnerAnimatedIcon->
icon() );
142 return mSelectOnFocus;
147 if ( mSelectOnFocus == selectOnFocus )
162 if ( showSpinner == mShowSpinner )
167 if ( !mBusySpinnerAnimatedIcon )
170 mBusySpinnerAnimatedIcon->
connectFrameChanged(
this, &QgsFilterLineEdit::updateBusySpinner );
175 removeAction( mBusySpinnerAction );
176 mBusySpinnerAction =
nullptr;
183 bool QgsFilterLineEdit::shouldShowClear()
const 185 if ( !isEnabled() || isReadOnly() || !mClearButtonVisible )
188 switch ( mClearMode )
194 return value() != mDefaultValue;
201 if ( event->type() == QEvent::ReadOnlyChange )
204 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.
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
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.