Commit b6078017 authored by Thomas Zander's avatar Thomas Zander

Make the KoShapeContainer share its private class with the KoShape, one

less malloc and object allocation for each shapeContainer :)

svn path=/trunk/koffice/; revision=990517
parent 6b00258f
......@@ -74,7 +74,7 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
appData(0),
fill(0),
border(0),
me(shape),
q(shape),
shadow(0),
zIndex(0),
visible(true),
......@@ -84,16 +84,16 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
selectable(true),
detectCollision(false),
protectContent(false)
{
}
{
}
KoShapePrivate::~KoShapePrivate()
{
if (parent)
parent->removeChild(me);
parent->removeChild(q);
foreach(KoShapeManager *manager, shapeManagers) {
manager->remove(me);
manager->removeAdditional(me);
manager->remove(q);
manager->removeAdditional(q);
}
delete userData;
delete appData;
......@@ -109,10 +109,10 @@ KoShapePrivate::~KoShapePrivate()
void KoShapePrivate::shapeChanged(KoShape::ChangeType type)
{
if (parent)
parent->model()->childChanged(me, type);
me->shapeChanged(type);
parent->model()->childChanged(q, type);
q->shapeChanged(type);
foreach(KoShape * shape, dependees)
shape->shapeChanged(type, me);
shape->shapeChanged(type, q);
}
......
/* This file is part of the KDE project
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
* Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
*
* This library is free software; you can redistribute it and/or
......@@ -18,6 +18,7 @@
* Boston, MA 02110-1301, USA.
*/
#include "KoShapeContainer.h"
#include "KoShapeContainer_p.h"
#include "KoShapeContainerModel.h"
#include "KoShapeBorderModel.h"
#include "KoChildrenData.h"
......@@ -26,38 +27,41 @@
#include <QPainter>
#include <QPainterPath>
class KoShapeContainer::Private
KoShapeContainerPrivate::KoShapeContainerPrivate(KoShapeContainer *q)
: KoShapePrivate(q),
children(0)
{
public:
Private() : children(0) {}
~Private() {
if (children) {
foreach(KoShape *shape, children->childShapes())
shape->setParent(0);
delete children;
}
}
KoShapeContainerModel *children;
};
}
KoShapeContainerPrivate::~KoShapeContainerPrivate()
{
delete children;
}
KoShapeContainer::KoShapeContainer() : KoShape(), d(new Private())
KoShapeContainer::KoShapeContainer()
: KoShape(*(new KoShapeContainerPrivate(this)))
{
}
KoShapeContainer::KoShapeContainer(KoShapeContainerModel *model)
: KoShape(),
d(new Private())
: KoShape(*(new KoShapeContainerPrivate(this)))
{
Q_D(KoShapeContainer);
d->children = model;
}
KoShapeContainer::~KoShapeContainer()
{
delete d;
Q_D(KoShapeContainer);
if (d->children) {
foreach(KoShape *shape, d->children->childShapes())
shape->setParent(0);
}
}
void KoShapeContainer::addChild(KoShape *shape)
{
Q_D(KoShapeContainer);
Q_ASSERT(shape);
if (shape->parent() == this && childShapes().contains(shape))
return;
......@@ -72,6 +76,7 @@ void KoShapeContainer::addChild(KoShape *shape)
void KoShapeContainer::removeChild(KoShape *shape)
{
Q_D(KoShapeContainer);
Q_ASSERT(shape);
if (d->children == 0)
return;
......@@ -82,6 +87,7 @@ void KoShapeContainer::removeChild(KoShape *shape)
int KoShapeContainer::childCount() const
{
Q_D(const KoShapeContainer);
if (d->children == 0)
return 0;
return d->children->count();
......@@ -89,6 +95,7 @@ int KoShapeContainer::childCount() const
bool KoShapeContainer::isChildLocked(const KoShape *child) const
{
Q_D(const KoShapeContainer);
if (d->children == 0)
return false;
return d->children->isChildLocked(child);
......@@ -96,6 +103,7 @@ bool KoShapeContainer::isChildLocked(const KoShape *child) const
void KoShapeContainer::setClipping(const KoShape *child, bool clipping)
{
Q_D(KoShapeContainer);
if (d->children == 0)
return;
d->children->setClipping(child, clipping);
......@@ -103,6 +111,7 @@ void KoShapeContainer::setClipping(const KoShape *child, bool clipping)
void KoShapeContainer::paint(QPainter &painter, const KoViewConverter &converter)
{
Q_D(KoShapeContainer);
painter.save();
paintComponent(painter, converter);
painter.restore();
......@@ -150,6 +159,7 @@ void KoShapeContainer::paint(QPainter &painter, const KoViewConverter &converter
void KoShapeContainer::shapeChanged(ChangeType type, KoShape *shape)
{
Q_D(KoShapeContainer);
Q_UNUSED(shape);
if (d->children == 0)
return;
......@@ -163,6 +173,7 @@ void KoShapeContainer::shapeChanged(ChangeType type, KoShape *shape)
bool KoShapeContainer::childClipped(const KoShape *child) const
{
Q_D(const KoShapeContainer);
if (d->children == 0) // throw exception??
return false;
return d->children->childClipped(child);
......@@ -170,6 +181,7 @@ bool KoShapeContainer::childClipped(const KoShape *child) const
void KoShapeContainer::update() const
{
Q_D(const KoShapeContainer);
KoShape::update();
if (d->children)
foreach(KoShape *shape, d->children->childShapes())
......@@ -178,6 +190,7 @@ void KoShapeContainer::update() const
QList<KoShape*> KoShapeContainer::childShapes() const
{
Q_D(const KoShapeContainer);
if (d->children == 0)
return QList<KoShape*>();
......@@ -186,6 +199,7 @@ QList<KoShape*> KoShapeContainer::childShapes() const
KoShapeContainerModel *KoShapeContainer::model() const
{
Q_D(const KoShapeContainer);
return d->children;
}
/* This file is part of the KDE project
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -29,6 +29,7 @@
class QPainter;
class KoShapeContainerModel;
class KoShapeContainerPrivate;
/**
* This is the base class that all Flake group-shapes are based on.
......@@ -67,7 +68,6 @@ class KoShapeContainerModel;
*/
class FLAKE_EXPORT KoShapeContainer : public KoShape
{
public:
/**
......@@ -166,11 +166,13 @@ protected:
*/
virtual void childCountChanged() { }
/// constructor
KoShapeContainer(KoShapeContainerPrivate &);
private:
void shapeChanged(ChangeType type, KoShape *shape = 0);
class Private;
Private * const d;
Q_DECLARE_PRIVATE(KoShapeContainer)
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2009 Thomas Zander <zander@kde.org>
*
* 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 KOSHAPECONTAINERPRIVATE_H
#define KOSHAPECONTAINERPRIVATE_H
#include "KoShape_p.h"
class KoShapeContainerModel;
class KoShapeContainerPrivate : public KoShapePrivate
{
public:
KoShapeContainerPrivate(KoShapeContainer *q);
virtual ~KoShapeContainerPrivate();
KoShapeContainerModel *children;
};
#endif
......@@ -25,7 +25,7 @@ class KoShapePrivate
{
public:
KoShapePrivate(KoShape *shape);
~KoShapePrivate();
virtual ~KoShapePrivate();
void shapeChanged(KoShape::ChangeType type);
QSizeF size; // size in pt
......@@ -42,7 +42,7 @@ public:
KoShapeApplicationData *appData;
KoShapeBackground * fill; ///< Stands for the background color / fill etc.
KoShapeBorderModel *border; ///< points to a border, or 0 if there is no border
KoShape *me;
KoShape *q;
QList<KoShape*> dependees; ///< list of shape dependent on this shape
KoShapeShadow * shadow; ///< the current shape shadow
QMap<QByteArray, QString> additionalAttributes;
......
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