Commit a50bfb99 authored by Thorsten Zachmann's avatar Thorsten Zachmann

o save layers of shapes that are part of a container

o use layer of child shapes to find out the layer of a group shape.
  This is done as the group does not allow to save its layer in odf

This fixes loading and saving of grouped shapes. Before the fix the
group was always added to the default layer. Now the group is added to
the layer it is was in when saving.

OK to backport to 2.1? I think it is a important fix as some information
is lost during save/load of the document.

CCMAIL: koffice-devel@kde.org

svn path=/trunk/koffice/; revision=1047373
parent d55d31ba
......@@ -1248,8 +1248,14 @@ void KoShape::saveOdfAttributes(KoShapeSavingContext &context, int attributes) c
}
if (attributes & OdfLayer) {
if (d->parent && dynamic_cast<KoShapeLayer*>(d->parent))
context.xmlWriter().addAttribute("draw:layer", d->parent->name());
KoShape * parent = d->parent;
while ( parent ) {
if ( dynamic_cast<KoShapeLayer*>( parent ) ) {
context.xmlWriter().addAttribute("draw:layer", parent->name());
break;
}
parent = parent->parent();
}
}
if (attributes & OdfSize) {
......
......@@ -20,6 +20,7 @@
#include "KoShapeGroup.h"
#include "KoShapeContainerModel.h"
#include "KoShapeLayer.h"
#include "SimpleShapeContainerModel.h"
#include "KoShapeSavingContext.h"
#include "KoShapeLoadingContext.h"
......@@ -79,12 +80,27 @@ bool KoShapeGroup::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &
loadOdfAttributes(element, context, OdfMandatories | OdfAdditionalAttributes | OdfCommonChildElements);
KoXmlElement child;
QMap<KoShapeLayer*, int> usedLayers;
forEachElement(child, element) {
KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf(child, context);
KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape->parent());
if (layer) {
usedLayers[layer]++;
}
if (shape) {
addChild(shape);
}
}
KoShapeLayer *parent = 0;
int maxUseCount = 0;
// find most used layer and use this as parent for the group
for (QMap<KoShapeLayer*, int>::const_iterator it(usedLayers.constBegin()); it != usedLayers.constEnd(); ++it) {
if (it.value() > maxUseCount) {
maxUseCount = it.value();
parent = it.key();
}
}
setParent(parent);
QRectF bound;
bool boundInitialized = false;
......
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