Properties: Handle units changes correctly

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12885
This commit is contained in:
Jon Evans 2022-11-24 17:15:07 -05:00
parent 7a9467b0d5
commit 4285b38b74
3 changed files with 16 additions and 14 deletions

View File

@ -17,6 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <eda_draw_frame.h>
#include <properties/pg_editors.h>
#include <properties/pg_properties.h>
#include <widgets/unit_binder.h>
@ -29,6 +30,7 @@ PG_UNIT_EDITOR::PG_UNIT_EDITOR( EDA_DRAW_FRAME* aFrame ) :
m_frame( aFrame )
{
m_unitBinder = std::make_unique<PROPERTY_EDITOR_UNIT_BINDER>( m_frame );
m_unitBinder->SetUnits( m_frame->GetUserUnits() );
}
@ -62,6 +64,7 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr
if( aProperty->UsesAutoUnspecified() && textVal.empty() )
{
aVariant.MakeNull();
m_unitBinder->SetControl( nullptr );
return true;
}
@ -80,5 +83,7 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr
if( !changed && aVariant.IsNull() )
changed = true;
m_unitBinder->SetControl( nullptr );
return changed;
}

View File

@ -47,9 +47,9 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindo
UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale,
wxStaticText* aLabel, wxWindow* aValueCtrl,
wxStaticText* aUnitLabel, bool allowEval, bool aBindFrameEvents ) :
wxStaticText* aUnitLabel, bool allowEval, bool aBindFocusEvent ) :
m_frame( aParent ),
m_bindFrameEvents( aBindFrameEvents ),
m_bindFocusEvent( aBindFocusEvent ),
m_label( aLabel ),
m_valueCtrl( aValueCtrl ),
m_unitLabel( aUnitLabel ),
@ -87,24 +87,21 @@ UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale,
this );
}
if( m_bindFrameEvents )
if( m_bindFocusEvent )
{
Connect( DELAY_FOCUS, wxCommandEventHandler( UNIT_BINDER::delayedFocusHandler ), nullptr,
this );
m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
nullptr, this );
}
m_frame->Connect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
nullptr, this );
}
UNIT_BINDER::~UNIT_BINDER()
{
if( m_bindFrameEvents )
{
m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
nullptr, this );
}
m_frame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( UNIT_BINDER::onUnitsChanged ),
nullptr, this );
}

View File

@ -54,11 +54,11 @@ public:
*/
UNIT_BINDER( EDA_DRAW_FRAME* aParent,
wxStaticText* aLabel, wxWindow* aValueCtrl, wxStaticText* aUnitLabel,
bool aAllowEval = true, bool aBindFrameEvents = true );
bool aAllowEval = true, bool aBindFocusEvent = true );
UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale, wxStaticText* aLabel,
wxWindow* aValueCtrl, wxStaticText* aUnitLabel, bool aAllowEval = true,
bool aBindFrameEvents = true );
bool aBindFocusEvent = true );
virtual ~UNIT_BINDER() override;
@ -221,7 +221,7 @@ protected:
double setPrecision( double aValue, bool aValueUsesUserUnits );
EDA_BASE_FRAME* m_frame;
bool m_bindFrameEvents;
bool m_bindFocusEvent;
///< The bound widgets
wxStaticText* m_label;