File indexing completed on 2024-05-12 04:20:28
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCHARTABSTRACTAXIS_H 0010 #define KCHARTABSTRACTAXIS_H 0011 0012 // #include <QObject> 0013 // #include <QRectF> 0014 // #include <QWidget> 0015 0016 #include "kchart_export.h" 0017 #include "KChartGlobal.h" 0018 #include "KChartAbstractArea.h" 0019 #include "KChartTextAttributes.h" 0020 #include "KChartRulerAttributes.h" 0021 0022 QT_BEGIN_NAMESPACE 0023 class QPainter; 0024 class QSizeF; 0025 QT_END_NAMESPACE 0026 0027 0028 namespace KChart { 0029 0030 class Area; 0031 class AbstractCoordinatePlane; 0032 class PaintContext; 0033 class AbstractDiagram; 0034 0035 /** 0036 * The base class for axes. 0037 * 0038 * For being useful, axes need to be assigned to a diagram, see 0039 * AbstractCartesianDiagram::addAxis and AbstractCartesianDiagram::takeAxis. 0040 * 0041 * \sa PolarAxis, AbstractCartesianDiagram 0042 */ 0043 class KCHART_EXPORT AbstractAxis : public AbstractArea 0044 { 0045 Q_OBJECT 0046 0047 Q_DISABLE_COPY( AbstractAxis ) 0048 KCHART_DECLARE_PRIVATE_DERIVED_PARENT( AbstractAxis, AbstractDiagram* ) 0049 0050 public: 0051 explicit AbstractAxis( AbstractDiagram* diagram = nullptr ); 0052 ~AbstractAxis() override; 0053 0054 // FIXME implement when code os ready for it: 0055 // virtual Area* clone() const = 0; 0056 0057 // FIXME (Mirko) re-add when needed 0058 // void copyRelevantDetailsFrom( const KChartAxis* axis ); 0059 0060 /* virtual void paint( PaintContext* ) const = 0; 0061 virtual QSize sizeHint() const = 0;*/ 0062 //virtual void paintEvent( QPaintEvent* event) = 0; 0063 0064 /** 0065 * \brief Reimplement this method if you want to adjust axis labels 0066 * before they are printed. 0067 * 0068 * KChart is calling this method immediately before drawing the 0069 * text, this means: What you return here will be drawn without 0070 * further modifications. 0071 * 0072 * \param label The text of the label as KChart has calculated it 0073 * automatically (or as it was taken from a QStringList provided 0074 * by you, resp.) 0075 * 0076 * \note If you reimplement this method in a subclass of KChart::CartesianAxis, 0077 * and your reimplementation's return value depends on data other than @p label 0078 * (so KChart will not know when it changes), you must manually ensure that 0079 * layouts are adapted to any changed sizes of the axis labels. To do that, 0080 * call KChart::CartesianAxis::layoutPlanes() from your reimplementation when 0081 * you know that the external data changed and it will change label sizes - 0082 * or when you cannot exclude that. 0083 * 0084 * \return The text to be drawn. By default this is the same as \c label. 0085 */ 0086 virtual const QString customizedLabel( const QString& label ) const; 0087 0088 /** 0089 * Returns true if both axes have the same settings. 0090 */ 0091 bool compare( const AbstractAxis* other ) const; 0092 0093 /** 0094 * \internal 0095 * 0096 * Method invoked by AbstractCartesianDiagram::addAxis(). 0097 * 0098 * You should not call this function, unless you know exactly, 0099 * what you are doing. 0100 * 0101 * \sa connectSignals(), AbstractCartesianDiagram::addAxis() 0102 */ 0103 void createObserver( AbstractDiagram* diagram ); 0104 0105 /** 0106 * \internal 0107 * 0108 * Method invoked by AbstractCartesianDiagram::takeAxis(). 0109 * 0110 * You should not call this function, unless you know exactly, 0111 * what you are doing. 0112 * 0113 * \sa AbstractCartesianDiagram::takeAxis() 0114 */ 0115 void deleteObserver( AbstractDiagram* diagram ); 0116 const AbstractDiagram* diagram() const; 0117 bool observedBy( AbstractDiagram* diagram ) const; 0118 0119 /** 0120 * Wireing the signal/slot connections. 0121 * 0122 * This method gets called automatically, each time, when you assign 0123 * the axis to a diagram, either by passing a diagram* to the c'tor, 0124 * or by calling the diagram's setAxis method, resp. 0125 * 0126 * If overwriting this method in derived classes, make sure to call 0127 * this base method AbstractAxis::connectSignals(), so your axis 0128 * gets connected to the diagram's built-in signals. 0129 * 0130 * \sa AbstractCartesianDiagram::addAxis() 0131 */ 0132 virtual void connectSignals(); 0133 0134 /** 0135 \brief Use this to specify the text attributes to be used for axis labels. 0136 0137 By default, the reference area will be set at painting time. 0138 It will be the then-valid coordinate plane's parent widget, 0139 so normally, it will be the KChart::Chart. 0140 Thus the labels of all of your axes in all of your diagrams 0141 within that Chart will be drawn in same font size, by default. 0142 0143 \sa textAttributes, setLabels 0144 */ 0145 void setTextAttributes( const TextAttributes &a ); 0146 0147 /** 0148 \brief Returns the text attributes to be used for axis labels. 0149 0150 \sa setTextAttributes 0151 */ 0152 TextAttributes textAttributes() const; 0153 0154 /** 0155 \brief Use this to specify the attributes used to paint the axis ruler 0156 0157 Every axis has a default set of ruler attributes that is exactly the 0158 same among them. Use this method to specify your own attributes. 0159 0160 \sa rulerAttributes 0161 */ 0162 void setRulerAttributes( const RulerAttributes &a ); 0163 0164 /** 0165 \brief Returns the attributes to be used for painting the rulers 0166 0167 \sa setRulerAttributes 0168 */ 0169 RulerAttributes rulerAttributes() const; 0170 0171 /** 0172 \brief Use this to specify your own set of strings, to be used as axis labels. 0173 0174 Labels specified via setLabels take precedence: 0175 If a non-empty list is passed, KChart will use these strings as axis labels, 0176 instead of calculating them. 0177 0178 If you pass a smaller number of strings than the number of labels drawn at this 0179 axis, KChart will repeat the strings until all labels are drawn. 0180 As an example you could specify the seven days of the week as abscissa labels, 0181 which would be repeatedly used then. 0182 0183 By passing an empty QStringList you can reset the default behaviour. 0184 0185 \sa labels, setShortLabels 0186 */ 0187 void setLabels( const QStringList& list ); 0188 0189 /** 0190 Returns a list of strings, that are used as axis labels, as set via setLabels. 0191 0192 \sa setLabels 0193 */ 0194 QStringList labels() const; 0195 0196 /** 0197 \brief Use this to specify your own set of strings, to be used as axis labels, 0198 in case the normal labels are too long. 0199 0200 \note Setting done via setShortLabels will be ignored, if you did not pass 0201 a non-empty string list via setLabels too! 0202 0203 By passing an empty QStringList you can reset the default behaviour. 0204 0205 \sa shortLabels, setLabels 0206 */ 0207 void setShortLabels( const QStringList& list ); 0208 0209 /** 0210 Returns a list of strings, that are used as axis labels, as set via setShortLabels. 0211 0212 \note Setting done via setShortLabels will be ignored, if you did not pass 0213 a non-empty string list via setLabels too! 0214 0215 \sa setShortLabels 0216 */ 0217 QStringList shortLabels() const; 0218 0219 void setGeometry( const QRect& rect ) override = 0; 0220 QRect geometry() const override = 0; 0221 0222 /** 0223 \brief Convenience function, returns the coordinate plane, in which this axis is used. 0224 0225 If the axis is not used in a coordinate plane, the return value is Zero. 0226 */ 0227 const AbstractCoordinatePlane* coordinatePlane() const; 0228 0229 protected Q_SLOTS: 0230 /** called for initializing after the c'tor has completed */ 0231 virtual void delayedInit(); 0232 0233 public Q_SLOTS: 0234 void update(); 0235 0236 Q_SIGNALS: 0237 void coordinateSystemChanged(); 0238 }; 0239 } 0240 0241 #endif // KCHARTABSTRACTAXIS_H