Skip to content

Commit ce486da

Browse files
committedSep 24, 2014
line edit: do not display clear icon when read only
1 parent e194423 commit ce486da

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed
 

‎src/gui/editorwidgets/qgstexteditwrapper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,11 @@ void QgsTextEditWrapper::setEnabled( bool enabled )
139139
mPlainTextEdit->setReadOnly( !enabled );
140140

141141
if ( mLineEdit )
142-
mLineEdit->setReadOnly( !enabled );
142+
{
143+
QgsFilterLineEdit* qgsWidget = dynamic_cast<QgsFilterLineEdit*>( mLineEdit );
144+
if ( qgsWidget )
145+
qgsWidget->setReadOnly( !enabled );
146+
else
147+
mLineEdit->setReadOnly( !enabled );
148+
}
143149
}

‎src/gui/qgsfilterlineedit.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,19 @@ void QgsFilterLineEdit::clear()
8181
void QgsFilterLineEdit::changeEvent( QEvent *e )
8282
{
8383
QLineEdit::changeEvent( e );
84-
if ( !isEnabled() || isReadOnly() )
85-
btnClear->setVisible( false );
86-
else
87-
btnClear->setVisible( text() != mNullValue );
84+
btnClear->setVisible( isEnabled() && !isReadOnly() && !isNull() );
8885
}
8986

87+
void QgsFilterLineEdit::setReadOnly( bool readOnly )
88+
{
89+
QLineEdit::setReadOnly( readOnly );
90+
btnClear->setVisible( isEnabled() && !isReadOnly() && !isNull() );
91+
}
92+
93+
9094
void QgsFilterLineEdit::onTextChanged( const QString &text )
9195
{
92-
btnClear->setVisible( !isEnabled() && !isReadOnly() && text != mNullValue );
96+
btnClear->setVisible( isEnabled() && !isReadOnly() && !isNull() );
9397

9498
if ( isNull() )
9599
{

‎src/gui/qgsfilterlineedit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
5858
*/
5959
inline bool isNull() const { return text() == mNullValue; }
6060

61+
/**
62+
* @brief setReadOnly set the line edit to be read only and hide the clear button
63+
* @note Since QLineEdit::setReadOnly() is not virtual, it needs to be called for QgsFilterLineEdit
64+
*/
65+
void setReadOnly( bool readOnly );
66+
6167
signals:
6268
void cleared();
6369

0 commit comments

Comments
 (0)
Please sign in to comment.