Perceptual Color

extendeddoublevalidator.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef EXTENDEDDOUBLEVALIDATOR_H
5#define EXTENDEDDOUBLEVALIDATOR_H
6
7#include "constpropagatinguniquepointer.h"
8#include <qglobal.h>
9#include <qstring.h>
10#include <qvalidator.h>
11class QObject;
12
13#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
14#include <qtmetamacros.h>
15#else
16#include <qobjectdefs.h>
17#endif
18
19namespace PerceptualColor
20{
21class ExtendedDoubleValidatorPrivate;
22
23/** @internal
24 *
25 * @brief The @ref ExtendedDoubleValidator class provides range checking
26 * of floating-point numbers with support for prefix and/or suffix.
27 *
28 * This class behaves exactly like its base class <tt>QDoubleValidator</tt>
29 * with the difference that is allows to specify prefixes and/or suffixed
30 * that are considered by @ref validate(). */
31class ExtendedDoubleValidator : public QDoubleValidator
32{
34
35 /** @brief The prefix of the number.
36 *
37 * @sa @ref prefix()
38 * @sa @ref setPrefix()
39 * @sa @ref prefixChanged()
40 * @sa @ref ExtendedDoubleValidatorPrivate::m_prefix */
41 Q_PROPERTY(QString prefix READ prefix WRITE setPrefix NOTIFY prefixChanged)
42
43 /** @brief The suffix of the number.
44 *
45 * @sa @ref suffix()
46 * @sa @ref setSuffix()
47 * @sa @ref suffixChanged()
48 * @sa @ref ExtendedDoubleValidatorPrivate::m_suffix */
49 Q_PROPERTY(QString suffix READ suffix WRITE setSuffix NOTIFY suffixChanged)
50
51public:
52 Q_INVOKABLE explicit ExtendedDoubleValidator(QObject *parent = nullptr);
53 virtual ~ExtendedDoubleValidator() noexcept override;
54 /** @brief Getter for property @ref prefix
55 * @returns the property @ref prefix */
56 [[nodiscard]] QString prefix() const;
57 /** @brief Getter for property @ref suffix
58 * @returns the property @ref suffix */
59 [[nodiscard]] QString suffix() const;
60 /** @brief Validate input.
61 *
62 * @param input the input string
63 * @param pos the cursor position
64 * @returns
65 * - An input that does not contain the @ref prefix() and @ref suffix()
66 * (if these are not empty) is always invalid.
67 * - If an input contains correct prefix and suffix, the floating point
68 * portion is validated as <tt>QDoubleValidator</tt> does and
69 * the corresponding result is returned. */
70 [[nodiscard]] virtual QValidator::State validate(QString &input, int &pos) const override;
71
72public Q_SLOTS:
73 void setPrefix(const QString &prefix);
74 void setSuffix(const QString &suffix);
75
77 /** @brief Notify signal for property @ref prefix.
78 *
79 * @param prefix the new prefix */
80 void prefixChanged(const QString &prefix);
81 /** @brief Notify signal for property @ref suffix.
82 *
83 * @param suffix the new suffix */
84 void suffixChanged(const QString &suffix);
85
86private:
87 Q_DISABLE_COPY(ExtendedDoubleValidator)
88
89 /** @internal
90 *
91 * @brief Declare the private implementation as friend class.
92 *
93 * This allows the private class to access the protected members and
94 * functions of instances of <em>this</em> class. */
95 friend class ExtendedDoubleValidatorPrivate;
96 /** @brief Pointer to implementation (pimpl) */
97 ConstPropagatingUniquePointer<ExtendedDoubleValidatorPrivate> d_pointer;
98
99 /** @internal @brief Only for unit tests. */
100 friend class TestExtendedDoubleValidator;
101};
102
103} // namespace PerceptualColor
104
105#endif // EXTENDEDDOUBLEVALIDATOR_H
The namespace of this library.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.