Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_date_scale_draw.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_date_scale_draw.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_date_scale_draw.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_date_scale_draw.h" 11 #include "qwt_text.h" 11 12 12 13 class QwtDateScaleDraw::PrivateData 13 14 { 14 public: 15 PrivateData( Qt::TimeSpec spec ) :16 timeSpec( spec ) ,17 utcOffset( 0 ) ,18 week0Type( QwtDate::FirstThursday ) 15 public: 16 explicit PrivateData( Qt::TimeSpec spec ) 17 : timeSpec( spec ) 18 , utcOffset( 0 ) 19 , week0Type( QwtDate::FirstThursday ) 19 20 { 20 21 dateFormats[ QwtDate::Millisecond ] = "hh:mm:ss:zzz\nddd dd MMM yyyy"; … … 35 36 36 37 /*! 37 \brief Constructor 38 39 The default setting is to display tick labels for the 40 given time specification. The first week of a year is defined like 41 for QwtDate::FirstThursday. 42 43 \param timeSpec Time specification 44 45 \sa setTimeSpec(), setWeek0Type() 38 \brief Constructor 39 40 The default setting is to display tick labels for the 41 given time specification. The first week of a year is defined like 42 for QwtDate::FirstThursday. 43 44 \param timeSpec Time specification 45 46 \sa setTimeSpec(), setWeek0Type() 46 47 */ 47 48 QwtDateScaleDraw::QwtDateScaleDraw( Qt::TimeSpec timeSpec ) 48 49 { 49 d_data = new PrivateData( timeSpec );50 m_data = new PrivateData( timeSpec ); 50 51 } 51 52 … … 53 54 QwtDateScaleDraw::~QwtDateScaleDraw() 54 55 { 55 delete d_data;56 } 57 58 /*! 59 Set the time specification used for the tick labels 60 61 \param timeSpec Time specification 62 \sa timeSpec(), setUtcOffset(), toDateTime() 56 delete m_data; 57 } 58 59 /*! 60 Set the time specification used for the tick labels 61 62 \param timeSpec Time specification 63 \sa timeSpec(), setUtcOffset(), toDateTime() 63 64 */ 64 65 void QwtDateScaleDraw::setTimeSpec( Qt::TimeSpec timeSpec ) 65 66 { 66 d_data->timeSpec = timeSpec;67 } 68 69 /*! 70 \return Time specification used for the tick labels 71 \sa setTimeSpec(), utcOffset(), toDateTime() 67 m_data->timeSpec = timeSpec; 68 } 69 70 /*! 71 \return Time specification used for the tick labels 72 \sa setTimeSpec(), utcOffset(), toDateTime() 72 73 */ 73 74 Qt::TimeSpec QwtDateScaleDraw::timeSpec() const 74 75 { 75 return d_data->timeSpec;76 } 77 78 /*! 79 Set the offset in seconds from Coordinated Universal Time 80 81 \param seconds Offset in seconds 82 83 \note The offset has no effect beside for the time specification 76 return m_data->timeSpec; 77 } 78 79 /*! 80 Set the offset in seconds from Coordinated Universal Time 81 82 \param seconds Offset in seconds 83 84 \note The offset has no effect beside for the time specification 84 85 Qt::OffsetFromUTC. 85 86 86 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 87 \sa QDate::utcOffset(), setTimeSpec(), toDateTime() 87 88 */ 88 89 void QwtDateScaleDraw::setUtcOffset( int seconds ) 89 90 { 90 d_data->utcOffset = seconds;91 } 92 93 /*! 94 \return Offset in seconds from Coordinated Universal Time 95 \note The offset has no effect beside for the time specification 91 m_data->utcOffset = seconds; 92 } 93 94 /*! 95 \return Offset in seconds from Coordinated Universal Time 96 \note The offset has no effect beside for the time specification 96 97 Qt::OffsetFromUTC. 97 98 98 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 99 \sa QDate::setUtcOffset(), setTimeSpec(), toDateTime() 99 100 */ 100 101 int QwtDateScaleDraw::utcOffset() const 101 102 { 102 return d_data->utcOffset;103 } 104 105 /*! 106 Sets how to identify the first week of a year. 107 108 \param week0Type Mode how to identify the first week of a year 109 110 \sa week0Type(). 111 \note week0Type has no effect beside for intervals classified as 103 return m_data->utcOffset; 104 } 105 106 /*! 107 Sets how to identify the first week of a year. 108 109 \param week0Type Mode how to identify the first week of a year 110 111 \sa week0Type(). 112 \note week0Type has no effect beside for intervals classified as 112 113 QwtDate::Week. 113 114 */ 114 115 void QwtDateScaleDraw::setWeek0Type( QwtDate::Week0Type week0Type ) 115 116 { 116 d_data->week0Type = week0Type;117 } 118 119 /*! 120 \return Setting how to identify the first week of a year. 121 \sa setWeek0Type() 117 m_data->week0Type = week0Type; 118 } 119 120 /*! 121 \return Setting how to identify the first week of a year. 122 \sa setWeek0Type() 122 123 */ 123 124 QwtDate::Week0Type QwtDateScaleDraw::week0Type() const 124 125 { 125 return d_data->week0Type;126 } 127 128 /*! 129 Set the default format string for an datetime interval type 130 131 \param intervalType Interval type 132 \param format Default format string 133 134 \sa dateFormat(), dateFormatOfDate(), QwtDate::toString() 126 return m_data->week0Type; 127 } 128 129 /*! 130 Set the default format string for an datetime interval type 131 132 \param intervalType Interval type 133 \param format Default format string 134 135 \sa dateFormat(), dateFormatOfDate(), QwtDate::toString() 135 136 */ 136 137 void QwtDateScaleDraw::setDateFormat( 137 QwtDate::IntervalType intervalType, const QString &format )138 QwtDate::IntervalType intervalType, const QString& format ) 138 139 { 139 140 if ( intervalType >= QwtDate::Millisecond && 140 141 intervalType <= QwtDate::Year ) 141 142 { 142 d_data->dateFormats[ intervalType ] = format;143 } 144 } 145 146 /*! 147 \param intervalType Interval type 148 \return Default format string for an datetime interval type 149 \sa setDateFormat(), dateFormatOfDate() 143 m_data->dateFormats[ intervalType ] = format; 144 } 145 } 146 147 /*! 148 \param intervalType Interval type 149 \return Default format string for an datetime interval type 150 \sa setDateFormat(), dateFormatOfDate() 150 151 */ 151 152 QString QwtDateScaleDraw::dateFormat( … … 155 156 intervalType <= QwtDate::Year ) 156 157 { 157 return d_data->dateFormats[ intervalType ];158 return m_data->dateFormats[ intervalType ]; 158 159 } 159 160 … … 162 163 163 164 /*! 164 Format string for the representation of a datetime 165 166 dateFormatOfDate() is intended to be overloaded for 167 situations, where formats are individual for specific 168 datetime values. 169 170 The default setting ignores dateTime and return 171 the default format for the interval type. 172 173 \param dateTime Datetime value 174 \param intervalType Interval type 175 \return Format string 176 177 \sa setDateFormat(), QwtDate::toString() 178 */ 179 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime &dateTime,165 Format string for the representation of a datetime 166 167 dateFormatOfDate() is intended to be overloaded for 168 situations, where formats are individual for specific 169 datetime values. 170 171 The default setting ignores dateTime and return 172 the default format for the interval type. 173 174 \param dateTime Datetime value 175 \param intervalType Interval type 176 \return Format string 177 178 \sa setDateFormat(), QwtDate::toString() 179 */ 180 QString QwtDateScaleDraw::dateFormatOfDate( const QDateTime& dateTime, 180 181 QwtDate::IntervalType intervalType ) const 181 182 { … … 185 186 intervalType <= QwtDate::Year ) 186 187 { 187 return d_data->dateFormats[ intervalType ];188 } 189 190 return d_data->dateFormats[ QwtDate::Second ];191 } 192 193 /*! 194 \brief Convert a value into its representing label 195 196 The value is converted to a datetime value using toDateTime() 197 and converted to a plain text using QwtDate::toString(). 198 199 \param value Value 200 \return Label string. 201 202 \sa dateFormatOfDate() 203 */ 188 return m_data->dateFormats[ intervalType ]; 189 } 190 191 return m_data->dateFormats[ QwtDate::Second ]; 192 } 193 194 /*! 195 \brief Convert a value into its representing label 196 197 The value is converted to a datetime value using toDateTime() 198 and converted to a plain text using QwtDate::toString(). 199 200 \param value Value 201 \return Label string. 202 203 \sa dateFormatOfDate() 204 */ 204 205 QwtText QwtDateScaleDraw::label( double value ) const 205 206 { … … 208 209 dt, intervalType( scaleDiv() ) ); 209 210 210 return QwtDate::toString( dt, fmt, d_data->week0Type );211 } 212 213 /*! 214 Find the less detailed datetime unit, where no rounding 215 errors happen. 216 217 \param scaleDiv Scale division 218 \return Interval type 219 220 \sa dateFormatOfDate() 211 return QwtDate::toString( dt, fmt, m_data->week0Type ); 212 } 213 214 /*! 215 Find the less detailed datetime unit, where no rounding 216 errors happen. 217 218 \param scaleDiv Scale division 219 \return Interval type 220 221 \sa dateFormatOfDate() 221 222 */ 222 223 QwtDate::IntervalType QwtDateScaleDraw::intervalType( 223 const QwtScaleDiv &scaleDiv ) const224 const QwtScaleDiv& scaleDiv ) const 224 225 { 225 226 int intvType = QwtDate::Year; … … 227 228 bool alignedToWeeks = true; 228 229 229 const QList< double> ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick );230 const QList< double > ticks = scaleDiv.ticks( QwtScaleDiv::MajorTick ); 230 231 for ( int i = 0; i < ticks.size(); i++ ) 231 232 { … … 234 235 { 235 236 const QDateTime dt0 = QwtDate::floor( dt, 236 static_cast<QwtDate::IntervalType>( j ) ); 237 static_cast< QwtDate::IntervalType >( j ) ); 237 238 238 239 if ( dt0 != dt ) … … 257 258 intvType = QwtDate::Day; 258 259 259 return static_cast<QwtDate::IntervalType>( intvType ); 260 } 261 262 /*! 263 Translate a double value into a QDateTime object. 264 265 \return QDateTime object initialized with timeSpec() and utcOffset(). 266 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 260 return static_cast< QwtDate::IntervalType >( intvType ); 261 } 262 263 /*! 264 Translate a double value into a QDateTime object. 265 266 \return QDateTime object initialized with timeSpec() and utcOffset(). 267 \sa timeSpec(), utcOffset(), QwtDate::toDateTime() 267 268 */ 268 269 QDateTime QwtDateScaleDraw::toDateTime( double value ) const 269 270 { 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 ); 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 275 280 } 276 281
Note:
See TracChangeset
for help on using the changeset viewer.
