Kstars

listcomponent.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Jason Harris <kstars@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "listcomponent.h"
8
9#include "kstarsdata.h"
10#ifndef KSTARS_LITE
11#include "skymap.h"
12#endif
13
14ListComponent::ListComponent(SkyComposite *parent) : SkyComponent(parent)
15{
16}
17
18ListComponent::~ListComponent()
19{
20 clear();
21}
22
23void ListComponent::clear()
24{
25 qDeleteAll(m_ObjectList);
26 m_ObjectList.clear();
27 m_ObjectHash.clear();
28}
29
31{
32 // Append to the Object List
33 m_ObjectList.append(object);
34
35 // Insert multiple Names
36 m_ObjectHash.insert(object->name().toLower(), object);
37 m_ObjectHash.insert(object->longname().toLower(), object);
38 m_ObjectHash.insert(object->name2().toLower(), object);
39}
40
42{
43 if (!selected())
44 return;
45 auto data = KStarsData::Instance();
46 for (auto &object : m_ObjectList)
47 {
48 if (num)
49 object->updateCoords(num);
50 object->EquatorialToHorizontal(data->lst(), data->geo()->lat());
51 }
52}
53
55{
56 auto object = m_ObjectHash[name.toLower()];
57 if (object)
58 return object;
59 else if (!exact)
60 {
61 auto object = std::find_if(m_ObjectHash.begin(), m_ObjectHash.end(), [name](const auto & oneObject)
62 {
63 return oneObject && oneObject->name().contains(name, Qt::CaseInsensitive);
64 });
65 if (object != m_ObjectHash.end())
66 return *object;
67 }
68
69 return nullptr;
70}
71
72SkyObject *ListComponent::objectNearest(SkyPoint *p, double &maxrad)
73{
74 if (!selected())
75 return nullptr;
76
77 SkyObject *oBest = nullptr;
78 for (auto &object : m_ObjectList)
79 {
80 double r = object->angularDistanceTo(p).Degrees();
81 if (r < maxrad)
82 {
83 oBest = object;
84 maxrad = r;
85 }
86 }
87 return oBest;
88}
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
void appendListObject(SkyObject *object)
Add an object to the Object list.
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComponent for a SkyObject whose name matches the argument name the nam...
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
void update(KSNumbers *num=nullptr) override
Update the sky positions of this component.
SkyComponent represents an object on the sky map.
virtual bool selected()
SkyComposite is a kind of container class for SkyComponent objects.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
virtual QString name(void) const
Definition skyobject.h:146
virtual QString longname(void) const
Definition skyobject.h:165
QString name2(void) const
Definition skyobject.h:157
iterator begin()
void clear()
iterator end()
iterator insert(const Key &key, const T &value)
void append(QList< T > &&value)
void clear()
QString toLower() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:57:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.