~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kchart/shape/ChartDocument.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
 
3
 
   Copyright 2008 Johannes Simon <johannes.simon@gmail.com>
4
 
 
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.
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
 
   Library General Public License for more details.
14
 
 
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.
19
 
*/
20
 
 
21
 
// Own
22
 
#include "ChartDocument.h"
23
 
 
24
 
// Qt
25
 
#include <QWidget>
26
 
#include <QIODevice>
27
 
#include <QDebug>
28
 
#include <QPainter>
29
 
 
30
 
// KOffice
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>
38
 
#include <KoXmlNS.h>
39
 
#include <KoOdfStylesReader.h>
40
 
#include <KoGenStyles.h>
41
 
#include <KoEmbeddedDocumentSaver.h>
42
 
#include <KoView.h>
43
 
#include <KComponentData>
44
 
#include <KDebug>
45
 
 
46
 
// KChart
47
 
#include "ChartShape.h"
48
 
 
49
 
 
50
 
namespace KChart {
51
 
 
52
 
class ChartDocument::Private
53
 
{
54
 
public:
55
 
    Private();
56
 
    ~Private();
57
 
    
58
 
    ChartShape *parent;
59
 
};
60
 
 
61
 
ChartDocument::Private::Private()
62
 
{
63
 
}
64
 
 
65
 
ChartDocument::Private::~Private()
66
 
{
67
 
}
68
 
 
69
 
ChartDocument::ChartDocument( ChartShape *parent )
70
 
    : KoDocument( 0, 0 )
71
 
    , d ( new Private )
72
 
{
73
 
    d->parent = parent;
74
 
    // Needed by KoDocument::nativeOasisMimeType().
75
 
    // KoEmbeddedDocumentSaver uses that method to
76
 
    // get the mimetype of the embedded document.
77
 
    setComponentData( KComponentData( "kchart" ) );
78
 
}
79
 
 
80
 
ChartDocument::~ChartDocument()
81
 
{
82
 
    delete d;
83
 
}
84
 
 
85
 
 
86
 
bool ChartDocument::loadOdf( KoOdfReadStore &odfStore )
87
 
{
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.";
92
 
        return false;
93
 
    }
94
 
    KoXmlNode chartElementParentNode = bodyNode.namedItemNS( KoXmlNS::office, "chart" );
95
 
    if ( chartElementParentNode.isNull() ) {
96
 
        kError(35001) << "No <office:chart> element found.";
97
 
        return false;
98
 
    }
99
 
    KoXmlElement chartElement = chartElementParentNode.namedItemNS( KoXmlNS::chart, "chart" ).toElement();
100
 
    if ( chartElement.isNull() ) {
101
 
        kError(35001) << "No <chart:chart> element found.";
102
 
        return false;
103
 
    }
104
 
    KoOdfLoadingContext odfLoadingContext( odfStore.styles(), odfStore.store() );
105
 
    KoShapeLoadingContext context(odfLoadingContext, d->parent->resourceManager());
106
 
 
107
 
    return d->parent->loadOdfEmbedded( chartElement, context );
108
 
}
109
 
 
110
 
bool ChartDocument::loadXML( const KoXmlDocument &doc, KoStore *)
111
 
{
112
 
    Q_UNUSED( doc );
113
 
 
114
 
    // We don't support the old XML format any more.
115
 
    return false;
116
 
}
117
 
 
118
 
bool ChartDocument::saveOdf( SavingContext &context )
119
 
{
120
 
    KoOdfWriteStore &odfStore = context.odfStore;
121
 
    KoStore *store = odfStore.store();
122
 
    KoXmlWriter *manifestWriter = odfStore.manifestWriter();
123
 
    KoXmlWriter *contentWriter  = odfStore.contentWriter();
124
 
    if ( !contentWriter )
125
 
        return false;
126
 
    
127
 
    KoGenStyles mainStyles;
128
 
    KoXmlWriter *bodyWriter = odfStore.bodyWriter();
129
 
    if ( !bodyWriter )
130
 
        return false;
131
 
    
132
 
    KoEmbeddedDocumentSaver embeddedSaver = context.embeddedSaver;
133
 
    
134
 
    KoShapeSavingContext savingContext( *bodyWriter, mainStyles, embeddedSaver );
135
 
    
136
 
    bodyWriter->startElement( "office:body" );
137
 
    bodyWriter->startElement( "office:chart" );
138
 
    
139
 
    d->parent->saveOdf( savingContext );
140
 
    
141
 
    bodyWriter->endElement(); // office:chart
142
 
    bodyWriter->endElement(); // office:body
143
 
 
144
 
    mainStyles.saveOdfStyles( KoGenStyles::DocumentAutomaticStyles, contentWriter );
145
 
    odfStore.closeContentWriter();
146
 
 
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" );
150
 
 
151
 
    // save the styles.xml
152
 
    if ( !mainStyles.saveOdfStylesDotXml( store, manifestWriter ) )
153
 
        return false;
154
 
 
155
 
    if ( !savingContext.saveDataCenter( store, manifestWriter ) ) {
156
 
        return false;
157
 
    }
158
 
    
159
 
    return true;
160
 
}
161
 
 
162
 
KoView *ChartDocument::createViewInstance( QWidget *parent )
163
 
{
164
 
    Q_UNUSED( parent );
165
 
 
166
 
    return 0;
167
 
}
168
 
 
169
 
void ChartDocument::paintContent( QPainter &painter, const QRect &rect )
170
 
{
171
 
    Q_UNUSED( painter );
172
 
    Q_UNUSED( rect );
173
 
}
174
 
 
175
 
} // namespace KChart
176