[PATCH 15/23] kcalendarsystem: Simplify isValid(...) implementations.

Jon Severinsson jon at severinsson.net
Fri Oct 12 15:13:50 UTC 2012


All varians can trivially be implemented in KCalendarSystem using existing primitives, no need for virtual.
---
 kdecore/date/kcalendarsystem.cpp               |   27 +++---------------------
 kdecore/date/kcalendarsystem.h                 |    9 ++++----
 kdecore/date/kcalendarsystemcoptic.cpp         |   10 ---------
 kdecore/date/kcalendarsystemcoptic_p.h         |    2 --
 kdecore/date/kcalendarsystemethiopian.cpp      |   10 ---------
 kdecore/date/kcalendarsystemethiopian_p.h      |    2 --
 kdecore/date/kcalendarsystemgregorian.cpp      |   10 ---------
 kdecore/date/kcalendarsystemgregorian_p.h      |    2 --
 kdecore/date/kcalendarsystemhebrew.cpp         |   10 ---------
 kdecore/date/kcalendarsystemhebrew_p.h         |    2 --
 kdecore/date/kcalendarsystemindiannational.cpp |   10 ---------
 kdecore/date/kcalendarsystemindiannational_p.h |    2 --
 kdecore/date/kcalendarsystemislamiccivil.cpp   |   10 ---------
 kdecore/date/kcalendarsystemislamiccivil_p.h   |    2 --
 kdecore/date/kcalendarsystemjalali.cpp         |   10 ---------
 kdecore/date/kcalendarsystemjalali_p.h         |    2 --
 kdecore/date/kcalendarsystemjapanese.cpp       |   10 ---------
 kdecore/date/kcalendarsystemjapanese_p.h       |    2 --
 kdecore/date/kcalendarsystemjulian.cpp         |   10 ---------
 kdecore/date/kcalendarsystemjulian_p.h         |    2 --
 kdecore/date/kcalendarsystemminguo.cpp         |   10 ---------
 kdecore/date/kcalendarsystemminguo_p.h         |    2 --
 kdecore/date/kcalendarsystemqdate.cpp          |   15 -------------
 kdecore/date/kcalendarsystemqdate_p.h          |    2 --
 kdecore/date/kcalendarsystemthai.cpp           |   10 ---------
 kdecore/date/kcalendarsystemthai_p.h           |    2 --
 26 filer ändrade, 8 tillägg(+), 177 borttagningar(-)

diff --git a/kdecore/date/kcalendarsystem.cpp b/kdecore/date/kcalendarsystem.cpp
index 31a7059..e040154 100644
--- a/kdecore/date/kcalendarsystem.cpp
+++ b/kdecore/date/kcalendarsystem.cpp
@@ -824,23 +824,11 @@ bool KCalendarSystem::isValid(int year, int month, int day) const
 {
     Q_D(const KCalendarSystem);
 
-    if (year < d->earliestValidYear() || year > d->latestValidYear() ||
-            (!d->hasYearZero() && year == 0)) {
-        return false;
-    }
-
-    if (month < 1 || month > d->monthsInYear(year)) {
-        return false;
-    }
-
-    if (day < 1 || day > d->daysInMonth(year, month)) {
-        return false;
-    }
-
-    return true;
+    return year >= d->earliestValidYear() && year <= d->latestValidYear() && (d->hasYearZero() || year != 0) &&
+           month >= 1 && month <= d->monthsInYear(year) &&
+           day >= 1 && day <= d->daysInMonth(year, month);
 }
 
-// NOT VIRTUAL - If override needed use shared-d
 bool KCalendarSystem::isValid(int year, int dayOfYear) const
 {
     Q_D(const KCalendarSystem);
@@ -848,7 +836,6 @@ bool KCalendarSystem::isValid(int year, int dayOfYear) const
     return (isValid(year, 1, 1) && dayOfYear > 0 && dayOfYear <= d->daysInYear(year));
 }
 
-// NOT VIRTUAL - If override needed use shared-d
 bool KCalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const
 {
     Q_D(const KCalendarSystem);
@@ -901,14 +888,6 @@ bool KCalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfI
     return true;
 }
 
-bool KCalendarSystem::isValid(const QDate &date) const
-{
-    if (date.isNull() || date < earliestValidDate() || date > latestValidDate()) {
-        return false;
-    }
-    return true;
-}
-
 bool KCalendarSystem::setDate(QDate &date, int year, int month, int day) const
 {
     date = QDate();
diff --git a/kdecore/date/kcalendarsystem.h b/kdecore/date/kcalendarsystem.h
index a2f857d..c1eb159 100644
--- a/kdecore/date/kcalendarsystem.h
+++ b/kdecore/date/kcalendarsystem.h
@@ -199,9 +199,8 @@ public:
      * @param day the day portion of the date to check
      * @return @c true if the date is valid, @c false otherwise
      */
-    virtual bool isValid(int year, int month, int day) const = 0;
+    bool isValid(int year, int month, int day) const;
 
-    //KDE5 make virtual?
     /**
      * @since 4.4
      *
@@ -213,7 +212,6 @@ public:
      */
     bool isValid(int year, int dayOfYear) const;
 
-    //KDE5 make virtual?
     /**
      * @since 4.5
      *
@@ -246,7 +244,10 @@ public:
      * @param date the date to check
      * @return @c true if the date is valid, @c false otherwise
      */
-    virtual bool isValid(const QDate &date) const;
+    inline bool isValid(const QDate &date) const
+    {
+        return date.isValid() && date >= earliestValidDate() && date <= latestValidDate();
+    }
 
     /**
      * Changes the date's year, month and day. The range of the year, month
diff --git a/kdecore/date/kcalendarsystemcoptic.cpp b/kdecore/date/kcalendarsystemcoptic.cpp
index 0578dfa..e01a7e3 100644
--- a/kdecore/date/kcalendarsystemcoptic.cpp
+++ b/kdecore/date/kcalendarsystemcoptic.cpp
@@ -436,16 +436,6 @@ QDate KCalendarSystemCoptic::latestValidDate() const
     return QDate::fromJulianDay(5477164);
 }
 
-bool KCalendarSystemCoptic::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemCoptic::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 bool KCalendarSystemCoptic::isLeapYear(int year) const
 {
     return KCalendarSystem::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemcoptic_p.h b/kdecore/date/kcalendarsystemcoptic_p.h
index b077800..c6488cd 100644
--- a/kdecore/date/kcalendarsystemcoptic_p.h
+++ b/kdecore/date/kcalendarsystemcoptic_p.h
@@ -46,8 +46,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemethiopian.cpp b/kdecore/date/kcalendarsystemethiopian.cpp
index 4074e4e..5d37e16 100644
--- a/kdecore/date/kcalendarsystemethiopian.cpp
+++ b/kdecore/date/kcalendarsystemethiopian.cpp
@@ -335,16 +335,6 @@ QDate KCalendarSystemEthiopian::latestValidDate() const
     return QDate::fromJulianDay(5376721);
 }
 
-bool KCalendarSystemEthiopian::isValid(int year, int month, int day) const
-{
-    return KCalendarSystemCoptic::isValid(year, month, day);
-}
-
-bool KCalendarSystemEthiopian::isValid(const QDate &date) const
-{
-    return KCalendarSystemCoptic::isValid(date);
-}
-
 bool KCalendarSystemEthiopian::isLeapYear(int year) const
 {
     return KCalendarSystemCoptic::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemethiopian_p.h b/kdecore/date/kcalendarsystemethiopian_p.h
index 2669654..9020b8d 100644
--- a/kdecore/date/kcalendarsystemethiopian_p.h
+++ b/kdecore/date/kcalendarsystemethiopian_p.h
@@ -47,8 +47,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemgregorian.cpp b/kdecore/date/kcalendarsystemgregorian.cpp
index 7f16d8e..1a5aaa8 100644
--- a/kdecore/date/kcalendarsystemgregorian.cpp
+++ b/kdecore/date/kcalendarsystemgregorian.cpp
@@ -427,16 +427,6 @@ QDate KCalendarSystemGregorian::latestValidDate() const
     return QDate::fromJulianDay(5373484);
 }
 
-bool KCalendarSystemGregorian::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemGregorian::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 bool KCalendarSystemGregorian::isLeapYear(int year) const
 {
     return KCalendarSystem::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemgregorian_p.h b/kdecore/date/kcalendarsystemgregorian_p.h
index 464ac8d..51414ad 100644
--- a/kdecore/date/kcalendarsystemgregorian_p.h
+++ b/kdecore/date/kcalendarsystemgregorian_p.h
@@ -51,8 +51,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemhebrew.cpp b/kdecore/date/kcalendarsystemhebrew.cpp
index 38df98e..fdae5a3 100644
--- a/kdecore/date/kcalendarsystemhebrew.cpp
+++ b/kdecore/date/kcalendarsystemhebrew.cpp
@@ -917,16 +917,6 @@ QDate KCalendarSystemHebrew::latestValidDate() const
     return QDate::fromJulianDay(3313431);
 }
 
-bool KCalendarSystemHebrew::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemHebrew::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 int KCalendarSystemHebrew::dayOfWeek(const QDate &date) const
 {
     class h_date * sd = toHebrew(date);
diff --git a/kdecore/date/kcalendarsystemhebrew_p.h b/kdecore/date/kcalendarsystemhebrew_p.h
index 330a15d..b202e80 100644
--- a/kdecore/date/kcalendarsystemhebrew_p.h
+++ b/kdecore/date/kcalendarsystemhebrew_p.h
@@ -50,8 +50,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual int dayOfWeek(const QDate &date) const;
 
diff --git a/kdecore/date/kcalendarsystemindiannational.cpp b/kdecore/date/kcalendarsystemindiannational.cpp
index 1907d84..fe8b0b7 100644
--- a/kdecore/date/kcalendarsystemindiannational.cpp
+++ b/kdecore/date/kcalendarsystemindiannational.cpp
@@ -432,16 +432,6 @@ QDate KCalendarSystemIndianNational::latestValidDate() const
     return QDate::fromJulianDay(5402054);
 }
 
-bool KCalendarSystemIndianNational::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemIndianNational::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 bool KCalendarSystemIndianNational::isLeapYear(int year) const
 {
     return KCalendarSystem::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemindiannational_p.h b/kdecore/date/kcalendarsystemindiannational_p.h
index 03f98c4..8635b64 100644
--- a/kdecore/date/kcalendarsystemindiannational_p.h
+++ b/kdecore/date/kcalendarsystemindiannational_p.h
@@ -50,8 +50,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemislamiccivil.cpp b/kdecore/date/kcalendarsystemislamiccivil.cpp
index 270e584..56abff4 100644
--- a/kdecore/date/kcalendarsystemislamiccivil.cpp
+++ b/kdecore/date/kcalendarsystemislamiccivil.cpp
@@ -432,16 +432,6 @@ QDate KCalendarSystemIslamicCivil::latestValidDate() const
     return QDate::fromJulianDay(5491751);
 }
 
-bool KCalendarSystemIslamicCivil::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemIslamicCivil::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 bool KCalendarSystemIslamicCivil::isLeapYear(int year) const
 {
     return KCalendarSystem::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemislamiccivil_p.h b/kdecore/date/kcalendarsystemislamiccivil_p.h
index 59dd87b..87f22f4 100644
--- a/kdecore/date/kcalendarsystemislamiccivil_p.h
+++ b/kdecore/date/kcalendarsystemislamiccivil_p.h
@@ -52,8 +52,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemjalali.cpp b/kdecore/date/kcalendarsystemjalali.cpp
index a866321..71feab3 100644
--- a/kdecore/date/kcalendarsystemjalali.cpp
+++ b/kdecore/date/kcalendarsystemjalali.cpp
@@ -440,16 +440,6 @@ QDate KCalendarSystemJalali::latestValidDate() const
     return QDate::fromJulianDay(2507140);
 }
 
-bool KCalendarSystemJalali::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemJalali::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 bool KCalendarSystemJalali::isLeapYear(int year) const
 {
     return KCalendarSystem::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemjalali_p.h b/kdecore/date/kcalendarsystemjalali_p.h
index 0a2b8e0..5a0dc7f 100644
--- a/kdecore/date/kcalendarsystemjalali_p.h
+++ b/kdecore/date/kcalendarsystemjalali_p.h
@@ -41,8 +41,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemjapanese.cpp b/kdecore/date/kcalendarsystemjapanese.cpp
index da741e5..144d7ae 100644
--- a/kdecore/date/kcalendarsystemjapanese.cpp
+++ b/kdecore/date/kcalendarsystemjapanese.cpp
@@ -140,16 +140,6 @@ QDate KCalendarSystemJapanese::latestValidDate() const
     return QDate::fromJulianDay(5373484);
 }
 
-bool KCalendarSystemJapanese::isValid(int year, int month, int day) const
-{
-    return KCalendarSystemGregorian::isValid(year, month, day);
-}
-
-bool KCalendarSystemJapanese::isValid(const QDate &date) const
-{
-    return KCalendarSystemGregorian::isValid(date);
-}
-
 bool KCalendarSystemJapanese::isLeapYear(int year) const
 {
     return KCalendarSystemGregorian::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemjapanese_p.h b/kdecore/date/kcalendarsystemjapanese_p.h
index f7f11a0..d1ad504 100644
--- a/kdecore/date/kcalendarsystemjapanese_p.h
+++ b/kdecore/date/kcalendarsystemjapanese_p.h
@@ -47,8 +47,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemjulian.cpp b/kdecore/date/kcalendarsystemjulian.cpp
index 85b2592..74eb6ef 100644
--- a/kdecore/date/kcalendarsystemjulian.cpp
+++ b/kdecore/date/kcalendarsystemjulian.cpp
@@ -441,16 +441,6 @@ QDate KCalendarSystemJulian::latestValidDate() const
     return QDate::fromJulianDay(5373557);
 }
 
-bool KCalendarSystemJulian::isValid(int year, int month, int day) const
-{
-    return KCalendarSystem::isValid(year, month, day);
-}
-
-bool KCalendarSystemJulian::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 bool KCalendarSystemJulian::isLeapYear(int year) const
 {
     return KCalendarSystem::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemjulian_p.h b/kdecore/date/kcalendarsystemjulian_p.h
index 30c8672..93c9b8d 100644
--- a/kdecore/date/kcalendarsystemjulian_p.h
+++ b/kdecore/date/kcalendarsystemjulian_p.h
@@ -50,8 +50,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemminguo.cpp b/kdecore/date/kcalendarsystemminguo.cpp
index fbb19e8..68a23e1 100644
--- a/kdecore/date/kcalendarsystemminguo.cpp
+++ b/kdecore/date/kcalendarsystemminguo.cpp
@@ -114,16 +114,6 @@ QDate KCalendarSystemMinguo::latestValidDate() const
     return QDate::fromJulianDay(6071462);
 }
 
-bool KCalendarSystemMinguo::isValid(int year, int month, int day) const
-{
-    return KCalendarSystemGregorian::isValid(year, month, day);
-}
-
-bool KCalendarSystemMinguo::isValid(const QDate &date) const
-{
-    return KCalendarSystemGregorian::isValid(date);
-}
-
 bool KCalendarSystemMinguo::isLeapYear(int year) const
 {
     return KCalendarSystemGregorian::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemminguo_p.h b/kdecore/date/kcalendarsystemminguo_p.h
index 20c567e..497d835 100644
--- a/kdecore/date/kcalendarsystemminguo_p.h
+++ b/kdecore/date/kcalendarsystemminguo_p.h
@@ -47,8 +47,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemqdate.cpp b/kdecore/date/kcalendarsystemqdate.cpp
index 79a8114..f73e7f0 100644
--- a/kdecore/date/kcalendarsystemqdate.cpp
+++ b/kdecore/date/kcalendarsystemqdate.cpp
@@ -428,21 +428,6 @@ QDate KCalendarSystemQDate::latestValidDate() const
     return QDate::fromJulianDay(5373484);
 }
 
-bool KCalendarSystemQDate::isValid(int year, int month, int day) const
-{
-    // Limit to max year 9999 for now, QDate allows to be greater
-    if (year <= 9999) {
-        return QDate::isValid(year, month, day);
-    }
-
-    return false;
-}
-
-bool KCalendarSystemQDate::isValid(const QDate &date) const
-{
-    return KCalendarSystem::isValid(date);
-}
-
 int KCalendarSystemQDate::year(const QDate &date) const
 {
     return date.year();
diff --git a/kdecore/date/kcalendarsystemqdate_p.h b/kdecore/date/kcalendarsystemqdate_p.h
index 7582b85..dbe52f9 100644
--- a/kdecore/date/kcalendarsystemqdate_p.h
+++ b/kdecore/date/kcalendarsystemqdate_p.h
@@ -50,8 +50,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual int year(const QDate &date) const;
     virtual int month(const QDate &date) const;
diff --git a/kdecore/date/kcalendarsystemthai.cpp b/kdecore/date/kcalendarsystemthai.cpp
index c14aacb..642835c 100644
--- a/kdecore/date/kcalendarsystemthai.cpp
+++ b/kdecore/date/kcalendarsystemthai.cpp
@@ -120,16 +120,6 @@ QDate KCalendarSystemThai::latestValidDate() const
     return QDate::fromJulianDay(5175158);
 }
 
-bool KCalendarSystemThai::isValid(int year, int month, int day) const
-{
-    return KCalendarSystemGregorian::isValid(year, month, day);
-}
-
-bool KCalendarSystemThai::isValid(const QDate &date) const
-{
-    return KCalendarSystemGregorian::isValid(date);
-}
-
 bool KCalendarSystemThai::isLeapYear(int year) const
 {
     return KCalendarSystemGregorian::isLeapYear(year);
diff --git a/kdecore/date/kcalendarsystemthai_p.h b/kdecore/date/kcalendarsystemthai_p.h
index 3e1eb31..a59789a 100644
--- a/kdecore/date/kcalendarsystemthai_p.h
+++ b/kdecore/date/kcalendarsystemthai_p.h
@@ -47,8 +47,6 @@ public:
     virtual QDate epoch() const;
     virtual QDate earliestValidDate() const;
     virtual QDate latestValidDate() const;
-    virtual bool isValid(int year, int month, int day) const;
-    virtual bool isValid(const QDate &date) const;
 
     virtual bool isLeapYear(int year) const;
     virtual bool isLeapYear(const QDate &date) const;
-- 
1.7.10.4



More information about the Kde-frameworks-devel mailing list