File indexing completed on 2024-04-14 03:42:49
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "planetsitem.h" 0008 #include "projections/projector.h" 0009 #include "solarsystemsinglecomponent.h" 0010 #include "ksplanet.h" 0011 #include "planetmoonscomponent.h" 0012 0013 #include "skynodes/planetmoonsnode.h" 0014 #include "skynodes/planetnode.h" 0015 #include "Options.h" 0016 0017 PlanetsItem::PlanetsItem(QList<SolarSystemSingleComponent *> planets, 0018 /* QList<PlanetMoonsComponent *> moons, */ RootNode *rootNode) 0019 : SkyItem(LabelsItem::label_t::PLANET_LABEL, rootNode), m_planetComponents(planets) /*, m_moonsComponents(moons)*/ 0020 { 0021 foreach (SolarSystemSingleComponent *planetComp, m_planetComponents) 0022 { 0023 KSPlanetBase *planet = planetComp->planet(); 0024 PlanetMoonsNode *pNode = new PlanetMoonsNode(planet, rootNode); 0025 appendChildNode(pNode); 0026 0027 // foreach(PlanetMoonsComponent * moonsComp, m_moonsComponents) { 0028 // // Find planet of moons 0029 // if(planet == moonsComp->getPlanet()) { 0030 // pNode->addMoons(moonsComp->getMoons()); 0031 // } 0032 // } 0033 } 0034 } 0035 0036 SolarSystemSingleComponent *PlanetsItem::getParentComponent(SkyObject *planet) 0037 { 0038 foreach (SolarSystemSingleComponent *planetComp, m_planetComponents) 0039 { 0040 if (planetComp->planet() == planet) 0041 return planetComp; 0042 } 0043 return nullptr; 0044 } 0045 0046 void PlanetsItem::update() 0047 { 0048 show(); 0049 //Traverse all children nodes of RootNode 0050 QSGNode *n = firstChild(); 0051 while (n != 0) 0052 { 0053 PlanetMoonsNode *pNode = static_cast<PlanetMoonsNode *>(n); 0054 n = n->nextSibling(); 0055 0056 bool selected = getParentComponent(pNode->skyObject())->selected(); 0057 if (selected) 0058 pNode->update(); 0059 else 0060 pNode->hide(); 0061 } 0062 } 0063 0064 void PlanetsItem::show() 0065 { 0066 rootNode()->labelsItem()->getLabelNode(LabelsItem::label_t::JUPITER_MOON_LABEL)->show(); 0067 SkyItem::show(); 0068 } 0069 0070 void PlanetsItem::hide() 0071 { 0072 rootNode()->labelsItem()->getLabelNode(LabelsItem::label_t::JUPITER_MOON_LABEL)->hide(); 0073 SkyItem::hide(); 0074 }