File indexing completed on 2024-05-05 04:43:22

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2010 by Adam Pigg (adam@piggz.co.uk)
0003  * Copyright (C) 2012 by Dag Andersen (danders@get2net.dk)
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 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  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #include "KReportOdtFrameReportRenderer.h"
0020 #include "odtframe/KoOdtFrameReportDocument.h"
0021 #include "odtframe/KoOdtFrameReportTextBox.h"
0022 #include "odtframe/KoOdtFrameReportImage.h"
0023 #include "odtframe/KoOdtFrameReportPicture.h"
0024 #include "odtframe/KoOdtFrameReportLine.h"
0025 #include "odtframe/KoOdtFrameReportCheckBox.h"
0026 #include "KReportRenderObjects.h"
0027 
0028 namespace KReportPrivate {
0029 
0030   
0031 KoOdtFrameReportRenderer::KoOdtFrameReportRenderer()
0032 {
0033 
0034 }
0035 
0036 KoOdtFrameReportRenderer::~KoOdtFrameReportRenderer()
0037 {
0038 }
0039 
0040 bool KoOdtFrameReportRenderer::render(const KoReportRendererContext& context, ORODocument* document, int /*page*/)
0041 {
0042     int uid = 1;
0043     KoOdtFrameReportDocument doc;
0044     doc.setPageOptions(document->pageOptions());
0045     for (int page = 0; page < document->pages(); page++) {
0046         OROPage *p = document->page(page);
0047         for (int i = 0; i < p->primitives(); i++) {
0048             OROPrimitive *prim = p->primitive(i);
0049             if (prim->type() == OROTextBox::TextBox) {
0050                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportTextBox(static_cast<OROTextBox*>(prim));
0051                 sp->setUID(uid++);
0052                 doc.addPrimitive(sp);
0053             } else if (prim->type() == OROImage::Image) {
0054                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportImage(static_cast<OROImage*>(prim));
0055                 sp->setUID(uid++);
0056                 doc.addPrimitive(sp);
0057             } else if (prim->type() == OROPicture::Picture) {
0058                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportPicture(static_cast<OROPicture*>(prim));
0059                 sp->setUID(uid++);
0060                 doc.addPrimitive(sp);
0061             } else if (prim->type() == OROLine::Line) {
0062                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportLine(static_cast<OROLine*>(prim));
0063                 sp->setUID(uid++);
0064                 doc.addPrimitive(sp);
0065             } else if (prim->type() == OROCheck::Check) {
0066                 KoOdtFrameReportPrimitive *sp = new KoOdtFrameReportCheckBox(static_cast<OROCheck*>(prim));
0067                 sp->setUID(uid++);
0068                 doc.addPrimitive(sp);
0069             } else {
0070                 kreportWarning() << "unhandled primitive type" << prim->type();
0071             }
0072         }
0073     }
0074     return doc.saveDocument(context.destinationUrl.path()) == QFile::NoError;
0075 }
0076 
0077 }