Implement wxNumericProperty as a base class for all wxPG numeric properties

All numeric properties (wxIntProperty, wxUIntProperty, wxFloatProperty) share some features (like specific attributes, numeric validation, SpinCtrl editor support) so for the sake of clear design it would be good to derive them from the common base class (wxNumericProperty) in which all shared functions are implemented. This class is not intended to be instantiated so it's an abstract class.
This commit is contained in:
Artur Wieczorek
2019-06-28 20:45:04 +02:00
parent bd1b5c4111
commit 69632371e3
6 changed files with 366 additions and 192 deletions

View File

@@ -154,10 +154,35 @@ public:
#endif // wxUSE_VALIDATORS
// Base class for numeric properties.
// Cannot be instantiated directly.
class WXDLLIMPEXP_PROPGRID wxNumericProperty : public wxPGProperty
{
wxDECLARE_ABSTRACT_CLASS(wxNumericProperty);
public:
virtual ~wxNumericProperty();
virtual bool DoSetAttribute(const wxString& name, wxVariant& value) wxOVERRIDE;
virtual wxVariant AddSpinStepValue(long stepScale) const = 0;
wxVariant GetMinVal() const { return m_minVal; }
wxVariant GetMaxVal() const { return m_maxVal; }
bool UseSpinMotion() const { return m_spinMotion; }
protected:
wxNumericProperty(const wxString& label, const wxString& name);
wxVariant m_minVal;
wxVariant m_maxVal;
bool m_spinMotion;
wxVariant m_spinStep;
bool m_spinWrap;
};
// Basic property with integer value.
// Seamlessly supports 64-bit integer (wxLongLong) on overflow.
class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxPGProperty
class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxNumericProperty
{
WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty)
public:
@@ -182,37 +207,36 @@ public:
int argFlags = 0 ) const wxOVERRIDE;
static wxValidator* GetClassValidator();
virtual wxValidator* DoGetValidator() const wxOVERRIDE;
virtual wxVariant AddSpinStepValue(long stepScale) const wxOVERRIDE;
// Validation helpers.
#if wxUSE_LONGLONG
static bool DoValidation( const wxPGProperty* property,
static bool DoValidation( const wxNumericProperty* 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 wxNumericProperty* property,
wxLongLong_t& value,
wxPGValidationInfo* pValidationInfo,
int mode =
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
#endif // wxLongLong_t
#endif // wxUSE_LONGLONG
static bool DoValidation(const wxPGProperty* property,
static bool DoValidation(const wxNumericProperty* property,
long& value,
wxPGValidationInfo* pValidationInfo,
int mode =
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
protected:
};
// -----------------------------------------------------------------------
// Basic property with unsigned integer value.
// Seamlessly supports 64-bit integer (wxULongLong) on overflow.
class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxPGProperty
class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxNumericProperty
{
WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty)
public:
@@ -236,6 +260,7 @@ public:
virtual bool IntToValue( wxVariant& variant,
int number,
int argFlags = 0 ) const wxOVERRIDE;
virtual wxVariant AddSpinStepValue(long stepScale) const wxOVERRIDE;
protected:
wxByte m_base;
@@ -246,18 +271,18 @@ private:
// Validation helpers.
#if wxUSE_LONGLONG
static bool DoValidation(const wxPGProperty* property,
static bool DoValidation(const wxNumericProperty* 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 wxNumericProperty* property,
wxULongLong_t& value,
wxPGValidationInfo* pValidationInfo,
int mode =wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
#endif // wxULongLong_t
#endif // wxUSE_LONGLONG
static bool DoValidation(const wxPGProperty* property,
static bool DoValidation(const wxNumericProperty* property,
long& value,
wxPGValidationInfo* pValidationInfo,
int mode = wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE);
@@ -266,7 +291,7 @@ private:
// -----------------------------------------------------------------------
// Basic property with double-precision floating point value.
class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxPGProperty
class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxNumericProperty
{
WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty)
public:
@@ -285,13 +310,14 @@ public:
wxPGValidationInfo& validationInfo ) const wxOVERRIDE;
// Validation helper.
static bool DoValidation( const wxPGProperty* property,
static bool DoValidation( const wxNumericProperty* property,
double& value,
wxPGValidationInfo* pValidationInfo,
int mode =
wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
static wxValidator* GetClassValidator();
virtual wxValidator* DoGetValidator () const wxOVERRIDE;
virtual wxVariant AddSpinStepValue(long stepScale) const wxOVERRIDE;
protected:
int m_precision;