Skip to content

Commit

Permalink
allow defining custom clear value for Qgs(Double)SpinBox
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Dec 3, 2014
1 parent 2d3f05b commit 2b37e40
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 10 deletions.
17 changes: 16 additions & 1 deletion python/gui/editorwidgets/qgsdoublespinbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@ class QgsDoubleSpinBox : QDoubleSpinBox
%End

public:
enum ClearValue
{
MinimumValue,
MaximumValue,
CustomValue
};

explicit QgsDoubleSpinBox( QWidget *parent /TransferThis/ = 0 );

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

//! Set the current value to the minimum
//! Set the current value to the value defined by the clear value.
virtual void clear();

/**
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
*/
void setClearValue( ClearValue type, double customValue = 0 );
//! returns the value used when clear() is called.
double clearValue();

protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void changeEvent( QEvent* event );
Expand Down
17 changes: 16 additions & 1 deletion python/gui/editorwidgets/qgsspinbox.sip
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@ class QgsSpinBox : QSpinBox
%End

public:
enum ClearValue
{
MinimumValue,
MaximumValue,
CustomValue
};

explicit QgsSpinBox( QWidget *parent /TransferThis/ = 0 );

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

//! Set the current value to the minimum
//! Set the current value to the value defined by the clear value.
virtual void clear();

/**
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
*/
void setClearValue( ClearValue type, int customValue = 0 );
//! returns the value used when clear() is called.
int clearValue();

protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void changeEvent( QEvent* event );
Expand Down
20 changes: 19 additions & 1 deletion src/gui/editorwidgets/qgsdoublespinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
: QDoubleSpinBox( parent )
, mShowClearButton( true )
, mClearValueType( MinimumValue )
, mCustomClearValue( 0.0 )
{
mClearButton = new QToolButton( this );
mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) );
Expand Down Expand Up @@ -62,7 +64,23 @@ void QgsDoubleSpinBox::changed( const double& value )

void QgsDoubleSpinBox::clear()
{
setValue( minimum() );
setValue( clearValue() );
}

void QgsDoubleSpinBox::setClearValue( QgsDoubleSpinBox::ClearValue type, double customValue )
{
mClearValueType = type;
mCustomClearValue = customValue;
}

double QgsDoubleSpinBox::clearValue()
{
if ( mClearValueType == MinimumValue )
return minimum() ;
else if ( mClearValueType == MaximumValue )
return maximum();
else
return mCustomClearValue;
}

int QgsDoubleSpinBox::frameWidth() const
Expand Down
24 changes: 21 additions & 3 deletions src/gui/editorwidgets/qgsdoublespinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,40 @@
#include <QToolButton>

/**
* @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.
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
* The clear value can be either the minimum or the maiximum value of the spin box or a custom value.
* This value can then be handled by a special value text.
*/
class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
{
Q_OBJECT
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )

public:
enum ClearValue
{
MinimumValue,
MaximumValue,
CustomValue
};

explicit QgsDoubleSpinBox( QWidget *parent = 0 );

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

//! Set the current value to the minimum
//! Set the current value to the value defined by the clear value.
virtual void clear();

/**
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
*/
void setClearValue( ClearValue type, double customValue = 0 );
//! returns the value used when clear() is called.
double clearValue();

protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void changeEvent( QEvent* event );
Expand All @@ -49,6 +65,8 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
int frameWidth() const;

bool mShowClearButton;
ClearValue mClearValueType;
double mCustomClearValue;

QToolButton* mClearButton;
};
Expand Down
20 changes: 19 additions & 1 deletion src/gui/editorwidgets/qgsspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
QgsSpinBox::QgsSpinBox( QWidget *parent )
: QSpinBox( parent )
, mShowClearButton( true )
, mClearValueType( MinimumValue )
, mCustomClearValue( 0 )
{
mClearButton = new QToolButton( this );
mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) );
Expand Down Expand Up @@ -62,7 +64,23 @@ void QgsSpinBox::changed( const int& value )

void QgsSpinBox::clear()
{
setValue( minimum() );
setValue( clearValue() );
}

void QgsSpinBox::setClearValue( QgsSpinBox::ClearValue type, int customValue )
{
mClearValueType = type;
mCustomClearValue = customValue;
}

int QgsSpinBox::clearValue()
{
if ( mClearValueType == MinimumValue )
return minimum() ;
else if ( mClearValueType == MaximumValue )
return maximum();
else
return mCustomClearValue;
}

int QgsSpinBox::frameWidth() const
Expand Down
24 changes: 21 additions & 3 deletions src/gui/editorwidgets/qgsspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,40 @@
#include <QToolButton>

/**
* @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.
* @brief The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
* The clear value can be either the minimum or the maiximum value of the spin box or a custom value.
* This value can then be handled by a special value text.
*/
class GUI_EXPORT QgsSpinBox : public QSpinBox
{
Q_OBJECT
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )

public:
enum ClearValue
{
MinimumValue,
MaximumValue,
CustomValue
};

explicit QgsSpinBox( QWidget *parent = 0 );

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

//! Set the current value to the minimum
//! Set the current value to the value defined by the clear value.
virtual void clear();

/**
* @brief setClearValue defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param customValue if type is CustomValue, defines the numerical value used as the clear value
*/
void setClearValue( ClearValue type, int customValue = 0 );
//! returns the value used when clear() is called.
int clearValue();

protected:
virtual void resizeEvent( QResizeEvent* event );
virtual void changeEvent( QEvent* event );
Expand All @@ -49,6 +65,8 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
int frameWidth() const;

bool mShowClearButton;
ClearValue mClearValueType;
int mCustomClearValue;

QToolButton* mClearButton;
};
Expand Down

0 comments on commit 2b37e40

Please sign in to comment.