File indexing completed on 2024-04-28 03:56:42
0001 /* -*- C++ -*- 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2005 Andreas Nicolai <Andreas.Nicolai@gmx.net> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KPLOTAXIS_H 0009 #define KPLOTAXIS_H 0010 0011 #include <kplotting_export.h> 0012 0013 #include <QList> 0014 #include <QString> 0015 0016 #include <memory> 0017 0018 /** 0019 * @short Axis for KPlotWidget 0020 * 0021 * Contains all data for drawing an axis including format specification axis labels. 0022 * 0023 * @author Andreas Nicolai 0024 * @version 1.0 0025 */ 0026 class KPLOTTING_EXPORT KPlotAxis 0027 { 0028 public: 0029 /** 0030 * Constructor, constructs an axis with the label @p label. 0031 */ 0032 explicit KPlotAxis(const QString &label = QString()); 0033 0034 /** 0035 * Destructor. 0036 */ 0037 ~KPlotAxis(); 0038 0039 /** 0040 * @return whether the axis is visible or not 0041 */ 0042 bool isVisible() const; 0043 0044 /** 0045 * Sets the "visible" property of the axis. 0046 * @param visible if true, this axis will be drawn on the KPlotWidget 0047 */ 0048 void setVisible(bool visible); 0049 0050 /** 0051 * @return whether tick labels will be drawn for this axis 0052 */ 0053 bool areTickLabelsShown() const; 0054 0055 /** 0056 * Determine whether tick labels will be drawn for this axis. 0057 * @param b if true, tick labels will be drawn. 0058 */ 0059 void setTickLabelsShown(bool b); 0060 0061 /** 0062 * Sets the axis label. 0063 * Set the label to an empty string to omit the axis label. 0064 * @param label a string describing the data plotted on the axis. 0065 */ 0066 void setLabel(const QString &label); 0067 0068 /** 0069 * @return the label string for this axis 0070 */ 0071 QString label() const; 0072 0073 /** 0074 * @return the ticklabel string for the given value, rendered according 0075 * to the current format specification. 0076 * @param the value to be rendered as a tick label. 0077 * @sa setTickLabelFormat() 0078 */ 0079 QString tickLabel(double value) const; 0080 0081 /** 0082 * Set the display format for converting the double value of the 0083 * tick's position to the QString for the tick label. 0084 * 0085 * Normally, the format character is one of 'e', 'E', 'f', 'g', or 'G' 0086 * (see the documentation for QString::arg(double) for details). 0087 * 0088 * In addition, it is possible to set the format character to 't'; 0089 * in this case the tickmark value is interpreted as a time in hours, 0090 * and the ticklabel string will be in "hh:mm" clock format. 0091 * Note that when the format character is 't', the fieldWidth and prec 0092 * values are ignored. 0093 * 0094 * @param format the format specification character 0095 * @param fieldWidth the number of characters in the output string. 0096 * If set to 0, the string will be as wide as it needs to be to fully 0097 * render the value. 0098 * @param precision the number of characters following the decimal point. 0099 */ 0100 void setTickLabelFormat(char format = 'g', int fieldWidth = 0, int precision = -1); 0101 0102 /** 0103 * @return the field width of the tick labels 0104 */ 0105 int tickLabelWidth() const; 0106 0107 /** 0108 * @return the number format of the tick labels 0109 */ 0110 char tickLabelFormat() const; 0111 0112 /** 0113 * @return the number precision of the tick labels 0114 */ 0115 int tickLabelPrecision() const; 0116 0117 /** 0118 * Determine the positions of major and minor tickmarks for this axis. 0119 * @note this function is called by KPlotWidget whenever the plot's 0120 * limits are modified. 0121 * @param x0 the minimum data coordinate of the axis. 0122 * @param length the range covered by the axis, in data units. 0123 * @sa majorTickMarks() 0124 * @sa minorTickMarks() 0125 */ 0126 void setTickMarks(double x0, double length); 0127 0128 /** 0129 * @return the list of coordinates of the major tickmarks for this axis 0130 * @note the positions of tickmarks are automatically computed by setTickMarks(). 0131 * @sa setTickMarks() 0132 * @sa minorTickMarks() 0133 */ 0134 QList<double> majorTickMarks() const; 0135 0136 /** 0137 * @return the list with the minor tickmarks 0138 * @note the positions of tickmarks are automatically computed by setTickMarks(). 0139 * @sa setTickMarks() 0140 * @sa majorTickMarks() 0141 */ 0142 QList<double> minorTickMarks() const; 0143 0144 private: 0145 class Private; 0146 std::unique_ptr<Private> const d; 0147 0148 Q_DISABLE_COPY(KPlotAxis) 0149 }; 0150 0151 #endif // KPLOTAXIS_H