Skip to content
Permalink
Browse files

Add a selectOnFocus property to QgsFilterLineEdit

  • Loading branch information
m-kuhn committed Oct 26, 2017
1 parent 0267692 commit 7ec35e0859670207764b63f84c6804990b2a9e46
Showing with 61 additions and 1 deletion.
  1. +23 −0 python/gui/qgsfilterlineedit.sip
  2. +15 −1 src/gui/qgsfilterlineedit.cpp
  3. +23 −0 src/gui/qgsfilterlineedit.h
@@ -177,6 +177,21 @@ class QgsFilterLineEdit : QLineEdit
Show a spinner icon. This can be used for search boxes to indicate that
something is going on in the background.

.. versionadded:: 3.0
%End

bool selectOnFocus() const;
%Docstring
Will select all text when this widget receives the focus.

.. versionadded:: 3.0
:rtype: bool
%End

void setSelectOnFocus( bool selectOnFocus );
%Docstring
Will select all text when this widget receives the focus.

.. versionadded:: 3.0
%End

@@ -209,6 +224,14 @@ class QgsFilterLineEdit : QLineEdit
Show a spinner icon. This can be used for search boxes to indicate that
something is going on in the background.

.. versionadded:: 3.0
%End


void selectOnFocusChanged();
%Docstring
Will select all text when this widget receives the focus.

.. versionadded:: 3.0
%End

@@ -102,7 +102,7 @@ void QgsFilterLineEdit::mouseMoveEvent( QMouseEvent *e )
void QgsFilterLineEdit::focusInEvent( QFocusEvent *e )
{
QLineEdit::focusInEvent( e );
if ( e->reason() == Qt::MouseFocusReason && isNull() )
if ( e->reason() == Qt::MouseFocusReason && ( isNull() || mSelectOnFocus ) )
{
mFocusInEvent = true;
selectAll();
@@ -197,6 +197,20 @@ void QgsFilterLineEdit::updateBusySpinner()
update();
}

bool QgsFilterLineEdit::selectOnFocus() const
{
return mSelectOnFocus;
}

void QgsFilterLineEdit::setSelectOnFocus( bool selectOnFocus )
{
if ( mSelectOnFocus == selectOnFocus )
return;

mSelectOnFocus = selectOnFocus;
emit selectOnFocusChanged();
}

bool QgsFilterLineEdit::showSpinner() const
{
return mShowSpinner;
@@ -199,6 +199,20 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
*/
void setShowSpinner( bool showSpinner );

/**
* Will select all text when this widget receives the focus.
*
* \since QGIS 3.0
*/
bool selectOnFocus() const;

/**
* Will select all text when this widget receives the focus.
*
* \since QGIS 3.0
*/
void setSelectOnFocus( bool selectOnFocus );

public slots:

/**
@@ -231,6 +245,14 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
*/
void showSpinnerChanged();


/**
* Will select all text when this widget receives the focus.
*
* \since QGIS 3.0
*/
void selectOnFocusChanged();

protected:
void mousePressEvent( QMouseEvent *e ) override;
void mouseMoveEvent( QMouseEvent *e ) override;
@@ -255,6 +277,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
QString mStyleSheet;
bool mFocusInEvent = false;
bool mClearHover = false;
bool mSelectOnFocus = false;

QSize mClearIconSize;
QPixmap mClearIconPixmap;

0 comments on commit 7ec35e0

Please sign in to comment.
You can’t perform that action at this time.