File indexing completed on 2024-04-14 03:42:48

0001 /*
0002     SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "constellationartitem.h"
0007 
0008 #include "Options.h"
0009 #include "projections/projector.h"
0010 #include "constellationartcomponent.h"
0011 #include "skynodes/constellationartnode.h"
0012 
0013 ConstellationArtItem::ConstellationArtItem(ConstellationArtComponent *artComp, RootNode *rootNode)
0014     : SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_artComp(artComp)
0015 {
0016     loadNodes();
0017 }
0018 
0019 void ConstellationArtItem::deleteNodes()
0020 {
0021     m_artComp->deleteData();
0022     QSGNode *n = firstChild();
0023     while (n != 0)
0024     {
0025         QSGNode *d = n;
0026         n          = n->nextSibling();
0027         removeChildNode(d);
0028         delete d;
0029     }
0030 }
0031 
0032 void ConstellationArtItem::loadNodes()
0033 {
0034     m_artComp->loadData();
0035     if (!childCount())
0036     {
0037         QList<ConstellationsArt *> list = m_artComp->m_ConstList;
0038         foreach (ConstellationsArt *art, list)
0039         {
0040             ConstellationArtNode *constArt = new ConstellationArtNode(art);
0041             appendChildNode(constArt);
0042         }
0043     }
0044 }
0045 
0046 void ConstellationArtItem::update()
0047 {
0048     if (Options::showConstellationArt())
0049     {
0050         loadNodes();
0051         if (SkyMapLite::IsSlewing() == false)
0052         {
0053             show();
0054             //Traverse all children nodes of RootNode
0055             QSGNode *n = firstChild();
0056             while (n != 0)
0057             {
0058                 ConstellationArtNode *artNode = static_cast<ConstellationArtNode *>(n);
0059                 artNode->update();
0060                 n = n->nextSibling();
0061             }
0062         }
0063         else
0064         {
0065             hide();
0066         }
0067     }
0068     else
0069     {
0070         //Delete all images if we don't need to draw constellation art and save ~50 MB.
0071         deleteNodes();
0072     }
0073 }