diff --git a/libs/flake/KoShape.cpp b/libs/flake/KoShape.cpp index 8efe39fb83173e107eb7ff023d5d64337559b4fb..78b70fa8bb613f607c5da7d3bab169e72b816702 100644 --- a/libs/flake/KoShape.cpp +++ b/libs/flake/KoShape.cpp @@ -32,9 +32,12 @@ #include "KoShapeUserData.h" #include "KoShapeApplicationData.h" #include "KoShapeSavingContext.h" +#include "KoShapeLoadingContext.h" #include "KoViewConverter.h" +#include #include +#include #include #include @@ -648,6 +651,21 @@ QString KoShape::style( KoShapeSavingContext *context ) const return context->mainStyles().lookup( style, context->isSet( KoShapeSavingContext::PresentationShape ) ? "pr" : "gr" ); } +bool KoShape::loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingContext &context, int attributes ) +{ + if ( attributes & OdfMandatories ) { + if ( element.hasAttributeNS( KoXmlNS::draw, "layer" ) ) { + KoShapeLayer * layer = context.layer( element.attributeNS( KoXmlNS::draw, "layer" ) ); + if ( layer ) { + setParent( layer ); + } + + } + } + + return true; +} + void KoShape::saveOdfFrameAttributes(KoShapeSavingContext *context) { saveOdfAttributes(context, FrameAttributes); context->addOption(KoShapeSavingContext::FrameOpened); diff --git a/libs/flake/KoShape.h b/libs/flake/KoShape.h index c6b744da21b0d22c9df19f9ac9e7fdecadb4470b..59072f0aead84c27e7ab37a91bab66b7de9736c7 100644 --- a/libs/flake/KoShape.h +++ b/libs/flake/KoShape.h @@ -33,6 +33,8 @@ #include +#include + class QPainter; class QRectF; class QPainterPath; @@ -50,6 +52,7 @@ class KoShapeApplicationData; class KoShapeSavingContext; class KoCanvasBase; class KoGenStyle; +class KoShapeLoadingContext; /** * @@ -132,6 +135,16 @@ public: */ virtual void paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas); + /** + * Load a shape from odf + * + * @param context the KoShapeLoadingContext used for loading + * @param element element which represents the shape in odf + * + * TODO make it pure virtual + */ + virtual bool loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context ) { Q_UNUSED(element); Q_UNUSED(context); return true; } + /** * @brief store the shape data as ODF XML. * This is the method that will be called when saving a shape as a described in¬ @@ -575,6 +588,15 @@ protected: FrameAttributes = OdfMandatories | OdfSize | OdfPosition | OdfTransformation }; + /** + * This method is used during loading of the shape to load common attributes + * + * @param context the KoShapeLoadingContext used for loading + * @param element element which represents the shape in odf + * @param attributes a number of OdfAttribute items to state which attributes to load. + */ + bool loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingContext &context, int attributes ); + /** * This method can be used while saving the shape as ODF to add the data * stored on this shape to the current element. diff --git a/libs/flake/KoShapeLoadingContext.cpp b/libs/flake/KoShapeLoadingContext.cpp index ff608b5969e4ebee55488a698377be6f6bcef952..d5a4b2f4b15dfd6e2d8adf40c71f20e5a3f3eff3 100644 --- a/libs/flake/KoShapeLoadingContext.cpp +++ b/libs/flake/KoShapeLoadingContext.cpp @@ -19,7 +19,17 @@ #include "KoShapeLoadingContext.h" -KoShapeLoadingContext::KoShapeLoadingContext() +KoShapeLoadingContext::KoShapeLoadingContext( KoOasisLoadingContext & context ) +: m_context( context ) { } +KoOasisLoadingContext & KoShapeLoadingContext::koLoadingContext() +{ + return m_context; +} + +KoShapeLayer * KoShapeLoadingContext::layer( const QString & layerName ) +{ + return m_layers.value( layerName, 0 ); +} diff --git a/libs/flake/KoShapeLoadingContext.h b/libs/flake/KoShapeLoadingContext.h index 4c695cd3a62c2114c9982294df3f2eabb472ae49..ed1113b382ddd5bd2674658fc8d8fe60f019c563 100644 --- a/libs/flake/KoShapeLoadingContext.h +++ b/libs/flake/KoShapeLoadingContext.h @@ -19,14 +19,34 @@ #ifndef KOSHAPELOADINGCONTEXT_H #define KOSHAPELOADINGCONTEXT_H + +#include +#include + #include + +class KoOasisLoadingContext; +class KoShapeLayer; +class KoShape; + /** * Context passed to shapes during loading */ class FLAKE_EXPORT KoShapeLoadingContext { public: - KoShapeLoadingContext(); + KoShapeLoadingContext( KoOasisLoadingContext & context ); + + KoOasisLoadingContext & koLoadingContext(); + + KoShapeLayer * layer( const QString & layerName ); + + void addShapeId( KoShape * shape, const QString & id ); + +private: + KoOasisLoadingContext &m_context; + QMap m_layers; + QMap m_drawIds; }; #endif /* KOSHAPELOADINGCONTEXT_H */ diff --git a/libs/store/KoXmlReader.h b/libs/store/KoXmlReader.h index 50b3133d9bc45c14b1d55f0d65af07c43aedef59..97ea7c6e784776da03c1bdc1768f138e3ba3e17c 100644 --- a/libs/store/KoXmlReader.h +++ b/libs/store/KoXmlReader.h @@ -33,12 +33,12 @@ class QTextDecoder; #ifdef KOXML_USE_QDOM -#define KoXmlNode QDomNode -#define KoXmlElement QDomElement -#define KoXmlText QDomText -#define KoXmlCDATASection QDomCDATASection -#define KoXmlDocumentType QDomDocumentType -#define KoXmlDocument QDomDocument +typedef QDomNode KoXmlNode; +typedef QDomElement KoXmlElement; +typedef QDomText KoXmlText; +typedef QDomCDATASection KoXmlCDATASection; +typedef QDomDocumentType KoXmlDocumentType; +typedef QDomDocument KoXmlDocument; #else diff --git a/libs/store/KoXmlReaderForward.h b/libs/store/KoXmlReaderForward.h new file mode 100644 index 0000000000000000000000000000000000000000..1ed98fa7ca855aa2189ae394971cfcf4338474ab --- /dev/null +++ b/libs/store/KoXmlReaderForward.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + Copyright (C) 2005-2006 Ariya Hidayat + Copyright (C) 2007 Thorsten Zachmann + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KOXMLREADERFORWARD_H +#define KOXMLREADERFORWARD_H + +#define KOXML_USE_QDOM + +#ifdef KOXML_USE_QDOM + +#include + +typedef QDomNode KoXmlNode; +typedef QDomElement KoXmlElement; +typedef QDomText KoXmlText; +typedef QDomCDATASection KoXmlCDATASection; +typedef QDomDocumentType KoXmlDocumentType; +typedef QDomDocument KoXmlDocument; + +#else + +class KoXmlElement; +class KoXmlText; +class KoXmlCDATASection; +class KoXmlDocumentType; +class KoXmlDocument; +class KoXmlNodeData; + +#endif + +#endif // KOXMLREADERFORWARD_H