forked from quickshell/quickshell
core/reloader: trigger postReload with a signal
A signal is now used over the previous tree-searching method as some QML components such as Repeater fail to reparent created children to themselves, which breaks the tree.
This commit is contained in:
parent
1644ed5e19
commit
0416032a7c
6 changed files with 15 additions and 16 deletions
|
@ -161,8 +161,9 @@ void EngineGeneration::postReload() {
|
||||||
if (this->engine == nullptr || this->root == nullptr) return;
|
if (this->engine == nullptr || this->root == nullptr) return;
|
||||||
|
|
||||||
QsEnginePlugin::runOnReload();
|
QsEnginePlugin::runOnReload();
|
||||||
PostReloadHook::postReloadTree(this->root);
|
|
||||||
this->singletonRegistry.onPostReload();
|
emit this->firePostReload();
|
||||||
|
QObject::disconnect(this, &EngineGeneration::firePostReload, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineGeneration::setWatchingFiles(bool watching) {
|
void EngineGeneration::setWatchingFiles(bool watching) {
|
||||||
|
|
|
@ -75,6 +75,7 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void filesChanged();
|
void filesChanged();
|
||||||
void reloadFinished();
|
void reloadFinished();
|
||||||
|
void firePostReload();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void quit();
|
void quit();
|
||||||
|
|
|
@ -129,14 +129,18 @@ QObject* Reloadable::getChildByReloadId(QObject* parent, const QString& reloadId
|
||||||
void PostReloadHook::componentComplete() {
|
void PostReloadHook::componentComplete() {
|
||||||
auto* engineGeneration = EngineGeneration::findObjectGeneration(this);
|
auto* engineGeneration = EngineGeneration::findObjectGeneration(this);
|
||||||
if (!engineGeneration || engineGeneration->reloadComplete) this->postReload();
|
if (!engineGeneration || engineGeneration->reloadComplete) this->postReload();
|
||||||
|
else {
|
||||||
|
// disconnected by EngineGeneration::postReload
|
||||||
|
QObject::connect(
|
||||||
|
engineGeneration,
|
||||||
|
&EngineGeneration::firePostReload,
|
||||||
|
this,
|
||||||
|
&PostReloadHook::postReload
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostReloadHook::postReload() {
|
void PostReloadHook::postReload() {
|
||||||
this->isPostReload = true;
|
this->isPostReload = true;
|
||||||
this->onPostReload();
|
this->onPostReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostReloadHook::postReloadTree(QObject* root) {
|
|
||||||
for (auto* child: root->children()) PostReloadHook::postReloadTree(child);
|
|
||||||
if (auto* self = dynamic_cast<PostReloadHook*>(root)) self->postReload();
|
|
||||||
}
|
|
||||||
|
|
|
@ -131,10 +131,10 @@ public:
|
||||||
void classBegin() override {}
|
void classBegin() override {}
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
|
|
||||||
void postReload();
|
|
||||||
virtual void onPostReload() = 0;
|
virtual void onPostReload() = 0;
|
||||||
|
|
||||||
static void postReloadTree(QObject* root);
|
public slots:
|
||||||
|
void postReload();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isPostReload = false;
|
bool isPostReload = false;
|
||||||
|
|
|
@ -51,9 +51,3 @@ void SingletonRegistry::onReload(SingletonRegistry* old) {
|
||||||
singleton->reload(old == nullptr ? nullptr : old->registry.value(url));
|
singleton->reload(old == nullptr ? nullptr : old->registry.value(url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingletonRegistry::onPostReload() {
|
|
||||||
for (auto* singleton: this->registry.values()) {
|
|
||||||
PostReloadHook::postReloadTree(singleton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ public:
|
||||||
|
|
||||||
void registerSingleton(const QUrl& url, Singleton* singleton);
|
void registerSingleton(const QUrl& url, Singleton* singleton);
|
||||||
void onReload(SingletonRegistry* old);
|
void onReload(SingletonRegistry* old);
|
||||||
void onPostReload();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QUrl, Singleton*> registry;
|
QHash<QUrl, Singleton*> registry;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue