Kstars

cometsitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "cometsitem.h"
7 
8 #include "Options.h"
9 #include "projections/projector.h"
10 #include "kscomet.h"
11 
12 #include "rootnode.h"
13 #include "labelsitem.h"
14 #include "skylabeler.h"
15 
16 #include "skynodes/pointsourcenode.h"
17 
18 CometsItem::CometsItem(const QList<SkyObject *> &cometsList, RootNode *rootNode)
19  : SkyItem(LabelsItem::label_t::COMET_LABEL, rootNode), m_cometsList(cometsList)
20 {
21  recreateList();
22 }
23 
25 {
26  if (Options::zoomFactor() < 10 * MINZOOM)
27  {
28  hide();
29  return;
30  }
31 
32  show();
33 
34  bool hideLabel = !Options::showCometNames() || (SkyMapLite::Instance()->isSlewing() && Options::hideLabels());
35 
36  if (hideLabel)
37  {
38  hideLabels();
39  }
40  double rsunLabelLimit = Options::maxRadCometName();
41 
42  /*//FIXME: Should these be config'able?
43  skyp->setPen( QPen( QColor( "darkcyan" ) ) );
44  skyp->setBrush( QBrush( QColor( "darkcyan" ) ) );*/
45 
46  //Traverse all children nodes
47  QSGNode *n = firstChild();
48  while (n != 0)
49  {
50  SkyNode *skyNode = static_cast<SkyNode *>(n);
51  n = n->nextSibling();
52 
53  //TODO: Might be better move it to PointSourceNode
54  KSComet *com = static_cast<KSComet *>(skyNode->skyObject());
55  double mag = com->mag();
56  if (std::isnan(mag) == 0)
57  {
58  bool drawLabel = false;
59  if (!(hideLabel || com->rsun() >= rsunLabelLimit))
60  {
61  drawLabel = true;
62  }
63  skyNode->update(drawLabel);
64  }
65  else
66  {
67  skyNode->hide();
68  }
69  }
70 }
71 
73 {
74  //Delete all child nodes
75  while (QSGNode *n = firstChild())
76  {
77  removeChildNode(n);
78  delete n;
79  }
80 
81  foreach (SkyObject *comet, m_cometsList)
82  {
83  KSComet *com = static_cast<KSComet *>(comet);
85  }
86 }
A base class that is used for displaying SkyComponents on SkyMapLite.
Definition: skyitem.h:29
bool isSlewing() const
Definition: skymaplite.cpp:804
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
LabelsItem::label_t labelType()
Definition: skyitem.h:60
virtual void update() override
Determines the visibility of the object and its label and hides/updates them accordingly.
Definition: cometsitem.cpp:24
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
A subclass of KSPlanetBase that implements comets.
Definition: kscomet.h:43
double rsun() const
Definition: ksplanetbase.h:130
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition: skynode.h:48
float mag() const
Definition: skyobject.h:206
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
virtual void show() override
makes this node visible
Definition: skyitem.cpp:23
CometsItem(const QList< SkyObject * > &cometsList, RootNode *rootNode=nullptr)
Constructor.
Definition: cometsitem.cpp:18
A SkyNode derived class that represents stars and objects that are drawn as stars.
virtual void hide() override
hides this item and corresponding labels
Definition: skyitem.cpp:37
void recreateList()
recreates the node tree (deletes old nodes and appends new ones according to m_cometsList)
Definition: cometsitem.cpp:72
SkyObject * skyObject() const
returns SkyObject associated with this SkyNode
Definition: skynode.h:86
RootNode * rootNode()
Definition: skyitem.h:57
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
QSGNode * nextSibling() const const
Information about an object in the sky.
Definition: skyobject.h:41
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
void removeChildNode(QSGNode *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.