File indexing completed on 2024-05-12 16:33:35
0001 /* This file is part of the KDE project 0002 0003 Copyright 2007-2008 Johannes Simon <johannes.simon@gmail.com> 0004 Copyright 2008-2010 Inge Wallin <inge@lysator.liu.se> 0005 Copyright 2018 Dag Andersen <danders@get2net.dk> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #ifndef KCHART_PLOTAREA_H 0024 #define KCHART_PLOTAREA_H 0025 0026 // Qt 0027 #include <QObject> 0028 #include <QList> 0029 0030 // ChartShape 0031 #include "ChartShape.h" 0032 #include "DataSet.h" 0033 0034 namespace KChart { 0035 class CartesianCoordinatePlane; 0036 class PolarCoordinatePlane; 0037 class RadarCoordinatePlane; 0038 } 0039 0040 0041 class Ko3dScene; 0042 0043 0044 namespace KoChart { 0045 0046 /** 0047 * @brief The PlotArea class is the central chart element. It plots the data and draws the axes. 0048 * 0049 * There always exists exactly one instance of this class, owned by 0050 * the chart shape. The plot area itself takes ownership of the axes 0051 * and the chart wall. 0052 * 0053 * 3D support is not yet fully implemented, a chart floor is not 0054 * supported at all yet. 0055 * 0056 * This class also plays a central role when loading from or saving to 0057 * ODF. Though it does not handle anything in particular itself, it 0058 * utilizes the DataSet, ChartTableModel, Axis, Surface, and 0059 * ChartProxyModel classes to handle ODF data and properties embedded 0060 * in the <chart:plotarea> element. 0061 */ 0062 0063 class PlotArea : public QObject, public KoShape 0064 { 0065 friend class Surface; 0066 friend class Axis; 0067 Q_OBJECT 0068 0069 public: 0070 explicit PlotArea(ChartShape *parent); 0071 ~PlotArea(); 0072 0073 void plotAreaInit(); 0074 0075 ChartProxyModel *proxyModel() const; 0076 0077 ChartType chartType() const; 0078 ChartSubtype chartSubType() const; 0079 void setChartType(ChartType type); 0080 void setChartSubType(ChartSubtype subType); 0081 0082 QList<Axis*> axes() const; 0083 QList<DataSet*> dataSets() const; 0084 int dataSetCount() const; 0085 bool addAxis(Axis *axis); 0086 /// Remove and delete the @p axis. 0087 /// Also deletes the title 0088 bool removeAxis(Axis *axis); 0089 /// Remove the @p axis, but do not delete it. 0090 /// The title is not touched. 0091 bool takeAxis(Axis *axis); 0092 0093 // TODO: Rename this into primaryXAxis() 0094 Axis *xAxis() const; 0095 // TODO: Rename this into primaryYAxis() 0096 Axis *yAxis() const; 0097 Axis *secondaryXAxis() const; 0098 Axis *secondaryYAxis() const; 0099 0100 bool isThreeD() const; 0101 Ko3dScene *threeDScene() const; 0102 0103 /** 0104 * Determines from what range of cells the data in this chart 0105 * comes from. This region also contains the name of the sheet. 0106 * See table:cell-range-address, ODF v1.2, $18.595 0107 */ 0108 CellRegion cellRangeAddress() const; 0109 0110 /** 0111 * Determines whether x and y axis are swapped. Default is 'false'. 0112 * See chart:vertical attribute in ODF v1.2, $19.63 0113 * 0114 * NOTE: Only bar charts can be vertical so only returns true if chartType() is BarChartType 0115 */ 0116 bool isVertical() const; 0117 0118 /** 0119 * Defines at what angle, relative to the right-most point 0120 * of a pie or ring chart, the first slice is going to be drawn, 0121 * going counter-clockwise. 0122 * See chart:angle-offset property, as defined in ODF v1.2. 0123 */ 0124 qreal angleOffset() const; 0125 0126 /** 0127 * @see angleOffset 0128 */ 0129 void setAngleOffset(qreal angle); 0130 0131 /// The chart:hole-size attribute specifies the diameter of the inner hole of a ring chart 0132 /// as percentage of the outer diameter of the outermost ring. 0133 qreal holeSize() const; 0134 /// @see holeSize() 0135 void setHoleSize(qreal value); 0136 0137 bool loadOdf(const KoXmlElement &plotAreaElement, KoShapeLoadingContext &context) override; 0138 bool loadOdfSeries(const KoXmlElement &seriesElement, KoShapeLoadingContext &context); 0139 0140 void saveOdf(KoShapeSavingContext &context) const override; 0141 void saveOdfSubType(KoXmlWriter &bodyWriter, KoGenStyle &plotAreaStyle) const; 0142 0143 0144 void setThreeD(bool threeD); 0145 0146 /** 0147 * @see cellRangeAddress 0148 */ 0149 void setCellRangeAddress(const CellRegion ®ion); 0150 0151 /** 0152 * @see isVertical 0153 */ 0154 void setVertical(bool vertical); 0155 0156 ChartShape *parent() const; 0157 0158 void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override; 0159 0160 bool registerKdDiagram(KChart::AbstractDiagram *diagram); 0161 bool deregisterKdDiagram(KChart::AbstractDiagram *diagram); 0162 0163 void relayout() const; 0164 0165 void registerKdPlane(KChart::AbstractCoordinatePlane *plane); 0166 0167 void addTitleToLayout(); 0168 0169 void setStockRangeLinePen(const QPen &pen); 0170 QPen stockRangeLinePen() const; 0171 void setStockGainBrush(const QBrush &brush); 0172 QBrush stockGainBrush() const; 0173 void setStockLossBrush(const QBrush &brush); 0174 QBrush stockLossBrush() const; 0175 0176 QString symbolType() const; 0177 void setSymbolType(const QString &type); 0178 QString symbolName() const; 0179 void setSymbolName(const QString &name); 0180 DataSet::ValueLabelType valueLabelType() const; 0181 void setValueLabelType(const DataSet::ValueLabelType &type); 0182 0183 public Q_SLOTS: 0184 void requestRepaint() const; 0185 void proxyModelStructureChanged(); 0186 void plotAreaUpdate(); 0187 0188 void updateKChartStockAttributes(); 0189 0190 Q_SIGNALS: 0191 void angleOffsetChanged(qreal); 0192 void holeSizeChanged(qreal); 0193 0194 private: 0195 void addAxesTitlesToLayout(); 0196 void paintPixmap(QPainter &painter, const KoViewConverter &converter); 0197 0198 // For class Axis 0199 KChart::CartesianCoordinatePlane *kdCartesianPlane(Axis *axis = 0) const; 0200 KChart::PolarCoordinatePlane *kdPolarPlane() const; 0201 KChart::RadarCoordinatePlane *kdRadarPlane() const; 0202 KChart::Chart *kdChart() const; 0203 0204 class Private; 0205 Private *const d; 0206 }; 0207 0208 } // Namespace KoChart 0209 0210 #endif // KCHART_PLOTAREA_H 0211