From 0dc98a7d2346f96ae9e1510613a9efe70e92494a Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 8 Feb 2015 12:45:36 +0000 Subject: [PATCH] Implement validator for wxArrayDoubleProperty in propgrid sample. In wxArrayDoubleProperty::DoGetValidator() there is instantiated a wxTextValidator accepting numeric characters, token delimiter and spaces. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78457 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/propgrid/sampleprops.cpp | 32 ++++++++++++++++++++++++-------- samples/propgrid/sampleprops.h | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/samples/propgrid/sampleprops.cpp b/samples/propgrid/sampleprops.cpp index 2069c9fa7b..1a696d0c88 100644 --- a/samples/propgrid/sampleprops.cpp +++ b/samples/propgrid/sampleprops.cpp @@ -595,8 +595,6 @@ bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid, bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const { - double tval; - wxString tstr; // Add values to a temporary array so that in case // of error we can opt not to use them. wxArrayDouble new_array; @@ -609,26 +607,23 @@ bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& t if ( !token.empty() ) { - + double tval; // If token was invalid, exit the loop now if ( !token.ToDouble(&tval) ) { - tstr.Printf ( _("\"%s\" is not a floating-point number."), token.c_str() ); + wxLogDebug( _("\"%s\" is not a floating-point number."), token.c_str() ); ok = false; break; } - // TODO: Put validator code here new_array.Add(tval); - } WX_PG_TOKENIZER1_END() - // When invalid token found, show error message and don't change anything + // When invalid token found don't change anything if ( !ok ) { - //ShowError( tstr ); return false; } @@ -652,3 +647,24 @@ bool wxArrayDoubleProperty::DoSetAttribute( const wxString& name, wxVariant& val return false; } +wxValidator* wxArrayDoubleProperty::DoGetValidator() const +{ +#if wxUSE_VALIDATORS + WX_PG_DOGETVALIDATOR_ENTRY() + + wxTextValidator* validator = new wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST); + + // Accept characters for numeric elements + wxNumericPropertyValidator numValidator(wxNumericPropertyValidator::NumericType::Float); + wxArrayString incChars(numValidator.GetIncludes()); + // Accept also a delimiter and space character + incChars.Add(m_delimiter); + incChars.Add(" "); + + validator->SetIncludes(incChars); + + WX_PG_DOGETVALIDATOR_EXIT(validator) +#else + return NULL; +#endif +} diff --git a/samples/propgrid/sampleprops.h b/samples/propgrid/sampleprops.h index 87b46cb234..bc4cef7b49 100644 --- a/samples/propgrid/sampleprops.h +++ b/samples/propgrid/sampleprops.h @@ -126,6 +126,8 @@ public: // Generates cache for displayed text virtual void GenerateValueAsString ( wxString& target, int prec, bool removeZeroes ) const; + wxValidator* DoGetValidator() const wxOVERRIDE; + protected: wxString m_display; // Stores cache for displayed text int m_precision; // Used when formatting displayed string.