Properties: clean up some unit handling

Make sure units show up properly in editor on focus kill
Make sure editor shows correct value initially
This commit is contained in:
Jon Evans 2022-12-06 08:55:48 -05:00
parent 40f9a59255
commit 071a2ec46d
3 changed files with 28 additions and 3 deletions

View File

@ -76,13 +76,28 @@ wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGPr
else if( dynamic_cast<PGPROPERTY_ANGLE*>( aProperty ) ) else if( dynamic_cast<PGPROPERTY_ANGLE*>( aProperty ) )
m_unitBinder->SetUnits( EDA_UNITS::DEGREES ); m_unitBinder->SetUnits( EDA_UNITS::DEGREES );
UpdateControl( aProperty, win );
return ret; return ret;
} }
void PG_UNIT_EDITOR::UpdateControl( wxPGProperty* aProperty, wxWindow* aCtrl ) const void PG_UNIT_EDITOR::UpdateControl( wxPGProperty* aProperty, wxWindow* aCtrl ) const
{ {
m_unitBinder->ChangeValue( aProperty->GetValueAsString() ); wxVariant var = aProperty->GetValue();
if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
{
m_unitBinder->ChangeValue( var.GetLong() );
}
else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
{
m_unitBinder->ChangeValue( var.GetDouble() );
}
else
{
wxFAIL_MSG( wxT( "PG_UNIT_EDITOR should only be used with numeric properties!" ) );
}
} }

View File

@ -194,7 +194,6 @@ bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString&
wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aArgFlags ) const wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aArgFlags ) const
{ {
wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG, wxEmptyString ); wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG, wxEmptyString );
// TODO(JE) This should be handled by UNIT_BINDER
long distanceIU = aVariant.GetLong(); long distanceIU = aVariant.GetLong();

View File

@ -236,7 +236,18 @@ void UNIT_BINDER::onKillFocus( wxFocusEvent& aEvent )
if( m_eval.Process( textEntry->GetValue() ) ) if( m_eval.Process( textEntry->GetValue() ) )
{ {
textEntry->GetSelection( &m_selStart, &m_selEnd ); textEntry->GetSelection( &m_selStart, &m_selEnd );
textEntry->ChangeValue( m_eval.Result() );
wxString value = m_eval.Result();
if( m_unitsInValue )
{
if( !( m_units == EDA_UNITS::DEGREES || m_units == EDA_UNITS::PERCENT ) )
value += wxT( " " );
value += EDA_UNIT_UTILS::GetLabel( m_units, m_dataType );
}
textEntry->ChangeValue( value );
#ifdef __WXGTK__ #ifdef __WXGTK__
// Manually copy the selected text to the primary selection clipboard // Manually copy the selected text to the primary selection clipboard