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