File indexing completed on 2024-05-12 16:33:26

0001 /* This file is part of the KDE project
0002 
0003    Copyright 2007 Johannes Simon <johannes.simon@gmail.com>
0004    Copyright 2009 Inge Wallin    <inge@lysator.liu.se>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library 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 GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KCHART_AXIS_H
0023 #define KCHART_AXIS_H
0024 
0025 
0026 // Qt
0027 #include <QObject>
0028 
0029 // KoChart
0030 #include "ChartShape.h"
0031 
0032 #include <KChartCartesianAxis.h>
0033 
0034 namespace KoOdfNumberStyles {
0035     struct NumericStyleFormat;
0036 }
0037 
0038 namespace KoChart {
0039 
0040 enum OdfGridClass {
0041     OdfMajorGrid,
0042     OdfMinorGrid
0043 };
0044 
0045 /**
0046  * @brief The Axis class handles axis as well as grid settings.
0047  *
0048  * Data series can be attached to axes that represent an
0049  * ordinate. This is done to customize the scaling, i.e., the relation
0050  * in which the data of a series is visualized.
0051  */
0052 
0053 class Axis : public QObject
0054 {
0055     Q_OBJECT
0056 
0057 public:
0058     Axis(PlotArea *parent, AxisDimension dimension);
0059     ~Axis();
0060 
0061     // odf chart:name that identifies the axis
0062     QString name() const;
0063     void setName(const QString &name);
0064 
0065     PlotArea *plotArea() const;
0066     KoShape *title() const;
0067     QString titleText() const;
0068     bool showLabels() const;
0069     bool showOverlappingDataLabels() const;
0070     QString id() const;
0071     AxisDimension dimension() const;
0072     QList<DataSet*> dataSets() const;
0073     qreal majorInterval() const;
0074     qreal minorInterval() const;
0075     int minorIntervalDivisor() const;
0076     bool useAutomaticMajorInterval() const;
0077     bool useAutomaticMinorInterval() const;
0078     bool showInnerMinorTicks() const;
0079     bool showOuterMinorTicks() const;
0080     bool showInnerMajorTicks() const;
0081     bool showOuterMajorTicks() const;
0082     bool scalingIsLogarithmic() const;
0083     bool showMajorGrid() const;
0084     bool showMinorGrid() const;
0085     Qt::Orientation orientation() const;
0086     QFont font() const;
0087     qreal fontSize() const;
0088     bool isVisible() const;
0089     bool showRuler() const;
0090 
0091     void setTitleText(const QString &text);
0092     void setShowLabels(bool show);
0093     void setShowOverlappingDataLabels(bool show);
0094 
0095     /**
0096      * Attaches a data set to this axis, adding it to a diagram
0097      * of its chart type, creating it if necessary
0098      */
0099     bool attachDataSet(DataSet *dataSet);
0100 
0101     /**
0102      * Detaches a data set from this axis, removing it from the diagram of
0103      * its chart type, and deleting it if it was the last data set in this diagram.
0104      */
0105     bool detachDataSet(DataSet *dataSet, bool silent = false);
0106 
0107     /**
0108      * Detaches all data sets in this axis, deleting any diagram
0109      * that this axis might have owned.
0110      */
0111     void clearDataSets();
0112 
0113     void setMajorInterval(qreal interval);
0114     void setMinorInterval(qreal interval);
0115     void setMinorIntervalDivisor(int divisor);
0116     void setUseAutomaticMajorInterval(bool automatic);
0117     void setUseAutomaticMinorInterval(bool automatic);
0118     void setShowInnerMinorTicks(bool showTicks);
0119     void setShowOuterMinorTicks(bool showTicks);
0120     void setShowInnerMajorTicks(bool showTicks);
0121     void setShowOuterMajorTicks(bool showTicks);
0122     void setScalingLogarithmic(bool logarithmicScaling);
0123     void setShowMajorGrid(bool showGrid);
0124     void setShowMinorGrid(bool showGrid);
0125     void setThreeD(bool threeD);
0126     void setFont(const QFont &font);
0127     void setFontSize(qreal size);
0128     void setVisible(bool visible);
0129     void setShowRuler(bool show);
0130 
0131     KoOdfNumberStyles::NumericStyleFormat *numericStyleFormat() const;
0132     void SetNumericStyleFormat(KoOdfNumberStyles::NumericStyleFormat *numericStyleFormat) const;
0133 
0134     bool loadOdf(const KoXmlElement &axisElement, KoShapeLoadingContext &context);
0135     bool loadOdfChartSubtypeProperties(const KoXmlElement &axisElement,
0136                                         KoShapeLoadingContext &context);
0137     void saveOdf(KoShapeSavingContext &context);
0138     void saveOdfGrid(KoShapeSavingContext &context, OdfGridClass gridClass);
0139 
0140     // KChart stuff
0141     KChart::CartesianAxis *kdAxis() const;
0142     KChart::AbstractCoordinatePlane *kdPlane() const;
0143 
0144     void plotAreaChartTypeChanged(ChartType chartType);
0145     void plotAreaChartSubTypeChanged(ChartSubtype chartSubType);
0146     void plotAreaIsVerticalChanged();
0147 
0148     void registerAxis(Axis *axis);
0149     void registerDiagram(KChart::AbstractCartesianDiagram *diagram);
0150     void removeAxisFromDiagrams(bool clear = false);
0151 
0152     void update() const;
0153     void requestRepaint() const;
0154     void layoutPlanes();
0155 
0156     /**
0157      * Returns the gap between bars as a  percent of the width of one bar
0158      *
0159      * Negative numbers signify that bars overlap
0160      * This is the negative representation of the chart:overlap property.
0161      *
0162      * From odf 1.2 spec:
0163      * The chart:overlap attribute specifies how much bars within the same category in a bar chart overlap.
0164      * The attribute value is an integer that is interpreted as a percentage relative to the width of a single bar.
0165      * Negative values specify gaps between bars.
0166      * This attribute is evaluated for chart styles that are applied to a <chart:axis> element when a chart:dimension attribute set to y.
0167      * Note: This allows bars to be attached to different axis arranged differently as long as they are grouped per axis (chart:group-bars-per-axis attribute is true).
0168      */
0169     int gapBetweenBars() const;
0170     /**
0171      * Returns the gap between sets of bars as a  percent of the width of one bar
0172      * This represents the chart:gap-width property.
0173      *
0174      * From the odf 1.2 spec:
0175      * The chart:gap-width attribute specifies a gap between neighboring groups of bars in a bar chart
0176      * (that is the distance between the last bar in one category and t*he first bar in the following category).
0177      * It is specified as an integer percentage relative to the width of a single bar.
0178      * This attribute is evaluated for chart styles that are applied to a <chart:axis> element with chart:dimension attribute set to y.
0179      * Note: Bars attached to different axis can be arranged differently as long as they are grouped per axis (chart:group-bars-per-axis attribute has the value true).
0180      */
0181     int gapBetweenSets() const;
0182 
0183     /**
0184      * Set axis position to @p odfpos
0185      * odfpos can be "start", "end" or a double value
0186      */
0187     void setOdfAxisPosition(const QString &odfpos);
0188     /// @return the axis position in odf format
0189     /// @see setOdfAxisPosition()
0190     QString odfAxisPosition() const;
0191     /**
0192      * Update the chart axis position from the odf position
0193      * ODF defines:
0194      * end: Translates to Top for x-axes and Right for y-axes
0195      *      If reversed: Translates to Bottom for x-axes and Left for y-axes
0196      * start: Translates to Bottom for x-axes and Left for y-axes
0197      *        If reversed: Translates to Top for x-axes and Right for y-axes
0198      * value: Not supported, defaults to "start"
0199      *
0200      * @see odfAxisPosition()
0201      */
0202     void updateKChartAxisPosition();
0203     /// @return the KChart axis position
0204     KChart::CartesianAxis::Position kchartAxisPosition() const;
0205     // @return the actual KChart axis position
0206     // This is not quite kchartAxisPosition() as it also depends on bar diagram orientation
0207     KChart::CartesianAxis::Position actualAxisPosition() const;
0208 
0209     /// @return true if direction is reversed
0210     bool axisDirectionReversed() const;
0211 
0212     void setOdfAxisLabelsPosition(const QString &odfpos);
0213     QString odfAxisLabelsPosition() const;
0214 
0215 public Q_SLOTS:
0216     void setGapBetweenBars(int percent);
0217     void setGapBetweenSets(int percent);
0218     void setAngleOffset(qreal angle);
0219     void setHoleSize(qreal value);
0220 
0221     void updateKChartStockAttributes();
0222 
0223 private:
0224     class Private;
0225     Private *const d;
0226 };
0227 
0228 } // Namespace KoChart
0229 
0230 QDebug operator<<(QDebug dbg, KoChart::Axis *a);
0231 
0232 #endif