[PATCH 06/23] kcalendarsystem: Remove dummy function implementations.
Jon Severinsson
jon at severinsson.net
Fri Oct 12 15:13:41 UTC 2012
Make these virtual methods pure virtual instad.
---
kdecore/date/kcalendarsystem.cpp | 235 -------------------------------
kdecore/date/kcalendarsystem.h | 6 +-
kdecore/date/kcalendarsystemprivate_p.h | 30 ++--
3 filer ändrade, 18 tillägg(+), 253 borttagningar(-)
diff --git a/kdecore/date/kcalendarsystem.cpp b/kdecore/date/kcalendarsystem.cpp
index f9bf8a2..138c62d 100644
--- a/kdecore/date/kcalendarsystem.cpp
+++ b/kdecore/date/kcalendarsystem.cpp
@@ -256,152 +256,6 @@ KCalendarSystemPrivate::~KCalendarSystemPrivate()
delete m_eraList;
}
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-KLocale::CalendarSystem KCalendarSystemPrivate::calendarSystem() const
-{
- return KLocale::QDateCalendar;
-}
-
-// Dummy version as an example, remember to translate (see Gregorian for example)
-// Add the Era's in chronological order, from earliest to latest
-// This method MUST be re-implemented in any new Calendar System
-void KCalendarSystemPrivate::loadDefaultEraList()
-{
- addEra('-', 1, q->epoch().addDays(-1), -1, q->earliestValidDate(), QLatin1String("Before KDE"), QLatin1String("BK"), QLatin1String("%Ey %EC"));
- addEra('+', 1, q->epoch(), 1, q->latestValidDate(), QLatin1String("Anno KDE"), QLatin1String("AK"), QLatin1String("%Ey %EC"));
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::monthsInYear(int year) const
-{
- Q_UNUSED(year)
- return 12;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::daysInMonth(int year, int month) const
-{
- if (month == 2) {
- if (isLeapYear(year)) {
- return 29;
- } else {
- return 28;
- }
- }
-
- if (month == 4 || month == 6 || month == 9 || month == 11) {
- return 30;
- }
-
- return 31;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::daysInYear(int year) const
-{
- if (isLeapYear(year)) {
- return 366;
- } else {
- return 365;
- }
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::daysInWeek() const
-{
- return 7;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-bool KCalendarSystemPrivate::isLeapYear(int year) const
-{
- if (year < 1) {
- year = year + 1;
- }
-
- if (year % 4 == 0) {
- if (year % 100 != 0) {
- return true;
- } else if (year % 400 == 0) {
- return true;
- }
- }
-
- return false;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-bool KCalendarSystemPrivate::hasLeapMonths() const
-{
- return false;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-bool KCalendarSystemPrivate::hasYearZero() const
-{
- return false;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::maxDaysInWeek() const
-{
- return 7;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::maxMonthsInYear() const
-{
- return 12;
-}
-
-// Convenince, faster than calling year( ealiestValidDate() ),
-// needed in fake-virtual functions so don't remove
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::earliestValidYear() const
-{
- return -4712;
-}
-
-// Convenince, faster than calling year( latestValidDate() ),
-// needed in fake-virtual functions so don't remove
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-int KCalendarSystemPrivate::latestValidYear() const
-{
- return 9999;
-}
-
-// Dummy version
-// This method MUST be re-implemented in any new Calendar System
-QString KCalendarSystemPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const
-{
- Q_UNUSED(month);
- Q_UNUSED(year);
- Q_UNUSED(format);
- Q_UNUSED(possessive);
- return QString();
-}
-
-// Dummy version
-// This method MUST be re-implemented in any new Calendar System
-QString KCalendarSystemPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const
-{
- Q_UNUSED(weekDay);
- Q_UNUSED(format);
- return QString();
-}
-
// Reimplement if special maths handling required, e.g. Hebrew.
int KCalendarSystemPrivate::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const
{
@@ -1110,26 +964,6 @@ QString KCalendarSystem::calendarLabel() const
return KCalendarSystem::calendarLabel(calendarSystem());
}
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-QDate KCalendarSystem::epoch() const
-{
- return QDate::fromJulianDay(38);
-}
-
-QDate KCalendarSystem::earliestValidDate() const
-{
- return epoch();
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-QDate KCalendarSystem::latestValidDate() const
-{
- // Default to Gregorian 9999-12-31
- return QDate::fromJulianDay(5373484);
-}
-
bool KCalendarSystem::isValid(int year, int month, int day) const
{
Q_D(const KCalendarSystem);
@@ -2411,75 +2245,6 @@ int KCalendarSystem::weekStartDay() const
return locale()->weekStartDay();
}
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST
-// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid
-// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but
-// are required for internal maths
-bool KCalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const
-{
- // Formula from The Calendar FAQ by Claus Tondering
- // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000
- // NOTE: Coded from scratch from mathematical formulas, not copied from
- // the Boost licensed source code
-
- int a = jd + 32044;
- int b = ((4 * a) + 3) / 146097;
- int c = a - ((146097 * b) / 4);
- int d = ((4 * c) + 3) / 1461;
- int e = c - ((1461 * d) / 4);
- int m = ((5 * e) + 2) / 153;
- day = e - (((153 * m) + 2) / 5) + 1;
- month = m + 3 - (12 * (m / 10));
- year = (100 * b) + d - 4800 + (m / 10);
-
- // If year is -ve then is BC. In Gregorian there is no year 0, but the maths
- // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside
- if (year < 1) {
- year = year - 1;
- }
-
- return true;
-}
-
-// Dummy version using Gregorian as an example
-// This method MUST be re-implemented in any new Calendar System
-// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST
-// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid
-// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but
-// are required for internal maths
-bool KCalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const
-{
- // Formula from The Calendar FAQ by Claus Tondering
- // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000
- // NOTE: Coded from scratch from mathematical formulas, not copied from
- // the Boost licensed source code
-
- // If year is -ve then is BC. In Gregorian there is no year 0, but the maths
- // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally
- int y;
- if (year < 1) {
- y = year + 1;
- } else {
- y = year;
- }
-
- int a = (14 - month) / 12;
- y = y + 4800 - a;
- int m = month + (12 * a) - 3;
-
- jd = day
- + (((153 * m) + 2) / 5)
- + (365 * y)
- + (y / 4)
- - (y / 100)
- + (y / 400)
- - 32045;
-
- return true;
-}
-
const KLocale * KCalendarSystem::locale() const
{
Q_D(const KCalendarSystem);
diff --git a/kdecore/date/kcalendarsystem.h b/kdecore/date/kcalendarsystem.h
index d4eef22..9aa7415 100644
--- a/kdecore/date/kcalendarsystem.h
+++ b/kdecore/date/kcalendarsystem.h
@@ -278,7 +278,7 @@ public:
*
* @return epoch of calendar system
*/
- virtual QDate epoch() const;
+ virtual QDate epoch() const = 0;
/**
* Returns the earliest date valid in this calendar system implementation.
@@ -290,7 +290,7 @@ public:
*
* @return date the earliest valid date
*/
- virtual QDate earliestValidDate() const;
+ virtual QDate earliestValidDate() const = 0;
/**
* Returns the latest date valid in this calendar system implementation.
@@ -300,7 +300,7 @@ public:
*
* @return date the latest valid date
*/
- virtual QDate latestValidDate() const;
+ virtual QDate latestValidDate() const = 0;
/**
* Returns whether a given date is valid in this calendar system.
diff --git a/kdecore/date/kcalendarsystemprivate_p.h b/kdecore/date/kcalendarsystemprivate_p.h
index 3f7cd43..7550934 100644
--- a/kdecore/date/kcalendarsystemprivate_p.h
+++ b/kdecore/date/kcalendarsystemprivate_p.h
@@ -36,21 +36,21 @@ public:
virtual ~KCalendarSystemPrivate();
// Virtual methods each calendar system must re-implement
- virtual KLocale::CalendarSystem calendarSystem() const;
- virtual void loadDefaultEraList();
- virtual int monthsInYear(int year) const;
- virtual int daysInMonth(int year, int month) const;
- virtual int daysInYear(int year) const;
- virtual int daysInWeek() const;
- virtual bool isLeapYear(int year) const;
- virtual bool hasLeapMonths() const;
- virtual bool hasYearZero() const;
- virtual int maxDaysInWeek() const;
- virtual int maxMonthsInYear() const;
- virtual int earliestValidYear() const;
- virtual int latestValidYear() const;
- virtual QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive = false) const;
- virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const;
+ virtual KLocale::CalendarSystem calendarSystem() const = 0;
+ virtual void loadDefaultEraList() = 0;
+ virtual int monthsInYear(int year) const = 0;
+ virtual int daysInMonth(int year, int month) const = 0;
+ virtual int daysInYear(int year) const = 0;
+ virtual int daysInWeek() const = 0;
+ virtual bool isLeapYear(int year) const = 0;
+ virtual bool hasLeapMonths() const = 0;
+ virtual bool hasYearZero() const = 0;
+ virtual int maxDaysInWeek() const = 0;
+ virtual int maxMonthsInYear() const = 0;
+ virtual int earliestValidYear() const = 0;
+ virtual int latestValidYear() const = 0;
+ virtual QString monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive = false) const = 0;
+ virtual QString weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const = 0;
// Virtual methods to re-implement if special maths needed
virtual int week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const;
--
1.7.10.4
More information about the Kde-frameworks-devel
mailing list