Commit 480d4852 authored by Thomas Zander's avatar Thomas Zander

Properly define the lifetime of a Shape / Frame / FrameSet in KWord so we don't have memory leaks.

This refactor has as effect that KWord now removes frames by removing its shape and deleting (done
in the remove command) the shape will delete the frame and possibly the frameset.

For this reason the KoShape needs to 'own' some add on application data; I added the
KoShapeApplicationData interface for that.

svn path=/trunk/koffice/; revision=607382
parent ed65aeaf
......@@ -27,13 +27,15 @@
#include "KoShapeBorderModel.h"
#include "KoShapeManager.h"
#include "KoShapeUserData.h"
#include "KoShapeApplicationData.h"
#include "KoViewConverter.h"
#include <QPainter>
#include <QtDebug>
#include <QVariant>
#include <QPainterPath>
#include <kdebug.h>
: m_backgroundBrush(Qt::NoBrush)
, m_border(0)
......@@ -51,13 +53,16 @@ KoShape::KoShape()
, m_keepAspect( false )
, m_selectable( true )
, m_userData(0)
, m_appData(0)
kDebug() << "KoShape::~KoShape\n";
delete m_userData;
delete m_appData;
void KoShape::paintDecorations(QPainter &painter, const KoViewConverter &converter, bool selected) {
......@@ -343,6 +348,16 @@ KoShapeUserData *KoShape::userData() const {
return m_userData;
void KoShape::setApplicationData(KoShapeApplicationData *appData) {
delete m_appData;
m_appData = appData;
KoShapeApplicationData *KoShape::applicationData() const {
return m_appData;
bool KoShape::hasTransparency() {
if( == Qt::NoBrush)
return true;
......@@ -41,6 +41,7 @@ class KoShapeBorderModel;
class KoShapeManager;
class KoShapeUserData;
class KoViewConverter;
class KoShapeApplicationData;
......@@ -456,6 +457,18 @@ public:
KoShapeUserData *userData() const;
* Set a data object on the shape to be used by an application.
* This is specifically useful when an application wants to have data that is per shape
* and should be deleted when the shape is destructed.
* @param applicationData the new application data, or 0 to delete the current one.
void setApplicationData(KoShapeApplicationData *applicationData);
* Return the current applicationData.
KoShapeApplicationData *applicationData() const;
* Return the Id of this shape, indentifying the type of shape by the id of the factory.
* @see KoShapeFactory::shapeId()
......@@ -549,6 +562,7 @@ private:
void addShapeManager( KoShapeManager * manager ) { m_shapeManagers.insert( manager ); }
void removeShapeManager( KoShapeManager * manager ) { m_shapeManagers.remove( manager ); }
KoShapeUserData *m_userData;
KoShapeApplicationData *m_appData;
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <>
* 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
* 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.
#include <koffice_export.h>
* The KoShapeAppliationData class is used to associate application specific data with a shape.
* See also the KoShapeUserData class that is specifically set for the benefit of shapes and tools.
* KoShapeAppliationData provides an abstract interface for container classes
* that are used to associate application-specific data with shapes in KoShape
* Generally, subclasses of this class provide functions to allow data to
* be stored and retrieved, and instances are attached to KoShape using
* KoShape::setApplicationData(). This makes it possible for an application to attach
* application specific data (like a Frame in KWord) and have the deletion of a shape also delete
* that data.
* Each subclass should provide a reimplementation of the destructor to ensure that
* any private data is automatically cleaned up when user data objects are deleted.
class FLAKE_EXPORT KoShapeApplicationData {
virtual ~KoShapeApplicationData() {}
......@@ -78,6 +78,8 @@ void KoShapeManager::setShapes( const QList<KoShape *> &shapes )
void KoShapeManager::add( KoShape *shape )
shape->addShapeManager( this );
if( ! dynamic_cast<KoShapeGroup*>( shape ))
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