effects: Do not take ownership of QuickEffect::delegate
QuickEffect::setDelegate is exposed QML API. The lifespan of assigned objects is therefore managed by the QML engine, and we should be watching for deletion not actually deleting it.
This commit is contained in:
parent
b2a48d09e7
commit
e13a30f00f
2 changed files with 7 additions and 6 deletions
|
@ -65,7 +65,7 @@ public:
|
||||||
}
|
}
|
||||||
bool isItemOnScreen(QQuickItem *item, Output *screen) const;
|
bool isItemOnScreen(QQuickItem *item, Output *screen) const;
|
||||||
|
|
||||||
std::unique_ptr<QQmlComponent> delegate;
|
QPointer<QQmlComponent> delegate;
|
||||||
QUrl source;
|
QUrl source;
|
||||||
std::map<Output *, std::unique_ptr<QQmlContext>> contexts;
|
std::map<Output *, std::unique_ptr<QQmlContext>> contexts;
|
||||||
std::map<Output *, std::unique_ptr<QQmlIncubator>> incubators;
|
std::map<Output *, std::unique_ptr<QQmlIncubator>> incubators;
|
||||||
|
@ -248,7 +248,7 @@ void QuickSceneEffect::setSource(const QUrl &url)
|
||||||
}
|
}
|
||||||
if (d->source != url) {
|
if (d->source != url) {
|
||||||
d->source = url;
|
d->source = url;
|
||||||
d->delegate.reset();
|
d->delegate.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ void QuickSceneEffect::setDelegate(QQmlComponent *delegate)
|
||||||
}
|
}
|
||||||
if (d->delegate.get() != delegate) {
|
if (d->delegate.get() != delegate) {
|
||||||
d->source = QUrl();
|
d->source = QUrl();
|
||||||
d->delegate.reset(delegate);
|
d->delegate = delegate;
|
||||||
Q_EMIT delegateChanged();
|
Q_EMIT delegateChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,11 +472,12 @@ void QuickSceneEffect::startInternal()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->delegate = std::make_unique<QQmlComponent>(effects->qmlEngine());
|
d->delegate = new QQmlComponent(effects->qmlEngine(), this);
|
||||||
d->delegate->loadUrl(d->source);
|
d->delegate->loadUrl(d->source);
|
||||||
|
|
||||||
if (d->delegate->isError()) {
|
if (d->delegate->isError()) {
|
||||||
qWarning().nospace() << "Failed to load " << d->source << ": " << d->delegate->errors();
|
qWarning().nospace() << "Failed to load " << d->source << ": " << d->delegate->errors();
|
||||||
d->delegate.reset();
|
d->delegate.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Q_EMIT delegateChanged();
|
Q_EMIT delegateChanged();
|
||||||
|
|
|
@ -158,7 +158,7 @@ OverviewEffect::OverviewEffect()
|
||||||
OverviewConfig::instance(effects->config());
|
OverviewConfig::instance(effects->config());
|
||||||
reconfigure(ReconfigureAll);
|
reconfigure(ReconfigureAll);
|
||||||
|
|
||||||
auto delegate = new QQmlComponent(effects->qmlEngine());
|
auto delegate = new QQmlComponent(effects->qmlEngine(), this);
|
||||||
connect(delegate, &QQmlComponent::statusChanged, this, [delegate]() {
|
connect(delegate, &QQmlComponent::statusChanged, this, [delegate]() {
|
||||||
if (delegate->isError()) {
|
if (delegate->isError()) {
|
||||||
qWarning() << "Failed to load overview:" << delegate->errorString();
|
qWarning() << "Failed to load overview:" << delegate->errorString();
|
||||||
|
|
Loading…
Reference in a new issue