Index: trunk/BNC/qwt/qwt_date_scale_engine.cpp
===================================================================
--- trunk/BNC/qwt/qwt_date_scale_engine.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_date_scale_engine.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -10,7 +10,9 @@
 #include "qwt_date_scale_engine.h"
 #include "qwt_math.h"
-#include "qwt_transform.h"
+#include "qwt_interval.h"
+
 #include <qdatetime.h>
-#include <limits.h>
+
+#include <limits>
 
 static inline double qwtMsecsForType( int type )
@@ -28,5 +30,5 @@
     };
 
-    if ( type < 0 || type >= static_cast<int>( sizeof( msecs ) / sizeof( msecs[0] ) ) )
+    if ( type < 0 || type >= static_cast< int >( sizeof( msecs ) / sizeof( msecs[0] ) ) )
         return 1.0;
 
@@ -38,11 +40,11 @@
 {
     double d = value / stepSize;
-    d = up ? ::ceil( d ) : ::floor( d );
-
-    return static_cast<int>( d * stepSize );
-}
-
-static double qwtIntervalWidth( const QDateTime &minDate,
-    const QDateTime &maxDate, QwtDate::IntervalType intervalType )
+    d = up ? std::ceil( d ) : std::floor( d );
+
+    return static_cast< int >( d * stepSize );
+}
+
+static double qwtIntervalWidth( const QDateTime& minDate,
+    const QDateTime& maxDate, QwtDate::IntervalType intervalType )
 {
     switch( intervalType )
@@ -50,23 +52,19 @@
         case QwtDate::Millisecond:
         {
+            return minDate.msecsTo( maxDate );
+        }
+        case QwtDate::Second:
+        {
+            return minDate.secsTo( maxDate );
+        }
+        case QwtDate::Minute:
+        {
             const double secsTo = minDate.secsTo( maxDate );
-            const double msecs = maxDate.time().msec() -
-                minDate.time().msec();
-
-            return secsTo * 1000 + msecs;
-        }
-        case QwtDate::Second:
-        {
-            return minDate.secsTo( maxDate );
-        }
-        case QwtDate::Minute:
+            return std::floor( secsTo / 60 );
+        }
+        case QwtDate::Hour:
         {
             const double secsTo = minDate.secsTo( maxDate );
-            return ::floor( secsTo / 60 );
-        }
-        case QwtDate::Hour:
-        {
-            const double secsTo = minDate.secsTo( maxDate );
-            return ::floor( secsTo / 3600 );
+            return std::floor( secsTo / 3600 );
         }
         case QwtDate::Day:
@@ -76,5 +74,5 @@
         case QwtDate::Week:
         {
-            return ::floor( minDate.daysTo( maxDate ) / 7.0 );
+            return std::floor( minDate.daysTo( maxDate ) / 7.0 );
         }
         case QwtDate::Month:
@@ -105,5 +103,5 @@
 
 static double qwtRoundedIntervalWidth(
-    const QDateTime &minDate, const QDateTime &maxDate,
+    const QDateTime& minDate, const QDateTime& maxDate,
     QwtDate::IntervalType intervalType )
 {
@@ -142,6 +140,6 @@
             const double stepSize = double( intervalSize ) / numSteps;
 
-            const double p = ::floor( ::log( stepSize ) / ::log( double( base ) ) );
-            const double fraction = qPow( base, p );
+            const double p = std::floor( std::log( stepSize ) / std::log( double( base ) ) );
+            const double fraction = std::pow( base, p );
 
             for ( uint n = base; n >= 1; n /= 2 )
@@ -165,5 +163,5 @@
     const int limits[], size_t numLimits )
 {
-    const int v = qCeil( intervalSize / double( numSteps ) );
+    const int v = qwtCeil( intervalSize / double( numSteps ) );
 
     for ( uint i = 0; i < numLimits - 1; i++ )
@@ -215,7 +213,7 @@
             const double v = intervalSize / double( numSteps );
             if ( v <= 5.0 )
-                stepSize = qCeil( v );
+                stepSize = std::ceil( v );
             else
-                stepSize = qCeil( v / 7 ) * 7;
+                stepSize = std::ceil( v / 7 ) * 7;
 
             break;
@@ -285,5 +283,5 @@
 
             if ( numSteps > 0 )
-                minStepSize = double( stepSize ) / numSteps;
+                minStepSize = stepSize / numSteps;
 
             break;
@@ -309,5 +307,5 @@
 
             if ( numSteps > 0 )
-                minStepSize = double( stepSize ) / numSteps;
+                minStepSize = stepSize / numSteps;
 
             break;
@@ -333,5 +331,5 @@
 
             if ( numSteps > 0 )
-                minStepSize = double( stepSize ) / numSteps;
+                minStepSize = stepSize / numSteps;
 
             break;
@@ -370,5 +368,5 @@
 
             if ( stepSize < maxMinSteps )
-                maxMinSteps = static_cast<int>( stepSize );
+                maxMinSteps = static_cast< int >( stepSize );
 
             static int limits[] = { 1, 2, 3, 4, 6, 12 };
@@ -378,5 +376,5 @@
 
             if ( numSteps > 0 )
-                minStepSize = double( stepSize ) / numSteps;
+                minStepSize = stepSize / numSteps;
 
             break;
@@ -399,5 +397,5 @@
 
                 if ( numSteps > 0 )
-                    minStepSize = double( stepSize ) / numSteps;
+                    minStepSize = stepSize / numSteps;
             }
 
@@ -417,9 +415,9 @@
 }
 
-static QList<double> qwtDstTicks( const QDateTime &dateTime,
+static QList< double > qwtDstTicks( const QDateTime& dateTime,
     int secondsMajor, int secondsMinor )
 {
     if ( secondsMinor <= 0 )
-        QList<double>();
+        return QList< double >();
 
     QDateTime minDate = dateTime.addSecs( -secondsMajor );
@@ -438,5 +436,7 @@
     }
 
-    QList<double> ticks;
+    QList< double > ticks;
+    ticks.reserve( 3600 / secondsMinor);
+
     for ( int i = 0; i < 3600; i += secondsMinor )
         ticks += dstMin + i * 1000.0;
@@ -446,5 +446,5 @@
 
 static QwtScaleDiv qwtDivideToSeconds(
-    const QDateTime &minDate, const QDateTime &maxDate,
+    const QDateTime& minDate, const QDateTime& maxDate,
     double stepSize, int maxMinSteps,
     QwtDate::IntervalType intervalType )
@@ -470,5 +470,5 @@
 
     const double s = qwtMsecsForType( intervalType ) / 1000;
-    const int secondsMajor = static_cast<int>( stepSize * s );
+    const int secondsMajor = static_cast< int >( stepSize * s );
     const double secondsMinor = minStepSize * s;
 
@@ -480,7 +480,7 @@
     double dstOff = 0;
 
-    QList<double> majorTicks;
-    QList<double> mediumTicks;
-    QList<double> minorTicks;
+    QList< double > majorTicks;
+    QList< double > mediumTicks;
+    QList< double > minorTicks;
 
     for ( QDateTime dt = minDate; dt <= maxDate;
@@ -513,5 +513,5 @@
         if ( secondsMinor > 0.0 )
         {
-            const int numMinorSteps = qFloor( secondsMajor / secondsMinor );
+            const int numMinorSteps = qwtFloor( secondsMajor / secondsMinor );
 
             for ( int i = 1; i < numMinorSteps; i++ )
@@ -554,5 +554,5 @@
 
 static QwtScaleDiv qwtDivideToMonths(
-    QDateTime &minDate, const QDateTime &maxDate,
+    QDateTime& minDate, const QDateTime& maxDate,
     double stepSize, int maxMinSteps )
 {
@@ -584,7 +584,7 @@
     }
 
-    QList<double> majorTicks;
-    QList<double> mediumTicks;
-    QList<double> minorTicks;
+    QList< double > majorTicks;
+    QList< double > mediumTicks;
+    QList< double > minorTicks;
 
     for ( QDateTime dt = minDate;
@@ -638,10 +638,10 @@
 
 static QwtScaleDiv qwtDivideToYears(
-    const QDateTime &minDate, const QDateTime &maxDate,
+    const QDateTime& minDate, const QDateTime& maxDate,
     double stepSize, int maxMinSteps )
 {
-    QList<double> majorTicks;
-    QList<double> mediumTicks;
-    QList<double> minorTicks;
+    QList< double > majorTicks;
+    QList< double > mediumTicks;
+    QList< double > minorTicks;
 
     double minStepSize = 0.0;
@@ -655,5 +655,5 @@
     int numMinorSteps = 0;
     if ( minStepSize > 0.0 )
-        numMinorSteps = qFloor( stepSize / minStepSize );
+        numMinorSteps = qwtFloor( stepSize / minStepSize );
 
     bool dateBC = minDate.date().year() < -1;
@@ -679,5 +679,5 @@
 
             const double years = qRound( i * minStepSize );
-            if ( years >= INT_MAX / 12 )
+            if ( years >= std::numeric_limits< int >::max() / 12 )
             {
                 tickDate = dt.addYears( years );
@@ -717,10 +717,10 @@
 class QwtDateScaleEngine::PrivateData
 {
-public:
-    PrivateData( Qt::TimeSpec spec ):
-        timeSpec( spec ),
-        utcOffset( 0 ),
-        week0Type( QwtDate::FirstThursday ),
-        maxWeeks( 4 )
+  public:
+    explicit PrivateData( Qt::TimeSpec spec )
+        : timeSpec( spec )
+        , utcOffset( 0 )
+        , week0Type( QwtDate::FirstThursday )
+        , maxWeeks( 4 )
     {
     }
@@ -734,19 +734,19 @@
 
 /*!
-  \brief Constructor
-
-  The engine is initialized to build scales for the
-  given time specification. It classifies intervals > 4 weeks
-  as >= Qt::Month. The first week of a year is defined like
-  for QwtDate::FirstThursday.
-
-  \param timeSpec Time specification
-
-  \sa setTimeSpec(), setMaxWeeks(), setWeek0Type()
+   \brief Constructor
+
+   The engine is initialized to build scales for the
+   given time specification. It classifies intervals > 4 weeks
+   as >= Qt::Month. The first week of a year is defined like
+   for QwtDate::FirstThursday.
+
+   \param timeSpec Time specification
+
+   \sa setTimeSpec(), setMaxWeeks(), setWeek0Type()
  */
-QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec ):
-    QwtLinearScaleEngine( 10 )
-{
-    d_data = new PrivateData( timeSpec );
+QwtDateScaleEngine::QwtDateScaleEngine( Qt::TimeSpec timeSpec )
+    : QwtLinearScaleEngine( 10 )
+{
+    m_data = new PrivateData( timeSpec );
 }
 
@@ -754,115 +754,115 @@
 QwtDateScaleEngine::~QwtDateScaleEngine()
 {
-    delete d_data;
+    delete m_data;
 }
 
 /*!
-  Set the time specification used by the engine
-
-  \param timeSpec Time specification
-  \sa timeSpec(), setUtcOffset(), toDateTime()
+   Set the time specification used by the engine
+
+   \param timeSpec Time specification
+   \sa timeSpec(), setUtcOffset(), toDateTime()
  */
 void QwtDateScaleEngine::setTimeSpec( Qt::TimeSpec timeSpec )
 {
-    d_data->timeSpec = timeSpec;
+    m_data->timeSpec = timeSpec;
 }
 
 /*!
-  \return Time specification used by the engine
-  \sa setTimeSpec(), utcOffset(), toDateTime()
+   \return Time specification used by the engine
+   \sa setTimeSpec(), utcOffset(), toDateTime()
  */
 Qt::TimeSpec QwtDateScaleEngine::timeSpec() const
 {
-    return d_data->timeSpec;
+    return m_data->timeSpec;
 }
 
 /*!
-  Set the offset in seconds from Coordinated Universal Time
-
-  \param seconds Offset in seconds
-
-  \note The offset has no effect beside for the time specification
+   Set the offset in seconds from Coordinated Universal Time
+
+   \param seconds Offset in seconds
+
+   \note The offset has no effect beside for the time specification
         Qt::OffsetFromUTC.
 
-  \sa QDate::utcOffset(), setTimeSpec(), toDateTime()
+   \sa QDate::utcOffset(), setTimeSpec(), toDateTime()
  */
 void QwtDateScaleEngine::setUtcOffset( int seconds )
 {
-    d_data->utcOffset = seconds;
+    m_data->utcOffset = seconds;
 }
 
 /*!
-  \return Offset in seconds from Coordinated Universal Time
-  \note The offset has no effect beside for the time specification
+   \return Offset in seconds from Coordinated Universal Time
+   \note The offset has no effect beside for the time specification
         Qt::OffsetFromUTC.
 
-  \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime()
+   \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime()
  */
 int QwtDateScaleEngine::utcOffset() const
 {
-    return d_data->utcOffset;
+    return m_data->utcOffset;
 }
 
 /*!
-  Sets how to identify the first week of a year.
-
-  \param week0Type Mode how to identify the first week of a year
-
-  \sa week0Type(), setMaxWeeks()
-  \note week0Type has no effect beside for intervals classified as
+   Sets how to identify the first week of a year.
+
+   \param week0Type Mode how to identify the first week of a year
+
+   \sa week0Type(), setMaxWeeks()
+   \note week0Type has no effect beside for intervals classified as
         QwtDate::Week.
  */
 void QwtDateScaleEngine::setWeek0Type( QwtDate::Week0Type week0Type )
 {
-    d_data->week0Type = week0Type;
+    m_data->week0Type = week0Type;
 }
 
 /*!
-  \return Setting how to identify the first week of a year.
-  \sa setWeek0Type(), maxWeeks()
+   \return Setting how to identify the first week of a year.
+   \sa setWeek0Type(), maxWeeks()
  */
 QwtDate::Week0Type QwtDateScaleEngine::week0Type() const
 {
-    return d_data->week0Type;
+    return m_data->week0Type;
 }
 
 /*!
-  Set a upper limit for the number of weeks, when an interval
-  can be classified as Qt::Week.
-
-  The default setting is 4 weeks.
-
-  \param weeks Upper limit for the number of weeks
-
-  \note In business charts a year is often divided
+   Set a upper limit for the number of weeks, when an interval
+   can be classified as Qt::Week.
+
+   The default setting is 4 weeks.
+
+   \param weeks Upper limit for the number of weeks
+
+   \note In business charts a year is often divided
         into weeks [1-52]
-  \sa maxWeeks(), setWeek0Type()
+   \sa maxWeeks(), setWeek0Type()
  */
 void QwtDateScaleEngine::setMaxWeeks( int weeks )
 {
-    d_data->maxWeeks = qMax( weeks, 0 );
+    m_data->maxWeeks = qMax( weeks, 0 );
 }
 
 /*!
-  \return Upper limit for the number of weeks, when an interval
+   \return Upper limit for the number of weeks, when an interval
           can be classified as Qt::Week.
-  \sa setMaxWeeks(), week0Type()
+   \sa setMaxWeeks(), week0Type()
  */
 int QwtDateScaleEngine::maxWeeks() const
 {
-    return d_data->maxWeeks;
+    return m_data->maxWeeks;
 }
 
 /*!
-  Classification of a date/time interval division
-
-  \param minDate Minimum ( = earlier ) of the interval
-  \param maxDate Maximum ( = later ) of the interval
-  \param maxSteps Maximum for the number of steps
-
-  \return Interval classification
+   Classification of a date/time interval division
+
+   \param minDate Minimum ( = earlier ) of the interval
+   \param maxDate Maximum ( = later ) of the interval
+   \param maxSteps Maximum for the number of steps
+
+   \return Interval classification
  */
 QwtDate::IntervalType QwtDateScaleEngine::intervalType(
-    const QDateTime &minDate, const QDateTime &maxDate,
+    const QDateTime& minDate, const QDateTime& maxDate,
     int maxSteps ) const
 {
@@ -880,5 +880,5 @@
     const int weeks = qwtRoundedIntervalWidth( minDate, maxDate, QwtDate::Week );
 
-    if ( weeks > d_data->maxWeeks )
+    if ( weeks > m_data->maxWeeks )
     {
         if ( days > 4 * maxSteps * 7 )
@@ -908,21 +908,21 @@
 
 /*!
-  Align and divide an interval
-
-  The algorithm aligns and divides the interval into steps.
-
-  Datetime interval divisions are usually not equidistant and the
-  calculated stepSize can only be used as an approximation
-  for the steps calculated by divideScale().
-
-  \param maxNumSteps Max. number of steps
-  \param x1 First limit of the interval (In/Out)
-  \param x2 Second limit of the interval (In/Out)
-  \param stepSize Step size (Out)
-
-  \sa QwtScaleEngine::setAttribute()
-*/
+   Align and divide an interval
+
+   The algorithm aligns and divides the interval into steps.
+
+   Datetime interval divisions are usually not equidistant and the
+   calculated stepSize can only be used as an approximation
+   for the steps calculated by divideScale().
+
+   \param maxNumSteps Max. number of steps
+   \param x1 First limit of the interval (In/Out)
+   \param x2 Second limit of the interval (In/Out)
+   \param stepSize Step size (Out)
+
+   \sa QwtScaleEngine::setAttribute()
+ */
 void QwtDateScaleEngine::autoScale( int maxNumSteps,
-    double &x1, double &x2, double &stepSize ) const
+    double& x1, double& x2, double& stepSize ) const
 {
     stepSize = 0.0;
@@ -989,5 +989,5 @@
                    calculates one.
    \return Calculated scale division
-*/
+ */
 QwtScaleDiv QwtDateScaleEngine::divideScale( double x1, double x2,
     int maxMajorSteps, int maxMinorSteps, double stepSize ) const
@@ -996,6 +996,6 @@
         maxMajorSteps = 1;
 
-    const double min = qMin( x1, x2 );
-    const double max = qMax( x1, x2 );
+    const double min = qwtMinF( x1, x2 );
+    const double max = qwtMaxF( x1, x2 );
 
     const QDateTime from = toDateTime( min );
@@ -1012,5 +1012,5 @@
         // the stepSize is used as a hint only
 
-        maxMajorSteps = qCeil( ( max - min ) / stepSize );
+        maxMajorSteps = qwtCeil( ( max - min ) / stepSize );
     }
 
@@ -1047,5 +1047,5 @@
 
 QwtScaleDiv QwtDateScaleEngine::buildScaleDiv(
-    const QDateTime &minDate, const QDateTime &maxDate,
+    const QDateTime& minDate, const QDateTime& maxDate,
     int maxMajorSteps, int maxMinorSteps,
     QwtDate::IntervalType intervalType ) const
@@ -1091,21 +1091,21 @@
 
 /*!
-  Align a date/time value for a step size
-
-  For Qt::Day alignments there is no "natural day 0" -
-  instead the first day of the year is used to avoid jumping
-  major ticks positions when panning a scale. For other alignments
-  ( f.e according to the first day of the month ) alignDate()
-  has to be overloaded.
-
-  \param dateTime Date/time value
-  \param stepSize Step size
-  \param intervalType Interval type
-  \param up When true dateTime is ceiled - otherwise it is floored
-
-  \return Aligned date/time value
+   Align a date/time value for a step size
+
+   For Qt::Day alignments there is no "natural day 0" -
+   instead the first day of the year is used to avoid jumping
+   major ticks positions when panning a scale. For other alignments
+   ( f.e according to the first day of the month ) alignDate()
+   has to be overloaded.
+
+   \param dateTime Date/time value
+   \param stepSize Step size
+   \param intervalType Interval type
+   \param up When true dateTime is ceiled - otherwise it is floored
+
+   \return Aligned date/time value
  */
 QDateTime QwtDateScaleEngine::alignDate(
-    const QDateTime &dateTime, double stepSize,
+    const QDateTime& dateTime, double stepSize,
     QwtDate::IntervalType intervalType, bool up ) const
 {
@@ -1116,5 +1116,9 @@
     if ( dateTime.timeSpec() == Qt::OffsetFromUTC )
     {
+#if QT_VERSION >= 0x050200
+        dt.setOffsetFromUtc( 0 );
+#else
         dt.setUtcOffset( 0 );
+#endif
     }
 
@@ -1124,5 +1128,5 @@
         {
             const int ms = qwtAlignValue(
-                dt.time().msec(), stepSize, up ) ;
+                dt.time().msec(), stepSize, up );
 
             dt = QwtDate::floor( dateTime, QwtDate::Second );
@@ -1204,5 +1208,5 @@
         {
             const QDate date = QwtDate::dateOfWeek0(
-                dt.date().year(), d_data->week0Type );
+                dt.date().year(), m_data->week0Type );
 
             int numWeeks = date.daysTo( dt.date() ) / 7;
@@ -1274,5 +1278,9 @@
     if ( dateTime.timeSpec() == Qt::OffsetFromUTC )
     {
+#if QT_VERSION >= 0x050200
+        dt.setOffsetFromUtc( dateTime.offsetFromUtc() );
+#else
         dt.setUtcOffset( dateTime.utcOffset() );
+#endif
     }
 
@@ -1281,14 +1289,14 @@
 
 /*!
-  Translate a double value into a QDateTime object.
-
-  For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate()
-
-  \return QDateTime object initialized with timeSpec() and utcOffset().
-  \sa timeSpec(), utcOffset(), QwtDate::toDateTime()
+   Translate a double value into a QDateTime object.
+
+   For QDateTime result is bounded by QwtDate::minDate() and QwtDate::maxDate()
+
+   \return QDateTime object initialized with timeSpec() and utcOffset().
+   \sa timeSpec(), utcOffset(), QwtDate::toDateTime()
  */
 QDateTime QwtDateScaleEngine::toDateTime( double value ) const
 {
-    QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );
+    QDateTime dt = QwtDate::toDateTime( value, m_data->timeSpec );
     if ( !dt.isValid() )
     {
@@ -1296,11 +1304,15 @@
             ? QwtDate::minDate() : QwtDate::maxDate();
 
-        dt = QDateTime( date, QTime( 0, 0 ), d_data->timeSpec );
-    }
-
-    if ( d_data->timeSpec == Qt::OffsetFromUTC )
-    {
-        dt = dt.addSecs( d_data->utcOffset );
-        dt.setUtcOffset( d_data->utcOffset );
+        dt = QDateTime( date, QTime( 0, 0 ), m_data->timeSpec );
+    }
+
+    if ( m_data->timeSpec == Qt::OffsetFromUTC )
+    {
+        dt = dt.addSecs( m_data->utcOffset );
+#if QT_VERSION >= 0x050200
+        dt.setOffsetFromUtc( m_data->utcOffset );
+#else
+        dt.setUtcOffset( m_data->utcOffset );
+#endif
     }
 
