Changeset View
Changeset View
Standalone View
Standalone View
kstars/skycomponents/skycomposite.h
Context not available. | |||||
15 | * * | 15 | * * | ||
---|---|---|---|---|---|
16 | ***************************************************************************/ | 16 | ***************************************************************************/ | ||
17 | 17 | | |||
18 | #ifndef SKYCOMPOSITE_H | 18 | #pragma once | ||
19 | #define SKYCOMPOSITE_H | | |||
20 | 19 | | |||
21 | #include <QList> | 20 | #include <QList> | ||
21 | #include <QMap> | ||||
22 | 22 | | |||
23 | #include "skycomponent.h" | 23 | #include "skycomponent.h" | ||
24 | 24 | | |||
25 | class KSNumbers; | 25 | class KSNumbers; | ||
26 | 26 | | |||
27 | /** | 27 | /** | ||
28 | *@class SkyComposite | 28 | * @class SkyComposite | ||
29 | *SkyComposite is a kind of container class for SkyComponent | 29 | * SkyComposite is a kind of container class for SkyComponent objects. The SkyComposite is | ||
30 | *objects. The SkyComposite is responsible for distributing calls | 30 | * responsible for distributing calls to functions like draw() and update() to its children, | ||
31 | *to functions like draw() and update() to its children, | 31 | * which can be SkyComponents or other SkyComposites with their own children. This is based | ||
32 | *which can be SkyComponents or other SkyComposites with their | 32 | * on the "composite/component" design pattern. | ||
33 | *own children. This is based on the "composite/component" | 33 | * | ||
34 | *design pattern. | 34 | * Performance tuning: Sometimes it will be better to override a virtual function and do | ||
35 | * | 35 | * the work in the composite instead of delegating the request to all sub components. | ||
36 | *Performance tuning: Sometimes it will be better to override a | 36 | * | ||
37 | *virtual function and do the work in the composite instead of | 37 | * @author Thomas Kabelmann | ||
38 | *delegating the request to all sub components. | 38 | * @version 0.1 | ||
39 | * | 39 | */ | ||
40 | *@author Thomas Kabelmann | | |||
41 | *@version 0.1 | | |||
42 | */ | | |||
43 | class SkyComposite : public SkyComponent | 40 | class SkyComposite : public SkyComponent | ||
44 | { | 41 | { | ||
45 | public: | 42 | public: | ||
46 | /** @short Constructor | 43 | /** | ||
47 | * @p parent pointer to the parent SkyComponent | 44 | * @short Constructor | ||
48 | */ | 45 | * @p parent pointer to the parent SkyComponent | ||
49 | explicit SkyComposite(SkyComposite *parent); | 46 | */ | ||
47 | explicit SkyComposite(SkyComposite *parent = nullptr); | ||||
50 | 48 | | |||
51 | /** *@short Destructor */ | 49 | /** *@short Destructor */ | ||
52 | virtual ~SkyComposite(); | 50 | virtual ~SkyComposite(); | ||
53 | 51 | | |||
54 | /** @short Delegate draw requests to all sub components | 52 | /** | ||
55 | * @p psky Reference to the QPainter on which to paint | 53 | * @short Delegate draw requests to all sub components | ||
56 | */ | 54 | * @p psky Reference to the QPainter on which to paint | ||
55 | */ | ||||
57 | void draw(SkyPainter *skyp) Q_DECL_OVERRIDE; | 56 | void draw(SkyPainter *skyp) Q_DECL_OVERRIDE; | ||
58 | 57 | | |||
59 | /** @short Delegate update-position requests to all sub components | 58 | /** | ||
60 | * | 59 | * @short Delegate update-position requests to all sub components | ||
61 | * This function usually just updates the Horizontal (Azimuth/Altitude) | 60 | * | ||
62 | * coordinates. However, the precession and nutation must also be | 61 | * This function usually just updates the Horizontal (Azimuth/Altitude) coordinates. | ||
63 | * recomputed periodically. Requests to do so are sent through the | 62 | * However, the precession and nutation must also be recomputed periodically. Requests to | ||
64 | * doPrecess parameter. | 63 | * do so are sent through the doPrecess parameter. | ||
65 | * @p num Pointer to the KSNumbers object | 64 | * @p num Pointer to the KSNumbers object | ||
66 | * @sa updatePlanets() | 65 | * @sa updatePlanets() | ||
67 | * @sa updateMoons() | 66 | * @sa updateMoons() | ||
68 | * @note By default, the num parameter is nullptr, indicating that | 67 | * @note By default, the num parameter is nullptr, indicating that Precession/Nutation | ||
69 | * Precession/Nutation computation should be skipped; this computation | 68 | * computation should be skipped; this computation is only occasionally required. | ||
70 | * is only occasionally required. | 69 | */ | ||
71 | */ | | |||
72 | void update(KSNumbers *num = 0) Q_DECL_OVERRIDE; | 70 | void update(KSNumbers *num = 0) Q_DECL_OVERRIDE; | ||
73 | 71 | | |||
74 | /** @short Add a new sub component to the composite | 72 | /** | ||
75 | * @p comp Pointer to the SkyComponent to be added | 73 | * @short Add a new sub component to the composite | ||
76 | * @p priority A priority ordering for various operations on the list of all sky components (notably objectNearest()) | 74 | * @p comp Pointer to the SkyComponent to be added | ||
77 | */ | 75 | * @p priority A priority ordering for various operations on the list of all sky components | ||
76 | * (notably objectNearest()) | ||||
77 | */ | ||||
78 | void addComponent(SkyComponent *comp, int priority = 1024); | 78 | void addComponent(SkyComponent *comp, int priority = 1024); | ||
79 | 79 | | |||
80 | /** @short Remove a sub component from the composite | 80 | /** | ||
81 | * @p comp Pointer to the SkyComponent to be removed. | 81 | * @short Remove a sub component from the composite | ||
82 | */ | 82 | * @p comp Pointer to the SkyComponent to be removed. | ||
83 | */ | ||||
83 | void removeComponent(SkyComponent *const comp); | 84 | void removeComponent(SkyComponent *const comp); | ||
84 | 85 | | |||
85 | /** @short Search the children of this SkyComposite for | 86 | /** | ||
86 | * a SkyObject whose name matches the argument. | 87 | * @short Search the children of this SkyComposite for a SkyObject whose name matches | ||
87 | * | 88 | * the argument. | ||
88 | * The objects' primary, secondary and long-form names will | 89 | * | ||
89 | * all be checked for a match. | 90 | * The objects' primary, secondary and long-form names will all be checked for a match. | ||
90 | * @p name the name to be matched | 91 | * @p name the name to be matched | ||
91 | * @return a pointer to the SkyObject whose name matches | 92 | * @return a pointer to the SkyObject whose name matches | ||
92 | * the argument, or a nullptr pointer if no match was found. | 93 | * the argument, or a nullptr pointer if no match was found. | ||
93 | */ | 94 | */ | ||
94 | SkyObject *findByName(const QString &name) Q_DECL_OVERRIDE; | 95 | SkyObject *findByName(const QString &name) Q_DECL_OVERRIDE; | ||
95 | 96 | | |||
96 | /** @short Identify the nearest SkyObject to the given SkyPoint, | 97 | /** | ||
97 | * among the children of this SkyComposite | 98 | * @short Identify the nearest SkyObject to the given SkyPoint, among the children of | ||
98 | * @p p pointer to the SkyPoint around which to search. | 99 | * this SkyComposite | ||
99 | * @p maxrad reference to current search radius | 100 | * @p p pointer to the SkyPoint around which to search. | ||
100 | * @return a pointer to the nearest SkyObject | 101 | * @p maxrad reference to current search radius | ||
101 | */ | 102 | * @return a pointer to the nearest SkyObject | ||
103 | */ | ||||
102 | SkyObject *objectNearest(SkyPoint *p, double &maxrad) Q_DECL_OVERRIDE; | 104 | SkyObject *objectNearest(SkyPoint *p, double &maxrad) Q_DECL_OVERRIDE; | ||
103 | 105 | | |||
104 | QList<SkyComponent *> components() { return m_Components.values(); } | 106 | QList<SkyComponent *> components() { return m_Components.values(); } | ||
Context not available. | |||||
108 | private: | 110 | private: | ||
109 | QMap<int, SkyComponent *> m_Components; | 111 | QMap<int, SkyComponent *> m_Components; | ||
110 | }; | 112 | }; | ||
111 | | ||||
112 | #endif | | |||
Context not available. |