cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatorfilesize.h
1/*
2 * SPDX-FileCopyrightText: (C) 2018-2023 Matthias Fehring <mf@huessenbergnetz.de>
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef CUTELYSTVALIDATORFILESIZE_H
7#define CUTELYSTVALIDATORFILESIZE_H
8
9#include "validatorrule.h"
10
11#include <Cutelyst/cutelyst_global.h>
12
13#include <QLocale>
14
15namespace Cutelyst {
16
17class ValidatorFileSizePrivate;
18
61class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorFileSize : public ValidatorRule
62{
63public:
67 enum Option : quint8 {
68 NoOption = 0,
69 OnlyBinary = 1,
70 OnlyDecimal = 2,
71 ForceBinary = 3,
73 ForceDecimal = 4
75 };
76
92 ValidatorFileSize(const QString &field,
93 Option option = NoOption,
94 const QVariant &min = QVariant(),
95 const QVariant &max = QVariant(),
96 const ValidatorMessages &messages = ValidatorMessages(),
97 const QString &defValKey = QString());
98
103
118 static bool validate(const QString &value,
119 double min = -1,
120 double max = -1,
121 Option option = NoOption,
122 const QLocale &locale = QLocale(),
123 double *fileSize = nullptr);
124
137 static void inputPattern(Context *c,
138 const QString &stashKey = QStringLiteral("fileSizePattern"));
139
140protected:
147 ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
148
152 QString genericValidationError(Context *c,
153 const QVariant &errorData = QVariant()) const override;
154
158 QString genericValidationDataError(Context *c, const QVariant &errorData) const override;
159
160private:
161 Q_DECLARE_PRIVATE(ValidatorFileSize) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
162 Q_DISABLE_COPY(ValidatorFileSize)
163};
164
165} // namespace Cutelyst
166
167#endif // CUTELYSTVALIDATORFILESIZE_H
The Cutelyst Context.
Definition context.h:42
Checks if the input field contains a valid file size string like 1.5 GB.
~ValidatorFileSize() override
Deconstructs the file size validator.
Option
Options for ValidatorFileSize.
Base class for all validator rules.
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.