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   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 )
 
static const double UI_SCALE_FACTOR
UI scaling factor.
Animated icon is keeping an animation running if there are listeners connected to frameChanged.
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.
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...
QIcon icon() const
Gets the icons representation in the current frame.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
void focusInEvent(QFocusEvent *e) override
void restoreState()
Restores the current state of the line edit (selection and cursor position)
void storeState()
Stores the current state of the line edit (selection and cursor position)
void selectOnFocusChanged()
Will select all text when this widget receives the focus.
void showSpinnerChanged()
Show a spinner icon.
virtual void clearValue()
Clears the widget and resets it to the null value.
@ ClearToNull
Reset value to null.
@ ClearToDefault
Reset value to default value (see defaultValue() )
bool isNull() const
Determine if the current text represents null.
bool selectOnFocus() const
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.
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
QgsFilterLineEdit(QWidget *parent=nullptr, const QString &nullValue=QString())
Constructor for QgsFilterLineEdit.
void setSelectOnFocus(bool selectOnFocus)
Will select all text when this widget receives the focus.
void mouseReleaseEvent(QMouseEvent *e) override
void cleared()
Emitted when the widget is cleared.
void setShowSpinner(bool showSpinner)
Show a spinner icon.
bool event(QEvent *event) override
Reimplemented to enable/disable the clear action depending on read-only status.
void valueChanged(const QString &value)
Same as textChanged() but with support for null values.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.