NDEVR
API Documentation
QCustomValidator

Responsible on most user input fields for correcting the input when possible or allerting the user that the input is incorrect. More...

Classes

struct  InvalidProperties
 Contains the result of a validation check, including the validity state, a suggested fix-up message, and an optional character range. More...

Public Types

enum  ValidityMessage {
  e_is_valid , e_unexpected_format , e_value_is_not_a_real_number , e_too_many_decimals ,
  e_value_too_high , e_value_too_low , e_value_is_empty , e_string_is_too_long ,
  e_string_is_too_short , e_file_exists
}
 Describes the type of validation failure encountered during input checking. More...

Public Member Functions

 QCustomValidator (const QCustomValidator &validator)
 Copy constructor.
 QCustomValidator (const TypeInfo &info, QObject *parent=nullptr)
 Constructs a validator configured for the specified type info.
 QCustomValidator (QObject *parent=nullptr)
 Constructs a validator with default settings.
void clearNumberOfDecimals ()
 Clears the decimal place limit, allowing any number of decimals.
void fixup (QString &input) const override
 Fixes up a Qt string input by correcting or clamping invalid values.
void fixup (StringAllocatingView &input) const
 Fixes up an NDEVR string input by correcting or clamping invalid values.
void fixup (StringAllocatingView &input, bool to_unit, bool from_unit=true) const
 Fixes up an NDEVR string input with optional unit conversion.
fltp08 getMax () const
 Returns the maximum allowed numeric value.
TranslatedString getMessageString (ValidityMessage message)
 Returns a user-facing translated message for the given validity state.
fltp08 getMin () const
 Returns the minimum allowed numeric value.
InvalidProperties getValidity (const StringView &input) const
 Returns detailed validity information for the given input string.
fltp08 max () const
 Returns the maximum allowed numeric value.
fltp08 min () const
 Returns the minimum allowed numeric value.
const QCustomValidatoroperator= (const QCustomValidator &other)
 Assignment operator.
const Stringregex () const
 Returns the regular expression pattern for validation.
void setAllowEmpty (bool allow_empty)
 Sets whether an empty input is considered valid.
void setAllowNewline (bool allow_newline)
 Sets whether newline characters are allowed in the input.
void setAllowWrapping (bool allow_wrapping)
 Sets whether values are allowed to wrap from max to min and vice versa.
void setCustomCallback (const std::function< ValidityMessage(const StringView &)> &callback)
 Sets a custom validation callback that returns a ValidityMessage for the input.
template<class t_angle_type>
void setMax (Angle< t_angle_type > max)
 Sets the maximum allowed value from an angle type, converting to internal units.
void setMax (fltp08 max)
 Sets the maximum allowed numeric value.
template<class t_angle_type>
void setMin (Angle< t_angle_type > min)
 Sets the minimum allowed value from an angle type, converting to internal units.
void setMin (fltp08 min)
 Sets the minimum allowed numeric value.
void setNumberOfDecimals (uint04 decimals)
 Sets the maximum number of allowed decimal places.
void setRegex (const StringView &regex)
 Sets a regular expression pattern that the input must match.
void setStep (fltp08 step)
 Sets the step increment used for value adjustment (e.g., spin box arrows).
void setTypeInfo (const TypeInfo &info)
 Sets the type information used to configure validation rules.
void setUnitType (UnitCategory type)
 Sets the unit category type used for unit validation.
void setUnitValidator (const ConstPointer< Unit > &unit, uint01 dimension=Constant< uint01 >::Invalid)
 Sets the unit used for converting between display and internal values.
fltp08 step () const
 Returns the step increment value.
const TypeInfotypeInfo () const
 Returns the type information used by this validator.
const ConstPointer< Unit > & unit () const
 Returns the unit used for validation and conversion.
uint01 unitDimension () const
 Returns the unit dimension index used for multi-dimensional unit conversions.
const UnitCategoryunitType () const
 Returns the unit category type.
QValidator::State validate (QString &input, int &pos) const override
 Validates a Qt string input and returns the validation state.

Detailed Description

Responsible on most user input fields for correcting the input when possible or allerting the user that the input is incorrect.


Used on all QCustomLineEdit widgets and derivatives.

Definition at line 48 of file QCustomValidator.h.

Member Enumeration Documentation

◆ ValidityMessage

Describes the type of validation failure encountered during input checking.

Enumerator
e_is_valid 

The input is valid.

e_unexpected_format 

The input has an unexpected format.

e_value_is_not_a_real_number 

The input is not a valid real number.

e_too_many_decimals 

The input has more decimal places than allowed.

e_value_too_high 

The input value exceeds the maximum.

e_value_too_low 

The input value is below the minimum.

e_value_is_empty 

The input is empty when not allowed.

e_string_is_too_long 

The input string exceeds the maximum length.

e_string_is_too_short 

The input string is shorter than the minimum length.

e_file_exists 

The input refers to a file that already exists.

Definition at line 55 of file QCustomValidator.h.

Constructor & Destructor Documentation

◆ QCustomValidator() [1/3]

QCustomValidator::QCustomValidator ( QObject * parent = nullptr)
explicit

Constructs a validator with default settings.

Parameters
[in]parentThe parent QObject, or nullptr.

Referenced by QCustomValidator(), and operator=().

◆ QCustomValidator() [2/3]

QCustomValidator::QCustomValidator ( const TypeInfo & info,
QObject * parent = nullptr )
explicit

Constructs a validator configured for the specified type info.

Parameters
[in]infoThe type information used to configure validation rules.
[in]parentThe parent QObject, or nullptr.

◆ QCustomValidator() [3/3]

QCustomValidator::QCustomValidator ( const QCustomValidator & validator)

Copy constructor.

Parameters
[in]validatorThe validator to copy from.

References QCustomValidator().

Member Function Documentation

◆ fixup() [1/3]

void QCustomValidator::fixup ( QString & input) const
override

Fixes up a Qt string input by correcting or clamping invalid values.

Parameters
[in]inputThe string to fix up, modified in place.

◆ fixup() [2/3]

void QCustomValidator::fixup ( StringAllocatingView & input) const

Fixes up an NDEVR string input by correcting or clamping invalid values.

Parameters
[in]inputThe string to fix up, modified in place.

◆ fixup() [3/3]

void QCustomValidator::fixup ( StringAllocatingView & input,
bool to_unit,
bool from_unit = true ) const

Fixes up an NDEVR string input with optional unit conversion.

Parameters
[in]inputThe string to fix up, modified in place.
[in]to_unitWhether to convert the result to the display unit.
[in]from_unitWhether to convert the input from the display unit first.

◆ getMax()

fltp08 QCustomValidator::getMax ( ) const
inline

Returns the maximum allowed numeric value.

Returns
The maximum value.

Definition at line 189 of file QCustomValidator.h.

◆ getMessageString()

TranslatedString QCustomValidator::getMessageString ( ValidityMessage message)

Returns a user-facing translated message for the given validity state.

Parameters
[in]messageThe validity message to translate.
Returns
The translated message string.

◆ getMin()

fltp08 QCustomValidator::getMin ( ) const
inline

Returns the minimum allowed numeric value.

Returns
The minimum value.

Definition at line 194 of file QCustomValidator.h.

◆ getValidity()

InvalidProperties QCustomValidator::getValidity ( const StringView & input) const

Returns detailed validity information for the given input string.

Parameters
[in]inputThe string to check.
Returns
An InvalidProperties struct describing the validity state.

◆ max()

fltp08 QCustomValidator::max ( ) const
inlinenodiscard

Returns the maximum allowed numeric value.

Returns
The maximum value.

Definition at line 211 of file QCustomValidator.h.

Referenced by setMax(), and setMax().

◆ min()

fltp08 QCustomValidator::min ( ) const
inlinenodiscard

Returns the minimum allowed numeric value.

Returns
The minimum value.

Definition at line 216 of file QCustomValidator.h.

Referenced by setMin(), and setMin().

◆ operator=()

const QCustomValidator & QCustomValidator::operator= ( const QCustomValidator & other)

Assignment operator.

Parameters
[in]otherThe validator to copy from.
Returns
A const reference to this validator.

References QCustomValidator().

◆ regex()

const String & QCustomValidator::regex ( ) const
inlinenodiscard

Returns the regular expression pattern for validation.

Returns
A reference to the regex pattern string.

Definition at line 236 of file QCustomValidator.h.

Referenced by setRegex().

◆ setAllowEmpty()

void QCustomValidator::setAllowEmpty ( bool allow_empty)
inline

Sets whether an empty input is considered valid.

Parameters
[in]allow_emptyTrue to allow empty input, false to require a value.

Definition at line 169 of file QCustomValidator.h.

◆ setAllowNewline()

void QCustomValidator::setAllowNewline ( bool allow_newline)
inline

Sets whether newline characters are allowed in the input.

Parameters
[in]allow_newlineTrue to allow newlines, false to reject them.

Definition at line 174 of file QCustomValidator.h.

◆ setAllowWrapping()

void QCustomValidator::setAllowWrapping ( bool allow_wrapping)
inline

Sets whether values are allowed to wrap from max to min and vice versa.

Parameters
[in]allow_wrappingTrue to allow wrapping, false to clamp.

Definition at line 164 of file QCustomValidator.h.

◆ setCustomCallback()

void QCustomValidator::setCustomCallback ( const std::function< ValidityMessage(const StringView &)> & callback)
inline

Sets a custom validation callback that returns a ValidityMessage for the input.

Parameters
[in]callbackThe custom validation function.

Definition at line 159 of file QCustomValidator.h.

◆ setMax() [1/2]

template<class t_angle_type>
void QCustomValidator::setMax ( Angle< t_angle_type > max)
inline

Sets the maximum allowed value from an angle type, converting to internal units.

Parameters
[in]maxThe maximum angle value.

Definition at line 200 of file QCustomValidator.h.

References max().

◆ setMax() [2/2]

void QCustomValidator::setMax ( fltp08 max)
inline

Sets the maximum allowed numeric value.

Parameters
[in]maxThe maximum value.

Definition at line 179 of file QCustomValidator.h.

References max().

◆ setMin() [1/2]

template<class t_angle_type>
void QCustomValidator::setMin ( Angle< t_angle_type > min)
inline

Sets the minimum allowed value from an angle type, converting to internal units.

Parameters
[in]minThe minimum angle value.

Definition at line 206 of file QCustomValidator.h.

References min().

◆ setMin() [2/2]

void QCustomValidator::setMin ( fltp08 min)
inline

Sets the minimum allowed numeric value.

Parameters
[in]minThe minimum value.

Definition at line 184 of file QCustomValidator.h.

References min().

◆ setNumberOfDecimals()

void QCustomValidator::setNumberOfDecimals ( uint04 decimals)
inline

Sets the maximum number of allowed decimal places.

Parameters
[in]decimalsThe number of decimal places allowed.

Definition at line 144 of file QCustomValidator.h.

◆ setRegex()

void QCustomValidator::setRegex ( const StringView & regex)

Sets a regular expression pattern that the input must match.

Parameters
[in]regexThe regex pattern string.

References regex().

Referenced by DesignObjectComboWidget::setNDPO().

◆ setStep()

void QCustomValidator::setStep ( fltp08 step)
inline

Sets the step increment used for value adjustment (e.g., spin box arrows).

Parameters
[in]stepThe step increment value.

Definition at line 221 of file QCustomValidator.h.

References step().

◆ setTypeInfo()

void QCustomValidator::setTypeInfo ( const TypeInfo & info)
inline

Sets the type information used to configure validation rules.

Parameters
[in]infoThe type information.

Definition at line 262 of file QCustomValidator.h.

◆ setUnitType()

void QCustomValidator::setUnitType ( UnitCategory type)

Sets the unit category type used for unit validation.

Parameters
[in]typeThe unit category.

◆ setUnitValidator()

void QCustomValidator::setUnitValidator ( const ConstPointer< Unit > & unit,
uint01 dimension = Constantuint01 >::Invalid )

Sets the unit used for converting between display and internal values.

Parameters
[in]unitThe unit to use for validation and conversion.
[in]dimensionThe unit dimension index, or Invalid for default.

References unit().

◆ step()

fltp08 QCustomValidator::step ( ) const
nodiscard

Returns the step increment value.

Returns
The step increment.

Referenced by setStep().

◆ typeInfo()

const TypeInfo & QCustomValidator::typeInfo ( ) const
inlinenodiscard

Returns the type information used by this validator.

Returns
A const reference to the type info.

Definition at line 267 of file QCustomValidator.h.

◆ unit()

const ConstPointer< Unit > & QCustomValidator::unit ( ) const
inlinenodiscard

Returns the unit used for validation and conversion.

Returns
A const reference to the unit pointer.

Definition at line 252 of file QCustomValidator.h.

Referenced by setUnitValidator().

◆ unitDimension()

uint01 QCustomValidator::unitDimension ( ) const
inlinenodiscard

Returns the unit dimension index used for multi-dimensional unit conversions.

Returns
The dimension index.

Definition at line 272 of file QCustomValidator.h.

◆ unitType()

const UnitCategory & QCustomValidator::unitType ( ) const
inlinenodiscard

Returns the unit category type.

Returns
A const reference to the unit category.

Definition at line 257 of file QCustomValidator.h.

◆ validate()

QValidator::State QCustomValidator::validate ( QString & input,
int & pos ) const
override

Validates a Qt string input and returns the validation state.

Parameters
[in]inputThe string to validate.
[in]posThe cursor position, updated if the input is modified.
Returns
The QValidator::State (Acceptable, Intermediate, or Invalid).

The documentation for this class was generated from the following file: