File indexing completed on 2024-04-21 03:54:13
0001 /* -*- C++ -*- 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1997 Tim D. Gilman <tdgilman@best.org> 0004 SPDX-FileCopyrightText: 1998-2001 Mirko Boehm <mirko@kde.org> 0005 SPDX-FileCopyrightText: 2007 John Layt <john@layt.net> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "kdatevalidator.h" 0011 0012 #include <QDate> 0013 #include <QLocale> 0014 0015 class KDateValidatorPrivate 0016 { 0017 public: 0018 KDateValidatorPrivate(KDateValidator *qq) 0019 : q(qq) 0020 { 0021 } 0022 0023 ~KDateValidatorPrivate() 0024 { 0025 } 0026 0027 KDateValidator *const q; 0028 }; 0029 0030 KDateValidator::KDateValidator(QObject *parent) 0031 : QValidator(parent) 0032 { 0033 } 0034 0035 KDateValidator::~KDateValidator() = default; 0036 0037 QValidator::State KDateValidator::validate(QString &text, int &unused) const 0038 { 0039 Q_UNUSED(unused); 0040 0041 QDate temp; 0042 // ----- everything is tested in date(): 0043 return date(text, temp); 0044 } 0045 0046 QValidator::State KDateValidator::date(const QString &text, QDate &d) const 0047 { 0048 QLocale::FormatType formats[] = {QLocale::LongFormat, QLocale::ShortFormat, QLocale::NarrowFormat}; 0049 QLocale locale; 0050 0051 for (int i = 0; i < 3; i++) { 0052 QDate tmp = locale.toDate(text, formats[i]); 0053 if (tmp.isValid()) { 0054 d = tmp; 0055 return Acceptable; 0056 } 0057 } 0058 0059 return QValidator::Intermediate; 0060 } 0061 0062 void KDateValidator::fixup(QString &) const 0063 { 0064 } 0065 0066 #include "moc_kdatevalidator.cpp"