File indexing completed on 2024-05-12 15:54:10

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