Skip to content

Commit

Permalink
Fix weird line edit styling error on Ubuntu
Browse files Browse the repository at this point in the history
Ubuntu theme is incorrectly showing hidden actions in
line edits.

Fixes #18537

(cherry-picked from fb5caa7)
  • Loading branch information
nyalldawson committed Apr 2, 2018
1 parent 05eba14 commit 5672767
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
44 changes: 27 additions & 17 deletions src/gui/qgsfilterlineedit.cpp
Expand Up @@ -32,20 +32,8 @@ QgsFilterLineEdit::QgsFilterLineEdit( QWidget *parent, const QString &nullValue
// icon size is about 2/3 height of text, but minimum size of 16
int iconSize = std::floor( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 0.75, 16.0 ) );

QIcon clearIcon;
clearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
clearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );
mClearAction = new QAction( clearIcon, QString(), this );
mClearAction->setCheckable( false );
addAction( mClearAction, QLineEdit::TrailingPosition );
connect( mClearAction, &QAction::triggered, this, &QgsFilterLineEdit::clearValue );
mClearAction->setVisible( false );

QIcon searchIcon = QgsApplication::getThemeIcon( "/search.svg" );
mSearchAction = new QAction( searchIcon, QString(), this );
mSearchAction->setCheckable( false );
addAction( mSearchAction, QLineEdit::LeadingPosition );
mSearchAction->setVisible( false );
mClearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
mClearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );

connect( this, &QLineEdit::textChanged, this,
&QgsFilterLineEdit::onTextChanged );
Expand All @@ -59,13 +47,35 @@ void QgsFilterLineEdit::setShowClearButton( bool visible )

void QgsFilterLineEdit::setShowSearchIcon( bool visible )
{
mSearchIconVisible = visible;
mSearchAction->setVisible( visible );
if ( visible && !mSearchAction )
{
QIcon searchIcon = QgsApplication::getThemeIcon( "/search.svg" );
mSearchAction = new QAction( searchIcon, QString(), this );
mSearchAction->setCheckable( false );
addAction( mSearchAction, QLineEdit::LeadingPosition );
}
else if ( !visible && mSearchAction )
{
mSearchAction->deleteLater();
mSearchAction = nullptr;
}
}

void QgsFilterLineEdit::updateClearIcon()
{
mClearAction->setVisible( shouldShowClear() );
bool showClear = shouldShowClear();
if ( showClear && !mClearAction )
{
mClearAction = new QAction( mClearIcon, QString(), this );
mClearAction->setCheckable( false );
addAction( mClearAction, QLineEdit::TrailingPosition );
connect( mClearAction, &QAction::triggered, this, &QgsFilterLineEdit::clearValue );
}
else if ( !showClear && mClearAction )
{
mClearAction->deleteLater();
mClearAction = nullptr;
}
}

void QgsFilterLineEdit::focusInEvent( QFocusEvent *e )
Expand Down
11 changes: 6 additions & 5 deletions src/gui/qgsfilterlineedit.h
Expand Up @@ -19,6 +19,7 @@
#define QGSFILTERLINEEDIT_H

#include <QLineEdit>
#include <QIcon>
#include "qgis.h"
#include "qgis_gui.h"

Expand Down Expand Up @@ -64,7 +65,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
ClearToNull = 0, //!< Reset value to null
ClearToDefault, //!< Reset value to default value (see defaultValue() )
};
Q_ENUM( ClearMode );
Q_ENUM( ClearMode )

/**
* Constructor for QgsFilterLineEdit.
Expand Down Expand Up @@ -133,7 +134,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
* when no text is entered
* \since QGIS 3.0
*/
bool showSearchIcon() const { return mSearchIconVisible; }
bool showSearchIcon() const { return static_cast< bool >( mSearchAction ); }

/**
* Sets the default value for the widget. The default value is a value
Expand Down Expand Up @@ -271,12 +272,12 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
void updateClearIcon();

private:
QAction *mClearAction;
QAction *mSearchAction;
QIcon mClearIcon;
QAction *mClearAction = nullptr;
QAction *mSearchAction = nullptr;
QAction *mBusySpinnerAction = nullptr;

bool mClearButtonVisible = true;
bool mSearchIconVisible = false;
bool mShowSpinner = false;

ClearMode mClearMode = ClearToNull;
Expand Down

0 comments on commit 5672767

Please sign in to comment.