From 4db28fe725988119fe5e808c892535d91d863fea Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 30 Apr 2024 17:01:09 -0700 Subject: [PATCH] core/lazyloader: add activeAsync property --- src/core/lazyloader.cpp | 6 ++++++ src/core/lazyloader.hpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/core/lazyloader.cpp b/src/core/lazyloader.cpp index 8831670b..76317223 100644 --- a/src/core/lazyloader.cpp +++ b/src/core/lazyloader.cpp @@ -88,6 +88,12 @@ void LazyLoader::setActive(bool active) { } } +void LazyLoader::setActiveAsync(bool active) { + if (active == (this->targetActive || this->targetLoading)) return; + if (active) this->setLoading(true); + else this->setActive(false); +} + QQmlComponent* LazyLoader::component() const { return this->cleanupComponent ? nullptr : this->mComponent; } diff --git a/src/core/lazyloader.hpp b/src/core/lazyloader.hpp index 2e470135..8ef935f6 100644 --- a/src/core/lazyloader.hpp +++ b/src/core/lazyloader.hpp @@ -104,13 +104,23 @@ class LazyLoader: public Reloadable { /// If the component is not loaded, setting this property to true will start /// loading it asynchronously. If the component is already loaded, setting /// this property has no effect. + /// + /// See also: [activeAsync](#prop.activeAsync). Q_PROPERTY(bool loading READ isLoading WRITE setLoading NOTIFY loadingChanged); /// If the component is fully loaded. /// /// Setting this property to `true` will force the component to load to completion, /// blocking the UI, and setting it to `false` will destroy the component, requiring /// it to be loaded again. + /// + /// See also: [activeAsync](#prop.activeAsync). Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged); + /// If the component is fully loaded. + /// + /// Setting this property to true will asynchronously load the component similarly to + /// [loading](#prop.loading). Reading it or setting it to false will behanve + /// the same as [active](#prop.active). + Q_PROPERTY(bool activeAsync READ isActive WRITE setActiveAsync NOTIFY activeChanged); /// The component to load. Mutually exclusive to `source`. Q_PROPERTY(QQmlComponent* component READ component WRITE setComponent NOTIFY componentChanged); /// The URI to load the component from. Mutually exclusive to `component`. @@ -123,6 +133,7 @@ public: [[nodiscard]] bool isActive() const; void setActive(bool active); + void setActiveAsync(bool active); [[nodiscard]] bool isLoading() const; void setLoading(bool loading);