1
/* This file is part of the KDE project
3
Copyright 2008 Johannes Simon <johannes.simon@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
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
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
22
#include "ChartDocument.h"
31
#include <KoDocument.h>
32
#include <KoXmlWriter.h>
33
#include <KoOdfReadStore.h>
34
#include <KoOdfWriteStore.h>
35
#include <KoOdfLoadingContext.h>
36
#include <KoShapeLoadingContext.h>
37
#include <KoShapeSavingContext.h>
39
#include <KoOdfStylesReader.h>
40
#include <KoGenStyles.h>
41
#include <KoEmbeddedDocumentSaver.h>
43
#include <KComponentData>
47
#include "ChartShape.h"
52
class ChartDocument::Private
61
ChartDocument::Private::Private()
65
ChartDocument::Private::~Private()
69
ChartDocument::ChartDocument( ChartShape *parent )
74
// Needed by KoDocument::nativeOasisMimeType().
75
// KoEmbeddedDocumentSaver uses that method to
76
// get the mimetype of the embedded document.
77
setComponentData( KComponentData( "kchart" ) );
80
ChartDocument::~ChartDocument()
86
bool ChartDocument::loadOdf( KoOdfReadStore &odfStore )
88
KoXmlDocument doc = odfStore.contentDoc();
89
KoXmlNode bodyNode = doc.documentElement().namedItemNS( KoXmlNS::office, "body" );
90
if ( bodyNode.isNull() ) {
91
kError(35001) << "No <office:body> element found.";
94
KoXmlNode chartElementParentNode = bodyNode.namedItemNS( KoXmlNS::office, "chart" );
95
if ( chartElementParentNode.isNull() ) {
96
kError(35001) << "No <office:chart> element found.";
99
KoXmlElement chartElement = chartElementParentNode.namedItemNS( KoXmlNS::chart, "chart" ).toElement();
100
if ( chartElement.isNull() ) {
101
kError(35001) << "No <chart:chart> element found.";
104
KoOdfLoadingContext odfLoadingContext( odfStore.styles(), odfStore.store() );
105
KoShapeLoadingContext context(odfLoadingContext, d->parent->resourceManager());
107
return d->parent->loadOdfEmbedded( chartElement, context );
110
bool ChartDocument::loadXML( const KoXmlDocument &doc, KoStore *)
114
// We don't support the old XML format any more.
118
bool ChartDocument::saveOdf( SavingContext &context )
120
KoOdfWriteStore &odfStore = context.odfStore;
121
KoStore *store = odfStore.store();
122
KoXmlWriter *manifestWriter = odfStore.manifestWriter();
123
KoXmlWriter *contentWriter = odfStore.contentWriter();
124
if ( !contentWriter )
127
KoGenStyles mainStyles;
128
KoXmlWriter *bodyWriter = odfStore.bodyWriter();
132
KoEmbeddedDocumentSaver embeddedSaver = context.embeddedSaver;
134
KoShapeSavingContext savingContext( *bodyWriter, mainStyles, embeddedSaver );
136
bodyWriter->startElement( "office:body" );
137
bodyWriter->startElement( "office:chart" );
139
d->parent->saveOdf( savingContext );
141
bodyWriter->endElement(); // office:chart
142
bodyWriter->endElement(); // office:body
144
mainStyles.saveOdfStyles( KoGenStyles::DocumentAutomaticStyles, contentWriter );
145
odfStore.closeContentWriter();
147
// Add manifest line for content.xml and styles.xml
148
manifestWriter->addManifestEntry( url().path() + "/content.xml", "text/xml" );
149
manifestWriter->addManifestEntry( url().path() + "/styles.xml", "text/xml" );
151
// save the styles.xml
152
if ( !mainStyles.saveOdfStylesDotXml( store, manifestWriter ) )
155
if ( !savingContext.saveDataCenter( store, manifestWriter ) ) {
162
KoView *ChartDocument::createViewInstance( QWidget *parent )
169
void ChartDocument::paintContent( QPainter &painter, const QRect &rect )
175
} // namespace KChart