[Kstars-devel] KDE/kdeedu/kstars/kstars
Akarsh Simha
akarshsimha at gmail.com
Tue Feb 3 20:43:31 CET 2009
SVN commit 920788 by asimha:
Making StarComponent a singleton. This makes parts of the code more
elegant.
CCMAIL: kstars-devel at kde.org
M +1 -1 finddialog.cpp
M +2 -1 skycomponents/constellationlines.cpp
M +1 -1 skycomponents/skymapcomposite.cpp
M +0 -1 skycomponents/skymapcomposite.h
M +10 -0 skycomponents/starcomponent.cpp
M +15 -2 skycomponents/starcomponent.h
--- trunk/KDE/kdeedu/kstars/kstars/finddialog.cpp #920787:920788
@@ -240,7 +240,7 @@
// Looks like the user is looking for a HD star
if( ok ) {
KStars *p = (KStars*)parent();
- obj = p->data()->skyComposite()->getStarComponent()->findByHDIndex( HD );
+ obj = StarComponent::Instance()->findByHDIndex( HD );
}
}
}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/constellationlines.cpp #920787:920788
@@ -29,6 +29,7 @@
#include "ksutils.h"
#include "skyobject.h"
#include "starobject.h"
+#include "starcomponent.h"
#include "skymap.h"
#include "skymesh.h"
@@ -113,7 +114,7 @@
lineList = new LineList();
}
- StarObject *star = (StarObject*) data->skyComposite()->getStarComponent()->findByHDIndex( HDnum );
+ StarObject *star = (StarObject*) StarComponent::Instance()->findByHDIndex( HDnum );
if ( star && lineList ) {
lineList->append( star );
double pm = star->pmMagnitude();
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.cpp #920787:920788
@@ -68,7 +68,7 @@
m_MagellanicClouds = new MagellanicClouds( this );
addComponent( m_MagellanicClouds );
//Stars must come before constellation lines
- m_Stars = new StarComponent( this );
+ m_Stars = StarComponent::Create( this );
addComponent( m_Stars );
m_CoordinateGrid = new CoordinateGrid( this );
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.h #920787:920788
@@ -182,7 +182,6 @@
int starColorMode() const;
void setStarColorIntensity( int newIntensity );
int starColorIntensity() const;
- inline StarComponent *getStarComponent() const { return m_Stars; }
virtual void emitProgressText( const QString &message );
virtual QHash<int, QStringList>& objectNames();
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #920787:920788
@@ -41,6 +41,8 @@
#include <kde_file.h>
+StarComponent *StarComponent::pinstance = 0;
+
StarComponent::StarComponent(SkyComponent *parent )
: ListComponent(parent), m_reindexNum(J2000), m_FaintMagnitude(-5.0),
starsLoaded(false), focusStar(NULL)
@@ -62,10 +64,18 @@
for ( int i = 0; i <= MAX_LINENUMBER_MAG; i++ )
m_labelList[ i ] = new LabelList;
}
+
StarComponent::~StarComponent() {
// Empty
}
+StarComponent *StarComponent::Create( SkyComponent *parent ) {
+ if( pinstance )
+ delete pinstance;
+ pinstance = new StarComponent( parent );
+ return pinstance;
+}
+
bool StarComponent::selected() {
return Options::showStars();
}
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.h #920787:920788
@@ -53,12 +53,23 @@
class StarComponent: public ListComponent
{
-public:
+ protected:
+
StarComponent( SkyComponent* );
+ public:
+
virtual ~StarComponent();
+ /**@short Create an instance of StarComponent
+ */
+ static StarComponent *Create( SkyComponent* );
+
+ /**@return the instance of StarComponent if already created, NULL otherwise
+ */
+ static StarComponent *Instance() { return pinstance; }
+
//This function is empty; we need that so that the JiT update
//is the only one beiong used.
void update( KStarsData *data, KSNumbers *num );
@@ -95,6 +106,7 @@
float faintMagnitude() const { return m_FaintMagnitude; }
+
/**
*@short Read data for stars which will remain static in the memory
*
@@ -135,7 +147,6 @@
SkyObject* findByHDIndex( int HDnum );
- // TODO: Find the right place for this method
static void byteSwap( starData *stardata );
private:
@@ -199,6 +210,8 @@
starData stardata;
starName starname;
+ static StarComponent *pinstance;
+
};
#endif
More information about the Kstars-devel
mailing list