| 1 | /* -*- C++ -*- |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2005 Andreas Nicolai <Andreas.Nicolai@gmx.net> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef KPLOTAXIS_H |
| 9 | #define KPLOTAXIS_H |
| 10 | |
| 11 | #include <kplotting_export.h> |
| 12 | |
| 13 | #include <QList> |
| 14 | #include <QString> |
| 15 | |
| 16 | #include <memory> |
| 17 | |
| 18 | /*! |
| 19 | * \class KPlotAxis |
| 20 | * \inmodule KPlotting |
| 21 | * |
| 22 | * \brief Axis for KPlotWidget. |
| 23 | * |
| 24 | * Contains all data for drawing an axis including format specification axis labels. |
| 25 | */ |
| 26 | class KPLOTTING_EXPORT KPlotAxis |
| 27 | { |
| 28 | public: |
| 29 | /*! |
| 30 | * Constructor, constructs an axis with the label \a label. |
| 31 | */ |
| 32 | explicit KPlotAxis(const QString &label = QString()); |
| 33 | |
| 34 | ~KPlotAxis(); |
| 35 | |
| 36 | /*! |
| 37 | * Returns whether the axis is visible or not |
| 38 | */ |
| 39 | bool isVisible() const; |
| 40 | |
| 41 | /*! |
| 42 | * Sets the "visible" property of the axis. |
| 43 | * |
| 44 | * \a visible if true, this axis will be drawn on the KPlotWidget |
| 45 | */ |
| 46 | void setVisible(bool visible); |
| 47 | |
| 48 | /*! |
| 49 | * Returns whether tick labels will be drawn for this axis |
| 50 | */ |
| 51 | bool areTickLabelsShown() const; |
| 52 | |
| 53 | /*! |
| 54 | * Determine whether tick labels will be drawn for this axis. |
| 55 | * |
| 56 | * \a b if true, tick labels will be drawn. |
| 57 | */ |
| 58 | void setTickLabelsShown(bool b); |
| 59 | |
| 60 | /*! |
| 61 | * Sets the axis label. |
| 62 | * |
| 63 | * Set the label to an empty string to omit the axis label. |
| 64 | * |
| 65 | * \a label a string describing the data plotted on the axis. |
| 66 | */ |
| 67 | void setLabel(const QString &label); |
| 68 | |
| 69 | /*! |
| 70 | * Returns the label string for this axis |
| 71 | */ |
| 72 | QString label() const; |
| 73 | |
| 74 | /*! |
| 75 | * Returns the ticklabel string for the given value, rendered according |
| 76 | * to the current format specification. |
| 77 | * |
| 78 | * \a value the value to be rendered as a tick label. |
| 79 | * |
| 80 | * \sa setTickLabelFormat() |
| 81 | */ |
| 82 | QString tickLabel(double value) const; |
| 83 | |
| 84 | /*! |
| 85 | * Set the display format for converting the double value of the |
| 86 | * tick's position to the QString for the tick label. |
| 87 | * |
| 88 | * Normally, the format character is one of 'e', 'E', 'f', 'g', or 'G' |
| 89 | * (see the documentation for QString::arg(double) for details). |
| 90 | * |
| 91 | * In addition, it is possible to set the format character to 't'; |
| 92 | * in this case the tickmark value is interpreted as a time in hours, |
| 93 | * and the ticklabel string will be in "hh:mm" clock format. |
| 94 | * Note that when the format character is 't', the fieldWidth and prec |
| 95 | * values are ignored. |
| 96 | * |
| 97 | * \a format the format specification character |
| 98 | * |
| 99 | * \a fieldWidth the number of characters in the output string. |
| 100 | * |
| 101 | * If set to 0, the string will be as wide as it needs to be to fully |
| 102 | * render the value. |
| 103 | * |
| 104 | * \a precision the number of characters following the decimal point. |
| 105 | */ |
| 106 | void setTickLabelFormat(char format = 'g', int fieldWidth = 0, int precision = -1); |
| 107 | |
| 108 | /*! |
| 109 | * Returns the field width of the tick labels |
| 110 | */ |
| 111 | int tickLabelWidth() const; |
| 112 | |
| 113 | /*! |
| 114 | * Returns the number format of the tick labels |
| 115 | */ |
| 116 | char tickLabelFormat() const; |
| 117 | |
| 118 | /*! |
| 119 | * Returns the number precision of the tick labels |
| 120 | */ |
| 121 | int tickLabelPrecision() const; |
| 122 | |
| 123 | /*! |
| 124 | * Determine the positions of major and minor tickmarks for this axis. |
| 125 | * |
| 126 | * \note this function is called by KPlotWidget whenever the plot's |
| 127 | * limits are modified. |
| 128 | * |
| 129 | * \a x0 the minimum data coordinate of the axis. |
| 130 | * |
| 131 | * \a length the range covered by the axis, in data units. |
| 132 | * |
| 133 | * \sa majorTickMarks() |
| 134 | * \sa minorTickMarks() |
| 135 | */ |
| 136 | void setTickMarks(double x0, double length); |
| 137 | |
| 138 | /*! |
| 139 | * Returns the list of coordinates of the major tickmarks for this axis |
| 140 | * |
| 141 | * \note the positions of tickmarks are automatically computed by setTickMarks(). |
| 142 | * |
| 143 | * \sa setTickMarks() |
| 144 | * \sa minorTickMarks() |
| 145 | */ |
| 146 | QList<double> majorTickMarks() const; |
| 147 | |
| 148 | /*! |
| 149 | * Returns the list with the minor tickmarks |
| 150 | * |
| 151 | * \note the positions of tickmarks are automatically computed by setTickMarks(). |
| 152 | * |
| 153 | * \sa setTickMarks() |
| 154 | * \sa majorTickMarks() |
| 155 | */ |
| 156 | QList<double> minorTickMarks() const; |
| 157 | |
| 158 | private: |
| 159 | class Private; |
| 160 | std::unique_ptr<Private> const d; |
| 161 | |
| 162 | Q_DISABLE_COPY(KPlotAxis) |
| 163 | }; |
| 164 | |
| 165 | #endif // KPLOTAXIS_H |
| 166 | |