Skip to content

Commit 1a4b8bb

Browse files
committedDec 4, 2014
define the special text directly with the clear value
1 parent e887d07 commit 1a4b8bb

File tree

6 files changed

+100
-28
lines changed

6 files changed

+100
-28
lines changed
 

‎python/gui/editorwidgets/qgsdoublespinbox.sip

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class QgsDoubleSpinBox : QDoubleSpinBox
55
%End
66

77
public:
8-
enum ClearValue
8+
enum ClearValueMode
99
{
1010
MinimumValue,
1111
MaximumValue,
@@ -23,10 +23,17 @@ class QgsDoubleSpinBox : QDoubleSpinBox
2323
virtual void clear();
2424

2525
/**
26-
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
27-
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
26+
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
27+
* @param defines the numerical value used as the clear value
28+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
2829
*/
29-
void setClearValue( ClearValue type, double customValue = 0 );
30+
void setClearValue( double customValue, QString clearValueText = QString() );
31+
/**
32+
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
33+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
34+
*/
35+
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
36+
3037
//! returns the value used when clear() is called.
3138
double clearValue();
3239

‎python/gui/editorwidgets/qgsspinbox.sip

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class QgsSpinBox : QSpinBox
55
%End
66

77
public:
8-
enum ClearValue
8+
enum ClearValueMode
99
{
1010
MinimumValue,
1111
MaximumValue,
@@ -23,10 +23,17 @@ class QgsSpinBox : QSpinBox
2323
virtual void clear();
2424

2525
/**
26-
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
27-
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
26+
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
27+
* @param defines the numerical value used as the clear value
28+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
2829
*/
29-
void setClearValue( ClearValue type, int customValue = 0 );
30+
void setClearValue( int customValue, QString clearValueText = QString() );
31+
/**
32+
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
33+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
34+
*/
35+
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
36+
3037
//! returns the value used when clear() is called.
3138
int clearValue();
3239

‎src/gui/editorwidgets/qgsdoublespinbox.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
2828
: QDoubleSpinBox( parent )
2929
, mShowClearButton( true )
30-
, mClearValueType( MinimumValue )
30+
, mClearValueMode( MinimumValue )
3131
, mCustomClearValue( 0.0 )
3232
{
3333
mClearButton = new QToolButton( this );
@@ -67,17 +67,39 @@ void QgsDoubleSpinBox::clear()
6767
setValue( clearValue() );
6868
}
6969

70-
void QgsDoubleSpinBox::setClearValue( QgsDoubleSpinBox::ClearValue type, double customValue )
70+
void QgsDoubleSpinBox::setClearValue( double customValue , QString specialValueText )
7171
{
72-
mClearValueType = type;
72+
mClearValueMode = CustomValue;
7373
mCustomClearValue = customValue;
74+
75+
if ( !specialValueText.isEmpty() )
76+
{
77+
double v = value();
78+
clear();
79+
setSpecialValueText( specialValueText );
80+
setValue( v );
81+
}
82+
}
83+
84+
void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode, QString clearValueText )
85+
{
86+
mClearValueMode = mode;
87+
mCustomClearValue = 0;
88+
89+
if ( !clearValueText.isEmpty() )
90+
{
91+
double v = value();
92+
clear();
93+
setSpecialValueText( clearValueText );
94+
setValue( v );
95+
}
7496
}
7597

7698
double QgsDoubleSpinBox::clearValue()
7799
{
78-
if ( mClearValueType == MinimumValue )
100+
if ( mClearValueMode == MinimumValue )
79101
return minimum() ;
80-
else if ( mClearValueType == MaximumValue )
102+
else if ( mClearValueMode == MaximumValue )
81103
return maximum();
82104
else
83105
return mCustomClearValue;

‎src/gui/editorwidgets/qgsdoublespinbox.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
3030
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
3131

3232
public:
33-
enum ClearValue
33+
enum ClearValueMode
3434
{
3535
MinimumValue,
3636
MaximumValue,
@@ -47,10 +47,17 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
4747
virtual void clear();
4848

4949
/**
50-
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
51-
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
50+
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
51+
* @param defines the numerical value used as the clear value
52+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
5253
*/
53-
void setClearValue( ClearValue type, double customValue = 0 );
54+
void setClearValue( double customValue, QString clearValueText = QString() );
55+
/**
56+
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
57+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
58+
*/
59+
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
60+
5461
//! returns the value used when clear() is called.
5562
double clearValue();
5663

@@ -65,7 +72,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
6572
int frameWidth() const;
6673

6774
bool mShowClearButton;
68-
ClearValue mClearValueType;
75+
ClearValueMode mClearValueMode;
6976
double mCustomClearValue;
7077

7178
QToolButton* mClearButton;

‎src/gui/editorwidgets/qgsspinbox.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
QgsSpinBox::QgsSpinBox( QWidget *parent )
2828
: QSpinBox( parent )
2929
, mShowClearButton( true )
30-
, mClearValueType( MinimumValue )
30+
, mClearValueMode( MinimumValue )
3131
, mCustomClearValue( 0 )
3232
{
3333
mClearButton = new QToolButton( this );
@@ -67,17 +67,39 @@ void QgsSpinBox::clear()
6767
setValue( clearValue() );
6868
}
6969

70-
void QgsSpinBox::setClearValue( QgsSpinBox::ClearValue type, int customValue )
70+
void QgsSpinBox::setClearValue( int customValue, QString specialValueText )
7171
{
72-
mClearValueType = type;
72+
mClearValueMode = CustomValue;
7373
mCustomClearValue = customValue;
74+
75+
if ( !specialValueText.isEmpty() )
76+
{
77+
int v = value();
78+
clear();
79+
setSpecialValueText( specialValueText );
80+
setValue( v );
81+
}
82+
}
83+
84+
void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString specialValueText )
85+
{
86+
mClearValueMode = mode;
87+
mCustomClearValue = 0;
88+
89+
if ( !specialValueText.isEmpty() )
90+
{
91+
int v = value();
92+
clear();
93+
setSpecialValueText( specialValueText );
94+
setValue( v );
95+
}
7496
}
7597

7698
int QgsSpinBox::clearValue()
7799
{
78-
if ( mClearValueType == MinimumValue )
100+
if ( mClearValueMode == MinimumValue )
79101
return minimum() ;
80-
else if ( mClearValueType == MaximumValue )
102+
else if ( mClearValueMode == MaximumValue )
81103
return maximum();
82104
else
83105
return mCustomClearValue;

‎src/gui/editorwidgets/qgsspinbox.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
3030
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
3131

3232
public:
33-
enum ClearValue
33+
enum ClearValueMode
3434
{
3535
MinimumValue,
3636
MaximumValue,
@@ -47,10 +47,17 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
4747
virtual void clear();
4848

4949
/**
50-
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
51-
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
50+
* @brief setClearValue defines the clear value for the widget and will automatically set the clear value mode to CustomValue
51+
* @param defines the numerical value used as the clear value
52+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
5253
*/
53-
void setClearValue( ClearValue type, int customValue = 0 );
54+
void setClearValue( int customValue, QString clearValueText = QString() );
55+
/**
56+
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
57+
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
58+
*/
59+
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );
60+
5461
//! returns the value used when clear() is called.
5562
int clearValue();
5663

@@ -65,7 +72,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
6572
int frameWidth() const;
6673

6774
bool mShowClearButton;
68-
ClearValue mClearValueType;
75+
ClearValueMode mClearValueMode;
6976
int mCustomClearValue;
7077

7178
QToolButton* mClearButton;

0 commit comments

Comments
 (0)
Please sign in to comment.