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

« back to all changes in this revision

Viewing changes to kchart/kdchart/kdchartserializer/src/KDChartDiagramsSerializer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C++ -*-
2
 
   KDChart - a multi-platform charting engine
3
 
   */
4
 
 
5
 
/****************************************************************************
6
 
 ** Copyright (C) 2001-2003 Klaralvdalens Datakonsult AB.  All rights reserved.
7
 
 **
8
 
 ** This file is part of the KDChart library.
9
 
 **
10
 
 ** This file may be used under the terms of the GNU General Public
11
 
 ** License versions 2.0 or 3.0 as published by the Free Software
12
 
 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
13
 
 ** included in the packaging of this file.  Alternatively you may (at
14
 
 ** your option) use any later version of the GNU General Public
15
 
 ** License if such license has been publicly approved by
16
 
 ** Klarälvdalens Datakonsult AB (or its successors, if any).
17
 
 ** 
18
 
 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
19
 
 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
20
 
 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
21
 
 ** not expressly granted herein.
22
 
 ** 
23
 
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24
 
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25
 
 **
26
 
 **********************************************************************/
27
 
 
28
 
#include <KDChartDiagramsSerializer>
29
 
#include <KDChartDiagramsSerializer_p.h>
30
 
 
31
 
#include <KDChartSerializeCollector>
32
 
#include <KDChartCoordPlanesSerializer>
33
 
#include <KDChartAxesSerializer>
34
 
#include <KDChartAttributesModelSerializer>
35
 
 
36
 
#include <KDXMLTools>
37
 
 
38
 
#include <KDChartLineDiagram>
39
 
#include <KDChartBarDiagram>
40
 
#include <KDChartPieDiagram>
41
 
#include <KDChartPolarDiagram>
42
 
#include <KDChartRingDiagram>
43
 
#include <KDChartSerializer>
44
 
#include <KDChartAbstractSerializerFactory>
45
 
 
46
 
#include <qglobal.h>
47
 
#include <QMessageBox>
48
 
#include <QMetaObject>
49
 
// #include <QDomNodeList>
50
 
#include <QMetaProperty>
51
 
 
52
 
#define d d_func()
53
 
 
54
 
using namespace KDChart;
55
 
 
56
 
static const char* TagNameQtProperties = "properties";
57
 
/**
58
 
  \class KDChart::DiagramsSerializer KDChartDiagramsSerializer.h
59
 
 
60
 
  \brief Auxiliary methods reading/saving KD Chart data and configuration in streams.
61
 
  */
62
 
 
63
 
DiagramsSerializer::Private::Private( DiagramsSerializer* qq )
64
 
    : q( qq ),
65
 
      m_haveOwnCoordS( false ),
66
 
      m_coordS( 0 ),
67
 
      m_axesS( 0 ),
68
 
      m_attrModelS( 0 )
69
 
{
70
 
}
71
 
 
72
 
DiagramsSerializer::Private::~Private() {}
73
 
 
74
 
 
75
 
DiagramsSerializer::DiagramsSerializer( CoordPlanesSerializer* coordS )
76
 
    : _d( new Private( this ) )
77
 
{
78
 
    d->m_coordS = coordS;
79
 
    d->m_haveOwnCoordS = ( d->m_coordS == 0 );
80
 
    if( d->m_haveOwnCoordS )
81
 
        d->m_coordS = new CoordPlanesSerializer();
82
 
    d->m_axesS = new AxesSerializer();
83
 
    d->m_attrModelS = new AttributesModelSerializer();
84
 
    d->m_globalList = "kdchart:diagrams"; // default value, can be
85
 
    // overwritten by the title passed to DiagramsSerializer::saveDiagrams()
86
 
}
87
 
 
88
 
DiagramsSerializer::~DiagramsSerializer()
89
 
{
90
 
    delete d->m_attrModelS;
91
 
    delete d->m_axesS;
92
 
    if( d->m_haveOwnCoordS )
93
 
        delete d->m_coordS;
94
 
 
95
 
    delete _d; _d = 0;
96
 
}
97
 
 
98
 
void DiagramsSerializer::init()
99
 
{
100
 
}
101
 
 
102
 
void DiagramsSerializer::saveDiagrams(
103
 
        QDomDocument& doc,
104
 
        QDomElement& e,
105
 
        const ConstAbstractDiagramList& diags,
106
 
        const QString& title )const
107
 
{
108
 
    if( ! title.isEmpty() )
109
 
        d->m_globalList = title;
110
 
 
111
 
    // access (or append, resp.) the global list
112
 
    QDomElement* diagsList =
113
 
            SerializeCollector::instance()->findOrMakeElement( doc, d->m_globalList );
114
 
 
115
 
    // create the local list holding names pointing into the global list
116
 
    QDomElement pointersList =
117
 
            SerializeCollector::createPointersList( doc, e, d->m_globalList );
118
 
 
119
 
    Q_FOREACH ( const AbstractDiagram* p, diags )
120
 
    {
121
 
        bool wasFound;
122
 
        QDomElement diagElement =
123
 
                SerializeCollector::findOrMakeChild(
124
 
                doc,
125
 
                *diagsList,
126
 
                pointersList,
127
 
                "kdchart:diagram",
128
 
                p->metaObject()->className(),
129
 
                p,
130
 
                wasFound );
131
 
        if( ! wasFound ){
132
 
            const AbstractSerializerFactory* factory
133
 
                    = Serializer::elementSerializerFactory( p );
134
 
            if( factory ){
135
 
                factory->instance( p->metaObject()->className() )->saveElement( doc, diagElement, p );
136
 
            }else{
137
 
                qDebug() << "\nProblem: Can not store diagram:" << p->metaObject()->className();
138
 
            }
139
 
        }
140
 
    }
141
 
}
142
 
 
143
 
 
144
 
bool DiagramsSerializer::parseDiagram(
145
 
        const QDomNode& rootNode,
146
 
        const QDomNode& pointerNode,
147
 
        AbstractDiagram*& diagramPtr )const
148
 
{
149
 
    bool bOK = true;
150
 
    diagramPtr=0;
151
 
 
152
 
    QObject* ptr;
153
 
    QString ptrName;
154
 
    bool wasParsed;
155
 
    const bool pointerFound =
156
 
            AttributesSerializer::parseQObjectPointerNode(
157
 
                    pointerNode, ptr,
158
 
                    ptrName, wasParsed, true ) && ptr;
159
 
 
160
 
    if( ptrName.isEmpty() ){
161
 
        qDebug()<< "Could not parse diagram. Global pointer node is invalid.";
162
 
        bOK = false;
163
 
    }else{
164
 
        if( pointerFound ){
165
 
            diagramPtr = dynamic_cast<AbstractDiagram*>(ptr);
166
 
            if( ! diagramPtr ){
167
 
                qDebug()<< "Could not parse diagram. Global pointer"
168
 
                        << ptrName << "is no AbstractDiagram-ptr.";
169
 
                bOK = false;
170
 
            }
171
 
        }else{
172
 
            qDebug()<< "Could not parse diagram. Global pointer"
173
 
                << ptrName << "is no AbstractDiagram-ptr.";
174
 
            bOK = false;
175
 
        }
176
 
    }
177
 
 
178
 
 
179
 
    if( bOK && wasParsed ) return true;
180
 
 
181
 
 
182
 
    QDomElement container;
183
 
    if( bOK ){
184
 
        container = SerializeCollector::findStoredGlobalElement(
185
 
                rootNode, ptrName, "kdchart:diagrams" );
186
 
        bOK = ! container.tagName().isEmpty();
187
 
    }
188
 
 
189
 
    if( bOK ) {
190
 
        SerializeCollector::instance()->setWasParsed( diagramPtr, true );
191
 
 
192
 
        const AbstractSerializerFactory* const f = Serializer::elementSerializerFactory( diagramPtr );
193
 
 
194
 
        ptr = diagramPtr;
195
 
        bOK = f->instance( diagramPtr->metaObject()->className() )->parseElement( container, ptr );
196
 
    }
197
 
    return bOK;
198
 
}
199
 
 
200
 
bool DiagramsSerializer::Private::doParseDiagram(
201
 
        const QDomElement& container,
202
 
        AbstractDiagram*& diagramPtr )const
203
 
{
204
 
    bool result = false;
205
 
 
206
 
    LineDiagram*  lineDiag  = qobject_cast< LineDiagram* >(  diagramPtr );
207
 
    BarDiagram*   barDiag   = qobject_cast< BarDiagram* >(   diagramPtr );
208
 
    PieDiagram*   pieDiag   = qobject_cast< PieDiagram* >(   diagramPtr );
209
 
    PolarDiagram* polarDiag = qobject_cast< PolarDiagram* >( diagramPtr );
210
 
    RingDiagram*  ringDiag  = qobject_cast< RingDiagram* >(  diagramPtr );
211
 
    Plotter*      plotDiag  = qobject_cast< Plotter* >(      diagramPtr );
212
 
 
213
 
    if( lineDiag )
214
 
        result = parseLineDiagram(  container, *lineDiag );
215
 
    else if( barDiag )
216
 
        result = parseBarDiagram(   container,  *barDiag );
217
 
    else if( pieDiag )
218
 
        result = parsePieDiagram(   container, *pieDiag );
219
 
    else if( polarDiag )
220
 
        result = parsePolarDiagram( container, *polarDiag );
221
 
    else if( ringDiag )
222
 
        result = parseRingDiagram(  container, *ringDiag );
223
 
    else if( plotDiag )
224
 
        result = parsePlotter( container, *plotDiag );
225
 
 
226
 
    return result;
227
 
}
228
 
 
229
 
void DiagramsSerializer::saveElement( QDomDocument& doc, QDomElement& e, const QObject* obj ) const
230
 
{
231
 
    d->saveDiagram( doc, e, qobject_cast< const AbstractDiagram* >( obj ) );
232
 
}
233
 
 
234
 
bool DiagramsSerializer::parseElement( const QDomElement& container, QObject* ptr ) const
235
 
{
236
 
    AbstractDiagram* diag = qobject_cast< AbstractDiagram* >( ptr );
237
 
    return d->doParseDiagram( container, diag );
238
 
}
239
 
 
240
 
void DiagramsSerializer::Private::saveDiagram(
241
 
        QDomDocument& doc,
242
 
        QDomElement& e,
243
 
        const AbstractDiagram* p )const
244
 
{
245
 
    if( p == 0 )
246
 
        return;
247
 
 
248
 
    const LineDiagram*  lineDiag  = dynamic_cast<const LineDiagram*> (  p );
249
 
    const BarDiagram*   barDiag   = dynamic_cast<const BarDiagram*> (   p );
250
 
    const PieDiagram*   pieDiag   = dynamic_cast<const PieDiagram*> (   p );
251
 
    const PolarDiagram* polarDiag = dynamic_cast<const PolarDiagram*> ( p );
252
 
    const RingDiagram*  ringDiag  = dynamic_cast<const RingDiagram*> (  p );
253
 
 
254
 
    if( lineDiag )
255
 
        saveLineDiagram( doc, e, *lineDiag );
256
 
    else if( barDiag )
257
 
        saveBarDiagram( doc, e, *barDiag );
258
 
    else if( pieDiag )
259
 
        savePieDiagram( doc, e, *pieDiag );
260
 
    else if( polarDiag )
261
 
        savePolarDiagram( doc, e, *polarDiag );
262
 
    else if( ringDiag )
263
 
        saveRingDiagram( doc, e, *ringDiag );
264
 
}
265
 
 
266
 
bool DiagramsSerializer::Private::parseAbstractDiagram(
267
 
        const QDomElement& container, AbstractDiagram& diagram )const
268
 
{
269
 
    bool bOK = true;
270
 
    QDomNode node;
271
 
 
272
 
    //TODO(khz): Find a way to serialize the Model data!
273
 
    //
274
 
    // pass #1: assign the data model to the diagram
275
 
    //
276
 
    // This will be done to set the correct model first, so that
277
 
    // setting a RootIndex will use the right model then.
278
 
    /*
279
 
    node = container.firstChild();
280
 
    while( !node.isNull() ) {
281
 
        QDomElement element = node.toElement();
282
 
        if( !element.isNull() ) { // was really an element
283
 
            QString tagName = element.tagName();
284
 
            if( tagName == "Model" ) {
285
 
                QDomNode node2 = element.firstChild();
286
 
                if( ! node2.isNull() ) {
287
 
                    QDomElement ele2 = node2.toElement();
288
 
                    if( ! ele2.isNull() ) { // was really an element
289
 
                        QObject* ptr;
290
 
                        if( AttributesSerializer::parseQObjectPointerNode( ele2, ptr ) ){
291
 
                            QAbstractItemModel *model = dynamic_cast<QAbstractItemModel*>(ptr);
292
 
                            if( model ){
293
 
                                diagram.setModel( model );
294
 
                            }else{
295
 
                                qDebug()<< "Could not parse AbstractDiagram. Global pointer"
296
 
                                        << ele2.tagName() << "is not a KDChart::QAbstractItemModel-ptr.";
297
 
                                bOK = false;
298
 
                            }
299
 
                        }
300
 
                    }
301
 
                }
302
 
            }
303
 
        }
304
 
        node = node.nextSibling();
305
 
    }
306
 
    if( ! bOK ) return false;
307
 
    */
308
 
 
309
 
 
310
 
    // pass #2: retrieve all of the other settings, assuming that
311
 
    //          the data model has been set correctly to the diagram
312
 
    //
313
 
    // note: ATM pass #1 just is not done, so we can not set any RootIndex yet
314
 
    //       (khz, 2007 April 12)
315
 
    //
316
 
    node = container.firstChild();
317
 
    while( !node.isNull() ) {
318
 
        QDomElement element = node.toElement();
319
 
        if( !element.isNull() ) { // was really an element
320
 
            QString tagName = element.tagName();
321
 
            if( tagName == "AttributesModel" ) {
322
 
                QDomNode node2 = element.firstChild();
323
 
                if( ! node2.isNull() ) {
324
 
                    QDomElement ele2 = node2.toElement();
325
 
                    if( ! ele2.isNull() ) { // was really an element
326
 
                        AttributesModel* model=0;
327
 
                        QObject* ptr;
328
 
                        QString ptrName;
329
 
                        bool wasParsed;
330
 
                        const bool isExternalModel =
331
 
                                AttributesSerializer::parseQObjectPointerNode(
332
 
                                        ele2, ptr,
333
 
                                        ptrName, wasParsed, false ) && ptr;
334
 
                        if( ptrName.isEmpty() ){
335
 
                            qDebug()<< "Could not parse AbstractDiagram. Global pointer node"
336
 
                                    << ele2.tagName() << "is invalid.";
337
 
                            bOK = false;
338
 
                        }else{
339
 
                            if( isExternalModel ){
340
 
                                model = dynamic_cast<AttributesModel*>(ptr);
341
 
                                if( ! model ){
342
 
                                    qDebug()<< "Could not parse AbstractDiagram. Global pointer"
343
 
                                            << ptrName << "is no AttributesModel-ptr.";
344
 
                                    bOK = false;
345
 
                                }
346
 
                            }else{
347
 
                                // If no external model stored
348
 
                                // use the built-in attributes-model
349
 
                                model = diagram.attributesModel();
350
 
                            }
351
 
                        }
352
 
 
353
 
                        if( bOK && ! wasParsed ){
354
 
                            SerializeCollector::instance()->setWasParsed( model, true );
355
 
 
356
 
                            bOK = m_attrModelS->parseAttributesModel(
357
 
                                    container.ownerDocument().firstChild(),
358
 
                                    ptrName, *model );
359
 
                        }
360
 
 
361
 
                        if( bOK ){
362
 
                            if( isExternalModel )
363
 
                                diagram.setAttributesModel( model );
364
 
                            else
365
 
                                diagram.attributesModel()->initFrom( model );
366
 
                        }else{
367
 
                            qDebug()<< "Could not parse AbstractDiagram / AttributesModel"
368
 
                                    << ptrName;
369
 
                            bOK = false;
370
 
                        }
371
 
                    }else{
372
 
                        qDebug()<< "Could not parse AbstractDiagram. Node does not contain a valid element.";
373
 
                        bOK = false;
374
 
                    }
375
 
                }else{
376
 
                    qDebug()<< "Could not parse AbstractDiagram. Node does not contain a valid element.";
377
 
                    bOK = false;
378
 
                }
379
 
            } else if( tagName == "RootIndex" ) {
380
 
                bool isValid;
381
 
                int column, row;
382
 
                if( KDXML::readModelIndexNode( element, isValid, column, row ) &&
383
 
                    isValid &&
384
 
                    (column || row) )
385
 
                {
386
 
                    qDebug()<< "RootIndex(" << column << "," << row << ") was stored for AbstractDiagram in\n    "
387
 
                        << AttributesSerializer::showDomPath( container.parentNode().parentNode().toElement() ) << "\n"
388
 
                        "      Make sure to adjust it via setRootIndex() after you have called setModel().";
389
 
                }
390
 
            } else if( tagName == "CoodinatePlane" ) {
391
 
                AbstractCoordinatePlane* plane;
392
 
                if( m_coordS->parsePlane( container.ownerDocument().firstChild(), element.firstChild(), plane ) ){
393
 
                    diagram.setCoordinatePlane( plane );
394
 
                }else{
395
 
                    // We do *not* report an error, since this is no bug:
396
 
                    // The coordinate plane will be set when the diagram is added to the plane.
397
 
                    // qDebug()<< "Could not parse AbstractDiagram / CoodinatePlane. Global pointer is not a KDChart::AbstractCoordinatePlane-ptr.";
398
 
                    // bOK = false;
399
 
                }
400
 
            } else if( tagName == "AllowOverlappingDataValueTexts" ) {
401
 
                bool b;
402
 
                if( KDXML::readBoolNode( element, b ) ){
403
 
                    diagram.setAllowOverlappingDataValueTexts( b );
404
 
                }else{
405
 
                    qDebug()<< "Could not parse AbstractDiagram. Element"
406
 
                            << tagName << "has invalid content.";
407
 
                }
408
 
            } else if( tagName == "AntiAliasing" ) {
409
 
                bool b;
410
 
                if( KDXML::readBoolNode( element, b ) ){
411
 
                    diagram.setAntiAliasing( b );
412
 
                }else{
413
 
                    qDebug()<< "Could not parse AbstractDiagram. Element"
414
 
                            << tagName << "has invalid content.";
415
 
                }
416
 
            } else if( tagName == "PercentMode" ) {
417
 
                bool b;
418
 
                if( KDXML::readBoolNode( element, b ) ){
419
 
                    diagram.setPercentMode( b );
420
 
                }else{
421
 
                    qDebug()<< "Could not parse AbstractDiagram. Element"
422
 
                            << tagName << "has invalid content.";
423
 
                }
424
 
            } else if( tagName == "DatasetDimension" ) {
425
 
                int i;
426
 
                if( KDXML::readIntNode( element, i ) ){
427
 
                    diagram.setDatasetDimension( i );
428
 
                }else{
429
 
                    qDebug()<< "Could not parse AbstractDiagram. Element"
430
 
                            << tagName << "has invalid content.";
431
 
                }
432
 
            } else if ( tagName == TagNameQtProperties ) {
433
 
                // now parse parent class properties:
434
 
                if ( ! parseQtProperties( container, diagram ) ) {
435
 
                    qDebug() << "Could not parse base class Qt properties. Element"
436
 
                             << tagName << "has invalid content.";
437
 
                    bOK = false;
438
 
                }
439
 
            } else {
440
 
                qDebug() << "Unknown subelement of AbstractDiagram found:" << tagName;
441
 
                bOK = false;
442
 
            }
443
 
        }
444
 
        node = node.nextSibling();
445
 
    }
446
 
    return bOK;
447
 
}
448
 
 
449
 
void DiagramsSerializer::Private::saveAbstractDiagram(
450
 
        QDomDocument& doc,
451
 
        QDomElement& e,
452
 
        const AbstractDiagram& diagram,
453
 
        const QString& title )const
454
 
{
455
 
    QDomElement diagElement =
456
 
        doc.createElement( title );
457
 
    e.appendChild( diagElement );
458
 
 
459
 
    // save the attributes model
460
 
    m_attrModelS->saveAttributesModel(
461
 
        doc,
462
 
        diagElement,
463
 
        diagram.attributesModel(),
464
 
        diagram.usesExternalAttributesModel() );
465
 
 
466
 
    // save the root index
467
 
    if( diagram.rootIndex().isValid() &&
468
 
        (diagram.rootIndex().column() || diagram.rootIndex().row()) )
469
 
        KDXML::createModelIndexNode( doc, diagElement, "RootIndex",
470
 
                                     diagram.rootIndex() );
471
 
 
472
 
    // save the pointer to the associated coordinate plane,
473
 
    // and save the plane in the global structure if not there yet
474
 
    const CartesianCoordinatePlane* coordPlane =
475
 
            static_cast<const CartesianCoordinatePlane*>( diagram.coordinatePlane() );
476
 
    if( coordPlane && m_coordS ){
477
 
        QDomElement coordPlanePtrElement =
478
 
                doc.createElement( "CoodinatePlane" );
479
 
        diagElement.appendChild( coordPlanePtrElement );
480
 
        // access (or append, resp.) the global list
481
 
        QDomElement* planesList = SerializeCollector::instance()->findOrMakeElement( doc, m_coordS->globalList() );
482
 
 
483
 
        bool wasFound;
484
 
        QDomElement globalListElement =
485
 
                SerializeCollector::findOrMakeChild(
486
 
                doc,
487
 
                *planesList,
488
 
                coordPlanePtrElement,
489
 
                "kdchart:coordinate-plane",
490
 
                coordPlane->metaObject()->className(),
491
 
                coordPlane,
492
 
                wasFound );
493
 
        if( ! wasFound ){
494
 
            // Since the diagram is stored in the global structure anyway,
495
 
            // it is save to store it right now.
496
 
            // So it will not be forgotten, in case it is not embedded in any
497
 
            // of the coordinate planes.
498
 
            // The wasFound test makes sure it will not be stored twice.
499
 
            const AbstractSerializerFactory* factory = Serializer::elementSerializerFactory( coordPlane );
500
 
            const QObject* const obj = coordPlane;
501
 
            if( factory != 0 )
502
 
                factory->instance( coordPlane->metaObject()->className() )->saveElement( doc, globalListElement, obj );
503
 
        }
504
 
    }
505
 
 
506
 
    KDXML::createBoolNode( doc, diagElement, "AllowOverlappingDataValueTexts",
507
 
                           diagram.allowOverlappingDataValueTexts() );
508
 
    KDXML::createBoolNode( doc, diagElement, "AntiAliasing",
509
 
                           diagram.antiAliasing() );
510
 
    KDXML::createBoolNode( doc, diagElement, "PercentMode",
511
 
                           diagram.percentMode() );
512
 
    KDXML::createIntNode( doc, diagElement, "DatasetDimension",
513
 
                          diagram.datasetDimension() );
514
 
    // serialize Qt properties inherited from superclasses:
515
 
    saveQtProperties( doc, diagElement, diagram );
516
 
}
517
 
 
518
 
 
519
 
bool DiagramsSerializer::Private::parseCartCoordDiagram(
520
 
        const QDomElement& container, AbstractCartesianDiagram& diagram )const
521
 
{
522
 
    bool bOK = true;
523
 
    AbstractCartesianDiagram *refDiag=0;
524
 
    QPointF refDiagOffset(0.0, 0.0);
525
 
    QDomNode node = container.firstChild();
526
 
    while( !node.isNull() ) {
527
 
        QDomElement element = node.toElement();
528
 
        if( !element.isNull() ) { // was really an element
529
 
            QString tagName = element.tagName();
530
 
            if( tagName == "kdchart:abstract-diagram" ) {
531
 
                if( ! parseAbstractDiagram( element, diagram ) ){
532
 
                    qDebug() << "Could not parse base class of AbstractCartesianDiagram.";
533
 
                    bOK = false;
534
 
                }
535
 
            } else if( tagName == "kdchart:axes:pointers" ) {
536
 
                QDomNode node2 = element.firstChild();
537
 
                while( ! node2.isNull() ) {
538
 
                    AbstractAxis *axis;
539
 
                    if( m_axesS->parseAxis( container.ownerDocument().firstChild(), node2, axis )
540
 
                        && qobject_cast< CartesianAxis * >(axis) )
541
 
                    {
542
 
                        diagram.addAxis( qobject_cast< CartesianAxis * >(axis) );
543
 
                    }else{
544
 
                        qDebug()<< "Could not parse element of AbstractCartesianDiagram / kdchart:axes:pointers.";
545
 
                        bOK = false;
546
 
                    }
547
 
                    node2 = node2.nextSibling();
548
 
                }
549
 
            } else if( tagName == "ReferenceDiagram" ) {
550
 
                AbstractDiagram* diag;
551
 
                refDiag = 0;
552
 
                if( q->parseDiagram( container.ownerDocument().firstChild(), element.firstChild(), diag ) )
553
 
                    refDiag = dynamic_cast<AbstractCartesianDiagram *>(diag);
554
 
                if( ! refDiag ){
555
 
                    qDebug()<< "Could not parse AbstractCartesianDiagram. Reference-diagram of"
556
 
                            << container.tagName() << "is not a KDChart::AbstractCartesianDiagram-ptr.";
557
 
                    bOK = false;
558
 
                }
559
 
            } else if( tagName == "Offset" ) {
560
 
                QPointF pt;
561
 
                if( KDXML::readPointFNode( element, pt ) ){
562
 
                    refDiagOffset = pt;
563
 
                }else{
564
 
                    qDebug()<< "Could not parse AbstractCartesianDiagram. Element \"Offset\" is not a QPointF node.";
565
 
                }
566
 
            } else {
567
 
                qDebug() << "Unknown subelement of AbstractCartesianDiagram found:" << tagName;
568
 
                bOK = false;
569
 
            }
570
 
        }
571
 
        node = node.nextSibling();
572
 
    }
573
 
    if( refDiag )
574
 
        diagram.setReferenceDiagram( refDiag, refDiagOffset );
575
 
    return bOK;
576
 
}
577
 
 
578
 
void DiagramsSerializer::Private::saveCartCoordDiagram(
579
 
        QDomDocument& doc,
580
 
        QDomElement& e,
581
 
        const AbstractCartesianDiagram& diagram,
582
 
        const QString& title )const
583
 
{
584
 
    QDomElement diagElement =
585
 
        doc.createElement( title );
586
 
    e.appendChild( diagElement );
587
 
 
588
 
    // first save the information hold by the base class
589
 
    saveAbstractDiagram( doc, diagElement, diagram,
590
 
                         "kdchart:abstract-diagram" );
591
 
 
592
 
    // then save what is stored in the derived class
593
 
 
594
 
    // save the axes
595
 
    QList< const AbstractAxis* > abstractAxes;
596
 
    CartesianAxisList axes = diagram.axes();
597
 
    Q_FOREACH( const AbstractAxis* ax, axes )
598
 
        abstractAxes << ax;
599
 
    m_axesS->saveAxes( doc, diagElement, abstractAxes, "kdchart:axes" );
600
 
 
601
 
    // save the reference diagram(-pointer) and the respective offset, if any
602
 
    const AbstractCartesianDiagram* refDiag = diagram.referenceDiagram();
603
 
    if( refDiag ){
604
 
        QDomElement refDiagPtrElement =
605
 
                doc.createElement( "ReferenceDiagram" );
606
 
        diagElement.appendChild( refDiagPtrElement );
607
 
        // access (or append, resp.) the global list
608
 
        QDomElement* diagsList = SerializeCollector::instance()->findOrMakeElement( doc, m_globalList );
609
 
 
610
 
        bool wasFound;
611
 
        QDomElement globalListElement =
612
 
                SerializeCollector::findOrMakeChild(
613
 
                doc,
614
 
                *diagsList,
615
 
                refDiagPtrElement,
616
 
                "kdchart:diagram",
617
 
                refDiag->metaObject()->className(),
618
 
                refDiag,
619
 
                wasFound );
620
 
        if( ! wasFound ){
621
 
            // Since the diagram is stored in the global structure anyway,
622
 
            // it is save to store it right now.
623
 
            // So it will not be forgotten, in case it is not embedded in any
624
 
            // of the coordinate planes.
625
 
            // The wasFound test makes sure it will not be stored twice.
626
 
            saveDiagram( doc, globalListElement, refDiag );
627
 
        }
628
 
        KDXML::createPointFNode(
629
 
                doc, refDiagPtrElement, "Offset", diagram.referenceDiagramOffset() );
630
 
    }
631
 
}
632
 
 
633
 
 
634
 
bool DiagramsSerializer::Private::parsePolCoordDiagram(
635
 
        const QDomElement& container, AbstractPolarDiagram& diagram )const
636
 
{
637
 
    bool bOK = true;
638
 
    QDomNode node = container.firstChild();
639
 
    while( !node.isNull() ) {
640
 
        QDomElement element = node.toElement();
641
 
        if( !element.isNull() ) { // was really an element
642
 
            QString tagName = element.tagName();
643
 
            if( tagName == "kdchart:abstract-diagram" ) {
644
 
                if( ! parseAbstractDiagram( element, diagram ) ){
645
 
                    qDebug() << "Could not parse base class of AbstractPolarDiagram.";
646
 
                    bOK = false;
647
 
                }
648
 
            } else {
649
 
                qDebug() << "Unknown subelement of AbstractPolarDiagram found:" << tagName;
650
 
                bOK = false;
651
 
            }
652
 
        }
653
 
        node = node.nextSibling();
654
 
    }
655
 
    return bOK;
656
 
}
657
 
 
658
 
void DiagramsSerializer::Private::savePolCoordDiagram(
659
 
        QDomDocument& doc,
660
 
        QDomElement& e,
661
 
        const AbstractPolarDiagram& diagram,
662
 
        const QString& title )const
663
 
{
664
 
    QDomElement diagElement =
665
 
            doc.createElement( title );
666
 
    e.appendChild( diagElement );
667
 
 
668
 
    // first save the information hold by the base class
669
 
    saveAbstractDiagram( doc, diagElement, diagram,
670
 
                         "kdchart:abstract-diagram" );
671
 
    // that's all, there is no to-be-saved information in this class
672
 
}
673
 
 
674
 
 
675
 
bool DiagramsSerializer::Private::parseLineDiagram(
676
 
        const QDomElement& container, LineDiagram& diagram )const
677
 
{
678
 
    //qDebug() << "-------->" << container.tagName();
679
 
 
680
 
    bool bOK = true;
681
 
    if( !container.isNull() ) {
682
 
        //qDebug() << "\n    DiagramsSerializer::parseLineDiagram() processing" << diagName;
683
 
        QDomNode node = container.firstChild();
684
 
        while( !node.isNull() ) {
685
 
            QDomElement element = node.toElement();
686
 
            if( !element.isNull() ) { // was really an element
687
 
                QString tagName = element.tagName();
688
 
                if( tagName == "kdchart:cartesian-coordinate-diagram" ) {
689
 
                    if( ! parseCartCoordDiagram( element, diagram ) ){
690
 
                        qDebug() << "Could not parse base class of LineDiagram.";
691
 
                        bOK = false;
692
 
                    }
693
 
                } else if( tagName == "LineType" ) {
694
 
                    QString s;
695
 
                    if( KDXML::readStringNode( element, s ) ){
696
 
                        if( s.compare("Normal", Qt::CaseInsensitive) == 0 )
697
 
                            diagram.setType( LineDiagram::Normal );
698
 
                        else if( s.compare("Stacked", Qt::CaseInsensitive) == 0 )
699
 
                            diagram.setType( LineDiagram::Stacked );
700
 
                        else if( s.compare("Percent", Qt::CaseInsensitive) == 0 )
701
 
                            diagram.setType( LineDiagram::Percent );
702
 
                        else{
703
 
                            bOK = false;
704
 
                            Q_ASSERT( false ); // all of the types need to be handled
705
 
                        }
706
 
                    }
707
 
                    else
708
 
                        bOK = false;
709
 
                } else {
710
 
                    qDebug() << "Unknown subelement of LineDiagram found:" << tagName;
711
 
                    bOK = false;
712
 
                }
713
 
            }
714
 
            node = node.nextSibling();
715
 
        }
716
 
    }
717
 
    return bOK;
718
 
}
719
 
 
720
 
void DiagramsSerializer::Private::saveLineDiagram(
721
 
        QDomDocument& doc,
722
 
        QDomElement& diagElement,
723
 
        const LineDiagram& diagram )const
724
 
{
725
 
    // first save the information hold by the base class
726
 
    saveCartCoordDiagram( doc, diagElement, diagram,
727
 
                          "kdchart:cartesian-coordinate-diagram" );
728
 
    // then save what is stored in the derived class
729
 
    QString s;
730
 
    switch( diagram.type() ){
731
 
        case LineDiagram::Normal:
732
 
                s = "Normal";
733
 
                break;
734
 
        case LineDiagram::Stacked:
735
 
                s = "Stacked";
736
 
                break;
737
 
        case LineDiagram::Percent:
738
 
                s = "Percent";
739
 
                break;
740
 
        default:
741
 
            Q_ASSERT( false ); // all of the types need to be handled
742
 
            break;
743
 
    }
744
 
    KDXML::createStringNode( doc, diagElement, "LineType", s );
745
 
}
746
 
 
747
 
bool DiagramsSerializer::Private::parsePlotter(
748
 
        const QDomElement& container, Plotter& diagram )const
749
 
{
750
 
    //qDebug() << "-------->" << container.tagName();
751
 
 
752
 
    bool bOK = true;
753
 
    if( !container.isNull() ) {
754
 
        //qDebug() << "\n    DiagramsSerializer::parsePlotter() processing" << diagName;
755
 
        QDomNode node = container.firstChild();
756
 
        while( !node.isNull() ) {
757
 
            QDomElement element = node.toElement();
758
 
            if( !element.isNull() ) { // was really an element
759
 
                QString tagName = element.tagName();
760
 
                if( tagName == "kdchart:cartesian-coordinate-diagram" ) {
761
 
                    if( ! parseCartCoordDiagram( element, diagram ) ){
762
 
                        qDebug() << "Could not parse base class of Platter.";
763
 
                        bOK = false;
764
 
                    }
765
 
                } else if( tagName == "PlotType" ) {
766
 
                    QString s;
767
 
                    if( KDXML::readStringNode( element, s ) ){
768
 
                        if( s.compare("Normal", Qt::CaseInsensitive) == 0 )
769
 
                            diagram.setType( Plotter::Normal );
770
 
                        else{
771
 
                            bOK = false;
772
 
                            Q_ASSERT( false ); // all of the types need to be handled
773
 
                        }
774
 
                    }
775
 
                    else
776
 
                        bOK = false;
777
 
                } else {
778
 
                    qDebug() << "Unknown subelement of Plotter found:" << tagName;
779
 
                    bOK = false;
780
 
                }
781
 
            }
782
 
            node = node.nextSibling();
783
 
        }
784
 
    }
785
 
    return bOK;
786
 
}
787
 
 
788
 
void DiagramsSerializer::Private::savePlotter(
789
 
        QDomDocument& doc,
790
 
        QDomElement& diagElement,
791
 
        const Plotter& diagram )const
792
 
{
793
 
    // first save the information hold by the base class
794
 
    saveCartCoordDiagram( doc, diagElement, diagram,
795
 
                          "kdchart:cartesian-coordinate-diagram" );
796
 
    // then save what is stored in the derived class
797
 
    QString s;
798
 
    switch( diagram.type() ){
799
 
        case Plotter::Normal:
800
 
                s = "Normal";
801
 
                break;
802
 
        default:
803
 
            Q_ASSERT( false ); // all of the types need to be handled
804
 
            break;
805
 
    }
806
 
    KDXML::createStringNode( doc, diagElement, "PlotType", s );
807
 
}
808
 
 
809
 
bool DiagramsSerializer::Private::parseBarDiagram(
810
 
        const QDomElement& container, BarDiagram& diagram )const
811
 
{
812
 
    bool bOK = true;
813
 
    if( !container.isNull() ) {
814
 
        //qDebug() << "\n    DiagramsSerializer::parseBarDiagram() processing" << diagName;
815
 
        QDomNode node = container.firstChild();
816
 
        while( !node.isNull() ) {
817
 
            QDomElement element = node.toElement();
818
 
            if( !element.isNull() ) { // was really an element
819
 
                QString tagName = element.tagName();
820
 
                if( tagName == "kdchart:cartesian-coordinate-diagram" ) {
821
 
                    if( ! parseCartCoordDiagram( element, diagram ) ){
822
 
                        qDebug() << "Could not parse base class of BarDiagram.";
823
 
                        bOK = false;
824
 
                    }
825
 
                } else if( tagName == "BarType" ) {
826
 
                    QString s;
827
 
                    if( KDXML::readStringNode( element, s ) ){
828
 
                        if( s.compare("Normal", Qt::CaseInsensitive) == 0 )
829
 
                            diagram.setType( BarDiagram::Normal );
830
 
                        else if( s.compare("Stacked", Qt::CaseInsensitive) == 0 )
831
 
                            diagram.setType( BarDiagram::Stacked );
832
 
                        else if( s.compare("Percent", Qt::CaseInsensitive) == 0 )
833
 
                            diagram.setType( BarDiagram::Percent );
834
 
                        else if( s.compare("Rows", Qt::CaseInsensitive) == 0 )
835
 
                            diagram.setType( BarDiagram::Rows );
836
 
                        else{
837
 
                            bOK = false;
838
 
                            Q_ASSERT( false ); // all of the types need to be handled
839
 
                        }
840
 
                    }
841
 
                    else
842
 
                        bOK = false;
843
 
                } else {
844
 
                    qDebug() << "Unknown subelement of BarDiagram found:" << tagName;
845
 
                    bOK = false;
846
 
                }
847
 
            }
848
 
            node = node.nextSibling();
849
 
        }
850
 
    }
851
 
    return bOK;
852
 
}
853
 
 
854
 
void DiagramsSerializer::Private::saveBarDiagram(
855
 
        QDomDocument& doc,
856
 
        QDomElement& diagElement,
857
 
        const BarDiagram& diagram )const
858
 
{
859
 
    // first save the information hold by the base class
860
 
    saveCartCoordDiagram( doc, diagElement, diagram,
861
 
                          "kdchart:cartesian-coordinate-diagram" );
862
 
 
863
 
    // then save what is stored in the derived class
864
 
    QString s;
865
 
    switch( diagram.type() )
866
 
    {
867
 
    case BarDiagram::Normal:
868
 
        s = "Normal";
869
 
        break;
870
 
    case BarDiagram::Stacked:
871
 
        s = "Stacked";
872
 
        break;
873
 
    case BarDiagram::Percent:
874
 
        s = "Percent";
875
 
        break;
876
 
    case BarDiagram::Rows:
877
 
        s = "Rows";
878
 
        break;
879
 
    default:
880
 
        Q_ASSERT( false ); // all of the types need to be handled
881
 
        break;
882
 
    }
883
 
    KDXML::createStringNode( doc, diagElement, "BarType", s );
884
 
}
885
 
 
886
 
 
887
 
bool DiagramsSerializer::Private::parseAbstractPieDiagram(
888
 
        const QDomElement& container, AbstractPieDiagram& diagram )const
889
 
{
890
 
    bool bOK = true;
891
 
    QDomNode node = container.firstChild();
892
 
    while( !node.isNull() ) {
893
 
        QDomElement element = node.toElement();
894
 
        if( !element.isNull() ) { // was really an element
895
 
            QString tagName = element.tagName();
896
 
            if( tagName == "kdchart:polar-coordinate-diagram" ) {
897
 
                if( ! parsePolCoordDiagram( element, diagram ) ){
898
 
                    qDebug() << "Could not parse base class of AbstractPieDiagram.";
899
 
                    bOK = false;
900
 
                }
901
 
            } else if( tagName == "Granularity" ) {
902
 
                qreal r;
903
 
                if( KDXML::readRealNode( element, r ) ){
904
 
                    diagram.setGranularity( r );
905
 
                }else{
906
 
                    qDebug()<< "Could not parse AbstractPieDiagram. Element"
907
 
                            << tagName << "has invalid content.";
908
 
                }
909
 
            } else if( tagName == "StartPosition" ) {
910
 
                // setStartPosition is deprecated!
911
 
                /*
912
 
                int i;
913
 
                if( KDXML::readIntNode( element, i ) ){
914
 
                    diagram.setStartPosition( i );
915
 
                }else{
916
 
                    qDebug()<< "Could not parse AbstractPieDiagram. Element"
917
 
                            << tagName << "has invalid content.";
918
 
                }
919
 
                */
920
 
            } else {
921
 
                qDebug() << "Unknown subelement of AbstractPieDiagram found:" << tagName;
922
 
                bOK = false;
923
 
            }
924
 
        }
925
 
        node = node.nextSibling();
926
 
    }
927
 
    return bOK;
928
 
}
929
 
 
930
 
void DiagramsSerializer::Private::saveAbstractPieDiagram(
931
 
        QDomDocument& doc,
932
 
        QDomElement& e,
933
 
        const AbstractPieDiagram& diagram,
934
 
        const QString& title )const
935
 
{
936
 
    QDomElement diagElement =
937
 
            doc.createElement( title );
938
 
    e.appendChild( diagElement );
939
 
 
940
 
    // first save the information hold by the base class
941
 
    savePolCoordDiagram( doc, diagElement, diagram,
942
 
                         "kdchart:polar-coordinate-diagram" );
943
 
 
944
 
    // then save what is stored in the derived class
945
 
    KDXML::createRealNode( doc, diagElement, "Granularity",   diagram.granularity() );
946
 
    // setStartPosition is deprecated!
947
 
    //KDXML::createIntNode(  doc, diagElement, "StartPosition", diagram.startPosition() );
948
 
}
949
 
 
950
 
 
951
 
bool DiagramsSerializer::Private::parsePieDiagram(
952
 
        const QDomElement& container, PieDiagram& diagram )const
953
 
{
954
 
    bool bOK = true;
955
 
    if( !container.isNull() ) {
956
 
        //qDebug() << "\n    DiagramsSerializer::parsePieDiagram() processing" << diagName;
957
 
        QDomNode node = container.firstChild();
958
 
        while( !node.isNull() ) {
959
 
            QDomElement element = node.toElement();
960
 
            if( !element.isNull() ) { // was really an element
961
 
                QString tagName = element.tagName();
962
 
                if( tagName == "kdchart:abstract-pie-diagram" ) {
963
 
                    if( ! parseAbstractPieDiagram( element, diagram ) ){
964
 
                        qDebug() << "Could not parse base class of PieDiagram.";
965
 
                        bOK = false;
966
 
                    }
967
 
                } else {
968
 
                    qDebug() << "Unknown subelement of PieDiagram found:" << tagName;
969
 
                    bOK = false;
970
 
                }
971
 
            }
972
 
            node = node.nextSibling();
973
 
        }
974
 
    }
975
 
    return bOK;
976
 
}
977
 
 
978
 
void DiagramsSerializer::Private::savePieDiagram(
979
 
        QDomDocument& doc,
980
 
        QDomElement& diagElement,
981
 
        const PieDiagram& diagram )const
982
 
{
983
 
    // first save the information hold by the base class
984
 
    saveAbstractPieDiagram( doc, diagElement, diagram,
985
 
                            "kdchart:abstract-pie-diagram" );
986
 
    // that's all, there is no to-be-saved information in this class
987
 
}
988
 
 
989
 
 
990
 
bool DiagramsSerializer::Private::parsePolarDiagram(
991
 
        const QDomElement& container, PolarDiagram& diagram )const
992
 
{
993
 
    bool bOK = true;
994
 
    if( !container.isNull() ) {
995
 
        //qDebug() << "\n    DiagramsSerializer::parsePolarDiagram() processing" << diagName;
996
 
        QDomNode node = container.firstChild();
997
 
        while( !node.isNull() ) {
998
 
            QDomElement element = node.toElement();
999
 
            if( !element.isNull() ) { // was really an element
1000
 
                QString tagName = element.tagName();
1001
 
                if( tagName == "kdchart:polar-coordinate-diagram" ) {
1002
 
                    if( ! parsePolCoordDiagram( element, diagram ) ){
1003
 
                        qDebug() << "Could not parse base class of PolarDiagram.";
1004
 
                        bOK = false;
1005
 
                    }
1006
 
                } else if( tagName == "ZeroDegreePosition" ) {
1007
 
                    int i;
1008
 
                    if( KDXML::readIntNode( element, i ) ){
1009
 
                        diagram.setZeroDegreePosition( i );
1010
 
                    }else{
1011
 
                        qDebug()<< "Could not parse PolarDiagram. Element"
1012
 
                                << tagName << "has invalid content.";
1013
 
                    }
1014
 
                } else if( tagName == "RotateCircularLabels" ) {
1015
 
                    bool b;
1016
 
                    if( KDXML::readBoolNode( element, b ) ){
1017
 
                        diagram.setRotateCircularLabels( b );
1018
 
                    }else{
1019
 
                        qDebug()<< "Could not parse PolarDiagram. Element"
1020
 
                                << tagName << "has invalid content.";
1021
 
                    }
1022
 
                } else if( tagName == "CloseDatasets" ) {
1023
 
                    bool b;
1024
 
                    if( KDXML::readBoolNode( element, b ) ){
1025
 
                        diagram.setCloseDatasets( b );
1026
 
                    }else{
1027
 
                        qDebug()<< "Could not parse PolarDiagram. Element"
1028
 
                                << tagName << "has invalid content.";
1029
 
                    }
1030
 
                } else if( tagName == "ShowDelimitersAtPosition" ) {
1031
 
                    bool unknown = false;
1032
 
                    bool center = false;
1033
 
                    bool northWest = false;
1034
 
                    bool north = false;
1035
 
                    bool northEast = false;
1036
 
                    bool east = false;
1037
 
                    bool southEast = false;
1038
 
                    bool south = false;
1039
 
                    bool southWest = false;
1040
 
                    bool west = false;
1041
 
                    bool floating = false;
1042
 
                    if( KDXML::readPositionBooleansNode(
1043
 
                            element,
1044
 
                            unknown, center,
1045
 
                            northWest, north, northEast,
1046
 
                            east, southEast, south, southWest, west,
1047
 
                            floating ) )
1048
 
                    {
1049
 
                        diagram.setShowDelimitersAtPosition( Position::Unknown,  unknown );
1050
 
                        diagram.setShowDelimitersAtPosition( Position::Center,   center );
1051
 
                        diagram.setShowDelimitersAtPosition( Position::NorthWest,northWest );
1052
 
                        diagram.setShowDelimitersAtPosition( Position::North,    north );
1053
 
                        diagram.setShowDelimitersAtPosition( Position::NorthEast,northEast );
1054
 
                        diagram.setShowDelimitersAtPosition( Position::East,     east );
1055
 
                        diagram.setShowDelimitersAtPosition( Position::SouthEast,southEast );
1056
 
                        diagram.setShowDelimitersAtPosition( Position::South,    south );
1057
 
                        diagram.setShowDelimitersAtPosition( Position::SouthWest,southWest );
1058
 
                        diagram.setShowDelimitersAtPosition( Position::West,     west );
1059
 
                        diagram.setShowDelimitersAtPosition( Position::Floating, floating );
1060
 
                    }else{
1061
 
                        qDebug()<< "Could not parse PolarDiagram. Element"
1062
 
                                << tagName << "has invalid content.";
1063
 
                    }
1064
 
                } else if( tagName == "ShowLabelsAtPosition" ) {
1065
 
                    bool unknown = false;
1066
 
                    bool center = false;
1067
 
                    bool northWest = false;
1068
 
                    bool north = false;
1069
 
                    bool northEast = false;
1070
 
                    bool east = false;
1071
 
                    bool southEast = false;
1072
 
                    bool south = false;
1073
 
                    bool southWest = false;
1074
 
                    bool west = false;
1075
 
                    bool floating = false;
1076
 
                    if( KDXML::readPositionBooleansNode(
1077
 
                            element,
1078
 
                            unknown, center,
1079
 
                            northWest, north, northEast,
1080
 
                            east, southEast, south, southWest, west,
1081
 
                            floating ) )
1082
 
                    {
1083
 
                        diagram.setShowLabelsAtPosition( Position::Unknown,  unknown );
1084
 
                        diagram.setShowLabelsAtPosition( Position::Center,   center );
1085
 
                        diagram.setShowLabelsAtPosition( Position::NorthWest,northWest );
1086
 
                        diagram.setShowLabelsAtPosition( Position::North,    north );
1087
 
                        diagram.setShowLabelsAtPosition( Position::NorthEast,northEast );
1088
 
                        diagram.setShowLabelsAtPosition( Position::East,     east );
1089
 
                        diagram.setShowLabelsAtPosition( Position::SouthEast,southEast );
1090
 
                        diagram.setShowLabelsAtPosition( Position::South,    south );
1091
 
                        diagram.setShowLabelsAtPosition( Position::SouthWest,southWest );
1092
 
                        diagram.setShowLabelsAtPosition( Position::West,     west );
1093
 
                        diagram.setShowLabelsAtPosition( Position::Floating, floating );
1094
 
                    }else{
1095
 
                        qDebug()<< "Could not parse PolarDiagram. Element"
1096
 
                                << tagName << "has invalid content.";
1097
 
                    }
1098
 
                } else {
1099
 
                    qDebug() << "Unknown subelement of PolarDiagram found:" << tagName;
1100
 
                    bOK = false;
1101
 
                }
1102
 
            }
1103
 
            node = node.nextSibling();
1104
 
        }
1105
 
    }
1106
 
    return bOK;
1107
 
}
1108
 
 
1109
 
void DiagramsSerializer::Private::savePolarDiagram(
1110
 
        QDomDocument& doc,
1111
 
        QDomElement& diagElement,
1112
 
        const PolarDiagram& diagram )const
1113
 
{
1114
 
    // first save the information hold by the base class
1115
 
    savePolCoordDiagram( doc, diagElement, diagram,
1116
 
                         "kdchart:polar-coordinate-diagram" );
1117
 
 
1118
 
    // then save what is stored in the derived class
1119
 
    KDXML::createIntNode(  doc, diagElement, "ZeroDegreePosition",   diagram.zeroDegreePosition() );
1120
 
    KDXML::createBoolNode( doc, diagElement, "RotateCircularLabels", diagram.rotateCircularLabels() );
1121
 
    KDXML::createBoolNode( doc, diagElement, "CloseDatasets", diagram.closeDatasets() );
1122
 
    KDXML::createPositionBooleansNode(
1123
 
            doc, diagElement, "ShowDelimitersAtPosition",
1124
 
            diagram.showDelimitersAtPosition( Position::Unknown ),
1125
 
            diagram.showDelimitersAtPosition( Position::Center ),
1126
 
            diagram.showDelimitersAtPosition( Position::NorthWest ),
1127
 
            diagram.showDelimitersAtPosition( Position::North ),
1128
 
            diagram.showDelimitersAtPosition( Position::NorthEast ),
1129
 
            diagram.showDelimitersAtPosition( Position::East ),
1130
 
            diagram.showDelimitersAtPosition( Position::SouthEast ),
1131
 
            diagram.showDelimitersAtPosition( Position::South ),
1132
 
            diagram.showDelimitersAtPosition( Position::SouthWest ),
1133
 
            diagram.showDelimitersAtPosition( Position::West ),
1134
 
            diagram.showDelimitersAtPosition( Position::Floating ) );
1135
 
    KDXML::createPositionBooleansNode(
1136
 
            doc, diagElement, "ShowLabelsAtPosition",
1137
 
            diagram.showLabelsAtPosition( Position::Unknown ),
1138
 
            diagram.showLabelsAtPosition( Position::Center ),
1139
 
            diagram.showLabelsAtPosition( Position::NorthWest ),
1140
 
            diagram.showLabelsAtPosition( Position::North ),
1141
 
            diagram.showLabelsAtPosition( Position::NorthEast ),
1142
 
            diagram.showLabelsAtPosition( Position::East ),
1143
 
            diagram.showLabelsAtPosition( Position::SouthEast ),
1144
 
            diagram.showLabelsAtPosition( Position::South ),
1145
 
            diagram.showLabelsAtPosition( Position::SouthWest ),
1146
 
            diagram.showLabelsAtPosition( Position::West ),
1147
 
            diagram.showLabelsAtPosition( Position::Floating ) );
1148
 
}
1149
 
 
1150
 
bool DiagramsSerializer::Private::parseRingDiagram(
1151
 
        const QDomElement& container, RingDiagram& diagram )const
1152
 
{
1153
 
    bool bOK = true;
1154
 
    if( !container.isNull() ) {
1155
 
        //qDebug() << "\n    DiagramsSerializer::parseRingDiagram() processing" << diagName;
1156
 
        QDomNode node = container.firstChild();
1157
 
        while( !node.isNull() ) {
1158
 
            QDomElement element = node.toElement();
1159
 
            if( !element.isNull() ) { // was really an element
1160
 
                QString tagName = element.tagName();
1161
 
                if( tagName == "kdchart:abstract-pie-diagram" ) {
1162
 
                    if( ! parseAbstractPieDiagram( element, diagram ) ){
1163
 
                        qDebug() << "Could not parse base class of RingDiagram.";
1164
 
                        bOK = false;
1165
 
                    }
1166
 
                } else if( tagName == "RelativeThickness" ) {
1167
 
                    bool b;
1168
 
                    if( KDXML::readBoolNode( element, b ) ){
1169
 
                        diagram.setRelativeThickness( b );
1170
 
                    }else{
1171
 
                        qDebug()<< "Could not parse RingDiagram. Element"
1172
 
                                << tagName << "has invalid content.";
1173
 
                    }
1174
 
                } else {
1175
 
                    qDebug() << "Unknown subelement of RingDiagram found:" << tagName;
1176
 
                    bOK = false;
1177
 
                }
1178
 
            }
1179
 
            node = node.nextSibling();
1180
 
        }
1181
 
    }
1182
 
    return bOK;
1183
 
}
1184
 
 
1185
 
void DiagramsSerializer::Private::saveRingDiagram(
1186
 
        QDomDocument& doc,
1187
 
        QDomElement& diagElement,
1188
 
        const RingDiagram& diagram )const
1189
 
{
1190
 
    // first save the information hold by the base class
1191
 
    saveAbstractPieDiagram( doc, diagElement, diagram,
1192
 
                            "kdchart:abstract-pie-diagram" );
1193
 
 
1194
 
    // then save what is stored in the derived class
1195
 
    KDXML::createBoolNode(  doc, diagElement, "RelativeThickness",   diagram.relativeThickness() );
1196
 
}
1197
 
 
1198
 
void DiagramsSerializer::Private::saveQtProperties(
1199
 
    QDomDocument& doc,
1200
 
    QDomElement& e,
1201
 
    const AbstractDiagram& diagram ) const
1202
 
{   // this function saves all properties of a QObject that are in the
1203
 
    // white list, creating a element for the properties and one child
1204
 
    // element per property
1205
 
    static const QStringList SerializedPropertyWhiteList
1206
 
        ( QStringList() << "frameStyle" << "lineWidth" << "midLineWidth" );
1207
 
 
1208
 
    QDomElement element = doc.createElement( TagNameQtProperties );
1209
 
    e.appendChild( element );
1210
 
    for ( int i = 0; i < diagram.metaObject()->propertyCount(); ++i ) {
1211
 
        QMetaProperty p = diagram.metaObject()->property( i );
1212
 
        if ( SerializedPropertyWhiteList.contains( p.name() ) ) {
1213
 
            QVariant value = diagram.property( p.name() );
1214
 
            KDXML::createQVariantNode( doc, element, p.name(), value );
1215
 
        }
1216
 
    }
1217
 
}
1218
 
 
1219
 
bool DiagramsSerializer::Private::parseQtProperties(
1220
 
    const QDomElement& container,
1221
 
    AbstractDiagram& diagram ) const
1222
 
{
1223
 
    bool error = false;
1224
 
    QDomNodeList elements = container.elementsByTagName( "properties" );
1225
 
    if ( elements.size() != 1 ) {
1226
 
        qDebug() << "DiagramsSerializer::Private::parseQtProperties: XML syntax error, more than one properties elements";
1227
 
        error = true;
1228
 
    }
1229
 
    if ( elements.size() > 0 ) {
1230
 
        QDomElement properties = elements.at(0).toElement();
1231
 
 
1232
 
        QDomNode n = properties.firstChild();
1233
 
        while ( !n.isNull() ) {
1234
 
            QDomElement e = n.toElement();
1235
 
            if ( !e.isNull() ) {
1236
 
                QVariant value;
1237
 
                QString name;
1238
 
                if ( ! KDXML::readQVariantNode( e, value, name ) ) {
1239
 
                    qDebug() << "DiagramsSerializer::Private::parseQtProperties: error parsing property" << e.tagName();
1240
 
                    error = true;
1241
 
                } else {
1242
 
                    diagram.setProperty( qPrintable( name ), value );
1243
 
                }
1244
 
            }
1245
 
            n = n.nextSibling();
1246
 
        }
1247
 
    }
1248
 
    return ! error;
1249
 
}