KGuiAddons

kdatevalidator.cpp
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, temp);
44}
45
46QValidator::State KDateValidator::date(const QString &text, QDate &d) const
47{
50
51 for (int i = 0; i < 3; i++) {
52 QDate tmp = locale.toDate(text, formats[i]);
53 if (tmp.isValid()) {
54 d = tmp;
55 return Acceptable;
56 }
57 }
58
60}
61
62void KDateValidator::fixup(QString &) const
63{
64}
65
66#include "moc_kdatevalidator.cpp"
Validates user-entered dates.
bool isValid(int year, int month, int day)
QDate toDate(const QString &string, FormatType format) const const
QLocale locale() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.