改进代码

This commit is contained in:
feiyangqingyun
2021-10-08 10:52:05 +08:00
parent f6923b97a2
commit 200b7eeafb
171 changed files with 2894 additions and 1940 deletions

View File

@@ -31,7 +31,7 @@ static const QwtJulianDay maxJulianDayD = std::numeric_limits<int>::max();
#endif
static QString qwtExpandedFormat( const QString & format,
static QString qwtExpandedFormat( const QString & format,
const QDateTime &dateTime, QwtDate::Week0Type week0Type )
{
const int week = QwtDate::weekNumber( dateTime.date(), week0Type );
@@ -194,7 +194,7 @@ static inline Qt::DayOfWeek qwtFirstDayOfWeek()
#endif
}
static inline void qwtFloorTime(
static inline void qwtFloorTime(
QwtDate::IntervalType intervalType, QDateTime &dt )
{
// when dt is inside the special hour where DST is ending
@@ -223,7 +223,7 @@ static inline void qwtFloorTime(
{
dt.setTime( QTime( t.hour(), 0, 0 ) );
break;
}
}
default:
break;
}
@@ -232,7 +232,7 @@ static inline void qwtFloorTime(
dt = dt.toTimeSpec( Qt::LocalTime );
}
static inline QDateTime qwtToTimeSpec(
static inline QDateTime qwtToTimeSpec(
const QDateTime &dt, Qt::TimeSpec spec )
{
if ( dt.timeSpec() == spec )
@@ -254,6 +254,8 @@ static inline QDateTime qwtToTimeSpec(
return dt.toTimeSpec( spec );
}
#if 0
static inline double qwtToJulianDay( int year, int month, int day )
{
// code from QDate but using doubles to avoid overflows
@@ -279,9 +281,11 @@ static inline qint64 qwtFloorDiv( int a, int b )
{
if ( a < 0 )
a -= b - 1;
return a / b;
}
}
#endif
static inline QDate qwtToDate( int year, int month = 1, int day = 1 )
{
@@ -318,7 +322,7 @@ static inline QDate qwtToDate( int year, int month = 1, int day = 1 )
/*!
Translate from double to QDateTime
\param value Number of milliseconds since the epoch,
\param value Number of milliseconds since the epoch,
1970-01-01T00:00:00 UTC
\param timeSpec Time specification
\return Datetime value
@@ -372,7 +376,7 @@ double QwtDate::toDouble( const QDateTime &dateTime )
const double days = dt.date().toJulianDay() - QwtDate::JulianDayForEpoch;
const QTime time = dt.time();
const double secs = 3600.0 * time.hour() +
const double secs = 3600.0 * time.hour() +
60.0 * time.minute() + time.second();
return days * msecsPerDay + time.msec() + 1000.0 * secs;
@@ -382,7 +386,7 @@ double QwtDate::toDouble( const QDateTime &dateTime )
Ceil a datetime according the interval type
\param dateTime Datetime value
\param intervalType Interval type, how to ceil.
\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
@@ -450,7 +454,7 @@ QDateTime QwtDate::ceil( const QDateTime &dateTime, IntervalType intervalType )
case QwtDate::Month:
{
dt.setTime( QTime( 0, 0 ) );
dt.setDate( qwtToDate( dateTime.date().year(),
dt.setDate( qwtToDate( dateTime.date().year(),
dateTime.date().month() ) );
if ( dt < dateTime )
@@ -483,14 +487,14 @@ QDateTime QwtDate::ceil( const QDateTime &dateTime, IntervalType intervalType )
Floor a datetime according the interval type
\param dateTime Datetime value
\param intervalType Interval type, how to ceil.
\param intervalType Interval type, how to ceil.
F.e. when intervalType = QwtDate::Months,
the result will be ceiled to the next
the result will be ceiled to the next
beginning of a month
\return Floored datetime
\sa floor()
*/
QDateTime QwtDate::floor( const QDateTime &dateTime,
QDateTime QwtDate::floor( const QDateTime &dateTime,
IntervalType intervalType )
{
if ( dateTime.date() <= QwtDate::minDate() )
@@ -532,7 +536,7 @@ QDateTime QwtDate::floor( const QDateTime &dateTime,
{
dt.setTime( QTime( 0, 0 ) );
const QDate date = qwtToDate( dt.date().year(),
const QDate date = qwtToDate( dt.date().year(),
dt.date().month() );
dt.setDate( date );
@@ -555,7 +559,7 @@ QDateTime QwtDate::floor( const QDateTime &dateTime,
/*!
Minimum for the supported date range
The range of valid dates depends on how QDate stores the
The range of valid dates depends on how QDate stores the
Julian day internally.
- For Qt4 it is "Tue Jan 2 -4713"
@@ -576,7 +580,7 @@ QDate QwtDate::minDate()
/*!
Maximum for the supported date range
The range of valid dates depends on how QDate stores the
The range of valid dates depends on how QDate stores the
Julian day internally.
- For Qt4 it is "Tue Jun 3 5874898"
@@ -599,14 +603,14 @@ QDate QwtDate::maxDate()
\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() ).
( 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 )
{
const Qt::DayOfWeek firstDayOfWeek = qwtFirstDayOfWeek();
@@ -623,7 +627,7 @@ QDate QwtDate::dateOfWeek0( int year, Week0Type type )
if ( type == QwtDate::FirstThursday )
{
// according to ISO 8601 the first week is defined
// by the first thursday.
// by the first thursday.
int d = Qt::Thursday - firstDayOfWeek;
if ( d < 0 )
@@ -640,7 +644,7 @@ QDate QwtDate::dateOfWeek0( int year, Week0Type type )
Find the week number of a date
- QwtDate::FirstThursday\n
Corresponding to ISO 8601 ( see QDate::weekNumber() ).
Corresponding to ISO 8601 ( see QDate::weekNumber() ).
- QwtDate::FirstDay\n
Number of weeks that have begun since dateOfWeek0().
@@ -736,7 +740,7 @@ int QwtDate::utcOffset( const QDateTime &dateTime )
- ww\n
week number with a leading zero ( 01 - 53 )
As week 1 usually starts in the previous year a special rule
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.