1 /* This file is part of the KDE project
2  * Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk)
3  * Copyright (C) 2012 by Dag Andersen (danders@get2net.dk)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "KReportOdtFrameReportRenderer.h"
20 #include "odtframe/KoOdtFrameReportDocument.h"
21 #include "odtframe/KoOdtFrameReportTextBox.h"
22 #include "odtframe/KoOdtFrameReportImage.h"
23 #include "odtframe/KoOdtFrameReportPicture.h"
24 #include "odtframe/KoOdtFrameReportLine.h"
25 #include "odtframe/KoOdtFrameReportCheckBox.h"
26 #include "KReportRenderObjects.h"
27 
28 namespace KReportPrivate {
29 
30 
KoOdtFrameReportRenderer()31 KoOdtFrameReportRenderer::KoOdtFrameReportRenderer()
32 {
33 
34 }
35 
~KoOdtFrameReportRenderer()36 KoOdtFrameReportRenderer::~KoOdtFrameReportRenderer()
37 {
38 }
39 
render(const KoReportRendererContext & context,ORODocument * document,int)40 bool KoOdtFrameReportRenderer::render(const KoReportRendererContext& context, ORODocument* document, int /*page*/)
41 {
42     int uid = 1;
43     KoOdtFrameReportDocument doc;
44     doc.setPageOptions(document->pageOptions());
45     for (int page = 0; page < document->pages(); page++) {
46         OROPage *p = document->page(page);
47         for (int i = 0; i < p->primitives(); i++) {
48             OROPrimitive *prim = p->primitive(i);
49             if (prim->type() == OROTextBox::TextBox) {
50                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportTextBox(static_cast<OROTextBox*>(prim));
51                 sp->setUID(uid++);
52                 doc.addPrimitive(sp);
53             } else if (prim->type() == OROImage::Image) {
54                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportImage(static_cast<OROImage*>(prim));
55                 sp->setUID(uid++);
56                 doc.addPrimitive(sp);
57             } else if (prim->type() == OROPicture::Picture) {
58                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportPicture(static_cast<OROPicture*>(prim));
59                 sp->setUID(uid++);
60                 doc.addPrimitive(sp);
61             } else if (prim->type() == OROLine::Line) {
62                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportLine(static_cast<OROLine*>(prim));
63                 sp->setUID(uid++);
64                 doc.addPrimitive(sp);
65             } else if (prim->type() == OROCheck::Check) {
66                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportCheckBox(static_cast<OROCheck*>(prim));
67                 sp->setUID(uid++);
68                 doc.addPrimitive(sp);
69             } else {
70                 kreportWarning() << "unhandled primitive type" << prim->type();
71             }
72         }
73     }
74     return doc.saveDocument(context.destinationUrl.path()) == QFile::NoError;
75 }
76 
77 }
78