Cutelyst  2.5.0
validatorfilesize.h
1 /*
2  * Copyright (C) 2018 Matthias Fehring <kontakt@buschmann23.de>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef CUTELYSTVALIDATORFILESIZE_H
20 #define CUTELYSTVALIDATORFILESIZE_H
21 
22 #include <Cutelyst/cutelyst_global.h>
23 #include "validatorrule.h"
24 
25 namespace Cutelyst {
26 
27 class ValidatorFileSizePrivate;
28 
63 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorFileSize : public ValidatorRule
64 {
65 public:
69  enum Option : quint8 {
70  NoOption = 0,
71  OnlyBinary = 1,
72  OnlyDecimal = 2,
73  ForceBinary = 3,
74  ForceDecimal = 4
75  };
76 
88  ValidatorFileSize(const QString &field,
89  Option option = NoOption,
90  const QVariant &min = QVariant(),
91  const QVariant &max = QVariant(),
92  const ValidatorMessages &messages = ValidatorMessages(),
93  const QString &defValKey = QString());
94 
99 
112  static bool validate(const QString &value,
113  double min = -1,
114  double max = -1,
115  Option option = NoOption,
116  const QLocale &locale = QLocale(),
117  double *fileSize = nullptr);
118 
129  static void inputPattern(Context *c, const QString &stashKey = QStringLiteral("fileSizePattern"));
130 
131 protected:
138  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
139 
143  QString genericValidationError(Context *c, const QVariant &errorData = QVariant()) const override;
144 
151  QString genericValidationDataError(Context *c, const QVariant &errorData) const override;
152 
153 private:
154  Q_DECLARE_PRIVATE(ValidatorFileSize)
155  Q_DISABLE_COPY(ValidatorFileSize)
156 };
157 
158 }
159 
160 #endif // CUTELYSTVALIDATORFILESIZE_H
QMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
Option
Options for ValidatorFileSize.
The Cutelyst Context.
Definition: context.h:50
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Base class for all validator rules.
Checks if the input field contains a valid file size string like 1.5 GB.
Contains the result of a single input parameter validation.
Definition: validatorrule.h:62