Cutelyst  3.1.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 <QLocale>
24 #include "validatorrule.h"
25 
26 namespace Cutelyst {
27 
28 class ValidatorFileSizePrivate;
29 
64 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorFileSize : public ValidatorRule
65 {
66 public:
70  enum Option : quint8 {
71  NoOption = 0,
72  OnlyBinary = 1,
73  OnlyDecimal = 2,
74  ForceBinary = 3,
75  ForceDecimal = 4
76  };
77 
89  ValidatorFileSize(const QString &field,
90  Option option = NoOption,
91  const QVariant &min = QVariant(),
92  const QVariant &max = QVariant(),
93  const ValidatorMessages &messages = ValidatorMessages(),
94  const QString &defValKey = QString());
95 
99  ~ValidatorFileSize() override;
100 
113  static bool validate(const QString &value,
114  double min = -1,
115  double max = -1,
116  Option option = NoOption,
117  const QLocale &locale = QLocale(),
118  double *fileSize = nullptr);
119 
130  static void inputPattern(Context *c, const QString &stashKey = QStringLiteral("fileSizePattern"));
131 
132 protected:
139  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
140 
144  QString genericValidationError(Context *c, const QVariant &errorData = QVariant()) const override;
145 
152  QString genericValidationDataError(Context *c, const QVariant &errorData) const override;
153 
154 private:
155  Q_DECLARE_PRIVATE(ValidatorFileSize)
156  Q_DISABLE_COPY(ValidatorFileSize)
157 };
158 
159 }
160 
161 #endif // CUTELYSTVALIDATORFILESIZE_H
The Cutelyst Context.
Definition: context.h:52
Checks if the input field contains a valid file size string like 1.5 GB.
Option
Options for ValidatorFileSize.
Base class for all validator rules.
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.
Definition: validatorrule.h:62