Skip to content

Commit 2b37e40

Browse files
committedDec 3, 2014
allow defining custom clear value for Qgs(Double)SpinBox
1 parent 2d3f05b commit 2b37e40

File tree

6 files changed

+112
-10
lines changed

6 files changed

+112
-10
lines changed
 

‎python/gui/editorwidgets/qgsdoublespinbox.sip

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ class QgsDoubleSpinBox : QDoubleSpinBox
55
%End
66

77
public:
8+
enum ClearValue
9+
{
10+
MinimumValue,
11+
MaximumValue,
12+
CustomValue
13+
};
14+
815
explicit QgsDoubleSpinBox( QWidget *parent /TransferThis/ = 0 );
916

1017
//! determines if the widget will show a clear button
1118
//! @note the clear button will set the widget to its minimum value
1219
void setShowClearButton( const bool showClearButton );
1320
bool showClearButton() const;
1421

15-
//! Set the current value to the minimum
22+
//! Set the current value to the value defined by the clear value.
1623
virtual void clear();
1724

25+
/**
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
28+
*/
29+
void setClearValue( ClearValue type, double customValue = 0 );
30+
//! returns the value used when clear() is called.
31+
double clearValue();
32+
1833
protected:
1934
virtual void resizeEvent( QResizeEvent* event );
2035
virtual void changeEvent( QEvent* event );

‎python/gui/editorwidgets/qgsspinbox.sip

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ class QgsSpinBox : QSpinBox
55
%End
66

77
public:
8+
enum ClearValue
9+
{
10+
MinimumValue,
11+
MaximumValue,
12+
CustomValue
13+
};
14+
815
explicit QgsSpinBox( QWidget *parent /TransferThis/ = 0 );
916

1017
//! determines if the widget will show a clear button
1118
//! @note the clear button will set the widget to its minimum value
1219
void setShowClearButton( const bool showClearButton );
1320
bool showClearButton() const;
1421

15-
//! Set the current value to the minimum
22+
//! Set the current value to the value defined by the clear value.
1623
virtual void clear();
1724

25+
/**
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
28+
*/
29+
void setClearValue( ClearValue type, int customValue = 0 );
30+
//! returns the value used when clear() is called.
31+
int clearValue();
32+
1833
protected:
1934
virtual void resizeEvent( QResizeEvent* event );
2035
virtual void changeEvent( QEvent* event );

‎src/gui/editorwidgets/qgsdoublespinbox.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
2828
: QDoubleSpinBox( parent )
2929
, mShowClearButton( true )
30+
, mClearValueType( MinimumValue )
31+
, mCustomClearValue( 0.0 )
3032
{
3133
mClearButton = new QToolButton( this );
3234
mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) );
@@ -62,7 +64,23 @@ void QgsDoubleSpinBox::changed( const double& value )
6264

6365
void QgsDoubleSpinBox::clear()
6466
{
65-
setValue( minimum() );
67+
setValue( clearValue() );
68+
}
69+
70+
void QgsDoubleSpinBox::setClearValue( QgsDoubleSpinBox::ClearValue type, double customValue )
71+
{
72+
mClearValueType = type;
73+
mCustomClearValue = customValue;
74+
}
75+
76+
double QgsDoubleSpinBox::clearValue()
77+
{
78+
if ( mClearValueType == MinimumValue )
79+
return minimum() ;
80+
else if ( mClearValueType == MaximumValue )
81+
return maximum();
82+
else
83+
return mCustomClearValue;
6684
}
6785

6886
int QgsDoubleSpinBox::frameWidth() const

‎src/gui/editorwidgets/qgsdoublespinbox.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,40 @@
2020
#include <QToolButton>
2121

2222
/**
23-
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the minimum. This minum can then be handled by a special value text.
23+
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
24+
* The clear value can be either the minimum or the maiximum value of the spin box or a custom value.
25+
* This value can then be handled by a special value text.
2426
*/
2527
class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
2628
{
2729
Q_OBJECT
2830
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
2931

3032
public:
33+
enum ClearValue
34+
{
35+
MinimumValue,
36+
MaximumValue,
37+
CustomValue
38+
};
39+
3140
explicit QgsDoubleSpinBox( QWidget *parent = 0 );
3241

3342
//! determines if the widget will show a clear button
34-
//! @note the clear button will set the widget to its minimum value
3543
void setShowClearButton( const bool showClearButton );
3644
bool showClearButton() const {return mShowClearButton;}
3745

38-
//! Set the current value to the minimum
46+
//! Set the current value to the value defined by the clear value.
3947
virtual void clear();
4048

49+
/**
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
52+
*/
53+
void setClearValue( ClearValue type, double customValue = 0 );
54+
//! returns the value used when clear() is called.
55+
double clearValue();
56+
4157
protected:
4258
virtual void resizeEvent( QResizeEvent* event );
4359
virtual void changeEvent( QEvent* event );
@@ -49,6 +65,8 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
4965
int frameWidth() const;
5066

5167
bool mShowClearButton;
68+
ClearValue mClearValueType;
69+
double mCustomClearValue;
5270

5371
QToolButton* mClearButton;
5472
};

‎src/gui/editorwidgets/qgsspinbox.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
QgsSpinBox::QgsSpinBox( QWidget *parent )
2828
: QSpinBox( parent )
2929
, mShowClearButton( true )
30+
, mClearValueType( MinimumValue )
31+
, mCustomClearValue( 0 )
3032
{
3133
mClearButton = new QToolButton( this );
3234
mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) );
@@ -62,7 +64,23 @@ void QgsSpinBox::changed( const int& value )
6264

6365
void QgsSpinBox::clear()
6466
{
65-
setValue( minimum() );
67+
setValue( clearValue() );
68+
}
69+
70+
void QgsSpinBox::setClearValue( QgsSpinBox::ClearValue type, int customValue )
71+
{
72+
mClearValueType = type;
73+
mCustomClearValue = customValue;
74+
}
75+
76+
int QgsSpinBox::clearValue()
77+
{
78+
if ( mClearValueType == MinimumValue )
79+
return minimum() ;
80+
else if ( mClearValueType == MaximumValue )
81+
return maximum();
82+
else
83+
return mCustomClearValue;
6684
}
6785

6886
int QgsSpinBox::frameWidth() const

‎src/gui/editorwidgets/qgsspinbox.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,40 @@
2020
#include <QToolButton>
2121

2222
/**
23-
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the minimum. This minum can then be handled by a special value text.
23+
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
24+
* The clear value can be either the minimum or the maiximum value of the spin box or a custom value.
25+
* This value can then be handled by a special value text.
2426
*/
2527
class GUI_EXPORT QgsSpinBox : public QSpinBox
2628
{
2729
Q_OBJECT
2830
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )
2931

3032
public:
33+
enum ClearValue
34+
{
35+
MinimumValue,
36+
MaximumValue,
37+
CustomValue
38+
};
39+
3140
explicit QgsSpinBox( QWidget *parent = 0 );
3241

3342
//! determines if the widget will show a clear button
34-
//! @note the clear button will set the widget to its minimum value
3543
void setShowClearButton( const bool showClearButton );
3644
bool showClearButton() const {return mShowClearButton;}
3745

38-
//! Set the current value to the minimum
46+
//! Set the current value to the value defined by the clear value.
3947
virtual void clear();
4048

49+
/**
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
52+
*/
53+
void setClearValue( ClearValue type, int customValue = 0 );
54+
//! returns the value used when clear() is called.
55+
int clearValue();
56+
4157
protected:
4258
virtual void resizeEvent( QResizeEvent* event );
4359
virtual void changeEvent( QEvent* event );
@@ -49,6 +65,8 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
4965
int frameWidth() const;
5066

5167
bool mShowClearButton;
68+
ClearValue mClearValueType;
69+
int mCustomClearValue;
5270

5371
QToolButton* mClearButton;
5472
};

0 commit comments

Comments
 (0)
Please sign in to comment.