[ui] 3DViewer: make 'visible' property drive media load request

* remove the notion of manual media (un)loading from high-level UI
* visibility button now drives media loading:
   * if media is not available (not yet computed), it will be loaded once available if visibility is on
   * once loaded, media can't be explicitly unloaded 
* use an icon to indicate that the media is not available instead of colors
This commit is contained in:
Yann Lanthony 2018-12-06 16:32:46 +01:00
parent 717b4f8b37
commit 2e06ad1b83
2 changed files with 26 additions and 15 deletions

View file

@ -49,8 +49,6 @@ Entity {
var idx = find(source);
if(idx === -1)
return
// load / make media visible
m.mediaModel.get(idx).requested = true;
m.mediaModel.get(idx).visible = true;
loadRequest(idx);
}
@ -143,6 +141,7 @@ Entity {
readonly property var attribute: model.attribute
readonly property int idx: index
readonly property var modelSource: attribute || model.source
readonly property bool visible: model.visible
// multi-step binding to ensure MediaLoader source is properly
// updated when needed, whether raw source is valid or not
@ -163,7 +162,7 @@ Entity {
readonly property string finalSource: model.requested ? currentSource : ""
renderMode: root.renderMode
enabled: model.visible
enabled: visible
// QObject.destroyed signal is not accessible
// Use the object as NodeInstantiator model to be notified of its deletion
@ -173,6 +172,17 @@ Entity {
onObjectRemoved: remove(idx)
}
// 'visible' property drives media loading request
onVisibleChanged: {
// always request media loading if visible
if(model.visible)
model.requested = true;
// only cancel loading request if media is not valid
// (a media won't be unloaded if already loaded, only hidden)
else if(!model.valid)
model.requested = false;
}
function updateModelAndCache(forceRequest) {
// don't cache explicitely unloaded media
if(model.requested && object && dependencyReady) {
@ -184,8 +194,10 @@ Entity {
if(attribute) {
model.source = rawSource;
}
// auto-restore entity if raw source is in cache
// auto-restore entity if raw source is in cache ...
model.requested = forceRequest || (!model.valid && model.requested) || cache.contains(rawSource);
// ... and update media visibility (useful if media was hidden but loaded back from cache)
model.visible = model.requested;
model.valid = Filepath.exists(rawSource) && dependencyReady;
}