KChart

KChartAbstractAxis.h
1 /*
2  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #ifndef KCHARTABSTRACTAXIS_H
10 #define KCHARTABSTRACTAXIS_H
11 
12 // #include <QObject>
13 // #include <QRectF>
14 // #include <QWidget>
15 
16 #include "kchart_export.h"
17 #include "KChartGlobal.h"
18 #include "KChartAbstractArea.h"
19 #include "KChartTextAttributes.h"
20 #include "KChartRulerAttributes.h"
21 
22 QT_BEGIN_NAMESPACE
23 class QPainter;
24 class QSizeF;
25 QT_END_NAMESPACE
26 
27 
28 namespace KChart {
29 
30  class Area;
31  class AbstractCoordinatePlane;
32  class PaintContext;
33  class AbstractDiagram;
34 
35  /**
36  * The base class for axes.
37  *
38  * For being useful, axes need to be assigned to a diagram, see
39  * AbstractCartesianDiagram::addAxis and AbstractCartesianDiagram::takeAxis.
40  *
41  * \sa PolarAxis, AbstractCartesianDiagram
42  */
43  class KCHART_EXPORT AbstractAxis : public AbstractArea
44  {
45  Q_OBJECT
46 
47  Q_DISABLE_COPY( AbstractAxis )
48  KCHART_DECLARE_PRIVATE_DERIVED_PARENT( AbstractAxis, AbstractDiagram* )
49 
50  public:
51  explicit AbstractAxis( AbstractDiagram* diagram = nullptr );
52  ~AbstractAxis() override;
53 
54  // FIXME implement when code os ready for it:
55  // virtual Area* clone() const = 0;
56 
57  // FIXME (Mirko) re-add when needed
58  // void copyRelevantDetailsFrom( const KChartAxis* axis );
59 
60  /* virtual void paint( PaintContext* ) const = 0;
61  virtual QSize sizeHint() const = 0;*/
62  //virtual void paintEvent( QPaintEvent* event) = 0;
63 
64  /**
65  * \brief Reimplement this method if you want to adjust axis labels
66  * before they are printed.
67  *
68  * KChart is calling this method immediately before drawing the
69  * text, this means: What you return here will be drawn without
70  * further modifications.
71  *
72  * \param label The text of the label as KChart has calculated it
73  * automatically (or as it was taken from a QStringList provided
74  * by you, resp.)
75  *
76  * \note If you reimplement this method in a subclass of KChart::CartesianAxis,
77  * and your reimplementation's return value depends on data other than @p label
78  * (so KChart will not know when it changes), you must manually ensure that
79  * layouts are adapted to any changed sizes of the axis labels. To do that,
80  * call KChart::CartesianAxis::layoutPlanes() from your reimplementation when
81  * you know that the external data changed and it will change label sizes -
82  * or when you cannot exclude that.
83  *
84  * \return The text to be drawn. By default this is the same as \c label.
85  */
86  virtual const QString customizedLabel( const QString& label ) const;
87 
88  /**
89  * Returns true if both axes have the same settings.
90  */
91  bool compare( const AbstractAxis* other ) const;
92 
93  /**
94  * \internal
95  *
96  * Method invoked by AbstractCartesianDiagram::addAxis().
97  *
98  * You should not call this function, unless you know exactly,
99  * what you are doing.
100  *
101  * \sa connectSignals(), AbstractCartesianDiagram::addAxis()
102  */
103  void createObserver( AbstractDiagram* diagram );
104 
105  /**
106  * \internal
107  *
108  * Method invoked by AbstractCartesianDiagram::takeAxis().
109  *
110  * You should not call this function, unless you know exactly,
111  * what you are doing.
112  *
113  * \sa AbstractCartesianDiagram::takeAxis()
114  */
115  void deleteObserver( AbstractDiagram* diagram );
116  const AbstractDiagram* diagram() const;
117  bool observedBy( AbstractDiagram* diagram ) const;
118 
119  /**
120  * Wireing the signal/slot connections.
121  *
122  * This method gets called automatically, each time, when you assign
123  * the axis to a diagram, either by passing a diagram* to the c'tor,
124  * or by calling the diagram's setAxis method, resp.
125  *
126  * If overwriting this method in derived classes, make sure to call
127  * this base method AbstractAxis::connectSignals(), so your axis
128  * gets connected to the diagram's built-in signals.
129  *
130  * \sa AbstractCartesianDiagram::addAxis()
131  */
132  virtual void connectSignals();
133 
134  /**
135  \brief Use this to specify the text attributes to be used for axis labels.
136 
137  By default, the reference area will be set at painting time.
138  It will be the then-valid coordinate plane's parent widget,
139  so normally, it will be the KChart::Chart.
140  Thus the labels of all of your axes in all of your diagrams
141  within that Chart will be drawn in same font size, by default.
142 
143  \sa textAttributes, setLabels
144  */
145  void setTextAttributes( const TextAttributes &a );
146 
147  /**
148  \brief Returns the text attributes to be used for axis labels.
149 
150  \sa setTextAttributes
151  */
152  TextAttributes textAttributes() const;
153 
154  /**
155  \brief Use this to specify the attributes used to paint the axis ruler
156 
157  Every axis has a default set of ruler attributes that is exactly the
158  same among them. Use this method to specify your own attributes.
159 
160  \sa rulerAttributes
161  */
162  void setRulerAttributes( const RulerAttributes &a );
163 
164  /**
165  \brief Returns the attributes to be used for painting the rulers
166 
167  \sa setRulerAttributes
168  */
169  RulerAttributes rulerAttributes() const;
170 
171  /**
172  \brief Use this to specify your own set of strings, to be used as axis labels.
173 
174  Labels specified via setLabels take precedence:
175  If a non-empty list is passed, KChart will use these strings as axis labels,
176  instead of calculating them.
177 
178  If you pass a smaller number of strings than the number of labels drawn at this
179  axis, KChart will repeat the strings until all labels are drawn.
180  As an example you could specify the seven days of the week as abscissa labels,
181  which would be repeatedly used then.
182 
183  By passing an empty QStringList you can reset the default behaviour.
184 
185  \sa labels, setShortLabels
186  */
187  void setLabels( const QStringList& list );
188 
189  /**
190  Returns a list of strings, that are used as axis labels, as set via setLabels.
191 
192  \sa setLabels
193  */
194  QStringList labels() const;
195 
196  /**
197  \brief Use this to specify your own set of strings, to be used as axis labels,
198  in case the normal labels are too long.
199 
200  \note Setting done via setShortLabels will be ignored, if you did not pass
201  a non-empty string list via setLabels too!
202 
203  By passing an empty QStringList you can reset the default behaviour.
204 
205  \sa shortLabels, setLabels
206  */
207  void setShortLabels( const QStringList& list );
208 
209  /**
210  Returns a list of strings, that are used as axis labels, as set via setShortLabels.
211 
212  \note Setting done via setShortLabels will be ignored, if you did not pass
213  a non-empty string list via setLabels too!
214 
215  \sa setShortLabels
216  */
217  QStringList shortLabels() const;
218 
219  void setGeometry( const QRect& rect ) override = 0;
220  QRect geometry() const override = 0;
221 
222  /**
223  \brief Convenience function, returns the coordinate plane, in which this axis is used.
224 
225  If the axis is not used in a coordinate plane, the return value is Zero.
226  */
227  const AbstractCoordinatePlane* coordinatePlane() const;
228 
229  protected Q_SLOTS:
230  /** called for initializing after the c'tor has completed */
231  virtual void delayedInit();
232 
233  public Q_SLOTS:
234  void update();
235 
236  Q_SIGNALS:
237  void coordinateSystemChanged();
238  };
239 }
240 
241 #endif // KCHARTABSTRACTAXIS_H
An area in the chart with a background, a frame, etc.
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane,...
A set of attributes controlling the appearance of axis rulers.
AbstractDiagram defines the interface for diagram classes.
The base class for axes.
A set of text attributes.
Contains KChart macros.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Jul 1 2022 05:09:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.