File indexing completed on 2024-05-19 16:06:28
0001 /* This file is part of the KDE project 0002 0003 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0004 Copyright 2007-2010 Inge Wallin <inge@lysator.liu.se> 0005 Copyright 2007-2008 Johannes Simon <johannes.simon@gmail.com> 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_SHAPE_H 0024 #define KCHART_SHAPE_H 0025 0026 0027 // Qt 0028 #include <Qt> 0029 0030 // Calligra 0031 #include <KoShapeContainer.h> 0032 #include <KoFrameShape.h> 0033 0034 // KoChart 0035 #include "kochart_global.h" 0036 #include "KoChartInterface.h" 0037 0038 0039 class QAbstractItemModel; 0040 0041 class QPointF; 0042 class QSizeF; 0043 class QPen; 0044 class QBrush; 0045 class QColor; 0046 class QString; 0047 class QFont; 0048 0049 class KoCanvasBase; 0050 class KoDocumentResourceManager; 0051 class KoShapeLoadingContext; 0052 class KoShapeSavingContext; 0053 class KoStore; 0054 #include "KoXmlReaderForward.h" 0055 class KoXmlWriter; 0056 class KoGenStyles; 0057 class KoOdfLoadingContext; 0058 0059 0060 // FIXME: Remove all mentions of KChart from the public API. 0061 namespace KChart { 0062 class Chart; 0063 class Legend; 0064 class CartesianAxis; 0065 class CartesianCoordinatePlane; 0066 class AbstractCoordinatePlane; 0067 class AbstractDiagram; 0068 } 0069 0070 // Interface to SimpleTextShape plugin 0071 class KoTextShapeData; 0072 #define TextShapeId "TextShapeID" 0073 #define OdfLoadingHelperId "OdfLoadingHelperId" 0074 0075 namespace KoChart { 0076 0077 class DataSet; 0078 class ChartProxyModel; 0079 class Legend; 0080 class PlotArea; 0081 class Surface; 0082 class Axis; 0083 class ThreeDScene; 0084 class CellRegion; 0085 class ChartTableModel; 0086 class ChartLayout; 0087 class TableSource; 0088 class ChartDocument; 0089 0090 void saveOdfFont(KoGenStyle &style, const QFont& font, const QColor& color); 0091 QString saveOdfFont(KoGenStyles& mainStyles, const QFont& font, const QColor& color); 0092 QColor defaultDataSetColor(int dataSetNum); 0093 const char * odfCharttype(int charttype); 0094 0095 0096 class ChartShape 0097 : public QObject 0098 , public KoChart::ChartInterface // The public interface within Calligra 0099 , public KoFrameShape // For saving as a frame 0100 , public KoShapeContainer // The chart shape embeds other shapes. 0101 { 0102 Q_OBJECT 0103 Q_INTERFACES(KoChart::ChartInterface) 0104 0105 public: 0106 explicit ChartShape(KoDocumentResourceManager *documentResourceManager); 0107 ~ChartShape() override; 0108 0109 // Getter methods 0110 ChartProxyModel *proxyModel() const; 0111 0112 // Parts of the chart 0113 KoShape *title() const; 0114 TextLabelData *titleData() const; 0115 KoShape *subTitle() const; 0116 TextLabelData *subTitleData() const; 0117 KoShape *footer() const; 0118 TextLabelData *footerData() const; 0119 Legend *legend() const; 0120 PlotArea *plotArea() const; 0121 ChartLayout *layout() const; 0122 0123 /** 0124 * Returns a list of all labels in this chart, visible and hidden. 0125 * Use this method with caution, as it re-creates the list every 0126 * time you call it. 0127 */ 0128 QList<KoShape*> labels() const; 0129 0130 void showTitle(bool doShow); 0131 void showSubTitle(bool doShow); 0132 void showFooter(bool doShow); 0133 0134 /** 0135 * Returns the internal data table if existent, otherwise null. 0136 */ 0137 ChartTableModel *internalModel() const; 0138 0139 /** 0140 * Tells the ChartShape what model to use as internal table. When 0141 * the shape is loaded from ODF, it sets it itself. 0142 * 0143 * This method will assume that @a model has already been added to this 0144 * chart's TableSource. 0145 */ 0146 void setInternalModel(ChartTableModel *model); 0147 0148 /** 0149 * Returns a "map" containing all tables that are being used, 0150 * or may be used, in this chart. 0151 */ 0152 TableSource *tableSource() const; 0153 0154 /** 0155 * Returns true if the chart has no external data sources. 0156 * 0157 * This method is used to differentiate between charts that are embedded 0158 * into e.g. spreadsheets where these sheets provide the data, and 0159 * applications that do not provide the data, but where the data is stored 0160 * in an internal model in the chart document. 0161 * 0162 * For the first case, this method returns false, for the latter true. 0163 */ 0164 bool usesInternalModelOnly() const; 0165 void setUsesInternalModelOnly(bool doesSo); 0166 0167 ChartType chartType() const; 0168 ChartSubtype chartSubType() const; 0169 bool isThreeD() const; 0170 0171 /*** 0172 * Inherited from koChartInterface 0173 ***/ 0174 0175 /** 0176 * Sets the SheetAccessModel to be used by this chart. 0177 * 0178 * See sheets/SheetAccessModel.h for details. 0179 */ 0180 void setSheetAccessModel(QAbstractItemModel* model) override; 0181 0182 /** 0183 * Re-initializes the chart with data from an arbitrary region. 0184 * 0185 * @param region Name of region to use, e.g. "Table1.A1:B3" 0186 * @param firstRowIsLabel Whether to interpret the first row as labels 0187 * @param firstColumnIsLabel Whether to interpret the first column as labels 0188 * @param dataDirection orientation of a data set. Qt::Horizontal means a row is 0189 * to be interpreted as one data set, columns with Qt::Vertical. 0190 * 0191 * @see ChartProxyModel::init() 0192 */ 0193 void reset(const QString& region, 0194 bool firstRowIsLabel, 0195 bool firstColumnIsLabel, 0196 Qt::Orientation dataDirection) override; 0197 0198 void setChartType(ChartType type); 0199 void setChartSubType(ChartSubtype subType, bool reset = false); 0200 void setThreeD(bool threeD); 0201 0202 /// reimplemented 0203 void paintComponent(QPainter &painter, const KoViewConverter &converter, 0204 KoShapePaintingContext &paintcontext) override; 0205 void paintDecorations(QPainter &painter, const KoViewConverter &converter, 0206 const KoCanvasBase *canvas); 0207 0208 /// reimplemented 0209 bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) override; 0210 bool loadOdfFrameElement(const KoXmlElement &element, KoShapeLoadingContext &context) override; 0211 bool loadOdfData(const KoXmlElement &tableElement, KoShapeLoadingContext &context); 0212 0213 bool loadOdfChartElement(const KoXmlElement &chartElement, KoShapeLoadingContext &context); 0214 /// reimplemented 0215 void saveOdf(KoShapeSavingContext &context) const override; 0216 void saveOdfData(KoXmlWriter &bodyWriter, KoGenStyles &mainStyles) const; 0217 0218 /** 0219 * Used by unit tests to disable popping up of message boxes. 0220 * 0221 * User interaction is enabled by default. 0222 */ 0223 static void setEnableUserInteraction(bool enable); 0224 0225 using KoShapeContainer::update; 0226 /// reimplemented 0227 void update() const override; 0228 void relayout() const; 0229 0230 void requestRepaint() const; 0231 0232 /// the document resource manager we got on construction 0233 KoDocumentResourceManager *resourceManager() const; 0234 0235 ChartDocument *document() const; 0236 0237 Q_SIGNALS: 0238 void chartTypeChanged(ChartType, ChartType prev = LastChartType); 0239 void updateConfigWidget() const; 0240 0241 public Q_SLOTS: 0242 void updateAll(); 0243 0244 protected: 0245 void shapeChanged(ChangeType type, KoShape *shape = 0) override; 0246 0247 private: 0248 bool loadEmbeddedDocument(KoStore *store, const KoXmlElement &objectElement, 0249 const KoOdfLoadingContext &loadingContext); 0250 0251 class Private; 0252 Private *const d; 0253 }; 0254 0255 } // Namespace KoChart 0256 0257 #endif