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:
parent
6e97a2cbf2
commit
c3fa684a27
@ -242,13 +242,21 @@ public:
|
||||
|
||||
/** 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,
|
||||
wxLongLong_t& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
int mode =
|
||||
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
|
||||
#endif
|
||||
#endif // wxLongLong_t
|
||||
#endif // wxUSE_LONGLONG
|
||||
static bool DoValidation(const wxPGProperty* property,
|
||||
long& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
@ -311,12 +319,18 @@ private:
|
||||
void Init();
|
||||
|
||||
// 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,
|
||||
wxULongLong_t& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
|
||||
#endif
|
||||
#endif // wxULongLong_t
|
||||
#endif // wxUSE_LONGLONG
|
||||
static bool DoValidation(const wxPGProperty* property,
|
||||
long& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
|
@ -352,8 +352,7 @@ template<typename T>
|
||||
bool NumericValidation( const wxPGProperty* property,
|
||||
T& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
int mode, T defMin, T defMax,
|
||||
const wxString& strFmt )
|
||||
int mode, T defMin, T defMax)
|
||||
{
|
||||
T min = defMin;
|
||||
T max = defMax;
|
||||
@ -380,16 +379,20 @@ bool NumericValidation( const wxPGProperty* property,
|
||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||
{
|
||||
wxString msg;
|
||||
wxString smin = wxString::Format(strFmt, min);
|
||||
wxString smax = wxString::Format(strFmt, max);
|
||||
wxVariant vmin = WXVARIANT(min);
|
||||
wxString smin = property->ValueToString(vmin);
|
||||
if ( !maxOk )
|
||||
msg = wxString::Format(
|
||||
_("Value must be %s or higher."),
|
||||
smin.c_str());
|
||||
else
|
||||
{
|
||||
wxVariant vmax = WXVARIANT(max);
|
||||
wxString smax = property->ValueToString(vmax);
|
||||
msg = wxString::Format(
|
||||
_("Value must be between %s and %s."),
|
||||
smin.c_str(), smax.c_str());
|
||||
}
|
||||
pValidationInfo->SetFailureMessage(msg);
|
||||
}
|
||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||
@ -407,16 +410,20 @@ bool NumericValidation( const wxPGProperty* property,
|
||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||
{
|
||||
wxString msg;
|
||||
wxString smin = wxString::Format(strFmt, min);
|
||||
wxString smax = wxString::Format(strFmt, max);
|
||||
wxVariant vmax = WXVARIANT(max);
|
||||
wxString smax = property->ValueToString(vmax);
|
||||
if ( !minOk )
|
||||
msg = wxString::Format(
|
||||
_("Value must be %s or less."),
|
||||
smax.c_str());
|
||||
else
|
||||
{
|
||||
wxVariant vmin = WXVARIANT(min);
|
||||
wxString smin = property->ValueToString(vmin);
|
||||
msg = wxString::Format(
|
||||
_("Value must be between %s and %s."),
|
||||
smin.c_str(), smax.c_str());
|
||||
}
|
||||
pValidationInfo->SetFailureMessage(msg);
|
||||
}
|
||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||
@ -436,8 +443,7 @@ template<>
|
||||
bool NumericValidation( const wxPGProperty* property,
|
||||
double& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
int mode, double defMin, double defMax,
|
||||
const wxString& strFmt )
|
||||
int mode, double defMin, double defMax)
|
||||
{
|
||||
double min = defMin;
|
||||
double max = defMax;
|
||||
@ -487,16 +493,20 @@ bool NumericValidation( const wxPGProperty* property,
|
||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||
{
|
||||
wxString msg;
|
||||
wxString smin = wxString::Format(strFmt, min);
|
||||
wxString smax = wxString::Format(strFmt, max);
|
||||
wxVariant vmin = WXVARIANT(min);
|
||||
wxString smin = property->ValueToString(vmin);
|
||||
if ( !maxOk )
|
||||
msg = wxString::Format(
|
||||
_("Value must be %s or higher."),
|
||||
smin.c_str());
|
||||
else
|
||||
{
|
||||
wxVariant vmax = WXVARIANT(max);
|
||||
wxString smax = property->ValueToString(vmax);
|
||||
msg = wxString::Format(
|
||||
_("Value must be between %s and %s."),
|
||||
smin.c_str(), smax.c_str());
|
||||
}
|
||||
pValidationInfo->SetFailureMessage(msg);
|
||||
}
|
||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||
@ -514,16 +524,20 @@ bool NumericValidation( const wxPGProperty* property,
|
||||
if ( mode == wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE )
|
||||
{
|
||||
wxString msg;
|
||||
wxString smin = wxString::Format(strFmt, min);
|
||||
wxString smax = wxString::Format(strFmt, max);
|
||||
wxVariant vmax = WXVARIANT(max);
|
||||
wxString smax = property->ValueToString(vmax);
|
||||
if ( !minOk )
|
||||
msg = wxString::Format(
|
||||
_("Value must be %s or less."),
|
||||
smax.c_str());
|
||||
else
|
||||
{
|
||||
wxVariant vmin = WXVARIANT(min);
|
||||
wxString smin = property->ValueToString(vmin);
|
||||
msg = wxString::Format(
|
||||
_("Value must be between %s and %s."),
|
||||
smin.c_str(), smax.c_str());
|
||||
}
|
||||
pValidationInfo->SetFailureMessage(msg);
|
||||
}
|
||||
else if ( mode == wxPG_PROPERTY_VALIDATION_SATURATE )
|
||||
@ -536,19 +550,29 @@ bool NumericValidation( const wxPGProperty* property,
|
||||
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,
|
||||
wxLongLong_t& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
int mode )
|
||||
{
|
||||
return NumericValidation<wxLongLong_t>(property,
|
||||
value,
|
||||
pValidationInfo,
|
||||
mode, LLONG_MIN, LLONG_MAX,
|
||||
wxS("%") wxS(wxLongLongFmtSpec) wxS("d"));
|
||||
wxLongLong llval(value);
|
||||
return DoValidation(property, llval, pValidationInfo, mode);
|
||||
}
|
||||
#endif
|
||||
#endif // wxLongLong_t
|
||||
#endif // wxUSE_LONGLONG
|
||||
|
||||
bool wxIntProperty::DoValidation(const wxPGProperty* property,
|
||||
long& value,
|
||||
@ -556,14 +580,14 @@ bool wxIntProperty::DoValidation(const wxPGProperty* property,
|
||||
int mode)
|
||||
{
|
||||
return NumericValidation<long>(property, value, pValidationInfo,
|
||||
mode, LONG_MIN, LONG_MAX, wxS("%ld"));
|
||||
mode, LONG_MIN, LONG_MAX);
|
||||
}
|
||||
|
||||
bool wxIntProperty::ValidateValue( wxVariant& value,
|
||||
wxPGValidationInfo& validationInfo ) const
|
||||
{
|
||||
#if defined(wxLongLong_t) && wxUSE_LONGLONG
|
||||
wxLongLong_t ll = value.GetLongLong().GetValue();
|
||||
#if wxUSE_LONGLONG
|
||||
wxLongLong ll = value.GetLongLong();
|
||||
#else
|
||||
long ll = value.GetLong();
|
||||
#endif
|
||||
@ -772,17 +796,27 @@ bool wxUIntProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(ar
|
||||
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,
|
||||
wxULongLong_t& value,
|
||||
wxPGValidationInfo* pValidationInfo,
|
||||
int mode )
|
||||
{
|
||||
return NumericValidation<wxULongLong_t>(property, value, pValidationInfo,
|
||||
mode, 0, ULLONG_MAX,
|
||||
wxS("%") wxS(wxLongLongFmtSpec) wxS("u"));
|
||||
wxULongLong ullval(value);
|
||||
return DoValidation(property, ullval, pValidationInfo, mode);
|
||||
}
|
||||
#endif
|
||||
#endif // wxULongLong_t
|
||||
#endif // wxUSE_LONGLONG
|
||||
|
||||
bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
||||
long& value,
|
||||
@ -790,13 +824,13 @@ bool wxUIntProperty::DoValidation(const wxPGProperty* property,
|
||||
int mode)
|
||||
{
|
||||
return NumericValidation<long>(property, value, pValidationInfo,
|
||||
mode, 0, ULONG_MAX, wxS("%ld"));
|
||||
mode, 0, ULONG_MAX);
|
||||
}
|
||||
|
||||
bool wxUIntProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& validationInfo ) const
|
||||
{
|
||||
#if defined(wxULongLong_t) && wxUSE_LONGLONG
|
||||
wxULongLong_t uul = value.GetULongLong().GetValue();
|
||||
#if wxUSE_LONGLONG
|
||||
wxULongLong uul = value.GetULongLong();
|
||||
#else
|
||||
long uul = value.GetLong();
|
||||
#endif
|
||||
@ -986,8 +1020,7 @@ bool wxFloatProperty::DoValidation( const wxPGProperty* property,
|
||||
return NumericValidation<double>(property,
|
||||
value,
|
||||
pValidationInfo,
|
||||
mode, DBL_MIN, DBL_MAX,
|
||||
wxS("%g"));
|
||||
mode, DBL_MIN, DBL_MAX);
|
||||
}
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user