File indexing completed on 2024-05-12 16:33:29
0001 /* This file is part of the KDE project 0002 Copyright (C) 2018 Dag Andersen <danders@get2net.dk> 0003 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 // Own 0022 #include "ChartShapeFactory.h" 0023 0024 // Qt 0025 #include <QStringList> 0026 0027 // KF5 0028 #include <kiconloader.h> 0029 #include <kpluginfactory.h> 0030 #include <klocalizedstring.h> 0031 0032 // Calligra 0033 #include <KoIcon.h> 0034 #include <KoToolRegistry.h> 0035 #include <KoShapeRegistry.h> 0036 #include <KoShapeLoadingContext.h> 0037 #include <KoOdfLoadingContext.h> 0038 #include <KoDocumentResourceManager.h> 0039 #include <KoStyleStack.h> 0040 #include <KoProperties.h> 0041 0042 // Chart shape 0043 #include "ChartShape.h" 0044 #include "ChartToolFactory.h" 0045 #include "ChartProxyModel.h" 0046 #include "ChartTableModel.h" 0047 #include "PlotArea.h" 0048 #include "Axis.h" 0049 #include "Legend.h" 0050 #include "TableSource.h" 0051 #include "ChartLayout.h" 0052 0053 using namespace KoChart; 0054 0055 K_PLUGIN_FACTORY_WITH_JSON(ChartShapePluginFactory, "calligra_shape_chart.json", 0056 registerPlugin<ChartShapePlugin>();) 0057 0058 ChartShapePlugin::ChartShapePlugin(QObject * parent, const QVariantList&) 0059 : QObject(parent) 0060 { 0061 // Register the chart shape factory. 0062 KoShapeRegistry::instance()->add(new ChartShapeFactory()); 0063 0064 // Register all tools for the chart shape. 0065 KoToolRegistry::instance()->add(new ChartToolFactory()); 0066 } 0067 0068 0069 ChartShapeFactory::ChartShapeFactory() 0070 : KoShapeFactoryBase(ChartShapeId, i18n("Chart")) 0071 { 0072 setXmlElementNames("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", QStringList("object")); 0073 setToolTip(i18n("Business charts")); 0074 0075 KIconLoader::global()->addAppDir("kchart"); 0076 setIconName(koIconNameNeededWithSubs("", "x-shape-chart", "office-chart-bar")); 0077 0078 // Default 'app specific' config pages i.e. unless an app defines 0079 // other config pages, these are used. 0080 QList<KoShapeConfigFactoryBase*> panelFactories; 0081 // panelFactories.append(new ChartDataConfigFactory()); 0082 setOptionPanels(panelFactories); 0083 0084 setFamily("chart"); 0085 0086 int order = 0; 0087 KoShapeTemplate params; 0088 params.id = ChartShapeId; 0089 params.family = family(); 0090 0091 params.templateId = "Bar"; 0092 params.name = i18n("Bar Chart"); 0093 params.toolTip = i18n("Normal bar chart"); 0094 params.iconName = chartTypeIconName(BarChartType, NormalChartSubtype); 0095 KoProperties *properties = new KoProperties(); 0096 properties->setProperty("chart-type", BarChartType); 0097 properties->setProperty("chart-sub-type", NormalChartSubtype); 0098 params.properties = properties; 0099 params.order = order++; 0100 addTemplate(params); 0101 0102 params.templateId = "BarPercent"; 0103 params.name = i18n("Stacked Bar Chart"); 0104 params.toolTip = i18n("Stacked bar chart"); 0105 params.iconName = chartTypeIconName(BarChartType, StackedChartSubtype); 0106 properties = new KoProperties(); 0107 properties->setProperty("chart-type", BarChartType); 0108 properties->setProperty("chart-sub-type", StackedChartSubtype); 0109 params.properties = properties; 0110 params.order = order++; 0111 addTemplate(params); 0112 0113 params.templateId = "BarStacked"; 0114 params.name = i18n("Percent Bar Chart"); 0115 params.toolTip = i18n("Percent bar chart"); 0116 params.iconName = chartTypeIconName(BarChartType, PercentChartSubtype); 0117 properties = new KoProperties(); 0118 properties->setProperty("chart-type", BarChartType); 0119 properties->setProperty("chart-sub-type", PercentChartSubtype); 0120 params.properties = properties; 0121 params.order = order++; 0122 addTemplate(params); 0123 0124 params.templateId = "Line"; 0125 params.name = i18n("Line Chart"); 0126 params.toolTip = i18n("Normal line chart"); 0127 params.iconName = chartTypeIconName(LineChartType, NormalChartSubtype); 0128 properties = new KoProperties(); 0129 properties->setProperty("chart-type", LineChartType); 0130 properties->setProperty("chart-sub-type", NormalChartSubtype); 0131 params.properties = properties; 0132 params.order = order++; 0133 addTemplate(params); 0134 0135 params.templateId = "LinePercent"; 0136 params.name = i18n("Stacked Line Chart"); 0137 params.toolTip = i18n("Stacked line chart"); 0138 params.iconName = chartTypeIconName(LineChartType, StackedChartSubtype); 0139 properties = new KoProperties(); 0140 properties->setProperty("chart-type", LineChartType); 0141 properties->setProperty("chart-sub-type", StackedChartSubtype); 0142 params.properties = properties; 0143 params.order = order++; 0144 addTemplate(params); 0145 0146 params.templateId = "LineStacked"; 0147 params.name = i18n("Percent Line Chart"); 0148 params.toolTip = i18n("Percent line chart"); 0149 params.iconName = chartTypeIconName(LineChartType, PercentChartSubtype); 0150 properties = new KoProperties(); 0151 properties->setProperty("chart-type", LineChartType); 0152 properties->setProperty("chart-sub-type", PercentChartSubtype); 0153 params.properties = properties; 0154 params.order = order++; 0155 addTemplate(params); 0156 0157 params.templateId = "Area"; 0158 params.name = i18n("Area Chart"); 0159 params.toolTip = i18n("Normal area chart"); 0160 params.iconName = chartTypeIconName(AreaChartType, NormalChartSubtype); 0161 properties = new KoProperties(); 0162 properties->setProperty("chart-type", AreaChartType); 0163 properties->setProperty("chart-sub-type", NormalChartSubtype); 0164 params.properties = properties; 0165 params.order = order++; 0166 addTemplate(params); 0167 0168 params.templateId = "AreaPercent"; 0169 params.name = i18n("Stacked Area Chart"); 0170 params.toolTip = i18n("Stacked area chart"); 0171 params.iconName = chartTypeIconName(AreaChartType, StackedChartSubtype); 0172 properties = new KoProperties(); 0173 properties->setProperty("chart-type", AreaChartType); 0174 properties->setProperty("chart-sub-type", StackedChartSubtype); 0175 params.properties = properties; 0176 params.order = order++; 0177 addTemplate(params); 0178 0179 params.templateId = "AreaStacked"; 0180 params.name = i18n("Percent Area Chart"); 0181 params.toolTip = i18n("Percent area chart"); 0182 params.iconName = chartTypeIconName(AreaChartType, PercentChartSubtype); 0183 properties = new KoProperties(); 0184 properties->setProperty("chart-type", AreaChartType); 0185 properties->setProperty("chart-sub-type", PercentChartSubtype); 0186 params.properties = properties; 0187 params.order = order++; 0188 addTemplate(params); 0189 0190 params.templateId = "Pie"; 0191 params.name = i18n("Pie Chart"); 0192 params.toolTip = i18n("Pie chart"); 0193 params.iconName = chartTypeIconName(CircleChartType, NoChartSubtype); 0194 properties = new KoProperties(); 0195 properties->setProperty("chart-type", CircleChartType); 0196 properties->setProperty("chart-sub-type", NoChartSubtype); 0197 params.properties = properties; 0198 params.order = order++; 0199 addTemplate(params); 0200 0201 params.templateId = "Ring"; 0202 params.name = i18n("Ring Chart"); 0203 params.toolTip = i18n("Ring chart"); 0204 params.iconName = chartTypeIconName(RingChartType, NoChartSubtype); 0205 properties = new KoProperties(); 0206 properties->setProperty("chart-type", RingChartType); 0207 properties->setProperty("chart-sub-type", NoChartSubtype); 0208 params.properties = properties; 0209 params.order = order++; 0210 addTemplate(params); 0211 0212 params.templateId = "Bubble"; 0213 params.name = i18n("Bubble Chart"); 0214 params.toolTip = i18n("Bubble chart"); 0215 params.iconName = chartTypeIconName(BubbleChartType, NoChartSubtype); 0216 properties = new KoProperties(); 0217 properties->setProperty("chart-type", BubbleChartType); 0218 properties->setProperty("chart-sub-type", NoChartSubtype); 0219 params.properties = properties; 0220 params.order = order++; 0221 addTemplate(params); 0222 0223 params.templateId = "Scatter"; 0224 params.name = i18n("Scatter Chart"); 0225 params.toolTip = i18n("Scatter chart"); 0226 params.iconName = chartTypeIconName(ScatterChartType, NoChartSubtype); 0227 properties = new KoProperties(); 0228 properties->setProperty("chart-type", ScatterChartType); 0229 properties->setProperty("chart-sub-type", NoChartSubtype); 0230 params.properties = properties; 0231 params.order = order++; 0232 addTemplate(params); 0233 0234 params.templateId = "Radar"; 0235 params.name = i18n("Radar Chart"); 0236 params.toolTip = i18n("Radar chart"); 0237 params.iconName = chartTypeIconName(RadarChartType, NoChartSubtype); 0238 properties = new KoProperties(); 0239 properties->setProperty("chart-type", RadarChartType); 0240 properties->setProperty("chart-sub-type", NoChartSubtype); 0241 params.properties = properties; 0242 params.order = order++; 0243 addTemplate(params); 0244 0245 params.templateId = "RadarFilled"; 0246 params.name = i18n("Filled Radar Chart"); 0247 params.toolTip = i18n("Filled radar chart"); 0248 params.iconName = chartTypeIconName(FilledRadarChartType, NoChartSubtype); 0249 properties = new KoProperties(); 0250 properties->setProperty("chart-type", FilledRadarChartType); 0251 properties->setProperty("chart-sub-type", NoChartSubtype); 0252 params.properties = properties; 0253 params.order = order++; 0254 addTemplate(params); 0255 0256 params.templateId = "StockCandle"; 0257 params.name = i18n("Candle Stick Stock Chart"); 0258 params.toolTip = i18n("Japanese candle stick stock chart"); 0259 params.iconName = chartTypeIconName(StockChartType, CandlestickChartSubtype); 0260 properties = new KoProperties(); 0261 properties->setProperty("chart-type", StockChartType); 0262 properties->setProperty("chart-sub-type", CandlestickChartSubtype); 0263 params.properties = properties; 0264 params.order = order++; 0265 addTemplate(params); 0266 0267 params.templateId = "StockOHLC"; 0268 params.name = i18n("OHLC Stock Chart"); 0269 params.toolTip = i18n("Open High Low Close stock chart"); 0270 params.iconName = chartTypeIconName(StockChartType, OpenHighLowCloseChartSubtype); 0271 properties = new KoProperties(); 0272 properties->setProperty("chart-type", StockChartType); 0273 properties->setProperty("chart-sub-type", OpenHighLowCloseChartSubtype); 0274 params.properties = properties; 0275 params.order = order++; 0276 addTemplate(params); 0277 0278 params.templateId = "StockHLC"; 0279 params.name = i18n("HLC Stock Chart"); 0280 params.toolTip = i18n("High Low Close stock chart"); 0281 params.iconName = chartTypeIconName(StockChartType, HighLowCloseChartSubtype); 0282 properties = new KoProperties(); 0283 properties->setProperty("chart-type", StockChartType); 0284 properties->setProperty("chart-sub-type", HighLowCloseChartSubtype); 0285 params.properties = properties; 0286 params.order = order++; 0287 addTemplate(params); 0288 } 0289 0290 0291 bool ChartShapeFactory::supports(const KoXmlElement &element, KoShapeLoadingContext &context) const 0292 { 0293 if (element.namespaceURI() == "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 0294 && element.tagName() == "object") { 0295 0296 QString href = element.attribute("href"); 0297 if (!href.isEmpty()) { 0298 // check the mimetype 0299 if (href.startsWith(QLatin1String("./"))) { 0300 href.remove(0, 2); 0301 } 0302 const QString mimetype = context.odfLoadingContext().mimeTypeForPath(href); 0303 return mimetype.isEmpty() || mimetype == "application/vnd.oasis.opendocument.chart"; 0304 } 0305 } 0306 return false; 0307 } 0308 0309 KoShape *ChartShapeFactory::createShape(const KoProperties* properties, KoDocumentResourceManager *documentResources) const 0310 { 0311 qInfo()<<Q_FUNC_INFO<<properties->property("chart-type")<<properties->property("chart-sub-type"); 0312 switch (properties->intProperty("chart-type")) { 0313 case BarChartType: 0314 return createBarChart(documentResources, properties->intProperty("chart-sub-type")); 0315 case LineChartType: 0316 return createLineChart(documentResources, properties->intProperty("chart-sub-type")); 0317 case AreaChartType: 0318 return createAreaChart(documentResources, properties->intProperty("chart-sub-type")); 0319 case StockChartType: 0320 return createStockChart(documentResources, properties->intProperty("chart-sub-type")); 0321 case CircleChartType: 0322 return createPieChart(documentResources); 0323 case RingChartType: 0324 return createRingChart(documentResources); 0325 case BubbleChartType: 0326 return createBubbleChart(documentResources); 0327 case ScatterChartType: 0328 return createScatterChart(documentResources); 0329 case RadarChartType: 0330 return createRadarChart(documentResources); 0331 case FilledRadarChartType: 0332 return createFilledRadarChart(documentResources); 0333 default: 0334 return createDefaultShape(documentResources); 0335 } 0336 Q_ASSERT(false); 0337 return 0; 0338 } 0339 0340 KoShape *ChartShapeFactory::createShapeFromOdf(const KoXmlElement &element, 0341 KoShapeLoadingContext &context) 0342 { 0343 ChartShape* shape = new ChartShape(context.documentResourceManager()); 0344 0345 if (shape->shapeId().isEmpty()) 0346 shape->setShapeId(id()); 0347 0348 context.odfLoadingContext().styleStack().save(); 0349 bool loaded = shape->loadOdf(element, context); 0350 context.odfLoadingContext().styleStack().restore(); 0351 0352 if (!loaded) { 0353 delete shape; 0354 return 0; 0355 } 0356 0357 return shape; 0358 } 0359 0360 KoShape *ChartShapeFactory::createDefaultShape(KoDocumentResourceManager *documentResources) const 0361 { 0362 ChartShape* shape = new ChartShape(documentResources); 0363 ChartProxyModel *proxyModel = shape->proxyModel(); 0364 0365 // Fill cells with data. 0366 ChartTableModel *chartData = new ChartTableModel(); 0367 Table *internalTable = shape->tableSource()->add("local-data", chartData); 0368 Q_ASSERT(!shape->internalModel()); 0369 // setInternalModel() assumes that chartData has already been added to shape->tableSource(). 0370 shape->setInternalModel(chartData); 0371 // TODO (not implemented yet) 0372 // shape->tableSource()->setRenameOnNameClash(internalTable); 0373 chartData->setRowCount(4); 0374 chartData->setColumnCount(5); 0375 0376 // Vertical header data 0377 chartData->setData(chartData->index(1, 0), i18n("January")); 0378 chartData->setData(chartData->index(2, 0), i18n("July")); 0379 chartData->setData(chartData->index(3, 0), i18n("December")); 0380 0381 // Horizontal header data 0382 chartData->setData(chartData->index(0, 1), i18n("Column %1", 1)); 0383 chartData->setData(chartData->index(0, 2), i18n("Column %1", 2)); 0384 chartData->setData(chartData->index(0, 3), i18n("Column %1", 3)); 0385 chartData->setData(chartData->index(0, 4), i18n("Column %1", 4)); 0386 0387 // First row 0388 chartData->setData(chartData->index(1, 1), 5.7); 0389 chartData->setData(chartData->index(1, 2), 3.4); 0390 chartData->setData(chartData->index(1, 3), 1.2); 0391 chartData->setData(chartData->index(1, 4), 8.4); 0392 0393 // Second row 0394 chartData->setData(chartData->index(2, 1), 2.1); 0395 chartData->setData(chartData->index(2, 2), 6.5); 0396 chartData->setData(chartData->index(2, 3), 0.9); 0397 chartData->setData(chartData->index(2, 4), 1.5); 0398 0399 // Third row 0400 chartData->setData(chartData->index(3, 1), 7.9); 0401 chartData->setData(chartData->index(3, 2), 3.5); 0402 chartData->setData(chartData->index(3, 3), 8.6); 0403 chartData->setData(chartData->index(3, 4), 4.3); 0404 0405 proxyModel->setFirstRowIsLabel(true); 0406 proxyModel->setFirstColumnIsLabel(true); 0407 proxyModel->reset(CellRegion(internalTable, QRect(1, 1, 5, 4))); 0408 0409 shape->plotArea()->xAxis()->setTitleText(i18n("Month")); 0410 shape->plotArea()->xAxis()->title()->setVisible(true); 0411 shape->plotArea()->yAxis()->setTitleText(i18n("Growth in %")); 0412 shape->plotArea()->yAxis()->title()->setVisible(true); 0413 0414 shape->layout()->scheduleRelayout(); 0415 shape->layout()->layout(); 0416 0417 return shape; 0418 } 0419 0420 QList<KoShapeConfigWidgetBase*> ChartShapeFactory::createShapeOptionPanels() 0421 { 0422 return QList<KoShapeConfigWidgetBase*>(); 0423 } 0424 0425 void ChartShapeFactory::newDocumentResourceManager(KoDocumentResourceManager *manager) const 0426 { 0427 Q_UNUSED(manager); 0428 } 0429 0430 ChartShape *ChartShapeFactory::createBarChart(KoDocumentResourceManager *documentResources, int subtype) const 0431 { 0432 ChartShape* shape = static_cast<ChartShape*>(createDefaultShape(documentResources)); 0433 shape->setChartType(BarChartType); 0434 shape->setChartSubType(static_cast<ChartSubtype>(subtype)); 0435 return shape; 0436 } 0437 0438 ChartShape *ChartShapeFactory::createLineChart(KoDocumentResourceManager *documentResources, int subtype) const 0439 { 0440 ChartShape* shape = static_cast<ChartShape*>(createDefaultShape(documentResources)); 0441 shape->setChartType(LineChartType); 0442 shape->setChartSubType(static_cast<ChartSubtype>(subtype)); 0443 return shape; 0444 } 0445 0446 ChartShape *ChartShapeFactory::createAreaChart(KoDocumentResourceManager *documentResources, int subtype) const 0447 { 0448 ChartShape* shape = static_cast<ChartShape*>(createDefaultShape(documentResources)); 0449 shape->setChartType(AreaChartType); 0450 shape->setChartSubType(static_cast<ChartSubtype>(subtype)); 0451 return shape; 0452 } 0453 0454 ChartShape *ChartShapeFactory::createStockChart(KoDocumentResourceManager *documentResources, int subtype) const 0455 { 0456 ChartShape* shape = new ChartShape(documentResources); 0457 shape->setChartType(StockChartType); 0458 shape->setChartSubType(CandlestickChartSubtype); // we create data for this by default, and switch below if needed 0459 ChartProxyModel *proxyModel = shape->proxyModel(); 0460 0461 // Fill cells with data. 0462 ChartTableModel *chartData = new ChartTableModel(); 0463 Table *internalTable = shape->tableSource()->add("local-data", chartData); 0464 Q_ASSERT(!shape->internalModel()); 0465 // setInternalModel() assumes that chartData has already been added to shape->tableSource(). 0466 shape->setInternalModel(chartData); 0467 // TODO (not implemented yet) 0468 // shape->tableSource()->setRenameOnNameClash(internalTable); 0469 chartData->setRowCount(4); 0470 chartData->setColumnCount(5); 0471 0472 // Vertical header data (not used) 0473 chartData->setData(chartData->index(1, 0), i18n("Share A")); 0474 chartData->setData(chartData->index(2, 0), i18n("Share B")); 0475 chartData->setData(chartData->index(3, 0), i18n("Share C")); 0476 0477 // Horizontal header data 0478 chartData->setData(chartData->index(0, 1), i18n("Open")); 0479 chartData->setData(chartData->index(0, 2), i18n("High")); 0480 chartData->setData(chartData->index(0, 3), i18n("Low")); 0481 chartData->setData(chartData->index(0, 4), i18n("Close")); 0482 0483 QList<qreal> openValues; openValues << 10 << 15 << 20; 0484 QList<qreal> highValues; highValues << 12 << 15 << 30; 0485 QList<qreal> lowValues; lowValues << 6 << 13 << 20; 0486 QList<qreal> closeValues; closeValues << 7 << 13 << 30; 0487 int col = 1; 0488 0489 // Open 0490 chartData->setData(chartData->index(1, col), openValues.at(0)); 0491 chartData->setData(chartData->index(2, col), openValues.at(1)); 0492 chartData->setData(chartData->index(3, col), openValues.at(2)); 0493 ++col; 0494 0495 // High 0496 chartData->setData(chartData->index(1, col), highValues.at(0)); 0497 chartData->setData(chartData->index(2, col), highValues.at(1)); 0498 chartData->setData(chartData->index(3, col), highValues.at(2)); 0499 ++col; 0500 0501 // Low 0502 chartData->setData(chartData->index(1, col), lowValues.at(0)); 0503 chartData->setData(chartData->index(2, col), lowValues.at(1)); 0504 chartData->setData(chartData->index(3, col), lowValues.at(2)); 0505 ++col; 0506 0507 // Close 0508 chartData->setData(chartData->index(1, col), closeValues.at(0)); 0509 chartData->setData(chartData->index(2, col), closeValues.at(1)); 0510 chartData->setData(chartData->index(3, col), closeValues.at(2)); 0511 0512 proxyModel->setFirstRowIsLabel(true); 0513 proxyModel->setFirstColumnIsLabel(true); 0514 proxyModel->reset(CellRegion(internalTable, QRect(1, 1, 5, 4))); 0515 0516 shape->plotArea()->yAxis()->title()->setVisible(false); 0517 shape->plotArea()->xAxis()->title()->setVisible(false); 0518 shape->legend()->setVisible(false); 0519 0520 shape->setChartSubType(static_cast<ChartSubtype>(subtype), true); 0521 0522 shape->layout()->scheduleRelayout(); 0523 shape->layout()->layout(); 0524 0525 return shape; 0526 } 0527 0528 ChartShape *ChartShapeFactory::createPieChart(KoDocumentResourceManager *documentResources) const 0529 { 0530 ChartShape* shape = static_cast<ChartShape*>(createDefaultShape(documentResources)); 0531 shape->setChartType(CircleChartType); 0532 shape->setChartSubType(NoChartSubtype); 0533 return shape; 0534 } 0535 0536 ChartShape *ChartShapeFactory::createRingChart(KoDocumentResourceManager *documentResources) const 0537 { 0538 ChartShape* shape = static_cast<ChartShape*>(createDefaultShape(documentResources)); 0539 shape->setChartType(RingChartType); 0540 shape->setChartSubType(NoChartSubtype); 0541 return shape; 0542 } 0543 0544 ChartShape *ChartShapeFactory::createBubbleChart(KoDocumentResourceManager *documentResources) const 0545 { 0546 ChartShape* shape = new ChartShape(documentResources); 0547 shape->setChartType(BubbleChartType); 0548 shape->setChartSubType(NoChartSubtype); 0549 ChartProxyModel *proxyModel = shape->proxyModel(); 0550 0551 // Fill cells with data. 0552 ChartTableModel *chartData = new ChartTableModel(); 0553 Table *internalTable = shape->tableSource()->add("local-data", chartData); 0554 Q_ASSERT(!shape->internalModel()); 0555 // setInternalModel() assumes that chartData has already been added to shape->tableSource(). 0556 shape->setInternalModel(chartData); 0557 // TODO (not implemented yet) 0558 // shape->tableSource()->setRenameOnNameClash(internalTable); 0559 chartData->setRowCount(4); 0560 chartData->setColumnCount(5); 0561 0562 // Vertical header data (not used) 0563 chartData->setData(chartData->index(1, 0), i18n("January")); 0564 chartData->setData(chartData->index(2, 0), i18n("July")); 0565 chartData->setData(chartData->index(3, 0), i18n("December")); 0566 0567 // Horizontal header data 0568 chartData->setData(chartData->index(0, 1), i18n("Column %1", 1)); 0569 chartData->setData(chartData->index(0, 2), i18n("Column %1", 2)); 0570 chartData->setData(chartData->index(0, 3), i18n("Column %1", 3)); // not used 0571 chartData->setData(chartData->index(0, 4), i18n("Column %1", 4)); // not used 0572 0573 // First row 0574 chartData->setData(chartData->index(1, 1), 4.7); // Y value series 1 0575 chartData->setData(chartData->index(1, 2), 3.4); // bubble size series 1 0576 chartData->setData(chartData->index(1, 3), 1.2); // Y value series 2 0577 chartData->setData(chartData->index(1, 4), 8.4); // bubble size series 2 0578 0579 // Second row 0580 chartData->setData(chartData->index(2, 1), 2.1); 0581 chartData->setData(chartData->index(2, 2), 6.5); 0582 chartData->setData(chartData->index(2, 3), 4.9); 0583 chartData->setData(chartData->index(2, 4), 3.5); 0584 0585 // Third row 0586 chartData->setData(chartData->index(3, 1), 7.9); 0587 chartData->setData(chartData->index(3, 2), 1.5); 0588 chartData->setData(chartData->index(3, 3), 4.6); 0589 chartData->setData(chartData->index(3, 4), 4.3); 0590 0591 proxyModel->setFirstRowIsLabel(true); 0592 proxyModel->setFirstColumnIsLabel(true); 0593 proxyModel->reset(CellRegion(internalTable, QRect(1, 1, 5, 4))); 0594 0595 shape->plotArea()->xAxis()->title()->setVisible(false); 0596 shape->plotArea()->yAxis()->setTitleText(i18n("Growth")); 0597 0598 shape->layout()->scheduleRelayout(); 0599 shape->layout()->layout(); 0600 0601 return shape; 0602 } 0603 0604 ChartShape *ChartShapeFactory::createScatterChart(KoDocumentResourceManager *documentResources) const 0605 { 0606 ChartShape* shape = static_cast<ChartShape*>(createDefaultShape(documentResources)); 0607 shape->setChartType(ScatterChartType); 0608 shape->setChartSubType(NoChartSubtype); 0609 return shape; 0610 } 0611 0612 ChartShape *ChartShapeFactory::createRadarChart(KoDocumentResourceManager *documentResources) const 0613 { 0614 ChartShape* shape = new ChartShape(documentResources); 0615 shape->setChartType(RadarChartType); 0616 shape->setChartSubType(NoChartSubtype); 0617 radarData(shape); 0618 return shape; 0619 } 0620 0621 ChartShape *ChartShapeFactory::createFilledRadarChart(KoDocumentResourceManager *documentResources) const 0622 { 0623 ChartShape* shape = new ChartShape(documentResources); 0624 shape->setChartType(FilledRadarChartType); 0625 shape->setChartSubType(NoChartSubtype); 0626 radarData(shape); 0627 return shape; 0628 } 0629 0630 void ChartShapeFactory::radarData(ChartShape *shape) const 0631 { 0632 ChartProxyModel *proxyModel = shape->proxyModel(); 0633 0634 // Fill cells with data. 0635 ChartTableModel *chartData = new ChartTableModel(); 0636 Table *internalTable = shape->tableSource()->add("local-data", chartData); 0637 Q_ASSERT(!shape->internalModel()); 0638 // setInternalModel() assumes that chartData has already been added to shape->tableSource(). 0639 shape->setInternalModel(chartData); 0640 // TODO (not implemented yet) 0641 // shape->tableSource()->setRenameOnNameClash(internalTable); 0642 chartData->setRowCount(4); 0643 chartData->setColumnCount(3); 0644 0645 // Vertical header data (not used) 0646 chartData->setData(chartData->index(1, 0), i18n("January")); 0647 chartData->setData(chartData->index(2, 0), i18n("July")); 0648 chartData->setData(chartData->index(3, 0), i18n("December")); 0649 0650 // Horizontal header data 0651 chartData->setData(chartData->index(0, 1), i18n("Column %1", 1)); 0652 chartData->setData(chartData->index(0, 2), i18n("Column %1", 2)); 0653 0654 // First row 0655 chartData->setData(chartData->index(1, 1), 10); 0656 chartData->setData(chartData->index(1, 2), 3); 0657 chartData->setData(chartData->index(1, 3), 6); 0658 0659 // Second row 0660 chartData->setData(chartData->index(2, 1), 4); 0661 chartData->setData(chartData->index(2, 2), 8); 0662 chartData->setData(chartData->index(2, 3), 10); 0663 0664 // Third row 0665 chartData->setData(chartData->index(3, 1), 5); 0666 chartData->setData(chartData->index(3, 2), 10); 0667 chartData->setData(chartData->index(3, 3), 13); 0668 0669 proxyModel->setFirstRowIsLabel(true); 0670 proxyModel->setFirstColumnIsLabel(true); 0671 proxyModel->reset(CellRegion(internalTable, QRect(1, 1, chartData->columnCount(), chartData->rowCount()))); 0672 } 0673 0674 #include "ChartShapeFactory.moc"