Warning, file /office/calligra/libs/text/KoTextOdfSaveHelper.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0003  * Copyright (C) 2011 Boudewijn Rempt <boud@valdyas.org>
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 #include "KoTextOdfSaveHelper.h"
0022 
0023 #include <KoXmlWriter.h>
0024 #include <KoOdf.h>
0025 #include "KoTextWriter.h"
0026 #include <KoShapeSavingContext.h>
0027 #include <KoTextDocument.h>
0028 
0029 #include <QTextDocument>
0030 
0031 struct Q_DECL_HIDDEN KoTextOdfSaveHelper::Private {
0032     Private(const QTextDocument *document, int from, int to)
0033         : context(0)
0034         , document(document)
0035         , from(from)
0036         , to(to)
0037 #ifdef SHOULD_BUILD_RDF
0038         , rdfModel(0)
0039 #endif
0040     {
0041     }
0042 
0043     KoShapeSavingContext *context;
0044     const QTextDocument *document;
0045 
0046     int from;
0047     int to;
0048 
0049 #ifdef SHOULD_BUILD_RDF
0050     QSharedPointer<Soprano::Model> rdfModel; //< This is so cut/paste can serialize the relevant RDF to the clipboard
0051 #endif
0052 };
0053 
0054 
0055 KoTextOdfSaveHelper::KoTextOdfSaveHelper(const QTextDocument *document, int from, int to)
0056         : d(new Private(document, from, to))
0057 {
0058 }
0059 
0060 KoTextOdfSaveHelper::~KoTextOdfSaveHelper()
0061 {
0062     delete d;
0063 }
0064 
0065 bool KoTextOdfSaveHelper::writeBody()
0066 {
0067     if (d->to < d->from) {
0068         qSwap(d->to, d->from);
0069     }
0070     Q_ASSERT(d->context);
0071     KoXmlWriter & bodyWriter = d->context->xmlWriter();
0072     bodyWriter.startElement("office:body");
0073     bodyWriter.startElement(KoOdf::bodyContentElement(KoOdf::Text, true));
0074 
0075     KoTextWriter writer(*d->context, 0);
0076     writer.write(d->document, d->from, d->to);
0077 
0078     bodyWriter.endElement(); // office:element
0079     bodyWriter.endElement(); // office:body
0080     return true;
0081 }
0082 
0083 KoShapeSavingContext * KoTextOdfSaveHelper::context(KoXmlWriter * bodyWriter,
0084                                                     KoGenStyles & mainStyles,
0085                                                     KoEmbeddedDocumentSaver & embeddedSaver)
0086 {
0087     d->context = new KoShapeSavingContext(*bodyWriter, mainStyles, embeddedSaver);
0088     return d->context;
0089 }
0090 
0091 #ifdef SHOULD_BUILD_RDF
0092 void KoTextOdfSaveHelper::setRdfModel(QSharedPointer<Soprano::Model> m)
0093 {
0094     d->rdfModel = m;
0095 }
0096 
0097 QSharedPointer<Soprano::Model> KoTextOdfSaveHelper::rdfModel() const
0098 {
0099     return d->rdfModel;
0100 }
0101 #endif
0102 
0103 KoStyleManager *KoTextOdfSaveHelper::styleManager() const
0104 {
0105     return KoTextDocument(d->document).styleManager();
0106 }