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