SVN commit 917619

Add an appletDestroyed signal instead of catching the destruction in containments with qobject destroyed signal.
This fix errors because we give an invalid pointer to public appletRemoved signal.

svn path=/branches/KDE/4.2/kdelibs/; revision=917622
This commit is contained in:
Alexis Ménard 2009-01-28 08:13:19 +00:00
parent 06406afafa
commit ee34edad4a
5 changed files with 12 additions and 12 deletions

View File

@ -133,6 +133,9 @@ Applet::Applet(QObject *parentObject, const QVariantList &args)
Applet::~Applet() Applet::~Applet()
{ {
//let people know that i will die
emit appletDestroyed(this);
if (d->transient) { if (d->transient) {
d->resetConfigurationObject(); d->resetConfigurationObject();
} else if (d->extender) { } else if (d->extender) {

View File

@ -609,6 +609,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
void activate(); void activate();
/**
* Emitted when the applet is deleted
*/
void appletDestroyed(Plasma::Applet *applet);
public Q_SLOTS: public Q_SLOTS:
/** /**
* Sets the immutability type for this applet (not immutable, * Sets the immutability type for this applet (not immutable,

View File

@ -742,7 +742,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving())); connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving()));
connect(applet, SIGNAL(releaseVisualFocus()), this, SIGNAL(releaseVisualFocus())); connect(applet, SIGNAL(releaseVisualFocus()), this, SIGNAL(releaseVisualFocus()));
connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed(QObject*))); connect(applet, SIGNAL(appletDestroyed(Plasma::Applet*)), this, SLOT(appletDestroyed(Plasma::Applet*)));
if (pos != QPointF(-1, -1)) { if (pos != QPointF(-1, -1)) {
applet->setPos(pos); applet->setPos(pos);
@ -1709,16 +1709,8 @@ bool ContainmentPrivate::regionIsEmpty(const QRectF &region, Applet *ignoredAppl
return true; return true;
} }
void ContainmentPrivate::appletDestroyed(QObject *object) void ContainmentPrivate::appletDestroyed(Plasma::Applet *applet)
{ {
// we do a static_cast here since it really isn't an Applet by this
// point anymore since we are in the qobject dtor. we don't actually
// try and do anything with it, we just need the value of the pointer
// so this unsafe looking code is actually just fine.
//
// NOTE: DO NOT USE THE applet VARIABLE FOR ANYTHING OTHER THAN COMPARING
// THE ADDRESS! ACTUALLY USING THE OBJECT WILL RESULT IN A CRASH!!!
Applet *applet = static_cast<Plasma::Applet*>(object);
applets.removeAll(applet); applets.removeAll(applet);
if (focusedApplet == applet) { if (focusedApplet == applet) {
focusedApplet = 0; focusedApplet = 0;

View File

@ -507,7 +507,7 @@ class PLASMA_EXPORT Containment : public Applet
const QGraphicsItem *toolBoxItem() const; const QGraphicsItem *toolBoxItem() const;
private: private:
Q_PRIVATE_SLOT(d, void appletDestroyed(QObject*)) Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))
Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *item, Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *item,
Plasma::Animator::Animation anim)) Plasma::Animator::Animation anim))
Q_PRIVATE_SLOT(d, void triggerShowAddWidgets()) Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())

View File

@ -75,7 +75,7 @@ public:
void positionContainments(); void positionContainments();
void setLockToolText(); void setLockToolText();
void handleDisappeared(AppletHandle *handle); void handleDisappeared(AppletHandle *handle);
void appletDestroyed(QObject*); void appletDestroyed(Plasma::Applet*);
void containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim); void containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
void zoomIn(); void zoomIn();
void zoomOut(); void zoomOut();