Kstars

skycomposite.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "skycomposite.h"
8
9#include "skyobjects/skyobject.h"
10#include <qdebug.h>
11
15
17{
18 qDeleteAll(components());
19 m_Components.clear();
20}
21
22void SkyComposite::addComponent(SkyComponent *component, int priority)
23{
24 //qDebug() << Q_FUNC_INFO << "Adding sky component " << component << " of type " << typeid( *component ).name() << " with priority " << priority;
25 m_Components.insert(priority, component);
26 /*
27 foreach( SkyComponent *p, components() ) {
28 qDebug() << Q_FUNC_INFO << "List now has: " << p << " of type " << typeid( *p ).name();
29 }
30 */
31}
32
34{
35 // qDebug() << Q_FUNC_INFO << "Removing sky component " << component << " of type " << typeid( *component ).name();
36 for (auto it = m_Components.begin(); it != m_Components.end();)
37 {
38 if (it.value() == component)
39 it = m_Components.erase(it);
40 else
41 ++it;
42 }
43 /*
44 foreach( SkyComponent *p, components() ) {
45 qDebug() << Q_FUNC_INFO << "List now has: " << p << " of type " << typeid( *p ).name();
46 }
47 */
48}
49
51{
52 if (selected())
53 {
54 foreach (SkyComponent *component, components())
55 component->draw(skyp);
56 }
57}
58
60{
61 foreach (SkyComponent *component, components())
62 component->update(num);
63}
64
66{
67 for (const auto &oneComponent : components())
68 {
69 auto o = oneComponent->findByName(name, exact);
70 if (o)
71 return o;
72 }
73 return nullptr;
74}
75
77{
78 if (!selected())
79 return nullptr;
80 SkyObject *oBest = nullptr;
81 foreach (SkyComponent *comp, components())
82 {
83 //qDebug() << Q_FUNC_INFO << "Checking " << typeid( *comp ).name() <<" for oBest";
84 SkyObject *oTry = comp->objectNearest(p, maxrad);
85 if (oTry)
86 {
87 oBest = oTry;
88 maxrad =
89 p->angularDistanceTo(oBest).Degrees() *
90 0.95; // Set a new maxrad, smaller than original to give priority to the earlier objects in the list.
91 // qDebug() << Q_FUNC_INFO << "oBest = " << oBest << " of type " << typeid( *oTry ).name() << "; updated maxrad = " << maxrad;
92 }
93 }
94 // qDebug() << Q_FUNC_INFO << "Returning best match: oBest = " << oBest;
95 return oBest; //will be 0 if no object nearer than maxrad was found
96}
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
SkyComponent represents an object on the sky map.
virtual void draw(SkyPainter *skyp)=0
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
virtual SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Find the SkyObject nearest the given SkyPoint.
virtual void update(KSNumbers *)
Update the sky position(s) of this component.
virtual bool selected()
SkyComposite is a kind of container class for SkyComponent objects.
void addComponent(SkyComponent *comp, int priority=1024)
Add a new sub component to the composite comp Pointer to the SkyComponent to be added priority A prio...
void removeComponent(SkyComponent *const comp)
Remove a sub component from the composite comp Pointer to the SkyComponent to be removed.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Identify the nearest SkyObject to the given SkyPoint, among the children of this SkyComposite p point...
~SkyComposite() override
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComposite for a SkyObject whose name matches the argument.
void draw(SkyPainter *skyp) override
Delegate draw requests to all sub components psky Reference to the QPainter on which to paint.
void update(KSNumbers *num=nullptr) override
Delegate update-position requests to all sub components.
SkyComposite(SkyComposite *parent=nullptr)
Constructor parent pointer to the parent SkyComponent.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
The sky coordinates of a point in the sky.
Definition skypoint.h:45
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition skypoint.cpp:899
const double & Degrees() const
Definition dms.h:141
iterator begin()
void clear()
iterator end()
iterator erase(const_iterator first, const_iterator last)
iterator insert(const Key &key, const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.