[Kstars-devel] [kstars] kstars: KStarsData should not call methods on SkyMap, but only emit signals.

Akarsh Simha akarsh at kde.org
Wed May 13 10:30:00 UTC 2015


Git commit e3e9a08d75e372f5acd7b6bf09a6f62495f350ab by Akarsh Simha.
Committed on 13/05/2015 at 10:31.
Pushed by asimha into branch 'master'.

KStarsData should not call methods on SkyMap, but only emit signals.

KStarsData is a class that handles the simulation state and data. We
would not want it to have anything to do with SkyMap, which is a way
of rendering the view of the sky, and allowing the user to interact
with it.

So instead of calling methods on SkyMap and having a SkyMap pointer
passed around to its methods, KStarsData should only emit signals
every time the sky map needs to be updated.

This is just one baby step towards the ultimate, grand goal of
decoupling the computational aspects of KStars from the interface,
that many of us have had in mind. I might consider attempting pieces
of this gargantuan task since I have a personal interest -- the dream
of running a KStars engine on a server without X11, with an interface
that is web based, so that KStars can run as an astronomy computation
service. Whether this dream will be a reality or not is to be seen,
and its success is severely constrained by what little time we
developers have at our disposal.

What I want to start with, is to build on the old "--dump" command
line option that we had working in the past (doesn't seem to be
working now), that would dump an image of the sky without opening the
KStars window etc. However, the old way of doing dump required
SkyMap. Really, SkyMap should not be in the picture. If all I want is
an image of the sky, the user is not in a position to interact, so why
have an interactive SkyMap involved?

Comments and contributions towards this goal are welcome. I hope this
commit is one of many that will lead towards this goal.

CCMAIL: kstars-devel at kde.org

M  +1    -2    kstars/kstars.cpp
M  +3    -9    kstars/kstarsdata.cpp
M  +4    -4    kstars/kstarsdata.h
M  +12   -0    kstars/skymap.cpp
M  +6    -0    kstars/skymap.h

http://commits.kde.org/kstars/e3e9a08d75e372f5acd7b6bf09a6f62495f350ab

diff --git a/kstars/kstars.cpp b/kstars/kstars.cpp
index 936ef31..62c7a4d 100644
--- a/kstars/kstars.cpp
+++ b/kstars/kstars.cpp
@@ -345,10 +345,9 @@ void KStars::updateTime( const bool automaticDSTchange ) {
     // Save options and geo() to a pointer would not speedup because most of time options
     // and geo will accessed only one time.
     KStarsData *Data = data();
-    SkyMap *Map = map();
     // dms oldLST( Data->lst()->Degrees() );
 
-    Data->updateTime( Data->geo(), Map, automaticDSTchange );
+    Data->updateTime( Data->geo(), automaticDSTchange );
 
     //We do this outside of kstarsdata just to get the coordinates
     //displayed in the infobox to update every second.
diff --git a/kstars/kstarsdata.cpp b/kstars/kstarsdata.cpp
index 831fa7c..74a1090 100644
--- a/kstars/kstarsdata.cpp
+++ b/kstars/kstarsdata.cpp
@@ -184,7 +184,7 @@ bool KStarsData::initialize() {
     return true;
 }
 
-void KStarsData::updateTime( GeoLocation *geo, SkyMap *skymap, const bool automaticDSTchange ) {
+void KStarsData::updateTime( GeoLocation *geo, const bool automaticDSTchange ) {
     // sync LTime with the simulation clock
     LTime = geo->UTtoLT( ut() );
     syncLST();
@@ -228,15 +228,9 @@ void KStarsData::updateTime( GeoLocation *geo, SkyMap *skymap, const bool automa
     if ( fabs( ut().djd() - LastSkyUpdate.djd() ) > 0.1/Options::zoomFactor() || clock()->isManualMode() ) {
         LastSkyUpdate = ut();
         m_preUpdateID++;
-        skyComposite()->update(); //omit KSNumbers arg == just update Alt/Az coords
+        skyComposite()->update(); //omit KSNumbers arg == just update Alt/Az coords // <-- Eh? -- asimha. Looks like this behavior / ideology has changed drastically.
 
-        //Update focus
-        skymap->updateFocus();
-
-        if ( clock()->isManualMode() )
-            QTimer::singleShot( 0, skymap, SLOT( forceUpdateNow() ) );
-        else
-            skymap->forceUpdate();
+        emit skyUpdate( clock()->isManualMode() );
     }
 }
 
diff --git a/kstars/kstarsdata.h b/kstars/kstarsdata.h
index 3393d0d..69cec9e 100644
--- a/kstars/kstarsdata.h
+++ b/kstars/kstarsdata.h
@@ -233,7 +233,7 @@ signals:
     void progressText( const QString& );
 
     /** Should be used to refresh skymap. */
-    void update();
+    void skyUpdate( bool );
 
     /** If data changed, emit clearCache signal. */
     void clearCache();
@@ -246,14 +246,14 @@ public slots:
     void slotConsoleMessage( QString s ) { std::cout << (const char*)(s.toLocal8Bit()) << std::endl; }
 
     /**Update the Simulation Clock.  Update positions of Planets.  Update
-     * Alt/Az coordinates of objects.  Update precession.  Update Focus position.
-     * Draw new Skymap.
+     * Alt/Az coordinates of objects.  Update precession.
+     * emit the skyUpdate() signal so that SkyMap / whatever draws the sky can update itself
      *
      * This is ugly.
      * It _will_ change!
      * (JH:)hey, it's much less ugly now...can we lose the comment yet? :p
      */
-    void updateTime(GeoLocation *geo, SkyMap * skymap, const bool automaticDSTchange = true);
+    void updateTime(GeoLocation *geo, const bool automaticDSTchange = true);
 
     /**Sets the direction of time and stores it in bool TimeRunForwards. If scale >= 0
      * time is running forward else time runs backward. We need this to calculate just
diff --git a/kstars/skymap.cpp b/kstars/skymap.cpp
index 6630f9d..8bb210d 100644
--- a/kstars/skymap.cpp
+++ b/kstars/skymap.cpp
@@ -181,6 +181,7 @@ SkyMap::SkyMap() :
 
     connect( &m_HoverTimer,   SIGNAL( timeout() ), this, SLOT( slotTransientLabel() ) );
     connect( this, SIGNAL( destinationChanged() ), this, SLOT( slewFocus() ) );
+    connect( KStarsData::Instance(), SIGNAL( skyUpdate( bool ) ), this, SLOT( slotUpdateSky( bool ) ) );
 
     // Time infobox
     m_timeBox = new InfoBoxWidget( Options::shadeTimeBox(),
@@ -425,6 +426,17 @@ void SkyMap::slotCenter() {
     showFocusCoords(); //update FocusBox
 }
 
+void SkyMap::slotUpdateSky( bool now ) {
+    // Code moved from KStarsData::updateTime()
+    //Update focus
+    updateFocus();
+
+    if ( now )
+        QTimer::singleShot( 0, this, SLOT( forceUpdateNow() ) ); // Why is it done this way rather than just calling forceUpdateNow()? -- asimha
+    else
+        forceUpdate();
+}
+
 void SkyMap::slotDSS() {
     dms ra(0.0), dec(0.0);
     QString urlstring;
diff --git a/kstars/skymap.h b/kstars/skymap.h
index b82b3c4..b799331 100644
--- a/kstars/skymap.h
+++ b/kstars/skymap.h
@@ -305,6 +305,12 @@ public slots:
      */
     void forceUpdateNow() { forceUpdate( true ); }
 
+    /**
+     * @short Update the focus point and call forceUpdate()
+     * @param now is passed on to forceUpdate()
+     */
+    void slotUpdateSky( bool now );
+
     /** Toggle visibility of geo infobox */
     void slotToggleGeoBox(bool);
 


More information about the Kstars-devel mailing list