75 const wxPoint& aPos,
const wxSize& aSize )
const
79#if wxCHECK_VERSION( 3, 3, 0 )
80 wxString
text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
82 wxString
text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
84 wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize,
text,
nullptr, 0,
85 aProperty->GetMaxLength() );
86 wxPGWindowList ret( win,
nullptr );
114 wxVariant var = aProperty->GetValue();
116 if( var.GetType() == wxT(
"std::optional<int>" ) )
120 if( variantData->Value().has_value() )
121 m_unitBinder->ChangeValue( variantData->Value().value() );
125 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
129 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
131 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
133 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
137 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
142 else if( !aProperty->IsValueUnspecified() )
144 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
150 wxWindow* aCtrl, wxEvent& aEvent )
const
152 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
154 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
156 if( !textCtrl->HasFocus() )
158 textCtrl->SelectAll();
164 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
169 wxWindow* aCtrl )
const
174 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
175 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
176 wxString textVal = textCtrl->GetValue();
178 if( textVal == wxT(
"<...>" ) )
190 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
193 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
203 changed = ( aVariant.IsNull() || angle.
AsDegrees() != aVariant.GetDouble() );
215 changed = ( aVariant.IsNull() || result != aVariant.GetLongLong() );
223 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
226 std::optional<int> result;
230 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
234 aVariant = wxVariant( std::optional<int>() );
240 result = std::optional<int>(
m_unitBinder->GetValue() );
241 changed = ( aVariant.IsNull() || result != variantData->Value() );
245 aVariant = wxVariant( result );
253 changed = ( aVariant.IsNull() || result != aVariant.GetLong() );
264 if( !changed && aVariant.IsNull() )
278 const wxPoint& aPos,
const wxSize& aSize )
const
283 if( aProperty->IsValueUnspecified() )
284 aProperty->SetValueFromInt( 0 );
286 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
291 wxEvent& aEvent )
const
298 const wxPoint& aPos,
const wxSize& aSize )
const
309 colorProp->GetBackgroundColor(), defColor,
311 editor->SetPosition( aPos );
314 editor->Bind( COLOR_SWATCH_CHANGED,
315 [=]( wxCommandEvent& aEvt )
320 aGrid->ChangePropertyValue( colorProp, val );
323#if wxCHECK_VERSION( 3, 3, 0 )
324 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
326 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
332 editor->GetNewSwatchColor();
342 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
352 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
369 wxWindow* aCtrl )
const
371 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
372 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
373 wxString textVal = textCtrl->GetValue();
375 if( textVal == wxT(
"<...>" ) )
383 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
387 if( textVal.empty() )
389 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
392 aVariant = wxVariant( std::optional<double>() );
397 textVal.ToDouble( &dblValue );
398 std::optional<double> result( dblValue );
399 changed = ( aVariant.IsNull() || result != variantData->Value() );
403 aVariant = wxVariant( result );
404 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
411 textVal.ToDouble( &result );
412 changed = ( aVariant.IsNull() || result != aVariant.GetDouble() );
417 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), result ) );
423 if( !changed && aVariant.IsNull() )
432 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
433 wxVariant var = aProperty->GetValue();
435 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
437 if( var.GetType() == wxT(
"std::optional<double>" ) )
442 if( variantData->Value().has_value() )
443 strValue = wxString::Format( wxS(
"%g" ), variantData->Value().value() );
447 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
449 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
451 else if( !aProperty->IsValueUnspecified() )
453 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric properties!" ) );
const KIGFX::COLOR4D & Color()
A simple color swatch of the kind used to set layer colors.
const EDA_ANGLE & Angle()
void SetAngle(const EDA_ANGLE &aAngle)
The base class for create windows for drawing purpose.
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A wxEnumProperty that displays a color next to the enum value.
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
static const wxString EDITOR_NAME
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
bool OnEvent(wxPropertyGrid *aGrid, wxPGProperty *aProperty, wxWindow *aWindow, wxEvent &aEvent) const override
KIGFX::COLOR4D colorFromVariant(const wxVariant &aVariant) const
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
KIGFX::COLOR4D colorFromProperty(wxPGProperty *aProperty) const
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
static const wxString EDITOR_NAME
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
std::unique_ptr< PROPERTY_EDITOR_UNIT_BINDER > m_unitBinder
wxPGWindowList CreateControls(wxPropertyGrid *aPropGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
void UpdateFrame(EDA_DRAW_FRAME *aFrame)
When restarting an editor, the instance of PG_UNIT_EDITOR may be the same but the referenced frame is...
PG_UNIT_EDITOR(EDA_DRAW_FRAME *aFrame)
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
bool OnEvent(wxPropertyGrid *aPropGrid, wxPGProperty *aProperty, wxWindow *aCtrl, wxEvent &aEvent) const override
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
virtual ~PG_UNIT_EDITOR()
EDA_UNITS GetUserUnits() const
static std::string strValue(double aValue)