[Kstars-devel] KDE/kdeedu/kstars/kstars

Akarsh Simha akarshsimha at gmail.com
Sat May 9 00:52:53 CEST 2009


SVN commit 965445 by asimha:

Making the KStars class a singleton.

TODO: Get rid of all those KStars* pointers being passed around

CCMAIL: kstars-devel at kde.org



 M  +9 -0      kstars.cpp  
 M  +40 -16    kstars.h  
 M  +1 -1      main.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/kstars.cpp #965444:965445
@@ -57,6 +57,8 @@
 #include "indi/imagesequence.h"
 #endif
 
+KStars *KStars::pinstance = 0;
+
 KStars::KStars( bool doSplash, bool clockrun, const QString &startdate ) :
         KXmlGuiWindow(), kstarsData(0), splash(0), skymap(0), TimeStep(0),
         colorActionMenu(0), fovActionMenu(0),
@@ -125,6 +127,13 @@
 #endif
 }
 
+KStars *KStars::createInstance( bool doSplash, bool clockrun, const QString &startdate ) {
+    if( pinstance )
+        delete pinstance;
+    pinstance = new KStars( doSplash, clockrun, startdate );
+    return pinstance;
+}
+
 KStars::~KStars()
 {
     delete kstarsData;
--- trunk/KDE/kdeedu/kstars/kstars/kstars.h #965444:965445
@@ -62,31 +62,55 @@
 #endif
 
 /**
-	*@class KStars
-	*@short This is the main window for KStars.
-	*In addition to the GUI elements, the class contains the program clock,
-	*KStarsData, and SkyMap objects.  It also contains functions for the DCOP interface.
-	*@author Jason Harris
-	*@version 1.0
-	*/
+ *@class KStars
+ *@short This is the main window for KStars.
+ *In addition to the GUI elements, the class contains the program clock,
+ *KStarsData, and SkyMap objects.  It also contains functions for the D-Bus interface.
+ *@author Jason Harris
+ *@version 1.0
+ */
 
+// KStars is now a singleton class. Use KStars::createInstance() to
+// create an instance and KStars::Instance() to get a pointer to the
+// instance
+// asimha, 9th May 2009
+
 class KStars : public KXmlGuiWindow
 {
     Q_OBJECT
     Q_CLASSINFO("D-Bus Interface", "org.kde.kstars")
 
-public:
+private:
     /**
-    	*@short Constructor.
-    	*@param doSplash should the splash panel be displayed during
-    	*initialization.
-    	*@param startClockRunning should the clock be running on startup?
-    	*@param startDateString date (in string representation) to start running from.
-    	*
-    	* @todo Refer to documentation on date format.
-    	*/
+     *@short Constructor.
+     *@param doSplash should the splash panel be displayed during
+     *initialization.
+     *@param startClockRunning should the clock be running on startup?
+     *@param startDateString date (in string representation) to start running from.
+     *
+     * @todo Refer to documentation on date format.
+     */
     explicit KStars( bool doSplash, bool startClockRunning = true, const QString &startDateString = QString() );
 
+    static KStars *pinstance; // Pointer to an instance of KStars
+
+public:
+
+    /**
+     *@short Create an instance of this class. Destroy any previous instance
+     *@param doSplash
+     *@param clockrunning
+     *@param startDateString
+     *@note See KStars::KStars for details on parameters
+     *@return a pointer to the instance
+     */
+    static KStars *createInstance( bool doSplash, bool clockrunning = true, const QString &startDateString = QString() );
+
+    /**
+     *@return a pointer to the instance of this class
+     */
+    inline static KStars *Instance() { return pinstance; }
+
     /**Destructor.  Synchs config file.  Deletes objects.
     	*/
     ~KStars();
--- trunk/KDE/kdeedu/kstars/kstars/main.cpp #965444:965445
@@ -181,7 +181,7 @@
         datestring.clear();
     }
 
-    new KStars( true, ! args->isSet( "paused" ), datestring );
+    KStars::createInstance( true, ! args->isSet( "paused" ), datestring );
     args->clear();
     QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
     return a.exec();


More information about the Kstars-devel mailing list