qwt_date_scale_draw.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_date_scale_draw.h"
11 #include "qwt_text.h"
12 
14 {
15 public:
16  explicit PrivateData( Qt::TimeSpec spec ):
17  timeSpec( spec ),
18  utcOffset( 0 ),
19  week0Type( QwtDate::FirstThursday )
20  {
21  dateFormats[ QwtDate::Millisecond ] = "hh:mm:ss:zzz\nddd dd MMM yyyy";
22  dateFormats[ QwtDate::Second ] = "hh:mm:ss\nddd dd MMM yyyy";
23  dateFormats[ QwtDate::Minute ] = "hh:mm\nddd dd MMM yyyy";
24  dateFormats[ QwtDate::Hour ] = "hh:mm\nddd dd MMM yyyy";
25  dateFormats[ QwtDate::Day ] = "ddd dd MMM yyyy";
26  dateFormats[ QwtDate::Week ] = "Www yyyy";
27  dateFormats[ QwtDate::Month ] = "MMM yyyy";
28  dateFormats[ QwtDate::Year ] = "yyyy";
29  }
30 
31  Qt::TimeSpec timeSpec;
32  int utcOffset;
34  QString dateFormats[ QwtDate::Year + 1 ];
35 };
36 
49 {
50  d_data = new PrivateData( timeSpec );
51 }
52 
55 {
56  delete d_data;
57 }
58 
66 {
68 }
69 
74 Qt::TimeSpec QwtDateScaleDraw::timeSpec() const
75 {
76  return d_data->timeSpec;
77 }
78 
89 void QwtDateScaleDraw::setUtcOffset( int seconds )
90 {
91  d_data->utcOffset = seconds;
92 }
93 
102 {
103  return d_data->utcOffset;
104 }
105 
116 {
118 }
119 
125 {
126  return d_data->week0Type;
127 }
128 
138  QwtDate::IntervalType intervalType, const QString &format )
139 {
140  if ( intervalType >= QwtDate::Millisecond &&
141  intervalType <= QwtDate::Year )
142  {
144  }
145 }
146 
154 {
155  if ( intervalType >= QwtDate::Millisecond &&
156  intervalType <= QwtDate::Year )
157  {
158  return d_data->dateFormats[ intervalType ];
159  }
160 
161  return QString();
162 }
163 
180 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime &dateTime,
182 {
183  Q_UNUSED( dateTime )
184 
185  if ( intervalType >= QwtDate::Millisecond &&
186  intervalType <= QwtDate::Year )
187  {
188  return d_data->dateFormats[ intervalType ];
189  }
190 
192 }
193 
206 {
207  const QDateTime dt = toDateTime( value );
208  const QString fmt = dateFormatOfDate(
209  dt, intervalType( scaleDiv() ) );
210 
211  return QwtDate::toString( dt, fmt, d_data->week0Type );
212 }
213 
224  const QwtScaleDiv &scaleDiv ) const
225 {
226  int intvType = QwtDate::Year;
227 
228  bool alignedToWeeks = true;
229 
230  const QList<double> ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick );
231  for ( int i = 0; i < ticks.size(); i++ )
232  {
233  const QDateTime dt = toDateTime( ticks[i] );
234  for ( int j = QwtDate::Second; j <= intvType; j++ )
235  {
236  const QDateTime dt0 = QwtDate::floor( dt,
237  static_cast<QwtDate::IntervalType>( j ) );
238 
239  if ( dt0 != dt )
240  {
241  if ( j == QwtDate::Week )
242  {
243  alignedToWeeks = false;
244  }
245  else
246  {
247  intvType = j - 1;
248  break;
249  }
250  }
251  }
252 
253  if ( intvType == QwtDate::Millisecond )
254  break;
255  }
256 
257  if ( intvType == QwtDate::Week && !alignedToWeeks )
258  intvType = QwtDate::Day;
259 
260  return static_cast<QwtDate::IntervalType>( intvType );
261 }
262 
269 QDateTime QwtDateScaleDraw::toDateTime( double value ) const
270 {
271  QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );
272  if ( d_data->timeSpec == Qt::OffsetFromUTC )
273  {
274  dt = dt.addSecs( d_data->utcOffset );
275 #if QT_VERSION >= 0x050200
276  dt.setOffsetFromUtc( d_data->utcOffset );
277 #else
278  dt.setUtcOffset( d_data->utcOffset );
279 #endif
280  }
281 
282  return dt;
283 }
The interval is related to weeks.
Definition: qwt_date.h:93
QwtDateScaleDraw(Qt::TimeSpec=Qt::LocalTime)
Constructor.
virtual QString dateFormatOfDate(const QDateTime &, QwtDate::IntervalType) const
enum MQTTPropertyCodes value
The interval is related to years.
Definition: qwt_date.h:99
QDateTime toDateTime(double) const
The interval is related to months.
Definition: qwt_date.h:96
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
virtual QwtDate::IntervalType intervalType(const QwtScaleDiv &) const
virtual ~QwtDateScaleDraw()
Destructor.
QString dateFormat(QwtDate::IntervalType) const
static QDateTime floor(const QDateTime &, IntervalType)
Definition: qwt_date.cpp:425
A class representing a scale division.
Definition: qwt_scale_div.h:33
QwtDate::Week0Type week0Type() const
void setUtcOffset(int seconds)
IntervalType
Definition: qwt_date.h:75
The interval is related to minutes.
Definition: qwt_date.h:84
The interval is related to hours.
Definition: qwt_date.h:87
const QwtScaleDiv & scaleDiv() const
void setWeek0Type(QwtDate::Week0Type)
A class representing a text.
Definition: qwt_text.h:51
void setTimeSpec(Qt::TimeSpec)
void setDateFormat(QwtDate::IntervalType, const QString &)
The interval is related to milliseconds.
Definition: qwt_date.h:78
Week0Type
Definition: qwt_date.h:49
Qt::TimeSpec timeSpec() const
static QDateTime toDateTime(double value, Qt::TimeSpec=Qt::UTC)
Definition: qwt_date.cpp:261
PrivateData * d_data
QString dateFormats[QwtDate::Year+1]
A collection of methods around date/time values.
Definition: qwt_date.h:42
static QString toString(const QDateTime &, const QString &format, Week0Type)
Definition: qwt_date.cpp:686
The interval is related to seconds.
Definition: qwt_date.h:81
QList< double > ticks(int tickType) const
virtual QwtText label(double) const QWT_OVERRIDE
Convert a value into its representing label.
The interval is related to days.
Definition: qwt_date.h:90


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10