Make wxArrayDoubleProperty a parent of wxEditorDialogProperty
wxArrayDoubleProperty uses TextCtrlAndButton editor so it can be implemented as parent of wxEditorDialogProperty to re-use common functions and data.
This commit is contained in:
@@ -481,18 +481,18 @@ bool operator == (const wxArrayDouble& a, const wxArrayDouble& b)
|
|||||||
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxArrayDouble)
|
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxArrayDouble)
|
||||||
|
|
||||||
wxPG_IMPLEMENT_PROPERTY_CLASS(wxArrayDoubleProperty,
|
wxPG_IMPLEMENT_PROPERTY_CLASS(wxArrayDoubleProperty,
|
||||||
wxPGProperty,
|
wxEditorDialogProperty,
|
||||||
TextCtrlAndButton)
|
TextCtrlAndButton)
|
||||||
|
|
||||||
|
|
||||||
wxArrayDoubleProperty::wxArrayDoubleProperty (const wxString& label,
|
wxArrayDoubleProperty::wxArrayDoubleProperty (const wxString& label,
|
||||||
const wxString& name,
|
const wxString& name,
|
||||||
const wxArrayDouble& array )
|
const wxArrayDouble& array )
|
||||||
: wxPGProperty(label,name)
|
: wxEditorDialogProperty(label,name)
|
||||||
|
, m_precision(-1)
|
||||||
{
|
{
|
||||||
m_precision = -1;
|
m_dlgStyle = wxAEDIALOG_STYLE;
|
||||||
|
|
||||||
//
|
|
||||||
// Need to figure out delimiter needed for this locale
|
// Need to figure out delimiter needed for this locale
|
||||||
// (i.e. can't use comma when comma acts as decimal point in float).
|
// (i.e. can't use comma when comma acts as decimal point in float).
|
||||||
wxChar use_delimiter = ',';
|
wxChar use_delimiter = ',';
|
||||||
@@ -538,7 +538,6 @@ wxString wxArrayDoubleProperty::ValueToString( wxVariant& value,
|
|||||||
void wxArrayDoubleProperty::GenerateValueAsString( wxString& target, int prec, bool removeZeroes ) const
|
void wxArrayDoubleProperty::GenerateValueAsString( wxString& target, int prec, bool removeZeroes ) const
|
||||||
{
|
{
|
||||||
wxString between = ", ";
|
wxString between = ", ";
|
||||||
size_t i;
|
|
||||||
|
|
||||||
between[0] = m_delimiter;
|
between[0] = m_delimiter;
|
||||||
|
|
||||||
@@ -549,7 +548,7 @@ void wxArrayDoubleProperty::GenerateValueAsString( wxString& target, int prec, b
|
|||||||
if (removeZeroes)
|
if (removeZeroes)
|
||||||
style = wxNumberFormatter::Style_NoTrailingZeroes;
|
style = wxNumberFormatter::Style_NoTrailingZeroes;
|
||||||
|
|
||||||
for ( i=0; i<value.GetCount(); i++ )
|
for ( size_t i=0; i<value.GetCount(); i++ )
|
||||||
{
|
{
|
||||||
target += wxNumberFormatter::ToString(value[i], prec, style);
|
target += wxNumberFormatter::ToString(value[i], prec, style);
|
||||||
|
|
||||||
@@ -558,34 +557,28 @@ void wxArrayDoubleProperty::GenerateValueAsString( wxString& target, int prec, b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
|
bool wxArrayDoubleProperty::DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value)
|
||||||
wxWindow* WXUNUSED(primary),
|
|
||||||
wxEvent& event)
|
|
||||||
{
|
{
|
||||||
if ( propgrid->IsMainButtonEvent(event) )
|
wxASSERT_MSG(value.IsType("wxArrayDouble"), "Function called for incompatible property");
|
||||||
{
|
|
||||||
// Update the value in case of last minute changes
|
|
||||||
wxVariant useValue = propgrid->GetUncommittedPropertyValue();
|
|
||||||
|
|
||||||
wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue);
|
wxArrayDouble& curValue = wxArrayDoubleRefFromVariant(value);
|
||||||
|
|
||||||
// Create editor dialog.
|
// Create editor dialog.
|
||||||
wxArrayDoubleEditorDialog dlg;
|
wxArrayDoubleEditorDialog dlg;
|
||||||
dlg.SetPrecision(m_precision);
|
dlg.SetPrecision(m_precision);
|
||||||
dlg.Create( propgrid, wxEmptyString, m_label, value );
|
dlg.Create(pg->GetPanel(), wxEmptyString,
|
||||||
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
m_dlgTitle.empty() ? GetLabel() : m_dlgTitle, curValue, m_dlgStyle);
|
||||||
|
dlg.Move( pg->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
||||||
|
|
||||||
// Execute editor dialog
|
// Execute editor dialog
|
||||||
int res = dlg.ShowModal();
|
int res = dlg.ShowModal();
|
||||||
if ( res == wxID_OK && dlg.IsModified() )
|
if ( res == wxID_OK && dlg.IsModified() )
|
||||||
{
|
{
|
||||||
SetValueInEvent( WXVARIANT(dlg.GetArray()) );
|
value = WXVARIANT(dlg.GetArray());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
|
bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
|
||||||
{
|
{
|
||||||
@@ -639,7 +632,7 @@ bool wxArrayDoubleProperty::DoSetAttribute( const wxString& name, wxVariant& val
|
|||||||
GenerateValueAsString( m_display, m_precision, true );
|
GenerateValueAsString( m_display, m_precision, true );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return wxPGProperty::DoSetAttribute(name, value);
|
return wxEditorDialogProperty::DoSetAttribute(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxValidator* wxArrayDoubleProperty::DoGetValidator() const
|
wxValidator* wxArrayDoubleProperty::DoGetValidator() const
|
||||||
|
@@ -105,7 +105,7 @@ WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(wxDirsProperty, clas
|
|||||||
|
|
||||||
WX_PG_DECLARE_VARIANT_DATA(wxArrayDouble)
|
WX_PG_DECLARE_VARIANT_DATA(wxArrayDouble)
|
||||||
|
|
||||||
class wxArrayDoubleProperty : public wxPGProperty
|
class wxArrayDoubleProperty : public wxEditorDialogProperty
|
||||||
{
|
{
|
||||||
WX_PG_DECLARE_PROPERTY_CLASS(wxArrayDoubleProperty)
|
WX_PG_DECLARE_PROPERTY_CLASS(wxArrayDoubleProperty)
|
||||||
public:
|
public:
|
||||||
@@ -121,7 +121,6 @@ public:
|
|||||||
virtual bool StringToValue( wxVariant& variant,
|
virtual bool StringToValue( wxVariant& variant,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int argFlags = 0 ) const wxOVERRIDE;
|
int argFlags = 0 ) const wxOVERRIDE;
|
||||||
virtual bool OnEvent( wxPropertyGrid* propgrid, wxWindow* primary, wxEvent& event ) wxOVERRIDE;
|
|
||||||
virtual bool DoSetAttribute( const wxString& name, wxVariant& value ) wxOVERRIDE;
|
virtual bool DoSetAttribute( const wxString& name, wxVariant& value ) wxOVERRIDE;
|
||||||
|
|
||||||
// Generates cache for displayed text
|
// Generates cache for displayed text
|
||||||
@@ -132,6 +131,8 @@ public:
|
|||||||
wxPGValidationInfo& validationInfo) const wxOVERRIDE;
|
wxPGValidationInfo& validationInfo) const wxOVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool DisplayEditorDialog(wxPropertyGrid* pg, wxVariant& value) wxOVERRIDE;
|
||||||
|
|
||||||
wxString m_display; // Stores cache for displayed text
|
wxString m_display; // Stores cache for displayed text
|
||||||
int m_precision; // Used when formatting displayed string.
|
int m_precision; // Used when formatting displayed string.
|
||||||
wxChar m_delimiter; // Delimiter between array entries.
|
wxChar m_delimiter; // Delimiter between array entries.
|
||||||
|
Reference in New Issue
Block a user