qwt_date_scale_draw.cpp
Go to the documentation of this file.
1 /******************************************************************************
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 )
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 
48 QwtDateScaleDraw::QwtDateScaleDraw( Qt::TimeSpec timeSpec )
49 {
50  m_data = new PrivateData( timeSpec );
51 }
52 
55 {
56  delete m_data;
57 }
58 
65 void QwtDateScaleDraw::setTimeSpec( Qt::TimeSpec timeSpec )
66 {
68 }
69 
74 Qt::TimeSpec QwtDateScaleDraw::timeSpec() const
75 {
76  return m_data->timeSpec;
77 }
78 
89 void QwtDateScaleDraw::setUtcOffset( int seconds )
90 {
91  m_data->utcOffset = seconds;
92 }
93 
102 {
103  return m_data->utcOffset;
104 }
105 
116 {
118 }
119 
125 {
126  return m_data->week0Type;
127 }
128 
138  QwtDate::IntervalType intervalType, const QString& format )
139 {
142  {
144  }
145 }
146 
153  QwtDate::IntervalType intervalType ) const
154 {
157  {
158  return m_data->dateFormats[ intervalType ];
159  }
160 
161  return QString();
162 }
163 
180 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime& dateTime,
181  QwtDate::IntervalType intervalType ) const
182 {
183  Q_UNUSED( dateTime )
184 
187  {
188  return m_data->dateFormats[ intervalType ];
189  }
190 
192 }
193 
205 QwtText QwtDateScaleDraw::label( double value ) const
206 {
207  const QDateTime dt = toDateTime( value );
208  const QString fmt = dateFormatOfDate(
209  dt, intervalType( scaleDiv() ) );
210 
211  return QwtDate::toString( dt, fmt, m_data->week0Type );
212 }
213 
224  const QwtScaleDiv& scaleDiv ) const
225 {
226  int intvType = QwtDate::Year;
227 
228  bool alignedToWeeks = true;
229 
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, m_data->timeSpec );
272  if ( m_data->timeSpec == Qt::OffsetFromUTC )
273  {
274  dt = dt.addSecs( m_data->utcOffset );
275 #if QT_VERSION >= 0x050200
276  dt.setOffsetFromUtc( m_data->utcOffset );
277 #else
278  dt.setUtcOffset( m_data->utcOffset );
279 #endif
280  }
281 
282  return dt;
283 }
QwtDateScaleDraw::setTimeSpec
void setTimeSpec(Qt::TimeSpec)
Definition: qwt_date_scale_draw.cpp:65
QwtDate::Hour
@ Hour
The interval is related to hours.
Definition: qwt_date.h:94
QwtDate::Minute
@ Minute
The interval is related to minutes.
Definition: qwt_date.h:91
QwtDateScaleDraw::PrivateData::PrivateData
PrivateData(Qt::TimeSpec spec)
Definition: qwt_date_scale_draw.cpp:23
QwtDateScaleDraw::setWeek0Type
void setWeek0Type(QwtDate::Week0Type)
Definition: qwt_date_scale_draw.cpp:115
QwtDate::Week0Type
Week0Type
Definition: qwt_date.h:56
QwtDateScaleDraw::PrivateData::week0Type
QwtDate::Week0Type week0Type
Definition: qwt_date_scale_draw.cpp:40
QwtDate::toString
static QString toString(const QDateTime &, const QString &format, Week0Type)
Definition: qwt_date.cpp:686
QwtDate::Millisecond
@ Millisecond
The interval is related to milliseconds.
Definition: qwt_date.h:85
QwtDateScaleDraw::toDateTime
QDateTime toDateTime(double) const
Definition: qwt_date_scale_draw.cpp:269
QwtDateScaleDraw::week0Type
QwtDate::Week0Type week0Type() const
Definition: qwt_date_scale_draw.cpp:124
QwtAbstractScaleDraw::scaleDiv
const QwtScaleDiv & scaleDiv() const
Definition: qwt_abstract_scale_draw.cpp:133
QList< double >
QwtDateScaleDraw::PrivateData::utcOffset
int utcOffset
Definition: qwt_date_scale_draw.cpp:39
QwtScaleDiv::ticks
QList< double > ticks(int tickType) const
Definition: qwt_scale_div.cpp:309
QwtScaleDiv::MajorTick
@ MajorTick
Major ticks.
Definition: qwt_scale_div.h:49
QwtText
A class representing a text.
Definition: qwt_text.h:51
qwt_date_scale_draw.h
QwtDate::Week
@ Week
The interval is related to weeks.
Definition: qwt_date.h:100
QwtDate::IntervalType
IntervalType
Definition: qwt_date.h:82
QwtDate::FirstThursday
@ FirstThursday
Definition: qwt_date.h:72
QwtDate::Day
@ Day
The interval is related to days.
Definition: qwt_date.h:97
QwtDate::Second
@ Second
The interval is related to seconds.
Definition: qwt_date.h:88
QwtDateScaleDraw::PrivateData::dateFormats
QString dateFormats[QwtDate::Year+1]
Definition: qwt_date_scale_draw.cpp:41
QwtDateScaleDraw::QwtDateScaleDraw
QwtDateScaleDraw(Qt::TimeSpec=Qt::LocalTime)
Constructor.
Definition: qwt_date_scale_draw.cpp:48
QwtDateScaleDraw::timeSpec
Qt::TimeSpec timeSpec() const
Definition: qwt_date_scale_draw.cpp:74
QwtDateScaleDraw::PrivateData::timeSpec
Qt::TimeSpec timeSpec
Definition: qwt_date_scale_draw.cpp:38
QwtDateScaleDraw::label
virtual QwtText label(double) const QWT_OVERRIDE
Convert a value into its representing label.
Definition: qwt_date_scale_draw.cpp:205
QwtDate::toDateTime
static QDateTime toDateTime(double value, Qt::TimeSpec=Qt::UTC)
Definition: qwt_date.cpp:261
QwtDateScaleDraw::dateFormatOfDate
virtual QString dateFormatOfDate(const QDateTime &, QwtDate::IntervalType) const
Definition: qwt_date_scale_draw.cpp:180
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
QwtDateScaleDraw::PrivateData
Definition: qwt_date_scale_draw.cpp:13
QwtDateScaleDraw::intervalType
virtual QwtDate::IntervalType intervalType(const QwtScaleDiv &) const
Definition: qwt_date_scale_draw.cpp:223
QwtDate::Year
@ Year
The interval is related to years.
Definition: qwt_date.h:106
QwtDate::Month
@ Month
The interval is related to months.
Definition: qwt_date.h:103
QwtDate::floor
static QDateTime floor(const QDateTime &, IntervalType)
Definition: qwt_date.cpp:425
QwtDateScaleDraw::~QwtDateScaleDraw
virtual ~QwtDateScaleDraw()
Destructor.
Definition: qwt_date_scale_draw.cpp:54
QwtDateScaleDraw::utcOffset
int utcOffset() const
Definition: qwt_date_scale_draw.cpp:101
QwtScaleDiv
A class representing a scale division.
Definition: qwt_scale_div.h:33
qwt_text.h
QwtDateScaleDraw::setUtcOffset
void setUtcOffset(int seconds)
Definition: qwt_date_scale_draw.cpp:89
QwtDateScaleDraw::setDateFormat
void setDateFormat(QwtDate::IntervalType, const QString &)
Definition: qwt_date_scale_draw.cpp:137
QwtDateScaleDraw::dateFormat
QString dateFormat(QwtDate::IntervalType) const
Definition: qwt_date_scale_draw.cpp:152
QwtDateScaleDraw::m_data
PrivateData * m_data
Definition: qwt_date_scale_draw.h:89


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Aug 11 2024 02:24:24