Cutelyst  1.7.0
validatorrule.h
1 /*
2  * Copyright (C) 2017 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 Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifndef CUTELYSTVALIDATORRULE_H
20 #define CUTELYSTVALIDATORRULE_H
21 
22 #include <Cutelyst/cutelyst_global.h>
23 #include <Cutelyst/ParamsMultiMap>
24 
25 #include <QScopedPointer>
26 
27 namespace Cutelyst {
28 
29 class ValidatorRulePrivate;
30 
138 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorRule
139 {
140 public:
147  ValidatorRule(const QString &field, const QString &label = QString(), const QString &customError = QString());
148 
152  ~ValidatorRule();
153 
185  virtual QString validate() const = 0;
186 
191  QString field() const;
192 
197  QString label() const;
198 
202  QString value() const;
203 
212  bool trimBefore() const;
213 
214 
215 
220  void setField(const QString &field);
221 
226  void setLabel(const QString &label);
227 
232  void setParameters(const ParamsMultiMap &params);
233 
238  ParamsMultiMap parameters() const;
239 
244  void setCustomError(const QString &customError);
245 
250  void setCustomParsingError(const QString &custom);
251 
256  void setCustomValidationDataError(const QString &custom);
257 
266  void setTrimBefore(bool trimBefore);
267 
268 protected:
269  const QScopedPointer<ValidatorRulePrivate> d_ptr;
273  ValidatorRule(ValidatorRulePrivate &dd);
274 
282  QString validationError() const;
283 
290  virtual QString genericValidationError() const;
291 
299  QString parsingError() const;
300 
307  virtual QString genericParsingError() const;
308 
317  QString validationDataError() const;
318 
325  virtual QString genericValidationDataError() const;
326 
327 private:
328  Q_DECLARE_PRIVATE(ValidatorRule)
329  Q_DISABLE_COPY(ValidatorRule)
330 };
331 
332 }
333 
334 #endif //CUTELYSTVALIDATORRULE_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Base class for all validators.