Index: trunk/BNC/qwt/qwt_date.cpp
===================================================================
--- trunk/BNC/qwt/qwt_date.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_date.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -9,9 +9,10 @@
 
 #include "qwt_date.h"
+#include "qwt_math.h"
+
 #include <qdebug.h>
 #include <qlocale.h>
-#include <math.h>
+
 #include <limits>
-#include <limits.h>
 
 #if QT_VERSION >= 0x050000
@@ -24,14 +25,15 @@
 
 // QDate stores the Julian day as unsigned int, but
-// but it is QDate::fromJulianDay( int ). That's why
+// there is QDate::fromJulianDay( int ). That's why
 // we have the range [ 1, INT_MAX ]
+
 typedef int QwtJulianDay;
 static const QwtJulianDay minJulianDayD = 1;
-static const QwtJulianDay maxJulianDayD = std::numeric_limits<int>::max();
+static const QwtJulianDay maxJulianDayD = std::numeric_limits< int >::max();
 
 #endif
 
-static QString qwtExpandedFormat( const QString & format,
-    const QDateTime &dateTime, QwtDate::Week0Type week0Type )
+static QString qwtExpandedFormat( const QString& format,
+    const QDateTime& dateTime, QwtDate::Week0Type week0Type )
 {
     const int week = QwtDate::weekNumber( dateTime.date(), week0Type );
@@ -42,11 +44,11 @@
     QString weekNoWW;
     if ( weekNo.length() == 1 )
-        weekNoWW += "0";
+        weekNoWW += QLatin1Char( '0' );
 
     weekNoWW += weekNo;
 
     QString fmt = format;
-    fmt.replace( "ww", weekNoWW );
-    fmt.replace( "w", weekNo );
+    fmt.replace( QLatin1String( "ww" ), weekNoWW );
+    fmt.replace( QLatin1Char( 'w' ), weekNo );
 
     if ( week == 1 && dateTime.date().month() != 1 )
@@ -54,6 +56,6 @@
         // in case of week 1, we might need to increment the year
 
-        static QString s_yyyy = "yyyy";
-        static QString s_yy = "yy";
+        QLatin1String s_yyyy( "yyyy" );
+        QLatin1String s_yy( "yy" );
 
         // week 1 might start in the previous year
@@ -100,12 +102,13 @@
         {
             const QDate dt( dateTime.date().year() + 1, 1, 1 );
+            const QString dtString = QLocale().toString( dt, s_yyyy );
 
             if ( fmt.contains( s_yyyy ) )
             {
-                fmt.replace( s_yyyy, dt.toString( s_yyyy ) );
+                fmt.replace( s_yyyy, dtString );
             }
             else
             {
-                fmt.replace( s_yy, dt.toString( s_yyyy ) );
+                fmt.replace( s_yy, dtString );
             }
         }
@@ -117,84 +120,9 @@
 static inline Qt::DayOfWeek qwtFirstDayOfWeek()
 {
-#if QT_VERSION >= 0x040800
     return QLocale().firstDayOfWeek();
-#else
-
-    switch( QLocale().country() )
-    {
-        case QLocale::Maldives:
-            return Qt::Friday;
-
-        case QLocale::Afghanistan:
-        case QLocale::Algeria:
-        case QLocale::Bahrain:
-        case QLocale::Djibouti:
-        case QLocale::Egypt:
-        case QLocale::Eritrea:
-        case QLocale::Ethiopia:
-        case QLocale::Iran:
-        case QLocale::Iraq:
-        case QLocale::Jordan:
-        case QLocale::Kenya:
-        case QLocale::Kuwait:
-        case QLocale::LibyanArabJamahiriya:
-        case QLocale::Morocco:
-        case QLocale::Oman:
-        case QLocale::Qatar:
-        case QLocale::SaudiArabia:
-        case QLocale::Somalia:
-        case QLocale::Sudan:
-        case QLocale::Tunisia:
-        case QLocale::Yemen:
-            return Qt::Saturday;
-
-        case QLocale::AmericanSamoa:
-        case QLocale::Argentina:
-        case QLocale::Azerbaijan:
-        case QLocale::Botswana:
-        case QLocale::Canada:
-        case QLocale::China:
-        case QLocale::FaroeIslands:
-        case QLocale::Georgia:
-        case QLocale::Greenland:
-        case QLocale::Guam:
-        case QLocale::HongKong:
-        case QLocale::Iceland:
-        case QLocale::India:
-        case QLocale::Ireland:
-        case QLocale::Israel:
-        case QLocale::Jamaica:
-        case QLocale::Japan:
-        case QLocale::Kyrgyzstan:
-        case QLocale::Lao:
-        case QLocale::Malta:
-        case QLocale::MarshallIslands:
-        case QLocale::Macau:
-        case QLocale::Mongolia:
-        case QLocale::NewZealand:
-        case QLocale::NorthernMarianaIslands:
-        case QLocale::Pakistan:
-        case QLocale::Philippines:
-        case QLocale::RepublicOfKorea:
-        case QLocale::Singapore:
-        case QLocale::SyrianArabRepublic:
-        case QLocale::Taiwan:
-        case QLocale::Thailand:
-        case QLocale::TrinidadAndTobago:
-        case QLocale::UnitedStates:
-        case QLocale::UnitedStatesMinorOutlyingIslands:
-        case QLocale::USVirginIslands:
-        case QLocale::Uzbekistan:
-        case QLocale::Zimbabwe:
-            return Qt::Sunday;
-
-        default:
-            return Qt::Monday;
-    }
-#endif
 }
 
 static inline void qwtFloorTime(
-    QwtDate::IntervalType intervalType, QDateTime &dt )
+    QwtDate::IntervalType intervalType, QDateTime& dt )
 {
     // when dt is inside the special hour where DST is ending
@@ -234,5 +162,5 @@
 
 static inline QDateTime qwtToTimeSpec(
-    const QDateTime &dt, Qt::TimeSpec spec )
+    const QDateTime& dt, Qt::TimeSpec spec )
 {
     if ( dt.timeSpec() == spec )
@@ -240,5 +168,5 @@
 
     const qint64 jd = dt.date().toJulianDay();
-    if ( jd < 0 || jd >= INT_MAX )
+    if ( jd < 0 || jd >= std::numeric_limits< int >::max() )
     {
         // the conversion between local time and UTC
@@ -264,8 +192,8 @@
     const int m1 = ( month - 14 ) / 12;
     const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
-    const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
-
-    return ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
-            - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
+    const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 );
+
+    return std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
+           - std::floor( ( 3 * y1 ) / 4 ) + day - 32075;
 }
 
@@ -300,8 +228,8 @@
         const int m1 = ( month - 14 ) / 12;
         const int m2 = ( 367 * ( month - 2 - 12 * m1 ) ) / 12;
-        const double y1 = ::floor( ( 4900.0 + year + m1 ) / 100 );
-
-        const double jd = ::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
-            - ::floor( ( 3 * y1 ) / 4 ) + day - 32075;
+        const double y1 = std::floor( ( 4900.0 + year + m1 ) / 100 );
+
+        const double jd = std::floor( ( 1461.0 * ( year + 4800 + m1 ) ) / 4 ) + m2
+            - std::floor( ( 3 * y1 ) / 4 ) + day - 32075;
 
         if ( jd > maxJulianDayD )
@@ -311,5 +239,5 @@
         }
 
-        return QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
+        return QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) );
     }
     else
@@ -321,13 +249,13 @@
 
 /*!
-  Translate from double to QDateTime
-
-  \param value Number of milliseconds since the epoch,
+   Translate from double to QDateTime
+
+   \param value Number of milliseconds since the epoch,
                1970-01-01T00:00:00 UTC
-  \param timeSpec Time specification
-  \return Datetime value
-
-  \sa toDouble(), QDateTime::setMSecsSinceEpoch()
-  \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC
+   \param timeSpec Time specification
+   \return Datetime value
+
+   \sa toDouble(), QDateTime::setMSecsSinceEpoch()
+   \note The return datetime for Qt::OffsetFromUTC will be Qt::UTC
  */
 QDateTime QwtDate::toDateTime( double value, Qt::TimeSpec timeSpec )
@@ -335,5 +263,5 @@
     const int msecsPerDay = 86400000;
 
-    const double days = static_cast<qint64>( ::floor( value / msecsPerDay ) );
+    const double days = static_cast< qint64 >( std::floor( value / msecsPerDay ) );
 
     const double jd = QwtDate::JulianDayForEpoch + days;
@@ -344,7 +272,7 @@
     }
 
-    const QDate d = QDate::fromJulianDay( static_cast<QwtJulianDay>( jd ) );
-
-    const int msecs = static_cast<int>( value - days * msecsPerDay );
+    const QDate d = QDate::fromJulianDay( static_cast< QwtJulianDay >( jd ) );
+
+    const int msecs = static_cast< int >( value - days * msecsPerDay );
 
     static const QTime timeNull( 0, 0, 0, 0 );
@@ -359,14 +287,14 @@
 
 /*!
-  Translate from QDateTime to double
-
-  \param dateTime Datetime value
-  \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed.
-
-  \sa toDateTime(), QDateTime::toMSecsSinceEpoch()
-  \warning For values very far below or above 1970-01-01 UTC rounding errors
+   Translate from QDateTime to double
+
+   \param dateTime Datetime value
+   \return Number of milliseconds since 1970-01-01T00:00:00 UTC has passed.
+
+   \sa toDateTime(), QDateTime::toMSecsSinceEpoch()
+   \warning For values very far below or above 1970-01-01 UTC rounding errors
            will happen due to the limited significance of a double.
  */
-double QwtDate::toDouble( const QDateTime &dateTime )
+double QwtDate::toDouble( const QDateTime& dateTime )
 {
     const int msecsPerDay = 86400000;
@@ -384,14 +312,14 @@
 
 /*!
-  Ceil a datetime according the interval type
-
-  \param dateTime Datetime value
-  \param intervalType Interval type, how to ceil.
+   Ceil a datetime according the interval type
+
+   \param dateTime Datetime value
+   \param intervalType Interval type, how to ceil.
                       F.e. when intervalType = QwtDate::Months, the result
                       will be ceiled to the next beginning of a month
-  \return Ceiled datetime
-  \sa floor()
- */
-QDateTime QwtDate::ceil( const QDateTime &dateTime, IntervalType intervalType )
+   \return Ceiled datetime
+   \sa floor()
+ */
+QDateTime QwtDate::ceil( const QDateTime& dateTime, IntervalType intervalType )
 {
     if ( dateTime.date() >= QwtDate::maxDate() )
@@ -485,15 +413,15 @@
 
 /*!
-  Floor a datetime according the interval type
-
-  \param dateTime Datetime value
-  \param intervalType Interval type, how to ceil.
+   Floor a datetime according the interval type
+
+   \param dateTime Datetime value
+   \param intervalType Interval type, how to ceil.
                       F.e. when intervalType = QwtDate::Months,
                       the result will be ceiled to the next
                       beginning of a month
-  \return Floored datetime
-  \sa floor()
- */
-QDateTime QwtDate::floor( const QDateTime &dateTime,
+   \return Floored datetime
+   \sa floor()
+ */
+QDateTime QwtDate::floor( const QDateTime& dateTime,
     IntervalType intervalType )
 {
@@ -558,14 +486,14 @@
 
 /*!
-  Minimum for the supported date range
-
-  The range of valid dates depends on how QDate stores the
-  Julian day internally.
-
-  - For Qt4 it is "Tue Jan 2 -4713"
-  - For Qt5 it is "Thu Jan 1 -2147483648"
-
-  \return minimum of the date range
-  \sa maxDate()
+   Minimum for the supported date range
+
+   The range of valid dates depends on how QDate stores the
+   Julian day internally.
+
+   - For Qt4 it is "Tue Jan 2 -4713"
+   - For Qt5 it is "Thu Jan 1 -2147483648"
+
+   \return minimum of the date range
+   \sa maxDate()
  */
 QDate QwtDate::minDate()
@@ -579,15 +507,15 @@
 
 /*!
-  Maximum for the supported date range
-
-  The range of valid dates depends on how QDate stores the
-  Julian day internally.
-
-  - For Qt4 it is "Tue Jun 3 5874898"
-  - For Qt5 it is "Tue Dec 31 2147483647"
-
-  \return maximum of the date range
-  \sa minDate()
-  \note The maximum differs between Qt4 and Qt5
+   Maximum for the supported date range
+
+   The range of valid dates depends on how QDate stores the
+   Julian day internally.
+
+   - For Qt4 it is "Tue Jun 3 5874898"
+   - For Qt5 it is "Tue Dec 31 2147483647"
+
+   \return maximum of the date range
+   \sa minDate()
+   \note The maximum differs between Qt4 and Qt5
  */
 QDate QwtDate::maxDate()
@@ -601,14 +529,14 @@
 
 /*!
-  \brief Date of the first day of the first week for a year
-
-  The first day of a week depends on the current locale
-  ( QLocale::firstDayOfWeek() ).
-
-  \param year Year
-  \param type Option how to identify the first week
-  \return First day of week 0
-
-  \sa QLocale::firstDayOfWeek(), weekNumber()
+   \brief Date of the first day of the first week for a year
+
+   The first day of a week depends on the current locale
+   ( QLocale::firstDayOfWeek() ).
+
+   \param year Year
+   \param type Option how to identify the first week
+   \return First day of week 0
+
+   \sa QLocale::firstDayOfWeek(), weekNumber()
  */
 QDate QwtDate::dateOfWeek0( int year, Week0Type type )
@@ -628,5 +556,5 @@
     {
         // according to ISO 8601 the first week is defined
-        // by the first thursday.
+        // by the first Thursday.
 
         int d = Qt::Thursday - firstDayOfWeek;
@@ -642,18 +570,18 @@
 
 /*!
-  Find the week number of a date
-
-  - QwtDate::FirstThursday\n
+   Find the week number of a date
+
+   - QwtDate::FirstThursday\n
     Corresponding to ISO 8601 ( see QDate::weekNumber() ).
 
-  - QwtDate::FirstDay\n
+   - QwtDate::FirstDay\n
     Number of weeks that have begun since dateOfWeek0().
 
-  \param date Date
-  \param type Option how to identify the first week
-
-  \return Week number, starting with 1
- */
-int QwtDate::weekNumber( const QDate &date, Week0Type type )
+   \param date Date
+   \param type Option how to identify the first week
+
+   \return Week number, starting with 1
+ */
+int QwtDate::weekNumber( const QDate& date, Week0Type type )
 {
     int weekNo;
@@ -695,5 +623,5 @@
      0, dateTime has no offset
    - Qt::OffsetFromUTC
-     returns dateTime.utcOffset()
+     returns dateTime.offsetFromUtc()
    - Qt::LocalTime:
      number of seconds from the UTC
@@ -705,5 +633,5 @@
    \return Offset in seconds
  */
-int QwtDate::utcOffset( const QDateTime &dateTime )
+int QwtDate::utcOffset( const QDateTime& dateTime )
 {
     int seconds = 0;
@@ -717,5 +645,9 @@
         case Qt::OffsetFromUTC:
         {
+#if QT_VERSION >= 0x050200
+            seconds = dateTime.offsetFromUtc();
+#else
             seconds = dateTime.utcOffset();
+#endif
             break;
         }
@@ -731,27 +663,27 @@
 
 /*!
-  Translate a datetime into a string
-
-  Beside the format expressions documented in QDateTime::toString()
-  the following expressions are supported:
-
-  - w\n
+   Translate a datetime into a string
+
+   Beside the format expressions documented in QDateTime::toString()
+   the following expressions are supported:
+
+   - w\n
     week number: ( 1 - 53 )
-  - ww\n
+   - ww\n
     week number with a leading zero ( 01 - 53 )
 
-  As week 1 usually starts in the previous year a special rule
-  is applied for formats, where the year is expected to match the
-  week number - even if the date belongs to the previous year.
-
-  \param dateTime Datetime value
-  \param format Format string
-  \param week0Type Specification of week 0
-
-  \return Datetime string
-  \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw
- */
-QString QwtDate::toString( const QDateTime &dateTime,
-    const QString & format, Week0Type week0Type )
+   As week 1 usually starts in the previous year a special rule
+   is applied for formats, where the year is expected to match the
+   week number - even if the date belongs to the previous year.
+
+   \param dateTime Datetime value
+   \param format Format string
+   \param week0Type Specification of week 0
+
+   \return Datetime string
+   \sa QDateTime::toString(), weekNumber(), QwtDateScaleDraw
+ */
+QString QwtDate::toString( const QDateTime& dateTime,
+    const QString& format, Week0Type week0Type )
 {
     QString fmt = format;
@@ -761,4 +693,4 @@
     }
 
-    return dateTime.toString( fmt );
-}
+    return QLocale().toString( dateTime, fmt );
+}
