API Documentation
Loading...
Searching...
No Matches
QCustomValidator.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Widgets
28File: QCustomValidator
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Unit.h>
35#include <NDEVR/TypeInfo.h>
36#include <NDEVR/Pointer.h>
37#include <NDEVR/String.h>
38#include <QValidator>
39namespace NDEVR
40{
41 struct Unit;
42 /**--------------------------------------------------------------------------------------------------
43 \brief Responsible on most user input fields for correcting the input when possible or allerting
44 the user that the input is incorrect. Used on all QCustomLineEdit widgets and derivatives.
45 *-----------------------------------------------------------------------------------------------**/
46 class NDEVR_WIDGETS_API QCustomValidator : public QValidator
47 {
48 Q_OBJECT
49 public:
51 {
52 e_is_valid
53 , e_unexpected_format
54 , e_value_is_not_a_real_number
55 , e_too_many_decimals
56 , e_value_too_high
57 , e_value_too_low
58 , e_value_is_empty
59 , e_string_is_too_long
60 , e_string_is_too_short
62 };
63 public:
64 explicit QCustomValidator(QObject *parent = nullptr);
65 explicit QCustomValidator(const TypeInfo& info, QObject *parent = nullptr);
68 void fixup(QString & input) const override;
69 String& fixup(String& input, bool to_unit = true, bool from_unit = true) const;
70 QValidator::State validate(QString& input, int& pos) const override;
71 ValidityMessage getMessage(const String& input) const;
74 {
75 m_number_of_decimals = decimals;
76 }
77 //Return empty string for valid, otherwise error message
78 void setCustomCallback(const std::function<ValidityMessage(const String&)>& callback) { m_custom_validation_step = callback; }
79 void setAllowWrapping(bool allow_wrapping) { m_allow_wrapping = allow_wrapping; }
80 void setAllowEmpty(bool allow_empty) { m_allow_empty = allow_empty; }
81 void setMax(fltp08 max) { m_max = max; }
82 void setMin(fltp08 min) { m_min = min; }
83 template<class t_angle_type>
84 void setMax(Angle<t_angle_type> max) { m_max = max.template as<INTERNAL_ANGLE>(); }
85 template<class t_angle_type>
86 void setMin(Angle<t_angle_type> min) { m_min = min.template as<INTERNAL_ANGLE>(); }
87 [[nodiscard]] fltp08 max() const { return m_max; }
88 [[nodiscard]] fltp08 min() const { return m_min; }
89 void setStep(fltp08 step) { m_step = step; }
90 [[nodiscard]] fltp08 step() const;
91 void setRegex(const String& regex);
92 [[nodiscard]] const String& regex() const { return m_regex; }
95 [[nodiscard]] const ConstPointer<Unit>& unit() const { return m_unit; }
96 [[nodiscard]] const UnitCategory& unitType() const { return m_unit_type; }
97 void setTypeInfo(const TypeInfo& info) { m_type_info = info; }
98 [[nodiscard]] const TypeInfo& typeInfo() const { return m_type_info; }
99 [[nodiscard]] uint01 unitDimension() const { return m_unit_dimension; }
101 private:
102 ConstPointer<Unit> m_unit;
103 UnitCategory m_unit_type;
104 uint01 m_unit_dimension;
105 TypeInfo m_type_info;
106 uint04 m_number_of_decimals;
107 String m_regex;
108 fltp08 m_max;
109 fltp08 m_min;
110 fltp08 m_step;
111 bool m_allow_wrapping;
112 bool m_allow_empty;
113 std::function<ValidityMessage(const String&)> m_custom_validation_step = nullptr;
114 };
115}
#define NDEVR_WIDGETS_API
Definition DLLInfo.h:81
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:408
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition GraphicsPipeline.h:42
Responsible on most user input fields for correcting the input when possible or allerting.
Definition QCustomValidator.h:47
String & fixup(String &input, bool to_unit=true, bool from_unit=true) const
void setRegex(const String &regex)
ValidityMessage getMessage(const String &input) const
void setStep(fltp08 step)
Definition QCustomValidator.h:89
void fixup(QString &input) const override
void setNumberOfDecimals(uint04 decimals)
Definition QCustomValidator.h:73
void setUnitType(UnitCategory type)
const ConstPointer< Unit > & unit() const
Definition QCustomValidator.h:95
void setAllowWrapping(bool allow_wrapping)
Definition QCustomValidator.h:79
uint01 unitDimension() const
Definition QCustomValidator.h:99
void setTypeInfo(const TypeInfo &info)
Definition QCustomValidator.h:97
ValidityMessage
Definition QCustomValidator.h:51
QCustomValidator(const QCustomValidator &validator)
QCustomValidator(QObject *parent=nullptr)
void setMax(fltp08 max)
Definition QCustomValidator.h:81
QValidator::State validate(QString &input, int &pos) const override
const TypeInfo & typeInfo() const
Definition QCustomValidator.h:98
fltp08 min() const
Definition QCustomValidator.h:88
const String & regex() const
Definition QCustomValidator.h:92
fltp08 max() const
Definition QCustomValidator.h:87
void setMin(Angle< t_angle_type > min)
Definition QCustomValidator.h:86
const UnitCategory & unitType() const
Definition QCustomValidator.h:96
void setAllowEmpty(bool allow_empty)
Definition QCustomValidator.h:80
void setCustomCallback(const std::function< ValidityMessage(const String &)> &callback)
Definition QCustomValidator.h:78
void setUnitValidator(const ConstPointer< Unit > &unit, uint01 dimension=Constant< uint01 >::Invalid)
QCustomValidator(const TypeInfo &info, QObject *parent=nullptr)
const QCustomValidator & operator=(const QCustomValidator &other)
void setMax(Angle< t_angle_type > max)
Definition QCustomValidator.h:84
void setMin(fltp08 min)
Definition QCustomValidator.h:82
TranslatedString getMessageString(ValidityMessage message)
The core String class for the software.
Definition String.h:47
Any text displayed to the user should be defined as a TranslatedString which allows the.
Definition TranslatedString.h:13
Stores information about a type, relevant for certain templated functions.
Definition TypeInfo.h:43
Definition ACIColor.h:37
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:78
@ e_file_exists
Definition FileCache.h:13
UnitCategory
A category of unit describing what it relates to. Any category can have some number of units.
Definition Unit.h:14
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:94
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:146
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved.
Definition BaseValues.hpp:230