From 5df8969be7bf70c9ad33fa6a3e5c522554fe52c0 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Fri, 28 Jun 2019 16:51:58 +0800 Subject: [PATCH] Fix the three broken tests --- libs/flake/KoShapeContainer.cpp | 31 ++++++++++++++----------- libs/flake/KoShapeContainer.h | 4 ++++ libs/flake/KoShapeGroup.cpp | 4 ++-- libs/flake/text/KoSvgTextChunkShape.cpp | 2 +- plugins/flake/textshape/TextShape.cpp | 4 ++++ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/libs/flake/KoShapeContainer.cpp b/libs/flake/KoShapeContainer.cpp index 62ea9d25ed..f57c5517ff 100644 --- a/libs/flake/KoShapeContainer.cpp +++ b/libs/flake/KoShapeContainer.cpp @@ -44,8 +44,8 @@ KoShapeContainer::Private::~Private() } KoShapeContainer::Private::Private(const KoShapeContainer::Private &rhs, KoShapeContainer *q) - : shapeInterface(q), - model(0) + : shapeInterface(q) + , model(0) { Q_UNUSED(rhs); } @@ -61,17 +61,6 @@ KoShapeContainer::KoShapeContainer(const KoShapeContainer &rhs) : KoShape(rhs) , d(new Private(*(rhs.d.data()), this)) { - // HACK ALERT: the shapes are copied inside the model, - // but we still need to connect the to the - // hierarchy here! - if (d->model) { - Q_FOREACH (KoShape *shape, d->model->shapes()) { - if (shape) { // Note: shape can be 0 because not all shapes - // implement cloneShape, e.g. the text shape. - shape->setParent(this); - } - } - } } KoShapeContainer::~KoShapeContainer() @@ -175,6 +164,22 @@ void KoShapeContainer::setModel(KoShapeContainerModel *model) d->model = model; } +void KoShapeContainer::setModelInit(KoShapeContainerModel *model) +{ + setModel(model); + // HACK ALERT: the shapes are copied inside the model, + // but we still need to connect the to the + // hierarchy here! + if (d->model) { + Q_FOREACH (KoShape *shape, d->model->shapes()) { + if (shape) { // Note: shape can be 0 because not all shapes + // implement cloneShape, e.g. the text shape. + shape->setParent(this); + } + } + } +} + KoShapeContainer::ShapeInterface *KoShapeContainer::shapeInterface() { return &d->shapeInterface; diff --git a/libs/flake/KoShapeContainer.h b/libs/flake/KoShapeContainer.h index 63a0303bbd..3e33f41e1f 100644 --- a/libs/flake/KoShapeContainer.h +++ b/libs/flake/KoShapeContainer.h @@ -203,6 +203,10 @@ protected: * set the model for this container */ void setModel(KoShapeContainerModel *model); + /** + * set the model, and take control of all its children + */ + void setModelInit(KoShapeContainerModel *model); public: diff --git a/libs/flake/KoShapeGroup.cpp b/libs/flake/KoShapeGroup.cpp index e1b6d3a2c2..3aa2be219c 100644 --- a/libs/flake/KoShapeGroup.cpp +++ b/libs/flake/KoShapeGroup.cpp @@ -102,7 +102,7 @@ KoShapeGroup::KoShapeGroup() : KoShapeContainer() , d(new Private) { - setModel(new ShapeGroupContainerModel(this)); + setModelInit(new ShapeGroupContainerModel(this)); } KoShapeGroup::KoShapeGroup(const KoShapeGroup &rhs) @@ -111,7 +111,7 @@ KoShapeGroup::KoShapeGroup(const KoShapeGroup &rhs) { ShapeGroupContainerModel *otherModel = dynamic_cast(rhs.model()); KIS_ASSERT_RECOVER_RETURN(otherModel); - setModel(new ShapeGroupContainerModel(*otherModel, this)); + setModelInit(new ShapeGroupContainerModel(*otherModel, this)); } KoShapeGroup::~KoShapeGroup() diff --git a/libs/flake/text/KoSvgTextChunkShape.cpp b/libs/flake/text/KoSvgTextChunkShape.cpp index 26407b8202..9d6b785866 100644 --- a/libs/flake/text/KoSvgTextChunkShape.cpp +++ b/libs/flake/text/KoSvgTextChunkShape.cpp @@ -308,7 +308,7 @@ KoSvgTextChunkShape::KoSvgTextChunkShape(const KoSvgTextChunkShape &rhs) if (rhs.model()) { SimpleShapeContainerModel *otherModel = dynamic_cast(rhs.model()); KIS_ASSERT_RECOVER_RETURN(otherModel); - setModel(new SimpleShapeContainerModel(*otherModel)); + setModelInit(new SimpleShapeContainerModel(*otherModel)); } // XXX: this will immediately lead to a detach d->layoutInterface.reset(new KoSvgTextChunkShape::Private::LayoutInterface(this)); diff --git a/plugins/flake/textshape/TextShape.cpp b/plugins/flake/textshape/TextShape.cpp index 5876b8c694..f31b10bf88 100644 --- a/plugins/flake/textshape/TextShape.cpp +++ b/plugins/flake/textshape/TextShape.cpp @@ -97,6 +97,10 @@ TextShape::TextShape(const TextShape &rhs) , m_clip(rhs.m_clip) { /// TODO: we need to clone the model + KoTextShapeContainerModel *origModel = dynamic_cast(rhs.model()); + if (origModel) { + setModel(new KoTextShapeContainerModel()); + } // XXX: ? //reinterpret_cast(rhs.d_ptr)->model = new KoTextShapeContainerModel(); -- 2.24.1