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 ) )
92 mWaitingForMouseRelease =
true;
98 QLineEdit::mouseReleaseEvent( e );
99 if ( mWaitingForMouseRelease )
101 mWaitingForMouseRelease =
false;
108 switch ( mClearMode )
111 setText( mNullValue );
116 setText( mDefaultValue );
124 void QgsFilterLineEdit::onTextChanged(
const QString &text )
130 setStyleSheet( QStringLiteral(
"QLineEdit { font: italic; color: gray; } %1" ).arg( mStyleSheet ) );
135 setStyleSheet( mStyleSheet );
140 void QgsFilterLineEdit::updateBusySpinner()
142 if ( !mBusySpinnerAction )
144 mBusySpinnerAction = addAction( mBusySpinnerAnimatedIcon->
icon(), QLineEdit::TrailingPosition );
146 mBusySpinnerAction->setIcon( mBusySpinnerAnimatedIcon->
icon() );
151 return mSelectOnFocus;
156 if ( mSelectOnFocus == selectOnFocus )
171 if ( showSpinner == mShowSpinner )
176 if ( !mBusySpinnerAnimatedIcon )
179 mBusySpinnerAnimatedIcon->
connectFrameChanged(
this, &QgsFilterLineEdit::updateBusySpinner );
184 removeAction( mBusySpinnerAction );
185 mBusySpinnerAction =
nullptr;
192 bool QgsFilterLineEdit::shouldShowClear()
const 194 if ( !isEnabled() || isReadOnly() || !mClearButtonVisible )
197 switch ( mClearMode )
203 return value() != mDefaultValue;
210 if ( event->type() == QEvent::ReadOnlyChange ||
event->type() == QEvent::EnabledChange )
213 return QLineEdit::event( event );;
217 void QgsSpinBoxLineEdit::focusInEvent( QFocusEvent *e )
219 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.
QIcon icon() const
Gets the icons representation in the current frame.
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.
bool showSpinner() const
Show a spinner 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.
QString value() const
Returns the text of this edit with support for handling null values.
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 isNull() const
Determine if the current text represents null.
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...
bool selectOnFocus() const
Will select all text when this widget receives the focus.
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...