Skip to content

Commit

Permalink
Add a selectOnFocus property to QgsFilterLineEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 26, 2017
1 parent 0267692 commit 7ec35e0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
23 changes: 23 additions & 0 deletions python/gui/qgsfilterlineedit.sip
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion src/gui/qgsfilterlineedit.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions src/gui/qgsfilterlineedit.h
Expand Up @@ -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:

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 7ec35e0

Please sign in to comment.