1/* -*- C++ -*-
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1997 Tim D. Gilman <tdgilman@best.org>
4 SPDX-FileCopyrightText: 1998-2001 Mirko Boehm <mirko@kde.org>
5 SPDX-FileCopyrightText: 2007 John Layt <john@layt.net>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "kdatevalidator.h"
11
12#include <QDate>
13#include <QLocale>
14
15class KDateValidatorPrivate
16{
17public:
18 KDateValidatorPrivate(KDateValidator *qq)
19 : q(qq)
20 {
21 }
22
23 ~KDateValidatorPrivate()
24 {
25 }
26
27 KDateValidator *const q;
28};
29
30KDateValidator::KDateValidator(QObject *parent)
31 : QValidator(parent)
32{
33}
34
35KDateValidator::~KDateValidator() = default;
36
37QValidator::State KDateValidator::validate(QString &text, int &unused) const
38{
39 Q_UNUSED(unused);
40
41 QDate temp;
42 // ----- everything is tested in date():
43 return date(text, date&: temp);
44}
45
46QValidator::State KDateValidator::date(const QString &text, QDate &d) const
47{
48 QLocale::FormatType formats[] = {QLocale::LongFormat, QLocale::ShortFormat, QLocale::NarrowFormat};
49 QLocale locale;
50
51 for (int i = 0; i < 3; i++) {
52 QDate tmp = locale.toDate(string: text, formats[i]);
53 if (tmp.isValid()) {
54 d = tmp;
55 return Acceptable;
56 }
57 }
58
59 return QValidator::Intermediate;
60}
61
62void KDateValidator::fixup(QString &) const
63{
64}
65
66#include "moc_kdatevalidator.cpp"
67

source code of kguiaddons/src/text/kdatevalidator.cpp