* don't take address of temporaries
* reflect the "config can come from applet if it is parent" change in itemChange() as well * add a few comments and make the code a bit easier to read in places svn path=/trunk/KDE/kdelibs/; revision=989704
This commit is contained in:
parent
98735cc46a
commit
759f47be25
47
applet.cpp
47
applet.cpp
@ -1985,36 +1985,42 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ItemParentChange:
|
case ItemParentChange:
|
||||||
if (d->mainConfig && !d->isContainment &&
|
if (!d->isContainment) {
|
||||||
!containment() &&
|
Containment *c = containment();
|
||||||
dynamic_cast<Containment*>(value.value<QGraphicsItem *>())) {
|
if (d->mainConfig && !c) {
|
||||||
// if this is an applet, and we've just been assigned to our first containment,
|
|
||||||
// but the applet did something stupid like ask for the config() object prior to
|
|
||||||
// this happening (e.g. inits ctor) then let's repair that situation for them.
|
|
||||||
kWarning() << "Configuration object was requested prior to init(), which is too early. "
|
kWarning() << "Configuration object was requested prior to init(), which is too early. "
|
||||||
"Please fix this item:" << parentItem() << value.value<QGraphicsItem *>()
|
"Please fix this item:" << parentItem() << value.value<QGraphicsItem *>()
|
||||||
<< name();
|
<< name();
|
||||||
|
|
||||||
|
Applet *newC = dynamic_cast<Applet*>(value.value<QGraphicsItem *>());
|
||||||
|
if (newC) {
|
||||||
|
// if this is an applet, and we've just been assigned to our first containment,
|
||||||
|
// but the applet did something stupid like ask for the config() object prior to
|
||||||
|
// this happening (e.g. inits ctor) then let's repair that situation for them.
|
||||||
KConfigGroup *old = d->mainConfig;
|
KConfigGroup *old = d->mainConfig;
|
||||||
KConfigGroup appletConfig = dynamic_cast<Containment*>(value.value<QGraphicsItem *>())->config();
|
KConfigGroup appletConfig = newC->config();
|
||||||
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
||||||
d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId));
|
d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId));
|
||||||
old->copyTo(d->mainConfig);
|
old->copyTo(d->mainConfig);
|
||||||
old->deleteGroup();
|
old->deleteGroup();
|
||||||
delete old;
|
delete old;
|
||||||
} else if (!d->isContainment) {
|
|
||||||
Plasma::PopupApplet *pa = qobject_cast<Plasma::PopupApplet *>(this);
|
|
||||||
if (!pa) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::PopupApplet *pa = qobject_cast<Plasma::PopupApplet *>(this);
|
||||||
|
if (pa) {
|
||||||
//reconnect of popupapplets with new containment geometryChanged
|
//reconnect of popupapplets with new containment geometryChanged
|
||||||
if (containment()) {
|
if (c) {
|
||||||
disconnect(containment(), SIGNAL(geometryChanged()), pa, SLOT(updateDialogPosition()));
|
disconnect(containment(), SIGNAL(geometryChanged()), pa, SLOT(updateDialogPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Containment *cont = dynamic_cast<Containment*>(value.value<QGraphicsItem *>());
|
Plasma::Containment *cont = dynamic_cast<Containment*>(value.value<QGraphicsItem *>());
|
||||||
if (cont) {
|
if (cont) {
|
||||||
connect(cont, SIGNAL(geometryChanged()), pa, SLOT(updateDialogPosition()));
|
connect(cont, SIGNAL(geometryChanged()), pa, SLOT(updateDialogPosition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ItemPositionChange:
|
case ItemPositionChange:
|
||||||
return (immutability() == Mutable || isContainment() || formFactor() == Horizontal || formFactor() == Vertical) ? value : pos();
|
return (immutability() == Mutable || isContainment() || formFactor() == Horizontal || formFactor() == Vertical) ? value : pos();
|
||||||
break;
|
break;
|
||||||
@ -2409,11 +2415,18 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
|
|||||||
mainConfig = new KConfigGroup(&containmentConfig, QString::number(appletId));
|
mainConfig = new KConfigGroup(&containmentConfig, QString::number(appletId));
|
||||||
} else {
|
} else {
|
||||||
KConfigGroup appletConfig;
|
KConfigGroup appletConfig;
|
||||||
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(q->parent());
|
|
||||||
if (parentApplet && q->containment() && parentApplet != q->containment()) {
|
if (Containment *c = q->containment()) {
|
||||||
appletConfig = KConfigGroup(&parentApplet->config(), "Applets");
|
Plasma::Applet *parentApplet = qobject_cast<Applet *>(q->parent());
|
||||||
} else if (q->containment()) {
|
if (parentApplet && parentApplet != static_cast<Applet *>(c)) {
|
||||||
appletConfig = q->containment()->config();
|
// this applet is nested inside another applet! use it's config
|
||||||
|
// as the parent group in the config
|
||||||
|
appletConfig = parentApplet->config();
|
||||||
|
} else {
|
||||||
|
// applet directly in a Containment, as usual
|
||||||
|
appletConfig = c->config();
|
||||||
|
}
|
||||||
|
|
||||||
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
||||||
} else {
|
} else {
|
||||||
kWarning() << "requesting config for" << q->name() << "without a containment!";
|
kWarning() << "requesting config for" << q->name() << "without a containment!";
|
||||||
|
Loading…
Reference in New Issue
Block a user