Skip to content

Commit

Permalink
line edit: do not display clear icon when read only
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 24, 2014
1 parent e194423 commit ce486da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/gui/editorwidgets/qgstexteditwrapper.cpp
Expand Up @@ -139,5 +139,11 @@ void QgsTextEditWrapper::setEnabled( bool enabled )
mPlainTextEdit->setReadOnly( !enabled );

if ( mLineEdit )
mLineEdit->setReadOnly( !enabled );
{
QgsFilterLineEdit* qgsWidget = dynamic_cast<QgsFilterLineEdit*>( mLineEdit );
if ( qgsWidget )
qgsWidget->setReadOnly( !enabled );
else
mLineEdit->setReadOnly( !enabled );
}
}
14 changes: 9 additions & 5 deletions src/gui/qgsfilterlineedit.cpp
Expand Up @@ -81,15 +81,19 @@ void QgsFilterLineEdit::clear()
void QgsFilterLineEdit::changeEvent( QEvent *e )
{
QLineEdit::changeEvent( e );
if ( !isEnabled() || isReadOnly() )
btnClear->setVisible( false );
else
btnClear->setVisible( text() != mNullValue );
btnClear->setVisible( isEnabled() && !isReadOnly() && !isNull() );
}

void QgsFilterLineEdit::setReadOnly( bool readOnly )
{
QLineEdit::setReadOnly( readOnly );
btnClear->setVisible( isEnabled() && !isReadOnly() && !isNull() );
}


void QgsFilterLineEdit::onTextChanged( const QString &text )
{
btnClear->setVisible( !isEnabled() && !isReadOnly() && text != mNullValue );
btnClear->setVisible( isEnabled() && !isReadOnly() && !isNull() );

if ( isNull() )
{
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsfilterlineedit.h
Expand Up @@ -58,6 +58,12 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
*/
inline bool isNull() const { return text() == mNullValue; }

/**
* @brief setReadOnly set the line edit to be read only and hide the clear button
* @note Since QLineEdit::setReadOnly() is not virtual, it needs to be called for QgsFilterLineEdit
*/
void setReadOnly( bool readOnly );

signals:
void cleared();

Expand Down

0 comments on commit ce486da

Please sign in to comment.