Implement more detailed validation of wxArrayDoubleProperty in propgrid sample.
Added wxArrayDoubleProperty::ValidateValue() method checks if pending value is of proper type (wxArrayDouble). Pending value of improper type is used to signal that invalid numeric value was entered into the edit field. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78513 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
f9876c519e
commit
ac1d0a3a9d
@ -608,7 +608,6 @@ bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& t
|
||||
// If token was invalid, exit the loop now
|
||||
if ( !token.ToDouble(&tval) )
|
||||
{
|
||||
wxLogDebug( _("\"%s\" is not a floating-point number."), token.c_str() );
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
@ -618,10 +617,12 @@ bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& t
|
||||
|
||||
WX_PG_TOKENIZER1_END()
|
||||
|
||||
// When invalid token found don't change anything
|
||||
// When invalid token found signal the error
|
||||
// by returning pending value of non-wxArrayDouble type.
|
||||
if ( !ok )
|
||||
{
|
||||
return false;
|
||||
variant = (long)0;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !(wxArrayDoubleRefFromVariant(m_value) == new_array) )
|
||||
@ -665,3 +666,15 @@ wxValidator* wxArrayDoubleProperty::DoGetValidator() const
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool wxArrayDoubleProperty::ValidateValue(wxVariant& value,
|
||||
wxPGValidationInfo& validationInfo) const
|
||||
{
|
||||
if (!value.IsType("wxArrayDouble"))
|
||||
{
|
||||
validationInfo.SetFailureMessage(_("At least one element is not a valid floating-point number."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -127,6 +127,8 @@ public:
|
||||
virtual void GenerateValueAsString ( wxString& target, int prec, bool removeZeroes ) const;
|
||||
|
||||
wxValidator* DoGetValidator() const wxOVERRIDE;
|
||||
bool ValidateValue(wxVariant& value,
|
||||
wxPGValidationInfo& validationInfo) const wxOVERRIDE;
|
||||
|
||||
protected:
|
||||
wxString m_display; // Stores cache for displayed text
|
||||
|
Loading…
Reference in New Issue
Block a user