Don't commit changes on paint events or updateUI events.

Also use std::numeric_limits::epsilon for comparing doubles.

Fixes https://gitlab.com/kicad/code/kicad/issues/13851

(cherry picked from commit d714ff8549)
This commit is contained in:
Jeff Young 2023-03-04 00:08:41 +00:00
parent e3cf65fbdf
commit 9b61b350fe
3 changed files with 24 additions and 19 deletions

View File

@ -114,8 +114,7 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima
{ {
double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() ); double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() );
if( isnan( value ) if( isnan( value ) || SIM_VALUE::Equal( value, textEntry->GetValue().ToStdString() ) )
|| value == SIM_VALUE::ToDouble( textEntry->GetValue().ToStdString() ) )
{ {
// Don't mess up user formatting if eval'ing didn't actually change the value. // Don't mess up user formatting if eval'ing didn't actually change the value.
} }
@ -142,25 +141,23 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima
keyEvent.m_keyCode = keyEvent.ShiftDown() ? WXK_UP : WXK_DOWN; keyEvent.m_keyCode = keyEvent.ShiftDown() ? WXK_UP : WXK_DOWN;
keyEvent.m_shiftDown = false; keyEvent.m_shiftDown = false;
} }
}
}
#ifdef __WXMAC__ #ifdef __WXMAC__
if( wxPropertyGrid* propGrid = dynamic_cast<wxPropertyGrid*>( wnd_primary->GetParent() ) ) // This shouldn't be required, as wxPGTextCtrlEditor::OnTextCtrlEvent() should be
{ // setting the value to modified. But it doesn't on Mac (or the modified flag is
// This shouldn't be required, as wxPGTextCtrlEditor::OnTextCtrlEvent() should be setting // cleared at some point later), and even if it is set, the changes don't get
// the value to modified. But it doesn't on Mac (or the modified flag is cleared at some // committed.
// point later), and even if it is set, the changes don't get committed. // (We used to have code in DIALOG_SIM_MODEL to commit things on *some* actions, but
// (We used to have code in DIALOG_SIM_MODEL to commit things on *some* actions, but it // it wasn't complete and this appears to have at least a better hit rate.)
// wasn't complete and this appears to have at least a better hit rate.) propGrid->CallAfter(
propGrid->CallAfter( [propGrid]()
[propGrid]() {
{ propGrid->EditorsValueWasModified();
propGrid->EditorsValueWasModified(); propGrid->CommitChangesFromEditor();
propGrid->CommitChangesFromEditor(); } );
} );
}
#endif #endif
}
}
return false; return false;
} }
@ -191,7 +188,7 @@ bool SIM_STRING_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aT
{ {
double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() ); double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() );
if( isnan( value ) || value == SIM_VALUE::ToDouble( aText.ToStdString() ) ) if( isnan( value ) || SIM_VALUE::Equal( value, aText.ToStdString() ) )
{ {
// Don't mess up user formatting if eval'ing didn't actually change the value. // Don't mess up user formatting if eval'ing didn't actually change the value.
} }

View File

@ -451,3 +451,9 @@ int SIM_VALUE::ToInt( const std::string& aString, int aDefault )
return aDefault; return aDefault;
} }
bool SIM_VALUE::Equal( double aLH, const std::string& aRH )
{
return std::abs( aLH - ToDouble( aRH ) ) <= std::numeric_limits<double>::epsilon();
}

View File

@ -89,6 +89,8 @@ public:
static double ToDouble( const std::string& aString, double aDefault = NAN ); static double ToDouble( const std::string& aString, double aDefault = NAN );
static int ToInt( const std::string& aString, int aDefault = -1 ); static int ToInt( const std::string& aString, int aDefault = -1 );
static bool Equal( double aLH, const std::string& aRH );
}; };