[Kstars-devel] [kstars] kstars/skyobjects: Show date + time on solar system object trails.

Akarsh Simha akarsh at kde.org
Sun Jan 18 12:31:28 UTC 2015


Git commit 006fae742d270c43adc97dfa754197690a338f62 by Akarsh Simha.
Committed on 18/01/2015 at 12:29.
Pushed by asimha into branch 'master'.

Show date + time on solar system object trails.

This needs to be made configurable and better in general, but we now
draw labels indicating the date and time along the trail of a solar
system object (anything that is derived from KSPlanetBase).

This means, we can plot comet trajectories with date + time
annotations!  Example for Comet 2014 Q2 Lovejoy, which is currently
bright and sporting a nice tail:
http://wstaw.org/m/2015/01/18/2014Q2.gif

FEATURE
CCMAIL: kstars-devel at kde.org
GUI
DIGEST

M  +1    -1    kstars/skyobjects/ksplanetbase.cpp
M  +22   -7    kstars/skyobjects/trailobject.cpp
M  +2    -1    kstars/skyobjects/trailobject.h

http://commits.kde.org/kstars/006fae742d270c43adc97dfa754197690a338f62

diff --git a/kstars/skyobjects/ksplanetbase.cpp b/kstars/skyobjects/ksplanetbase.cpp
index a9c6b97..50bea45 100644
--- a/kstars/skyobjects/ksplanetbase.cpp
+++ b/kstars/skyobjects/ksplanetbase.cpp
@@ -130,7 +130,7 @@ void KSPlanetBase::findPosition( const KSNumbers *num, const dms *lat, const dms
         localizeCoords( num, lat, LST ); //correct for figure-of-the-Earth
 
     if ( hasTrail() ) {
-        addToTrail();
+        addToTrail( KStarsDateTime( num->getJD() ).toString( "yyyy.MM.dd hh:mm" ) + xi18nc("Universal time", "UT") ); // TODO: Localize date/time format?
         if ( Trail.size() > TrailObject::MaxTrail )
             clipTrail();
     }
diff --git a/kstars/skyobjects/trailobject.cpp b/kstars/skyobjects/trailobject.cpp
index 49897f4..1375303 100644
--- a/kstars/skyobjects/trailobject.cpp
+++ b/kstars/skyobjects/trailobject.cpp
@@ -15,16 +15,19 @@
  *                                                                         *
  ***************************************************************************/
 
-#include <QPainter>
+#include "trailobject.h"
 
-#include "Options.h"
 #include "kstarsdata.h"
 #include "skymap.h"
 #include "kspopupmenu.h"
-#include "trailobject.h"
+#include "skycomponents/skylabeler.h"
+#include "skypainter.h"
+#include "projections/projector.h"
+#include "Options.h"
+
+#include <QPainter>
 
 #include <typeinfo>
-#include "skypainter.h"
 
 QSet<TrailObject*> TrailObject::trailObjects;
 
@@ -54,20 +57,25 @@ void TrailObject::initPopupMenu( KSPopupMenu *pmenu ) {
     pmenu->createPlanetMenu( this );
 }
 
-void TrailObject::addToTrail() {
+void TrailObject::addToTrail( const QString &label ) {
     Trail.append( SkyPoint( *this ) );
+    m_TrailLabels.append( label );
     trailObjects.insert( this );
 }
 
 void TrailObject::clipTrail() {
-    if( Trail.size() )
+    if( Trail.size() ) {
         Trail.removeFirst();
-    if( Trail.size() )
+        Q_ASSERT( m_TrailLabels.size() );
+        m_TrailLabels.removeFirst();
+    }
+    if( Trail.size() ) // Eh? Shouldn't this be if( !Trail.size() ) -- asimha
         trailObjects.remove( this );
 }
 
 void TrailObject::clearTrail() {
     Trail.clear();
+    m_TrailLabels.clear();
     trailObjects.remove( this );
 }
 
@@ -93,6 +101,8 @@ void TrailObject::drawTrail(SkyPainter* skyp) const {
 
     QColor tcolor = QColor( data->colorScheme()->colorNamed( "PlanetTrailColor" ) );
     skyp->setPen( QPen(tcolor, 1) );
+    SkyLabeler *labeler = SkyLabeler::Instance();
+    labeler->setPen( tcolor );
     int n = Trail.size();
     for(int i = 1; i < n; ++i) {
         if ( Options::fadePlanetTrails() ) {
@@ -102,5 +112,10 @@ void TrailObject::drawTrail(SkyPainter* skyp) const {
         SkyPoint a = Trail[i-1];
         SkyPoint b = Trail[i];
         skyp->drawSkyLine(&a, &b);
+        if( i % 5 == 1 ) { // TODO: Make drawing of labels configurable, incl. frequency etc.
+            QPointF pt = SkyMap::Instance()->projector()->toScreen( &a );
+            labeler->drawGuideLabel( pt, m_TrailLabels[i - 1], 0.0 );
+        }
     }
+
 }
diff --git a/kstars/skyobjects/trailobject.h b/kstars/skyobjects/trailobject.h
index 686ef6d..6ef4900 100644
--- a/kstars/skyobjects/trailobject.h
+++ b/kstars/skyobjects/trailobject.h
@@ -49,7 +49,7 @@ public:
     inline const QList<SkyPoint>& trail() const { return Trail; }
 
     /** @short adds a point to the planet's trail */
-    void addToTrail();
+    void addToTrail( const QString &label = QString() );
 
     /** @short removes the oldest point from the trail */
     void clipTrail();
@@ -70,6 +70,7 @@ public:
     static const int MaxTrail = 400;
 protected:
     QList<SkyPoint> Trail;
+    QList<QString> m_TrailLabels;
     /// Store list of objects with trails.
     static QSet<TrailObject*> trailObjects;
 private:


More information about the Kstars-devel mailing list