Skip to content

Commit 4db28fe

Browse files
committed
core/lazyloader: add activeAsync property
1 parent 658f3cf commit 4db28fe

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/core/lazyloader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ void LazyLoader::setActive(bool active) {
8888
}
8989
}
9090

91+
void LazyLoader::setActiveAsync(bool active) {
92+
if (active == (this->targetActive || this->targetLoading)) return;
93+
if (active) this->setLoading(true);
94+
else this->setActive(false);
95+
}
96+
9197
QQmlComponent* LazyLoader::component() const {
9298
return this->cleanupComponent ? nullptr : this->mComponent;
9399
}

src/core/lazyloader.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,23 @@ class LazyLoader: public Reloadable {
104104
/// If the component is not loaded, setting this property to true will start
105105
/// loading it asynchronously. If the component is already loaded, setting
106106
/// this property has no effect.
107+
///
108+
/// See also: [activeAsync](#prop.activeAsync).
107109
Q_PROPERTY(bool loading READ isLoading WRITE setLoading NOTIFY loadingChanged);
108110
/// If the component is fully loaded.
109111
///
110112
/// Setting this property to `true` will force the component to load to completion,
111113
/// blocking the UI, and setting it to `false` will destroy the component, requiring
112114
/// it to be loaded again.
115+
///
116+
/// See also: [activeAsync](#prop.activeAsync).
113117
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged);
118+
/// If the component is fully loaded.
119+
///
120+
/// Setting this property to true will asynchronously load the component similarly to
121+
/// [loading](#prop.loading). Reading it or setting it to false will behanve
122+
/// the same as [active](#prop.active).
123+
Q_PROPERTY(bool activeAsync READ isActive WRITE setActiveAsync NOTIFY activeChanged);
114124
/// The component to load. Mutually exclusive to `source`.
115125
Q_PROPERTY(QQmlComponent* component READ component WRITE setComponent NOTIFY componentChanged);
116126
/// The URI to load the component from. Mutually exclusive to `component`.
@@ -123,6 +133,7 @@ class LazyLoader: public Reloadable {
123133

124134
[[nodiscard]] bool isActive() const;
125135
void setActive(bool active);
136+
void setActiveAsync(bool active);
126137

127138
[[nodiscard]] bool isLoading() const;
128139
void setLoading(bool loading);

0 commit comments

Comments
 (0)