From 3f2fc340754c543d2f2d7391f840525caf5c89e1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 13 May 2014 11:22:51 +0200 Subject: [PATCH] WX_UNIT_TEXT can handle default value. --- common/wxunittext.cpp | 12 ++++++++++-- include/wxunittext.h | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common/wxunittext.cpp b/common/wxunittext.cpp index f33be9ec5a..743f973dce 100644 --- a/common/wxunittext.cpp +++ b/common/wxunittext.cpp @@ -101,13 +101,15 @@ void WX_UNIT_TEXT::SetUnits( EDA_UNITS_T aUnits, bool aConvert ) void WX_UNIT_TEXT::SetValue( double aValue ) { - assert( aValue >= 0.0 ); - if( aValue >= 0.0 ) { m_inputValue->SetValue( wxString( Double2Str( aValue ).c_str(), wxConvUTF8 ) ); m_inputValue->MarkDirty(); } + else + { + m_inputValue->SetValue( DEFAULT_VALUE ); + } } @@ -169,6 +171,9 @@ boost::optional WX_UNIT_TEXT::GetValue() const wxString text = m_inputValue->GetValue(); double value; + if( text == DEFAULT_VALUE ) + return boost::optional( -1.0 ); + if( !text.ToDouble( &value ) ) return boost::optional(); @@ -189,3 +194,6 @@ void WX_UNIT_TEXT::onSpinDownEvent( wxSpinEvent& aEvent ) if( newValue >= 0.0 ) SetValue( newValue ); } + + +const wxString WX_UNIT_TEXT::DEFAULT_VALUE = _( "default "); diff --git a/include/wxunittext.h b/include/wxunittext.h index 92791f09ff..54c52e14dc 100644 --- a/include/wxunittext.h +++ b/include/wxunittext.h @@ -136,6 +136,9 @@ protected: ///> Step size (added/subtracted difference if spin buttons are used). double m_step; + + ///> Default value (or non-specified) + static const wxString DEFAULT_VALUE; }; #endif /* WXUNITTEXT_H_ */