19#include "moc_qgsfilterlineedit.cpp" 
   32  , mNullValue( nullValue )
 
   35  const int iconSize = std::floor( std::max( 
Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 0.75, 16.0 ) );
 
   37  mClearIcon.addPixmap( 
QgsApplication::getThemeIcon( 
"/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
 
   38  mClearIcon.addPixmap( 
QgsApplication::getThemeIcon( 
"/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );
 
   40  connect( 
this, &QLineEdit::textChanged, 
this, &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;
 
 
   74void QgsFilterLineEdit::updateClearIcon()
 
   76  const bool showClear = shouldShowClear();
 
   77  if ( showClear && !mClearAction )
 
   79    mClearAction = 
new QAction( mClearIcon, QString(), 
this );
 
   80    mClearAction->setCheckable( 
false );
 
   81    addAction( mClearAction, QLineEdit::TrailingPosition );
 
   84  else if ( !showClear && mClearAction )
 
   91    removeAction( mClearAction );
 
   92    mClearAction->deleteLater();
 
   93    mClearAction = 
nullptr;
 
   99  QLineEdit::focusInEvent( e );
 
  100  if ( e->reason() == Qt::MouseFocusReason && ( 
isNull() || mSelectOnFocus ) )
 
  102    mWaitingForMouseRelease = 
true;
 
 
  108  QLineEdit::mouseReleaseEvent( e );
 
  109  if ( mWaitingForMouseRelease )
 
  111    mWaitingForMouseRelease = 
false;
 
 
  118  switch ( mClearMode )
 
  121      setText( mNullValue );
 
  126      setText( mDefaultValue );
 
 
  134void QgsFilterLineEdit::onTextChanged( 
const QString &text )
 
  140    setStyleSheet( QStringLiteral( 
"QLineEdit { font: italic; color: gray; } %1" ).arg( mStyleSheet ) );
 
  145    setStyleSheet( mStyleSheet );
 
  150void QgsFilterLineEdit::updateBusySpinner()
 
  152  if ( !mBusySpinnerAction )
 
  154    mBusySpinnerAction = addAction( mBusySpinnerAnimatedIcon->
icon(), QLineEdit::TrailingPosition );
 
  156  mBusySpinnerAction->setIcon( mBusySpinnerAnimatedIcon->
icon() );
 
  161  return mSelectOnFocus;
 
 
  185    if ( !mBusySpinnerAnimatedIcon )
 
  188    mBusySpinnerAnimatedIcon->
connectFrameChanged( 
this, &QgsFilterLineEdit::updateBusySpinner );
 
  193    removeAction( mBusySpinnerAction );
 
  194    mBusySpinnerAction = 
nullptr;
 
 
  201bool QgsFilterLineEdit::shouldShowClear()
 const 
  203  if ( !isEnabled() || isReadOnly() || !mClearButtonVisible )
 
  206  switch ( mClearMode )
 
  212      return value() != mDefaultValue;
 
  219  if ( 
event->type() == QEvent::ReadOnlyChange || 
event->type() == QEvent::EnabledChange )
 
  222  return QLineEdit::event( 
event );
 
 
  227  mLineEditState.text = text();
 
  228  mLineEditState.selectionStart = selectionStart();
 
  229  mLineEditState.selectionLength = selectedText().length();
 
  230  mLineEditState.cursorPosition = cursorPosition();
 
  231  mLineEditState.hasStateStored = 
true;
 
 
  236  setText( mLineEditState.text );
 
  237  setCursorPosition( mLineEditState.cursorPosition );
 
  238  if ( mLineEditState.selectionStart > -1 )
 
  239    setSelection( mLineEditState.selectionStart, mLineEditState.selectionLength );
 
  240  mLineEditState.hasStateStored = 
false;
 
 
  244void 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 setDefaultValue(const QString &defaultValue)
Sets the default value for the widget.
 
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.