Fixed displaying validation error for numeric wxPG properties (wxUIntProperty, etc.)
When entered wxFloatProperty, wxIntProperty or wxUIntProperty is out of range then there is displayed a warning message presenting a valid range. Instead of displaying in this message numeric values in default (and fixed) format we should display values which are formatted based on to the current attributes of the property (like wxPG_UINT_PREFIX, wxPG_UINT_BASE, wxPG_FLOAT_PRECISION). To do so, we shouldn't format respective values on our own in NumericValidation() but instead call wxPGProperty()::ValueToString() which returns value string formatted in line with attributes. Closes #17601
This commit is contained in:
@@ -242,13 +242,21 @@ public:
|
|||||||
|
|
||||||
/** Validation helpers.
|
/** Validation helpers.
|
||||||
*/
|
*/
|
||||||
#if defined(wxLongLong_t) && wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
|
static bool DoValidation( const wxPGProperty* property,
|
||||||
|
wxLongLong& value,
|
||||||
|
wxPGValidationInfo* pValidationInfo,
|
||||||
|
int mode =
|
||||||
|
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
|
||||||
|
|
||||||
|
#if defined(wxLongLong_t)
|
||||||
static bool DoValidation( const wxPGProperty* property,
|
static bool DoValidation( const wxPGProperty* property,
|
||||||
wxLongLong_t& value,
|
wxLongLong_t& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
int mode =
|
int mode =
|
||||||
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
|
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
|
||||||
#endif
|
#endif // wxLongLong_t
|
||||||
|
#endif // wxUSE_LONGLONG
|
||||||
static bool DoValidation(const wxPGProperty* property,
|
static bool DoValidation(const wxPGProperty* property,
|
||||||
long& value,
|
long& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
@@ -311,12 +319,18 @@ private:
|
|||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
// Validation helpers.
|
// Validation helpers.
|
||||||
#if defined(wxULongLong_t) && wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
|
static bool DoValidation(const wxPGProperty* property,
|
||||||
|
wxULongLong& value,
|
||||||
|
wxPGValidationInfo* pValidationInfo,
|
||||||
|
int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
|
||||||
|
#if defined(wxULongLong_t)
|
||||||
static bool DoValidation(const wxPGProperty* property,
|
static bool DoValidation(const wxPGProperty* property,
|
||||||
wxULongLong_t& value,
|
wxULongLong_t& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
|
int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
|
||||||
#endif
|
#endif // wxULongLong_t
|
||||||
|
#endif // wxUSE_LONGLONG
|
||||||
static bool DoValidation(const wxPGProperty* property,
|
static bool DoValidation(const wxPGProperty* property,
|
||||||
long& value,
|
long& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
|
@@ -352,8 +352,7 @@ template<typename T>
|
|||||||
bool NumericValidation( const wxPGProperty* property,
|
bool NumericValidation( const wxPGProperty* property,
|
||||||
T& value,
|
T& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
int mode, T defMin, T defMax,
|
int mode, T defMin, T defMax)
|
||||||
const wxString& strFmt )
|
|
||||||
{
|
{
|
||||||
T min = defMin;
|
T min = defMin;
|
||||||
T max = defMax;
|
T max = defMax;
|
||||||
@@ -380,16 +379,20 @@ bool NumericValidation( const wxPGProperty* property,
|
|||||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxString smin = wxString::Format(strFmt, min);
|
wxVariant vmin = WXVARIANT(min);
|
||||||
wxString smax = wxString::Format(strFmt, max);
|
wxString smin = property->ValueToString(vmin);
|
||||||
if ( !maxOk )
|
if ( !maxOk )
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be %s or higher."),
|
_("Value must be %s or higher."),
|
||||||
smin.c_str());
|
smin.c_str());
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
wxVariant vmax = WXVARIANT(max);
|
||||||
|
wxString smax = property->ValueToString(vmax);
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be between %s and %s."),
|
_("Value must be between %s and %s."),
|
||||||
smin.c_str(), smax.c_str());
|
smin.c_str(), smax.c_str());
|
||||||
|
}
|
||||||
pValidationInfo->SetFailureMessage(msg);
|
pValidationInfo->SetFailureMessage(msg);
|
||||||
}
|
}
|
||||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||||
@@ -407,16 +410,20 @@ bool NumericValidation( const wxPGProperty* property,
|
|||||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxString smin = wxString::Format(strFmt, min);
|
wxVariant vmax = WXVARIANT(max);
|
||||||
wxString smax = wxString::Format(strFmt, max);
|
wxString smax = property->ValueToString(vmax);
|
||||||
if ( !minOk )
|
if ( !minOk )
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be %s or less."),
|
_("Value must be %s or less."),
|
||||||
smax.c_str());
|
smax.c_str());
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
wxVariant vmin = WXVARIANT(min);
|
||||||
|
wxString smin = property->ValueToString(vmin);
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be between %s and %s."),
|
_("Value must be between %s and %s."),
|
||||||
smin.c_str(), smax.c_str());
|
smin.c_str(), smax.c_str());
|
||||||
|
}
|
||||||
pValidationInfo->SetFailureMessage(msg);
|
pValidationInfo->SetFailureMessage(msg);
|
||||||
}
|
}
|
||||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||||
@@ -436,8 +443,7 @@ template<>
|
|||||||
bool NumericValidation( const wxPGProperty* property,
|
bool NumericValidation( const wxPGProperty* property,
|
||||||
double& value,
|
double& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
int mode, double defMin, double defMax,
|
int mode, double defMin, double defMax)
|
||||||
const wxString& strFmt )
|
|
||||||
{
|
{
|
||||||
double min = defMin;
|
double min = defMin;
|
||||||
double max = defMax;
|
double max = defMax;
|
||||||
@@ -487,16 +493,20 @@ bool NumericValidation( const wxPGProperty* property,
|
|||||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxString smin = wxString::Format(strFmt, min);
|
wxVariant vmin = WXVARIANT(min);
|
||||||
wxString smax = wxString::Format(strFmt, max);
|
wxString smin = property->ValueToString(vmin);
|
||||||
if ( !maxOk )
|
if ( !maxOk )
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be %s or higher."),
|
_("Value must be %s or higher."),
|
||||||
smin.c_str());
|
smin.c_str());
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
wxVariant vmax = WXVARIANT(max);
|
||||||
|
wxString smax = property->ValueToString(vmax);
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be between %s and %s."),
|
_("Value must be between %s and %s."),
|
||||||
smin.c_str(), smax.c_str());
|
smin.c_str(), smax.c_str());
|
||||||
|
}
|
||||||
pValidationInfo->SetFailureMessage(msg);
|
pValidationInfo->SetFailureMessage(msg);
|
||||||
}
|
}
|
||||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||||
@@ -514,16 +524,20 @@ bool NumericValidation( const wxPGProperty* property,
|
|||||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
wxString smin = wxString::Format(strFmt, min);
|
wxVariant vmax = WXVARIANT(max);
|
||||||
wxString smax = wxString::Format(strFmt, max);
|
wxString smax = property->ValueToString(vmax);
|
||||||
if ( !minOk )
|
if ( !minOk )
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be %s or less."),
|
_("Value must be %s or less."),
|
||||||
smax.c_str());
|
smax.c_str());
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
wxVariant vmin = WXVARIANT(min);
|
||||||
|
wxString smin = property->ValueToString(vmin);
|
||||||
msg = wxString::Format(
|
msg = wxString::Format(
|
||||||
_("Value must be between %s and %s."),
|
_("Value must be between %s and %s."),
|
||||||
smin.c_str(), smax.c_str());
|
smin.c_str(), smax.c_str());
|
||||||
|
}
|
||||||
pValidationInfo->SetFailureMessage(msg);
|
pValidationInfo->SetFailureMessage(msg);
|
||||||
}
|
}
|
||||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||||
@@ -536,19 +550,29 @@ bool NumericValidation( const wxPGProperty* property,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(wxLongLong_t) && wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
|
bool wxIntProperty::DoValidation( const wxPGProperty* property,
|
||||||
|
wxLongLong& value,
|
||||||
|
wxPGValidationInfo* pValidationInfo,
|
||||||
|
int mode )
|
||||||
|
{
|
||||||
|
return NumericValidation<wxLongLong>(property,
|
||||||
|
value,
|
||||||
|
pValidationInfo,
|
||||||
|
mode, wxLongLong(LLONG_MIN), wxLongLong(LLONG_MAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(wxLongLong_t)
|
||||||
bool wxIntProperty::DoValidation( const wxPGProperty* property,
|
bool wxIntProperty::DoValidation( const wxPGProperty* property,
|
||||||
wxLongLong_t& value,
|
wxLongLong_t& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
int mode )
|
int mode )
|
||||||
{
|
{
|
||||||
return NumericValidation<wxLongLong_t>(property,
|
wxLongLong llval(value);
|
||||||
value,
|
return DoValidation(property, llval, pValidationInfo, mode);
|
||||||
pValidationInfo,
|
|
||||||
mode, LLONG_MIN, LLONG_MAX,
|
|
||||||
wxS("%") wxS(wxLongLongFmtSpec) wxS("d"));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif // wxLongLong_t
|
||||||
|
#endif // wxUSE_LONGLONG
|
||||||
|
|
||||||
bool wxIntProperty::DoValidation(const wxPGProperty* property,
|
bool wxIntProperty::DoValidation(const wxPGProperty* property,
|
||||||
long& value,
|
long& value,
|
||||||
@@ -556,14 +580,14 @@ bool wxIntProperty::DoValidation(const wxPGProperty* property,
|
|||||||
int mode)
|
int mode)
|
||||||
{
|
{
|
||||||
return NumericValidation<long>(property, value, pValidationInfo,
|
return NumericValidation<long>(property, value, pValidationInfo,
|
||||||
mode, LONG_MIN, LONG_MAX, wxS("%ld"));
|
mode, LONG_MIN, LONG_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxIntProperty::ValidateValue( wxVariant& value,
|
bool wxIntProperty::ValidateValue( wxVariant& value,
|
||||||
wxPGValidationInfo& validationInfo ) const
|
wxPGValidationInfo& validationInfo ) const
|
||||||
{
|
{
|
||||||
#if defined(wxLongLong_t) && wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
wxLongLong_t ll = value.GetLongLong().GetValue();
|
wxLongLong ll = value.GetLongLong();
|
||||||
#else
|
#else
|
||||||
long ll = value.GetLong();
|
long ll = value.GetLong();
|
||||||
#endif
|
#endif
|
||||||
@@ -772,17 +796,27 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(wxULongLong_t) && wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
|
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
||||||
|
wxULongLong& value,
|
||||||
|
wxPGValidationInfo* pValidationInfo,
|
||||||
|
int mode )
|
||||||
|
{
|
||||||
|
return NumericValidation<wxULongLong>(property, value, pValidationInfo,
|
||||||
|
mode, wxULongLong(0), wxULongLong(ULLONG_MAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(wxULongLong_t)
|
||||||
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
||||||
wxULongLong_t& value,
|
wxULongLong_t& value,
|
||||||
wxPGValidationInfo* pValidationInfo,
|
wxPGValidationInfo* pValidationInfo,
|
||||||
int mode )
|
int mode )
|
||||||
{
|
{
|
||||||
return NumericValidation<wxULongLong_t>(property, value, pValidationInfo,
|
wxULongLong ullval(value);
|
||||||
mode, 0, ULLONG_MAX,
|
return DoValidation(property, ullval, pValidationInfo, mode);
|
||||||
wxS("%") wxS(wxLongLongFmtSpec) wxS("u"));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif // wxULongLong_t
|
||||||
|
#endif // wxUSE_LONGLONG
|
||||||
|
|
||||||
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
||||||
long& value,
|
long& value,
|
||||||
@@ -790,13 +824,13 @@ bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
|||||||
int mode)
|
int mode)
|
||||||
{
|
{
|
||||||
return NumericValidation<long>(property, value, pValidationInfo,
|
return NumericValidation<long>(property, value, pValidationInfo,
|
||||||
mode, 0, ULONG_MAX, wxS("%ld"));
|
mode, 0, ULONG_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
|
bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
|
||||||
{
|
{
|
||||||
#if defined(wxULongLong_t) && wxUSE_LONGLONG
|
#if wxUSE_LONGLONG
|
||||||
wxULongLong_t uul = value.GetULongLong().GetValue();
|
wxULongLong uul = value.GetULongLong();
|
||||||
#else
|
#else
|
||||||
long uul = value.GetLong();
|
long uul = value.GetLong();
|
||||||
#endif
|
#endif
|
||||||
@@ -986,8 +1020,7 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property,
|
|||||||
return NumericValidation<double>(property,
|
return NumericValidation<double>(property,
|
||||||
value,
|
value,
|
||||||
pValidationInfo,
|
pValidationInfo,
|
||||||
mode, DBL_MIN, DBL_MAX,
|
mode, DBL_MIN, DBL_MAX);
|
||||||
wxS("%g"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
Reference in New Issue
Block a user