KReport

KReportKSpreadRenderer.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "KReportKSpreadRenderer.h"
19
20#include "ods/KoSimpleOdsDocument.h"
21#include "ods/KoSimpleOdsCell.h"
22#include "ods/KoSimpleOdsSheet.h"
23#include "KReportRenderObjects.h"
24
25#include "kreport_debug.h"
26
27KoReportKSpreadRenderer::KoReportKSpreadRenderer()
28{
29}
30
31
32KoReportKSpreadRenderer::~KoReportKSpreadRenderer()
33{
34}
35
36bool KoReportKSpreadRenderer::render(const KoReportRendererContext& context, ORODocument* document, int page)
37{
38 Q_UNUSED(page);
39 KoSimpleOdsDocument *doc = new KoSimpleOdsDocument();
40 KoSimpleOdsSheet *sht = new KoSimpleOdsSheet();
41
42 //kreportDebug() << "Setting name to:" << document->title();
43 sht->setName(document->title());
44
45 bool renderedPageHeader = false;
46 bool renderedPageFooter = false;
47
48 // Render Each Section
49 for (int s = 0; s < document->sectionCount(); s++) {
50 OROSection *section = document->section(s);
51 section->sortPrimitives(OROSection::SortX);
52
53 if (section->type() == KReportSectionData::GroupHeader ||
54 section->type() == KReportSectionData::GroupFooter ||
55 section->type() == KReportSectionData::Detail ||
56 section->type() == KReportSectionData::ReportHeader ||
57 section->type() == KReportSectionData::ReportFooter ||
58 (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHeader) ||
59 (section->type() == KReportSectionData::PageFooterAny && !renderedPageFooter && s > document->sectionCount() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer
60 if (section->type() == KReportSectionData::PageHeaderAny)
61 renderedPageHeader = true;
62
63 if (section->type() == KReportSectionData::PageFooterAny)
64 renderedPageFooter = true;
65
66 //Render the objects in each section
67 for (int i = 0; i < section->primitiveCount(); i++) {
68 OROPrimitive * prim = section->primitive(i);
69
70 if (prim->type() == OROTextBox::TextBox) {
71 OROTextBox * tb = (OROTextBox*) prim;
72
73 sht->addCell(s, i, new KoSimpleOdsCell(tb->text()));
74 }
75 /*
76 else if (prim->type() == OROImage::Image)
77 {
78 kreportDebug() << "Saving an image";
79 OROImage * im = ( OROImage* ) prim;
80 tr += "<td>"
81 "<img src=\"./" + fi.fileName() + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
82 "</td>\n";
83 im->image().save(saveDir + "/object" + QString::number(s) + QString::number(i) + ".png");
84 }
85 else if (prim->type() == OROPicture::Picture)
86 {
87 kreportDebug() << "Saving a picture";
88 OROPicture * im = ( OROPicture* ) prim;
89
90 tr += "<td>"
91 "<img src=\"./" + fi.fileName() + "/object" + QString::number(s) + QString::number(i) + ".png\"></img>"
92 "</td>\n";
93 QImage image(im->size().toSize(), QImage::Format_RGB32);
94 QPainter painter(&image);
95 im->picture()->play(&painter);
96 image.save(saveDir + "/object" + QString::number(s) + QString::number(i) + ".png");
97 }*/
98 else {
99 kreportWarning() << "unhandled primitive type";
100 }
101 }
102 }
103 }
104
105 doc->addSheet(sht);
106
107 bool status;
108 if (doc->saveDocument(context.destinationUrl.path()) == QFile::NoError) {
109 status = true;
110 }
111 else {
112 status = false;
113 }
114
115 delete doc;
116 return status;
117}
Represents a single document containing one or more OROPage elements.
OROSection * section(int index)
Return a pointer to a given section.
int sectionCount() const
Return the total number of sections in the document.
Represents the basic primitive with a position and type. Other primitives are subclasses with a defin...
Represents a single a single row in a document and may contain zero or more OROPrimitives.
A text box primitive it defines a box region and text that will be rendered inside that region,...
Q_SCRIPTABLE CaptureState status()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:04 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.