Skip to content

Commit

Permalink
define the special text directly with the clear value
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Dec 4, 2014
1 parent e887d07 commit 1a4b8bb
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 28 deletions.
15 changes: 11 additions & 4 deletions python/gui/editorwidgets/qgsdoublespinbox.sip
Expand Up @@ -5,7 +5,7 @@ class QgsDoubleSpinBox : QDoubleSpinBox
%End

public:
enum ClearValue
enum ClearValueMode
{
MinimumValue,
MaximumValue,
Expand All @@ -23,10 +23,17 @@ class QgsDoubleSpinBox : QDoubleSpinBox
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
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
* @param defines the numerical value used as the clear value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValue( ClearValue type, double customValue = 0 );
void setClearValue( double customValue, QString clearValueText = QString() );
/**
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
double clearValue();

Expand Down
15 changes: 11 additions & 4 deletions python/gui/editorwidgets/qgsspinbox.sip
Expand Up @@ -5,7 +5,7 @@ class QgsSpinBox : QSpinBox
%End

public:
enum ClearValue
enum ClearValueMode
{
MinimumValue,
MaximumValue,
Expand All @@ -23,10 +23,17 @@ class QgsSpinBox : QSpinBox
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
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
* @param defines the numerical value used as the clear value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValue( ClearValue type, int customValue = 0 );
void setClearValue( int customValue, QString clearValueText = QString() );
/**
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
int clearValue();

Expand Down
32 changes: 27 additions & 5 deletions src/gui/editorwidgets/qgsdoublespinbox.cpp
Expand Up @@ -27,7 +27,7 @@
QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
: QDoubleSpinBox( parent )
, mShowClearButton( true )
, mClearValueType( MinimumValue )
, mClearValueMode( MinimumValue )
, mCustomClearValue( 0.0 )
{
mClearButton = new QToolButton( this );
Expand Down Expand Up @@ -67,17 +67,39 @@ void QgsDoubleSpinBox::clear()
setValue( clearValue() );
}

void QgsDoubleSpinBox::setClearValue( QgsDoubleSpinBox::ClearValue type, double customValue )
void QgsDoubleSpinBox::setClearValue( double customValue , QString specialValueText )
{
mClearValueType = type;
mClearValueMode = CustomValue;
mCustomClearValue = customValue;

if ( !specialValueText.isEmpty() )
{
double v = value();
clear();
setSpecialValueText( specialValueText );
setValue( v );
}
}

void QgsDoubleSpinBox::setClearValueMode(QgsDoubleSpinBox::ClearValueMode mode, QString clearValueText )
{
mClearValueMode = mode;
mCustomClearValue = 0;

if ( !clearValueText.isEmpty() )
{
double v = value();
clear();
setSpecialValueText( clearValueText );
setValue( v );
}
}

double QgsDoubleSpinBox::clearValue()
{
if ( mClearValueType == MinimumValue )
if ( mClearValueMode == MinimumValue )
return minimum() ;
else if ( mClearValueType == MaximumValue )
else if ( mClearValueMode == MaximumValue )
return maximum();
else
return mCustomClearValue;
Expand Down
17 changes: 12 additions & 5 deletions src/gui/editorwidgets/qgsdoublespinbox.h
Expand Up @@ -30,7 +30,7 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )

public:
enum ClearValue
enum ClearValueMode
{
MinimumValue,
MaximumValue,
Expand All @@ -47,10 +47,17 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
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
* @brief setClearValue defines the clear value as a custom value and will automatically set the clear value mode to CustomValue
* @param defines the numerical value used as the clear value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValue( ClearValue type, double customValue = 0 );
void setClearValue( double customValue, QString clearValueText = QString() );
/**
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
double clearValue();

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

bool mShowClearButton;
ClearValue mClearValueType;
ClearValueMode mClearValueMode;
double mCustomClearValue;

QToolButton* mClearButton;
Expand Down
32 changes: 27 additions & 5 deletions src/gui/editorwidgets/qgsspinbox.cpp
Expand Up @@ -27,7 +27,7 @@
QgsSpinBox::QgsSpinBox( QWidget *parent )
: QSpinBox( parent )
, mShowClearButton( true )
, mClearValueType( MinimumValue )
, mClearValueMode( MinimumValue )
, mCustomClearValue( 0 )
{
mClearButton = new QToolButton( this );
Expand Down Expand Up @@ -67,17 +67,39 @@ void QgsSpinBox::clear()
setValue( clearValue() );
}

void QgsSpinBox::setClearValue( QgsSpinBox::ClearValue type, int customValue )
void QgsSpinBox::setClearValue( int customValue, QString specialValueText )
{
mClearValueType = type;
mClearValueMode = CustomValue;
mCustomClearValue = customValue;

if ( !specialValueText.isEmpty() )
{
int v = value();
clear();
setSpecialValueText( specialValueText );
setValue( v );
}
}

void QgsSpinBox::setClearValueMode(QgsSpinBox::ClearValueMode mode, QString specialValueText )
{
mClearValueMode = mode;
mCustomClearValue = 0;

if ( !specialValueText.isEmpty() )
{
int v = value();
clear();
setSpecialValueText( specialValueText );
setValue( v );
}
}

int QgsSpinBox::clearValue()
{
if ( mClearValueType == MinimumValue )
if ( mClearValueMode == MinimumValue )
return minimum() ;
else if ( mClearValueType == MaximumValue )
else if ( mClearValueMode == MaximumValue )
return maximum();
else
return mCustomClearValue;
Expand Down
17 changes: 12 additions & 5 deletions src/gui/editorwidgets/qgsspinbox.h
Expand Up @@ -30,7 +30,7 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
Q_PROPERTY( bool showClearButton READ showClearButton WRITE setShowClearButton )

public:
enum ClearValue
enum ClearValueMode
{
MinimumValue,
MaximumValue,
Expand All @@ -47,10 +47,17 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
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
* @brief setClearValue defines the clear value for the widget and will automatically set the clear value mode to CustomValue
* @param defines the numerical value used as the clear value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValue( ClearValue type, int customValue = 0 );
void setClearValue( int customValue, QString clearValueText = QString() );
/**
* @brief setClearValueMode defines if the clear value should be the minimum or maximum values of the widget or a custom value
* @param clearValueText is the text displayed when the spin box is at the clear value. If not specified, no special value text is used.
*/
void setClearValueMode( ClearValueMode mode, QString clearValueText = QString() );

//! returns the value used when clear() is called.
int clearValue();

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

bool mShowClearButton;
ClearValue mClearValueType;
ClearValueMode mClearValueMode;
int mCustomClearValue;

QToolButton* mClearButton;
Expand Down

0 comments on commit 1a4b8bb

Please sign in to comment.