From ac1d0a3a9d8166ba4888186951be329f031930e1 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 17 Feb 2015 17:36:00 +0000 Subject: [PATCH] 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 --- samples/propgrid/sampleprops.cpp | 19 ++++++++++++++++--- samples/propgrid/sampleprops.h | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/samples/propgrid/sampleprops.cpp b/samples/propgrid/sampleprops.cpp index b1be4b1dfd..76a44ee1fe 100644 --- a/samples/propgrid/sampleprops.cpp +++ b/samples/propgrid/sampleprops.cpp @@ -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; +} diff --git a/samples/propgrid/sampleprops.h b/samples/propgrid/sampleprops.h index bc4cef7b49..889eb5de9d 100644 --- a/samples/propgrid/sampleprops.h +++ b/samples/propgrid/sampleprops.h @@ -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