Skip to content
Permalink
Browse files

allow defining custom clear value for Qgs(Double)SpinBox

  • Loading branch information
3nids committed Dec 3, 2014
1 parent 2d3f05b commit 2b37e40b17edd708b507f61cb39a898ec862a2b3
@@ -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 );
@@ -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 );
@@ -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" ) );
@@ -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
@@ -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 );
@@ -49,6 +65,8 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
int frameWidth() const;

bool mShowClearButton;
ClearValue mClearValueType;
double mCustomClearValue;

QToolButton* mClearButton;
};
@@ -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" ) );
@@ -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
@@ -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 );
@@ -49,6 +65,8 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
int frameWidth() const;

bool mShowClearButton;
ClearValue mClearValueType;
int mCustomClearValue;

QToolButton* mClearButton;
};

0 comments on commit 2b37e40

Please sign in to comment.
You can’t perform that action at this time.