QCPAxisTickerDateTime
Public Member Functions | |
QCPAxisTickerDateTime () | |
QString | dateTimeFormat () const |
Qt::TimeSpec | dateTimeSpec () const |
void | setDateTimeFormat (const QString &format) |
void | setDateTimeSpec (Qt::TimeSpec spec) |
void | setTickOrigin (const QDateTime &origin) |
void | setTickOrigin (double origin) |
void | setTimeZone (const QTimeZone &zone) |
QTimeZone | timeZone () const |
Public Member Functions inherited from QCPAxisTicker | |
QCPAxisTicker () | |
virtual void | generate (const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector< double > &ticks, QVector< double > *subTicks, QVector< QString > *tickLabels) |
void | setTickCount (int count) |
void | setTickOrigin (double origin) |
void | setTickStepStrategy (TickStepStrategy strategy) |
int | tickCount () const |
double | tickOrigin () const |
TickStepStrategy | tickStepStrategy () const |
Static Public Member Functions | |
static double | dateTimeToKey (const QDate &date, Qt::TimeSpec timeSpec=Qt::LocalTime) |
static double | dateTimeToKey (const QDateTime &dateTime) |
static QDateTime | keyToDateTime (double key) |
Protected Types | |
enum | DateStrategy { dsNone , dsUniformTimeInDay , dsUniformDayInMonth } |
Protected Member Functions | |
virtual QVector< double > | createTickVector (double tickStep, const QCPRange &range) override |
virtual int | getSubTickCount (double tickStep) override |
virtual QString | getTickLabel (double tick, const QLocale &locale, QChar formatChar, int precision) override |
virtual double | getTickStep (const QCPRange &range) override |
Protected Member Functions inherited from QCPAxisTicker | |
double | cleanMantissa (double input) const |
virtual QVector< QString > | createLabelVector (const QVector< double > &ticks, const QLocale &locale, QChar formatChar, int precision) |
virtual QVector< double > | createSubTickVector (int subTickCount, const QVector< double > &ticks) |
double | getMantissa (double input, double *magnitude=nullptr) const |
double | pickClosest (double target, const QVector< double > &candidates) const |
void | trimTicks (const QCPRange &range, QVector< double > &ticks, bool keepOneOutlier) const |
Protected Attributes | |
enum QCPAxisTickerDateTime::DateStrategy | mDateStrategy |
QString | mDateTimeFormat |
Qt::TimeSpec | mDateTimeSpec |
QTimeZone | mTimeZone |
Protected Attributes inherited from QCPAxisTicker | |
int | mTickCount |
double | mTickOrigin |
TickStepStrategy | mTickStepStrategy |
Additional Inherited Members | |
Public Types inherited from QCPAxisTicker | |
enum | TickStepStrategy { tssReadability , tssMeetTickCount } |
Detailed Description
Specialized axis ticker for calendar dates and times as axis ticks.
This QCPAxisTicker subclass generates ticks that correspond to real calendar dates and times. The plot axis coordinate is interpreted as Unix Time, so seconds since Epoch (January 1, 1970, 00:00 UTC). This is also used for example by QDateTime in the toTime_t()/setTime_t()
methods with a precision of one second. Since Qt 4.7, millisecond accuracy can be obtained from QDateTime by using QDateTime::fromMSecsSinceEpoch()/1000.0
. The static methods dateTimeToKey and keyToDateTime conveniently perform this conversion achieving a precision of one millisecond on all Qt versions.
The format of the date/time display in the tick labels is controlled with setDateTimeFormat. If a different time spec or time zone shall be used for the tick label appearance, see setDateTimeSpec or setTimeZone, respectively.
This ticker produces unequal tick spacing in order to provide intuitive date and time-of-day ticks. For example, if the axis range spans a few years such that there is one tick per year, ticks will be positioned on 1. January of every year. This is intuitive but, due to leap years, will result in slightly unequal tick intervals (visually unnoticeable). The same can be seen in the image above: even though the number of days varies month by month, this ticker generates ticks on the same day of each month.
If you would like to change the date/time that is used as a (mathematical) starting date for the ticks, use the setTickOrigin(const QDateTime &origin) method overload, which takes a QDateTime. If you pass 15. July, 9:45 to this method, the yearly ticks will end up on 15. July at 9:45 of every year.
The ticker can be created and assigned to an axis like this:
- Note
- If you rather wish to display relative times in terms of days, hours, minutes, seconds and milliseconds, and are not interested in the intricacies of real calendar dates with months and (leap) years, have a look at QCPAxisTickerTime instead.
Definition at line 1797 of file qcustomplot.h.
Member Enumeration Documentation
◆ DateStrategy
|
protected |
Definition at line 1831 of file qcustomplot.h.
Constructor & Destructor Documentation
◆ QCPAxisTickerDateTime()
QCPAxisTickerDateTime::QCPAxisTickerDateTime | ( | ) |
Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker.
Definition at line 6527 of file qcustomplot.cpp.
Member Function Documentation
◆ createTickVector()
|
overrideprotectedvirtual |
Uses the passed tickStep as a guiding value and applies corrections in order to obtain non-uniform tick intervals but intuitive tick labels, e.g. falling on the same day of each month.
\seebaseclassmethod
Reimplemented from QCPAxisTicker.
Definition at line 6739 of file qcustomplot.cpp.
◆ dateTimeFormat()
|
inline |
Definition at line 1803 of file qcustomplot.h.
◆ dateTimeSpec()
|
inline |
Definition at line 1804 of file qcustomplot.h.
◆ dateTimeToKey() [1/2]
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
A convenience method which turns a QDate object into a double value that corresponds to seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by QCPAxisTickerDateTime.
The returned value will be the start of the passed day of date, interpreted in the given timeSpec.
- See also
- keyToDateTime
Definition at line 6824 of file qcustomplot.cpp.
◆ dateTimeToKey() [2/2]
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
A convenience method which turns a QDateTime object into a double value that corresponds to seconds since Epoch (1. Jan 1970, 00:00 UTC). This is the format used as axis coordinates by QCPAxisTickerDateTime.
The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it works around the lack of a QDateTime::toMSecsSinceEpoch in Qt 4.6)
- See also
- keyToDateTime
Definition at line 6804 of file qcustomplot.cpp.
◆ getSubTickCount()
|
overrideprotectedvirtual |
Returns a sensible sub tick count with intervals appropriate for a date-time-display, such as weekly, monthly, bi-monthly, etc.
\seebaseclassmethod
Reimplemented from QCPAxisTicker.
Definition at line 6682 of file qcustomplot.cpp.
◆ getTickLabel()
|
overrideprotectedvirtual |
Generates a date/time tick label for tick coordinate tick, based on the currently set format (setDateTimeFormat), time spec (setDateTimeSpec), and possibly time zone (setTimeZone).
\seebaseclassmethod
Reimplemented from QCPAxisTicker.
Definition at line 6718 of file qcustomplot.cpp.
◆ getTickStep()
|
overrideprotectedvirtual |
Returns a sensible tick step with intervals appropriate for a date-time-display, such as weekly, monthly, bi-monthly, etc.
Note that this tick step isn't used exactly when generating the tick vector in createTickVector, but only as a guiding value requiring some correction for each individual tick interval. Otherwise this would lead to unintuitive date displays, e.g. jumping between first day in the month to the last day in the previous month from tick to tick, due to the non-uniform length of months. The same problem arises with leap years.
\seebaseclassmethod
Reimplemented from QCPAxisTicker.
Definition at line 6648 of file qcustomplot.cpp.
◆ keyToDateTime()
|
static |
A convenience method which turns key (in seconds since Epoch 1. Jan 1970, 00:00 UTC) into a QDateTime object. This can be used to turn axis coordinates to actual QDateTimes.
The accuracy achieved by this method is one millisecond, irrespective of the used Qt version (it works around the lack of a QDateTime::fromMSecsSinceEpoch in Qt 4.6)
- See also
- dateTimeToKey
Definition at line 6784 of file qcustomplot.cpp.
◆ setDateTimeFormat()
void QCPAxisTickerDateTime::setDateTimeFormat | ( | const QString & | format | ) |
Sets the format in which dates and times are displayed as tick labels. For details about the format string, see the documentation of QDateTime::toString().
Typical expressions are
d | The day as a number without a leading zero (1 to 31) |
dd | The day as a number with a leading zero (01 to 31) |
ddd | The abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. QLocale::system(). |
dddd | The long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to localize the name, i.e. QLocale::system(). |
M | The month as a number without a leading zero (1 to 12) |
MM | The month as a number with a leading zero (01 to 12) |
MMM | The abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses the system locale to localize the name, i.e. QLocale::system(). |
MMMM | The long localized month name (e.g. 'January' to 'December'). Uses the system locale to localize the name, i.e. QLocale::system(). |
yy | The year as a two digit number (00 to 99) |
yyyy | The year as a four digit number. If the year is negative, a minus sign is prepended, making five characters. |
h | The hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
hh | The hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
H | The hour without a leading zero (0 to 23, even with AM/PM display) |
HH | The hour with a leading zero (00 to 23, even with AM/PM display) |
m | The minute without a leading zero (0 to 59) |
mm | The minute with a leading zero (00 to 59) |
s | The whole second, without any leading zero (0 to 59) |
ss | The whole second, with a leading zero where applicable (00 to 59) |
z | The fractional part of the second, to go after a decimal point, without trailing zeroes (0 to 999). Thus "s.z" reports the seconds to full available (millisecond) precision without trailing zeroes. |
zzz | The fractional part of the second, to millisecond precision, including trailing zeroes where applicable (000 to 999). |
AP or A | Use AM/PM display. A/AP will be replaced by an upper-case version of either QLocale::amText() or QLocale::pmText(). |
ap or a | Use am/pm display. a/ap will be replaced by a lower-case version of either QLocale::amText() or QLocale::pmText(). |
t | The timezone (for example "CEST") |
Newlines can be inserted with "\n"
, literal strings (even when containing above expressions) by encapsulating them using single-quotes. A literal single quote can be generated by using two consecutive single quotes in the format.
- See also
- setDateTimeSpec, setTimeZone
Definition at line 6572 of file qcustomplot.cpp.
◆ setDateTimeSpec()
void QCPAxisTickerDateTime::setDateTimeSpec | ( | Qt::TimeSpec | spec | ) |
Sets the time spec that is used for creating the tick labels from corresponding dates/times.
The default value of QDateTime objects (and also QCPAxisTickerDateTime) is Qt::LocalTime
. However, if the displayed tick labels shall be given in UTC, set spec to Qt::UTC
.
Tick labels corresponding to other time zones can be achieved with setTimeZone (which sets spec to Qt::TimeZone
internally). Note that if spec is afterwards set to not be Qt::TimeZone
again, the setTimeZone setting will be ignored accordingly.
- See also
- setDateTimeFormat, setTimeZone
Definition at line 6590 of file qcustomplot.cpp.
◆ setTickOrigin() [1/2]
void QCPAxisTickerDateTime::setTickOrigin | ( | const QDateTime & | origin | ) |
Sets the tick origin (see QCPAxisTicker::setTickOrigin) as a QDateTime origin.
This is useful to define the month/day/time recurring at greater tick interval steps. For example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick per year, the ticks will end up on 15. July at 9:45 of every year.
Definition at line 6630 of file qcustomplot.cpp.
◆ setTickOrigin() [2/2]
void QCPAxisTickerDateTime::setTickOrigin | ( | double | origin | ) |
Sets the tick origin (see QCPAxisTicker::setTickOrigin) in seconds since Epoch (1. Jan 1970, 00:00 UTC). For the date time ticker it might be more intuitive to use the overload which directly takes a QDateTime, see setTickOrigin(const QDateTime &origin).
This is useful to define the month/day/time recurring at greater tick interval steps. For example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick per year, the ticks will end up on 15. July at 9:45 of every year.
Definition at line 6618 of file qcustomplot.cpp.
◆ setTimeZone()
void QCPAxisTickerDateTime::setTimeZone | ( | const QTimeZone & | zone | ) |
Sets the time zone that is used for creating the tick labels from corresponding dates/times. The time spec (setDateTimeSpec) is set to Qt::TimeZone
.
- See also
- setDateTimeFormat, setTimeZone
Definition at line 6602 of file qcustomplot.cpp.
◆ timeZone()
|
inline |
Definition at line 1806 of file qcustomplot.h.
Member Data Documentation
◆ mDateTimeFormat
|
protected |
Definition at line 1825 of file qcustomplot.h.
◆ mDateTimeSpec
|
protected |
Definition at line 1826 of file qcustomplot.h.
◆ mTimeZone
|
protected |
Definition at line 1828 of file qcustomplot.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.