![]() |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
Specialized axis ticker for calendar dates and times as axis ticks. More...
#include <qcustomplot.h>


Public Member Functions | |
| QCPAxisTickerDateTime () | |
| QString | dateTimeFormat () const |
| Qt::TimeSpec | dateTimeSpec () const |
| void | setDateTimeFormat (const QString &format) |
| void | setDateTimeSpec (Qt::TimeSpec spec) |
| void | setTickOrigin (double origin) |
| void | setTickOrigin (const QDateTime &origin) |
Public Member Functions inherited from QCPAxisTicker | |
| QCPAxisTicker () | |
| virtual | ~QCPAxisTicker () |
| TickStepStrategy | tickStepStrategy () const |
| int | tickCount () const |
| double | tickOrigin () const |
| void | setTickStepStrategy (TickStepStrategy strategy) |
| void | setTickCount (int count) |
| void | setTickOrigin (double origin) |
| virtual void | generate (const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector< double > &ticks, QVector< double > *subTicks, QVector< QString > *tickLabels) |
Static Public Member Functions | |
| static QDateTime | keyToDateTime (double key) |
| static double | dateTimeToKey (const QDateTime dateTime) |
| static double | dateTimeToKey (const QDate date) |
Protected Types | |
| enum | DateStrategy { dsNone , dsUniformTimeInDay , dsUniformDayInMonth } |
Protected Member Functions | |
| virtual double | getTickStep (const QCPRange &range) |
| virtual int | getSubTickCount (double tickStep) |
| virtual QString | getTickLabel (double tick, const QLocale &locale, QChar formatChar, int precision) |
| virtual QVector< double > | createTickVector (double tickStep, const QCPRange &range) |
Protected Member Functions inherited from QCPAxisTicker | |
| virtual QVector< double > | createSubTickVector (int subTickCount, const QVector< double > &ticks) |
| virtual QVector< QString > | createLabelVector (const QVector< double > &ticks, const QLocale &locale, QChar formatChar, int precision) |
| void | trimTicks (const QCPRange &range, QVector< double > &ticks, bool keepOneOutlier) const |
| double | pickClosest (double target, const QVector< double > &candidates) const |
| double | getMantissa (double input, double *magnitude=0) const |
| double | cleanMantissa (double input) const |
Protected Attributes | |
| QString | mDateTimeFormat |
| Qt::TimeSpec | mDateTimeSpec |
| enum QCPAxisTickerDateTime::DateStrategy | mDateStrategy |
Protected Attributes inherited from QCPAxisTicker | |
| TickStepStrategy | mTickStepStrategy |
| int | mTickCount |
| double | mTickOrigin |
Additional Inherited Members | |
Public Types inherited from QCPAxisTicker | |
| enum | TickStepStrategy { tssReadability , tssMeetTickCount } |
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 (time zone) shall be used, see setDateTimeSpec.
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:
axistickerdatetime-creation
Definition at line 1904 of file qcustomplot.h.
|
protected |
| Enumerator | |
|---|---|
| dsNone | |
| dsUniformTimeInDay | |
| dsUniformDayInMonth | |
Definition at line 1931 of file qcustomplot.h.
| 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 5907 of file qcustomplot.cpp.
References QCPAxisTicker::setTickCount().
|
protectedvirtual |
Reimplemented from QCPAxisTicker.
Definition at line 6127 of file qcustomplot.cpp.
References QCPAxisTicker::createTickVector(), dateTimeToKey(), dsUniformDayInMonth, dsUniformTimeInDay, keyToDateTime(), mDateStrategy, QCPAxisTicker::mTickOrigin, and result.
|
inline |
Definition at line 1909 of file qcustomplot.h.
|
inline |
Definition at line 1910 of file qcustomplot.h.
|
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.
Definition at line 6225 of file qcustomplot.cpp.
|
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)
Definition at line 6209 of file qcustomplot.cpp.
Referenced by createTickVector(), and setTickOrigin().
|
protectedvirtual |
Reimplemented from QCPAxisTicker.
Definition at line 6034 of file qcustomplot.cpp.
References QCPAxisTicker::getSubTickCount(), and result.
|
protectedvirtual |
Reimplemented from QCPAxisTicker.
Definition at line 6109 of file qcustomplot.cpp.
References keyToDateTime(), mDateTimeFormat, and mDateTimeSpec.
|
protectedvirtual |
Reimplemented from QCPAxisTicker.
Definition at line 5984 of file qcustomplot.cpp.
References QCPAxisTicker::cleanMantissa(), dsNone, dsUniformDayInMonth, dsUniformTimeInDay, e, mDateStrategy, QCPAxisTicker::mTickCount, QCPAxisTicker::pickClosest(), result, and QCPRange::size().
|
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)
Definition at line 6189 of file qcustomplot.cpp.
Referenced by createTickVector(), and getTickLabel().
| 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().
Newlines can be inserted with "\n".
Definition at line 5923 of file qcustomplot.cpp.
References format, and mDateTimeFormat.
| 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 date time values passed to QCustomPlot (e.g. in the form of axis ranges or keys of a plottable) are given in the UTC spec, set spec to Qt::UTC to get the correct axis labels.
Definition at line 5938 of file qcustomplot.cpp.
References mDateTimeSpec.
| 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 5966 of file qcustomplot.cpp.
References dateTimeToKey(), origin, and setTickOrigin().
| 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 5953 of file qcustomplot.cpp.
References origin, and QCPAxisTicker::setTickOrigin().
Referenced by setTickOrigin().
|
protected |
Referenced by createTickVector(), and getTickStep().
|
protected |
Definition at line 1927 of file qcustomplot.h.
Referenced by getTickLabel(), and setDateTimeFormat().
|
protected |
Definition at line 1928 of file qcustomplot.h.
Referenced by getTickLabel(), and setDateTimeSpec().