source: SMSSender/lib/libgateway/src/business/validation/BCValidationResult.cpp @ 41:680c6a482e9d

3.0
Last change on this file since 41:680c6a482e9d was 41:680c6a482e9d, checked in by Sämy Zehnder <saemy.zehnder@…>, 12 years ago
File size: 1.8 KB
Line 
1/*
2 * BCValidationResult.cpp
3 *
4 *  Created on: Dec 18, 2009
5 *      Author: saemy
6 */
7
8#include "BCValidationResult.h"
9
10#include <QListIterator>
11
12/**
13 * If the given message is not empty, it is added as an error
14 * otherwise the result will be initialized as valid.
15 */
16BCValidationResult::BCValidationResult(const QString& message /* = "" */) {
17    if (message.trimmed() != "") {
18        addError(message);
19    }
20}
21
22void BCValidationResult::addError(const QString& message) {
23    if (message.trimmed() != "") {
24        errors_.append(message);
25    }
26}
27void BCValidationResult::addWarning(const QString& message) {
28    if (message.trimmed() != "") {
29        warnings_.append(message);
30    }
31}
32
33ValidationType BCValidationResult::validationType() const {
34    if (hasWarnings()) {
35        return Warning;
36    }
37    if (hasErrors()) {
38        return Error;
39    }
40
41    return Valid;
42}
43
44QList<QString> BCValidationResult::errors() const {
45    return errors_;
46}
47QList<QString> BCValidationResult::warnings() const {
48    return warnings_;
49}
50
51bool BCValidationResult::hasErrors() const {
52    return !errors().isEmpty();
53}
54bool BCValidationResult::hasWarnings() const {
55    return !warnings().isEmpty();
56}
57bool BCValidationResult::isValid() const {
58    return !hasErrors() && !hasWarnings();
59}
60
61QString BCValidationResult::getErrorString(const QString& delimiter /* = "\n" */) const {
62    return getStringFromList(errors(), delimiter);
63}
64QString BCValidationResult::getWarningString(const QString& delimiter /* = "\n" */) const {
65    return getStringFromList(errors(), delimiter);
66}
67QString BCValidationResult::getStringFromList(const QList<QString> list, const QString& delimiter) const {
68    QString messages = "";
69
70    QListIterator<QString> i(list);
71    while (i.hasNext()) {
72        messages += i.next() + delimiter;
73    }
74
75    return messages.left(messages.length() - delimiter.length());
76}
77
Note: See TracBrowser for help on using the repository browser.