cutelyst  4.4.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 <QLocale>
12 
13 namespace Cutelyst {
14 
15 class ValidatorFileSizePrivate;
16 
59 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorFileSize : public ValidatorRule
60 {
61 public:
65  enum Option : quint8 {
66  NoOption = 0,
67  OnlyBinary = 1,
68  OnlyDecimal = 2,
69  ForceBinary = 3,
71  ForceDecimal = 4
73  };
74 
90  ValidatorFileSize(const QString &field,
91  Option option = NoOption,
92  const QVariant &min = QVariant(),
93  const QVariant &max = QVariant(),
94  const ValidatorMessages &messages = ValidatorMessages(),
95  const QString &defValKey = QString());
96 
100  ~ValidatorFileSize() override;
101 
116  static bool validate(const QString &value,
117  double min = -1,
118  double max = -1,
119  Option option = NoOption,
120  const QLocale &locale = QLocale(),
121  double *fileSize = nullptr);
122 
135  static void inputPattern(Context *c,
136  const QString &stashKey = QStringLiteral("fileSizePattern"));
137 
138 protected:
145  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
146 
150  QString genericValidationError(Context *c,
151  const QVariant &errorData = QVariant()) const override;
152 
156  QString genericValidationDataError(Context *c, const QVariant &errorData) const override;
157 
158 private:
159  Q_DECLARE_PRIVATE(ValidatorFileSize) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
160  Q_DISABLE_COPY(ValidatorFileSize)
161 };
162 
163 } // namespace Cutelyst
164 
165 #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.
Definition: validatorrule.h:49