Kstars

listcomponent.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Jason Harris <[email protected]>
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 
14 ListComponent::ListComponent(SkyComposite *parent) : SkyComponent(parent)
15 {
16 }
17 
18 ListComponent::~ListComponent()
19 {
20  qDeleteAll(m_ObjectList);
21  m_ObjectList.clear();
22  m_ObjectHash.clear();
23 
24  clear();
25 }
26 
27 void ListComponent::clear()
28 {
29  while (!m_ObjectList.isEmpty())
30  {
31  SkyObject *o = m_ObjectList.takeFirst();
32  removeFromNames(o);
33  delete o;
34  }
35 }
36 
38 {
39  // Append to the Object List
40  m_ObjectList.append(object);
41 
42  // Insert multiple Names
43  m_ObjectHash.insert(object->name().toLower(), object);
44  m_ObjectHash.insert(object->longname().toLower(), object);
45  m_ObjectHash.insert(object->name2().toLower(), object);
46 }
47 
49 {
50  if (!selected())
51  return;
52  KStarsData *data = KStarsData::Instance();
53  foreach (SkyObject *o, m_ObjectList)
54  {
55  if (num)
56  o->updateCoords(num);
57  o->EquatorialToHorizontal(data->lst(), data->geo()->lat());
58  }
59 }
60 
61 SkyObject *ListComponent::findByName(const QString &name, bool exact)
62 {
63  Q_UNUSED(exact)
64  return m_ObjectHash[name.toLower()]; // == nullptr if not found.
65 }
66 
68 {
69  if (!selected())
70  return nullptr;
71 
72  SkyObject *oBest = nullptr;
73  foreach (SkyObject *o, m_ObjectList)
74  {
75  double r = o->angularDistanceTo(p).Degrees();
76  if (r < maxrad)
77  {
78  oBest = o;
79  maxrad = r;
80  }
81  }
82  return oBest;
83 }
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
CachingDms * lst()
Definition: kstarsdata.h:224
virtual QString name(void) const
Definition: skyobject.h:145
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition: skypoint.cpp:77
virtual void updateCoords(const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0),...
Definition: skypoint.cpp:582
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
const CachingDms * lat() const
Definition: geolocation.h:70
GeoLocation * geo()
Definition: kstarsdata.h:230
void appendListObject(SkyObject *object)
Add an object to the Object list.
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:899
QString toLower() const const
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)
const double & Degrees() const
Definition: dms.h:141
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...
virtual QString longname(void) const
Definition: skyobject.h:164
QString name2(void) const
Definition: skyobject.h:156
void update(KSNumbers *num=nullptr) override
Update the sky positions of this component.
Information about an object in the sky.
Definition: skyobject.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Sep 27 2023 04:02:11 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.