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 
13 {
14 public:
15  explicit PrivateData( Qt::TimeSpec spec ):
16  timeSpec( spec ),
17  utcOffset( 0 ),
18  week0Type( QwtDate::FirstThursday )
19  {
20  dateFormats[ QwtDate::Millisecond ] = "hh:mm:ss:zzz\nddd dd MMM yyyy";
21  dateFormats[ QwtDate::Second ] = "hh:mm:ss\nddd dd MMM yyyy";
22  dateFormats[ QwtDate::Minute ] = "hh:mm\nddd dd MMM yyyy";
23  dateFormats[ QwtDate::Hour ] = "hh:mm\nddd dd MMM yyyy";
24  dateFormats[ QwtDate::Day ] = "ddd dd MMM yyyy";
25  dateFormats[ QwtDate::Week ] = "Www yyyy";
26  dateFormats[ QwtDate::Month ] = "MMM yyyy";
27  dateFormats[ QwtDate::Year ] = "yyyy";
28  }
29 
30  Qt::TimeSpec timeSpec;
31  int utcOffset;
33  QString dateFormats[ QwtDate::Year + 1 ];
34 };
35 
48 {
49  d_data = new PrivateData( timeSpec );
50 }
51 
54 {
55  delete d_data;
56 }
57 
65 {
67 }
68 
73 Qt::TimeSpec QwtDateScaleDraw::timeSpec() const
74 {
75  return d_data->timeSpec;
76 }
77 
89 {
90  d_data->utcOffset = seconds;
91 }
92 
101 {
102  return d_data->utcOffset;
103 }
104 
115 {
117 }
118 
124 {
125  return d_data->week0Type;
126 }
127 
137  QwtDate::IntervalType intervalType, const QString &format )
138 {
139  if ( intervalType >= QwtDate::Millisecond &&
140  intervalType <= QwtDate::Year )
141  {
142  d_data->dateFormats[ intervalType ] = format;
143  }
144 }
145 
153 {
154  if ( intervalType >= QwtDate::Millisecond &&
155  intervalType <= QwtDate::Year )
156  {
157  return d_data->dateFormats[ intervalType ];
158  }
159 
160  return QString();
161 }
162 
179 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime &dateTime,
181 {
182  Q_UNUSED( dateTime )
183 
184  if ( intervalType >= QwtDate::Millisecond &&
185  intervalType <= QwtDate::Year )
186  {
187  return d_data->dateFormats[ intervalType ];
188  }
189 
191 }
192 
204 QwtText QwtDateScaleDraw::label( double value ) const
205 {
206  const QDateTime dt = toDateTime( value );
207  const QString fmt = dateFormatOfDate(
208  dt, intervalType( scaleDiv() ) );
209 
210  return QwtDate::toString( dt, fmt, d_data->week0Type );
211 }
212 
223  const QwtScaleDiv &scaleDiv ) const
224 {
225  int intvType = QwtDate::Year;
226 
227  bool alignedToWeeks = true;
228 
229  const QList<double> ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick );
230  for ( int i = 0; i < ticks.size(); i++ )
231  {
232  const QDateTime dt = toDateTime( ticks[i] );
233  for ( int j = QwtDate::Second; j <= intvType; j++ )
234  {
235  const QDateTime dt0 = QwtDate::floor( dt,
236  static_cast<QwtDate::IntervalType>( j ) );
237 
238  if ( dt0 != dt )
239  {
240  if ( j == QwtDate::Week )
241  {
242  alignedToWeeks = false;
243  }
244  else
245  {
246  intvType = j - 1;
247  break;
248  }
249  }
250  }
251 
252  if ( intvType == QwtDate::Millisecond )
253  break;
254  }
255 
256  if ( intvType == QwtDate::Week && !alignedToWeeks )
257  intvType = QwtDate::Day;
258 
259  return static_cast<QwtDate::IntervalType>( intvType );
260 }
261 
268 QDateTime QwtDateScaleDraw::toDateTime( double value ) const
269 {
270  QDateTime dt = QwtDate::toDateTime( value, d_data->timeSpec );
271  if ( d_data->timeSpec == Qt::OffsetFromUTC )
272  {
273  dt = dt.addSecs( d_data->utcOffset );
274  dt.setUtcOffset( d_data->utcOffset );
275  }
276 
277  return dt;
278 }
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
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
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:493
A class representing a scale division.
Definition: qwt_scale_div.h:36
QwtDate::Week0Type week0Type() const
void setUtcOffset(int seconds)
std::chrono::duration< std::int_fast64_t > 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
virtual QwtText label(double) const
Convert a value into its representing label.
Qt::TimeSpec timeSpec() const
static QDateTime toDateTime(double value, Qt::TimeSpec=Qt::UTC)
Definition: qwt_date.cpp:329
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:750
int i
The interval is related to seconds.
Definition: qwt_date.h:81
QList< double > ticks(int tickType) const
The interval is related to days.
Definition: qwt_date.h:90


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17