Commit 75993000 authored by Thomas Zander's avatar Thomas Zander

Implement saving of TextOnShape

svn path=/trunk/koffice/; revision=1151041
parent 3e10870c
......@@ -23,6 +23,7 @@
#include "KoConnectionShape_p.h"
#include "KoViewConverter.h"
#include "KoShapeContainer.h"
#include "KoShapeLoadingContext.h"
#include "KoShapeSavingContext.h"
#include "KoConnectionShapeLoadingUpdater.h"
......@@ -311,6 +312,8 @@ void KoConnectionShape::saveOdf(KoShapeSavingContext & context) const
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement();
}
......
......@@ -116,6 +116,8 @@ void KoPathShape::saveOdf(KoShapeSavingContext & context) const
context.xmlWriter().addAttribute("koffice:nodeTypes", d->nodeTypes());
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement();
}
......
......@@ -231,3 +231,7 @@ KoShapeContainerModel *KoShapeContainer::model() const
return d->model;
}
void KoShapeContainer::saveOdfChildElements(KoShapeSavingContext &context) const
{
Q_UNUSED(context);
}
......@@ -202,6 +202,8 @@ public:
*/
KoShapeContainerModel *model() const;
virtual void saveOdfChildElements(KoShapeSavingContext &context) const;
protected:
/**
* This hook is for inheriting classes that need to do something on adding/removing
......
......@@ -182,7 +182,9 @@ bool KoTextOnShapeContainer::loadOdf(const KoXmlElement &element, KoShapeLoading
void KoTextOnShapeContainer::saveOdf(KoShapeSavingContext &context) const
{
// TODO
Q_D(const KoTextOnShapeContainer);
if (d->content)
d->content->saveOdf(context);
}
void KoTextOnShapeContainer::setPlainText(const QString &text)
......@@ -193,6 +195,7 @@ void KoTextOnShapeContainer::setPlainText(const QString &text)
return;
}
KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(d->textShape->userData());
Q_ASSERT(shapeData); // would be a bug in kotext
Q_ASSERT(shapeData->document());
shapeData->document()->setPlainText(text);
}
......@@ -254,3 +257,16 @@ Qt::Alignment KoTextOnShapeContainer::textAlignment() const
return answer;
}
void KoTextOnShapeContainer::saveOdfChildElements(KoShapeSavingContext &context) const
{
Q_D(const KoTextOnShapeContainer);
if (d->textShape == 0) {
return;
}
KoTextShapeDataBase *shapeData = qobject_cast<KoTextShapeDataBase*>(d->textShape->userData());
Q_ASSERT(shapeData); // would be a bug in kotext
if (!shapeData->document()->isEmpty()) {
shapeData->saveOdf(context);
}
}
......@@ -82,6 +82,14 @@ public:
*/
void setPlainText(const QString &text);
/**
* This method is called by shapes owned by this container to allow the container to add
* ODf content as child elements of the same element that the shape itself saved into.
* This method is typically called in the shapes saveOdf() method before closing the
* xml element it saved into.
*/
virtual void saveOdfChildElements(KoShapeSavingContext &context) const;
private:
Q_DECLARE_PRIVATE(KoTextOnShapeContainer)
};
......
......@@ -29,6 +29,7 @@
class KoTextShapeDataBasePrivate;
class KoXmlElement;
class KoShapeLoadingContext;
class KoShapeSavingContext;
/**
* \internal
......@@ -61,6 +62,11 @@ public:
*/
virtual bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context) = 0;
/**
* Save the text to ODF.
*/
virtual void saveOdf(KoShapeSavingContext &context, int from = 0, int to = -1) const = 0;
/** Sets the vertical alignment of all the text inside the shape. */
void setVerticalAlignment(Qt::Alignment alignment);
/** Returns the vertical alignment of all the text in the shape */
......
......@@ -147,6 +147,14 @@ public:
*/
void saveOdf(KoShapeSavingContext &context, KoDocumentRdfBase *rdfData, int from = 0, int to = -1) const;
/**
* Store the TextShape data as ODF.
* Overloaded method provided for your convenience.
*/
virtual void saveOdf(KoShapeSavingContext &context, int from = 0, int to = -1) const {
saveOdf(context, 0, from, to);
}
/**
* Set the page direction.
* The page direction will determine behavior on the insertion of new text and those
......
......@@ -24,6 +24,7 @@
#include <KoPathPoint.h>
#include <KoShapeSavingContext.h>
#include <KoXmlReader.h>
#include <KoShapeContainer.h>
#include <KoXmlWriter.h>
#include <KoXmlNS.h>
#include <KoUnit.h>
......@@ -75,6 +76,8 @@ void EllipseShape::saveOdf(KoShapeSavingContext &context) const
context.xmlWriter().addAttribute("draw:end-angle", m_endAngle);
}
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement();
} else {
KoPathShape::saveOdf(context);
......
......@@ -31,6 +31,7 @@
#include <KoXmlWriter.h>
#include <KoXmlReader.h>
#include <KoShapeSavingContext.h>
#include <KoShapeContainer.h>
#include <KoUnit.h>
#include <KoOdfWorkaround.h>
#include <KoPathPoint.h>
......@@ -363,6 +364,8 @@ void EnhancedPathShape::saveOdf(KoShapeSavingContext &context) const
context.xmlWriter().endElement(); // draw:enhanced-geometry
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement(); // draw:custom-shape
if (m_mirrorHorizontally) {
......
......@@ -22,6 +22,7 @@
#include "RectangleShape.h"
#include <KoPathPoint.h>
#include <KoShapeContainer.h>
#include <KoShapeSavingContext.h>
#include <KoXmlReader.h>
#include <KoXmlWriter.h>
......@@ -80,6 +81,8 @@ void RectangleShape::saveOdf(KoShapeSavingContext & context) const
context.xmlWriter().addAttributePt("svg:ry", m_cornerRadiusY * (0.5*size().height()) / 100.0);
}
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement();
} else {
KoPathShape::saveOdf(context);
......
......@@ -23,6 +23,7 @@
#include <KoPathPoint.h>
#include <KoShapeLoadingContext.h>
#include <KoShapeSavingContext.h>
#include <KoShapeContainer.h>
#include <KoXmlReader.h>
#include <KoXmlNS.h>
#include <KoXmlWriter.h>
......@@ -386,6 +387,8 @@ void StarShape::saveOdf(KoShapeSavingContext & context) const
context.xmlWriter().endElement(); // draw:enhanced-geometry
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement(); // draw:custom-shape
}
else {
......@@ -401,6 +404,8 @@ void StarShape::saveOdf(KoShapeSavingContext & context) const
context.xmlWriter().addAttribute("draw:sharpness", QString("%1%").arg(percent));
}
saveOdfCommonChildElements(context);
if (parent())
parent()->saveOdfChildElements(context);
context.xmlWriter().endElement();
}
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment