Skip to content

Commit 946064d

Browse files
committed
Also remove labels and skyImages when cleaning the scene in a script.
1 parent e4f041b commit 946064d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/core/StelSkyLayerMgr.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,25 @@ QString StelSkyLayerMgr::insertSkyImage(const QString& uri, const QString& keyHi
149149
// Remove a sky image tile from the list of background images
150150
void StelSkyLayerMgr::removeSkyLayer(const QString& key)
151151
{
152-
//qDebug() << "StelSkyLayerMgr::removeSkyImage removing image:" << key;
152+
//qDebug() << "StelSkyLayerMgr::removeSkyLayer removing image:" << key;
153+
154+
if (key=="*")
155+
{
156+
QStringList keys = getAllKeys();
157+
158+
for (auto &k : std::as_const(keys))
159+
{
160+
// TODO: This list should contain all possible names of layers that are
161+
// not inserted by scripts and therefore should not be accidentally deleted.
162+
// So far I know of Nebulae, and maybe the custom nebulae from the NebulaeTextures plugin.
163+
QStringList permanentList= {"Nebulae"};
164+
//qDebug() << "Removing SkyImage " << k;
165+
if (! permanentList.contains(k))
166+
removeSkyLayer(k);
167+
}
168+
return;
169+
}
170+
153171
if (allSkyLayers.contains(key))
154172
{
155173
SkyLayerElem* bEl = allSkyLayers[key];

src/core/StelSkyLayerMgr.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public slots:
153153
//! from scripts - use the similarly named function in the core
154154
//! scripting API object to delete SkyLayers.
155155
//! @param key the reference key (id) generated by insertSkyImage.
156+
//! @note Use "*" to remove all sky images that had been added by scripts.
156157
void removeSkyLayer(const QString& key);
157158

158159
//! Return the list of all the layer currently loaded.

src/scripting/StelMainScriptAPI.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <QTemporaryFile>
7171
#include <QTimer>
7272
#include <QEventLoop>
73+
#include <LabelMgr.hpp>
7374

7475
#include <cmath>
7576

@@ -1206,6 +1207,11 @@ void StelMainScriptAPI::clear(const QString& state)
12061207
StelMovementMgr* movmgr = GETSTELMODULE(StelMovementMgr);
12071208
ZodiacalLight* zl = GETSTELMODULE(ZodiacalLight);
12081209
StelPropertyMgr* propMgr = StelApp::getInstance().getStelPropertyManager();
1210+
LabelMgr* lMgr = GETSTELMODULE(LabelMgr);
1211+
StelSkyLayerMgr* siMgr = GETSTELMODULE(StelSkyLayerMgr);
1212+
1213+
lMgr->deleteAllLabels();
1214+
siMgr->removeSkyLayer("*");
12091215

12101216
// Hide artificial satellites through StelProperties to avoid crash if plugin was not loaded
12111217
propMgr->setStelPropertyValue("Satellites.flagHintsVisible", false, true);

0 commit comments

Comments
 (0)