[Kstars-devel] RFC: Refactoring of SkyMap
Thomas Kabelmann
thomas.kabelmann at gmx.de
Wed Jul 27 14:02:00 CEST 2005
Hi everyone,
while looking in the code of current svn head, I found that class SkyMap is a
big mess. A "wc -l skymap*" says that ~5000 lines are in that class (comments
and free lines included).
My idea for refactoring the class is following:
- split SkyMap into SkyMap + SkyMapElements
- SkyMap stores all data like focus and so on
- SkyMapElement is an interface for all drawable elements (like horizon,
milkyway, ...)
- each element implements this interface so the skymap can store all elements
in a list -- the advantage is, skymap doesn't need a member variable for each
element and adding new elements just require to add this in the implemenation
of skymap, not in the interface
Here is some pseudo code for sketching my idea:
class SkyMap
{
...
SkyMap() {
elementList = new QList();
elementList.add(new Horizon());
...
elementList.add(new CoordinatGrid());
}
QList elementList;
paintEvent()
{
foreach (element in elementList)
element->draw();
}
}
class SkyMapElement
{
SkyMap *map;
public:
SkyMapElement(SkyMap *m) { map = m; }
virtual void draw() = 0;
}
class Horizon : SkyMapElement
{
void draw()
{
if (!Options::drawHorizon) return;
// insert drawing code here
}
}
The API is perhaps not complete, it's just an idea at this time. Any ideas,
comments?
Regards,
Thomas
More information about the Kstars-devel
mailing list