don't hang onto deleted actions

svn path=/trunk/KDE/kdelibs/; revision=885851
This commit is contained in:
Aaron J. Seigo 2008-11-18 00:33:44 +00:00
parent d6bd085b75
commit 5dbc0a7da0
3 changed files with 13 additions and 0 deletions

View File

@ -343,6 +343,7 @@ void IconWidget::setAction(QAction *action)
d->action = action; d->action = action;
if (action) { if (action) {
connect(action, SIGNAL(changed()), this, SLOT(syncToAction())); connect(action, SIGNAL(changed()), this, SLOT(syncToAction()));
connect(action, SIGNAL(destroyed(QObject*)), this, SLOT(clearAction()));
connect(this, SIGNAL(clicked()), action, SLOT(trigger())); connect(this, SIGNAL(clicked()), action, SLOT(trigger()));
d->syncToAction(); d->syncToAction();
} }
@ -1188,9 +1189,19 @@ void IconWidget::setUnpressed()
setPressed(false); setPressed(false);
} }
void IconWidgetPrivate::clearAction()
{
action = 0;
syncToAction();
emit q->changed();
}
void IconWidgetPrivate::syncToAction() void IconWidgetPrivate::syncToAction()
{ {
if (!action) { if (!action) {
q->setIcon(QIcon());
q->setText(QString());
q->setEnabled(false);
return; return;
} }
//we don't get told *what* changed, just that something changed //we don't get told *what* changed, just that something changed

View File

@ -278,6 +278,7 @@ public:
private: private:
Q_PRIVATE_SLOT(d, void syncToAction()) Q_PRIVATE_SLOT(d, void syncToAction())
Q_PRIVATE_SLOT(d, void clearAction())
void init(); void init();
void layoutIcons(const QStyleOptionGraphicsItem *option); void layoutIcons(const QStyleOptionGraphicsItem *option);
void hoverEffect(bool); void hoverEffect(bool);

View File

@ -175,6 +175,7 @@ public:
* update the icon's text, icon, etc. to reflect the properties of its associated action. * update the icon's text, icon, etc. to reflect the properties of its associated action.
*/ */
void syncToAction(); void syncToAction();
void clearAction();
IconWidget *q; IconWidget *q;
QString text; QString text;