Version: 3.0.2
wxFloatingPointValidator< T > Class Template Reference

#include <wx/valnum.h>

+ Inheritance diagram for wxFloatingPointValidator< T >:

Detailed Description

template<typename T>
class wxFloatingPointValidator< T >

Validator for text entries used for floating point numbers entry.

This validator can be used with wxTextCtrl or wxComboBox (and potentially any other class implementing wxTextEntry interface) to check that only valid floating point values can be entered into them. Currently only fixed format is supported on input, i.e. scientific format with mantissa and exponent is not supported.

This template class can be instantiated for either float or double, long double values are not currently supported.

Similarly to wxIntegerValidator<>, the range for the accepted values is by default set appropriately for the type. Additionally, this validator allows to specify the maximum number of digits that can be entered after the decimal separator. By default this is also set appropriately for the type used, e.g. 6 for float and 15 for double on a typical IEEE-754-based implementation. As with the range, the precision can be restricted after the validator creation if necessary.

When the validator displays numbers with decimal or thousands separators, the characters used for the separators (usually "." or ",") depend on the locale set with wxLocale (note that you shouldn't change locale with setlocale() as this can result in a mismatch between the separators used by wxLocale and the one used by the run-time library).

A simple example of using this class:

class MyDialog : public wxDialog
{
public:
MyDialog()
{
...
// Allow floating point numbers from 0 to 100 with 2 decimal
// digits only and handle empty string as 0 by default.
val(2, &m_value, wxNUM_VAL_ZERO_AS_BLANK);
val.SetRange(0, 100);
// Associate it with the text control:
new wxTextCtrl(this, ..., val);
}
private:
float m_value;
};

For more information, please see wxValidator Overview.

Library:  wxCore
Category:  Validators
See Also
wxValidator Overview, wxValidator, wxGenericValidator, wxTextValidator, wxMakeIntegerValidator()
Since
2.9.2

Public Types

typedef T ValueType
 Type of the values this validator is used with.
 
- Public Types inherited from wxNumValidator< T >
typedef T ValueType
 Type of the values this validator is used with.
 

Public Member Functions

 wxFloatingPointValidator (ValueType *value=NULL, int style=wxNUM_VAL_DEFAULT)
 Constructor for validator using the default precision.
 
 wxFloatingPointValidator (int precision, ValueType *value=NULL, int style=wxNUM_VAL_DEFAULT)
 Constructor for validator specifying the precision.
 
void SetPrecision (unsigned precision)
 Set precision.
 
- Public Member Functions inherited from wxNumValidator< T >
void SetMin (ValueType min)
 Sets the minimal value accepted by the validator.
 
void SetMax (ValueType max)
 Sets the maximal value accepted by the validator.
 
void SetRange (ValueType min, ValueType max)
 Sets both minimal and maximal values accepted by the validator.
 
void SetStyle (int style)
 Change the validator style.
 
virtual bool TransferToWindow ()
 Override base class method to format the control contents.
 
virtual bool TransferFromWindow ()
 Override base class method to validate the control contents.
 
- Public Member Functions inherited from wxValidator
 wxValidator ()
 Constructor.
 
virtual ~wxValidator ()
 Destructor.
 
virtual wxObjectClone () const
 All validator classes must implement the Clone() function, which returns an identical copy of itself.
 
wxWindowGetWindow () const
 Returns the window associated with the validator.
 
void SetWindow (wxWindow *window)
 Associates a window with the validator.
 
virtual bool Validate (wxWindow *parent)
 This overridable function is called when the value in the associated window must be validated.
 
- Public Member Functions inherited from wxEvtHandler
 wxEvtHandler ()
 Constructor.
 
virtual ~wxEvtHandler ()
 Destructor.
 
virtual void QueueEvent (wxEvent *event)
 Queue event for a later processing.
 
virtual void AddPendingEvent (const wxEvent &event)
 Post an event to be processed later.
 
template<typename T , typename T1 , ... >
void CallAfter (void(T::*method)(T1,...), T1 x1,...)
 Asynchronously call the given method.
 
template<typename T >
void CallAfter (const T &functor)
 Asynchronously call the given functor.
 
virtual bool ProcessEvent (wxEvent &event)
 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
 
bool ProcessEventLocally (wxEvent &event)
 Try to process the event in this handler and all those chained to it.
 
bool SafelyProcessEvent (wxEvent &event)
 Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process.
 
void ProcessPendingEvents ()
 Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail.
 
void DeletePendingEvents ()
 Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent().
 
virtual bool SearchEventTable (wxEventTable &table, wxEvent &event)
 Searches the event table, executing an event handler function if an appropriate one is found.
 
void Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 Connects the given function dynamically with the event handler, id and event type.
 
void Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
void Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
bool Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
 
bool Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
bool Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
template<typename EventTag , typename Functor >
void Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 Binds the given function, functor or method dynamically with the event.
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
void Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
 
template<typename EventTag , typename Functor >
bool Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
bool Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
 
void * GetClientData () const
 Returns user-supplied client data.
 
wxClientDataGetClientObject () const
 Returns a pointer to the user-supplied client data object.
 
void SetClientData (void *data)
 Sets user-supplied client data.
 
void SetClientObject (wxClientData *data)
 Set the client data object.
 
bool GetEvtHandlerEnabled () const
 Returns true if the event handler is enabled, false otherwise.
 
wxEvtHandlerGetNextHandler () const
 Returns the pointer to the next handler in the chain.
 
wxEvtHandlerGetPreviousHandler () const
 Returns the pointer to the previous handler in the chain.
 
void SetEvtHandlerEnabled (bool enabled)
 Enables or disables the event handler.
 
virtual void SetNextHandler (wxEvtHandler *handler)
 Sets the pointer to the next handler.
 
virtual void SetPreviousHandler (wxEvtHandler *handler)
 Sets the pointer to the previous handler.
 
void Unlink ()
 Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted).
 
bool IsUnlinked () const
 Returns true if the next and the previous handler pointers of this event handler instance are NULL.
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data.
 
 wxObject (const wxObject &other)
 Copy ctor.
 
virtual ~wxObject ()
 Destructor.
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class.
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj.
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone.
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer.
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data.
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public.
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 

Additional Inherited Members

- Static Public Member Functions inherited from wxValidator
static void SuppressBellOnError (bool suppress=true)
 This functions switches on or turns off the error sound produced by the validators if an invalid key is pressed.
 
static bool IsSilent ()
 Returns if the error sound is currently disabled.
 
- Protected Member Functions inherited from wxEvtHandler
virtual bool TryBefore (wxEvent &event)
 Method called by ProcessEvent() before examining this object event tables.
 
virtual bool TryAfter (wxEvent &event)
 Method called by ProcessEvent() as last resort.
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data.
 

Member Typedef Documentation

template<typename T>
typedef T wxFloatingPointValidator< T >::ValueType

Type of the values this validator is used with.

Constructor & Destructor Documentation

template<typename T>
wxFloatingPointValidator< T >::wxFloatingPointValidator ( ValueType value = NULL,
int  style = wxNUM_VAL_DEFAULT 
)

Constructor for validator using the default precision.

Parameters
valueA pointer to the variable associated with the validator. If non NULL, this variable should have a lifetime equal to or longer than the validator lifetime (which is usually determined by the lifetime of the window).
styleA combination of wxNumValidatorStyle enum values.
template<typename T>
wxFloatingPointValidator< T >::wxFloatingPointValidator ( int  precision,
ValueType value = NULL,
int  style = wxNUM_VAL_DEFAULT 
)

Constructor for validator specifying the precision.

Parameters
valueA pointer to the variable associated with the validator. If non NULL, this variable should have a lifetime equal to or longer than the validator lifetime (which is usually determined by the lifetime of the window).
styleA combination of wxNumValidatorStyle enum values.
precisionThe number of decimal digits after the decimal separator to show and accept.

Member Function Documentation

template<typename T>
void wxFloatingPointValidator< T >::SetPrecision ( unsigned  precision)

Set precision.

Precision is the number of digits shown (and accepted on input) after the decimal point. By default this is set to the maximal precision supported by the type handled by the validator in its constructor.