[Kstars-devel] [kstars/altvstime] kstars/tools: Altvstime tool implemented with QCustomPlot library - Compute Altitude by Time Button

Raphael Cojocaru raphael.cojocaru at yahoo.com
Tue Feb 16 18:12:44 UTC 2016


Git commit d028297081424bc5afdae090b8a0b258f50e7ab2 by Raphael Cojocaru.
Committed on 16/02/2016 at 17:49.
Pushed by raphaelc into branch 'altvstime'.

Altvstime tool implemented with QCustomPlot library - Compute Altitude by Time Button
As my previous commit presents, now is available a very easy way to get the information from the curve. All the user needs to do is to right-click on a point on the curve and a tooltip ( information box ) will show up.
In this commit I added the Local Sidereal Time ( LST ) in the tooltip. It contains now the Local Sidereal Time ( LST ), Local Time ( LT ) and Altitude.
I also implemented an useful way to get the Altitude for a certain moment of time. You need to select the hour and minutes and then press the "Compute" button. The skyobject can be selected directly from the PlotList. This brings more flexibility to Altvstime tool.

I attach here a short videoclip for a better understanding:
https://www.youtube.com/watch?v=25P9tPxJECs

CCMAIL: kstars-devel at kde.org

M  +57   -6    kstars/tools/altvstime.cpp
M  +8    -0    kstars/tools/altvstime.h
M  +151  -28   kstars/tools/altvstime.ui

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

diff --git a/kstars/tools/altvstime.cpp b/kstars/tools/altvstime.cpp
index cab28c8..396707d 100644
--- a/kstars/tools/altvstime.cpp
+++ b/kstars/tools/altvstime.cpp
@@ -150,6 +150,7 @@ AltVsTime::AltVsTime( QWidget* parent)  :
     connect( avtUI->longBox, SIGNAL( returnPressed() ), this, SLOT( slotAdvanceFocus() ) );
     connect( avtUI->latBox,  SIGNAL( returnPressed() ), this, SLOT( slotAdvanceFocus() ) );
     connect( avtUI->PlotList, SIGNAL( currentRowChanged(int) ), this, SLOT( slotHighlight(int) ) );
+    connect( avtUI->computeButton, SIGNAL( clicked() ), this, SLOT( slotComputeAltitudeByTime() ) );
 
     setMouseTracking( true );
 }
@@ -398,8 +399,8 @@ void AltVsTime::plotMousePress(QCPAbstractPlottable *abstractPlottable, QMouseEv
             if(graph){
                 double key = 0;
                 double value = 0;
-                QTime time(2,0,0,0);
-
+                QTime localTime(2,0,0,0);
+                QTime localSiderealTime(7,0,0,0);
                 bool ok = false;
                 double m = std::numeric_limits<double>::max();
 
@@ -415,7 +416,8 @@ void AltVsTime::plotMousePress(QCPAbstractPlottable *abstractPlottable, QMouseEv
                 }
 
                 if(ok){
-                    time = time.addSecs(int(key));
+                    localTime = localTime.addSecs(int(key));
+                    localSiderealTime = localSiderealTime.addSecs(int(key));
                     QToolTip::hideText();
                     QToolTip::showText(event->globalPos(),
                     tr("<table>"
@@ -423,14 +425,18 @@ void AltVsTime::plotMousePress(QCPAbstractPlottable *abstractPlottable, QMouseEv
                            "<th colspan=\"2\">%L1</th>"
                          "</tr>"
                          "<tr>"
-                           "<td>Time:   </td>" "<td>%L2</td>"
+                           "<td>LST:   </td>" "<td>%L3</td>"
                          "</tr>"
+                       "<tr>"
+                         "<td>LT:   </td>" "<td>%L2</td>"
+                       "</tr>"
                          "<tr>"
-                           "<td>Altitude:   </td>" "<td>%L3</td>"
+                           "<td>Altitude:   </td>" "<td>%L4</td>"
                          "</tr>"
                        "</table>").
                        arg(graph->name().isEmpty() ? "???" : graph->name()).
-                       arg(time.toString()).
+                       arg(localTime.toString()).
+                       arg(localSiderealTime.toString()).
                        arg(value),
                        avtUI->View, avtUI->View->rect());
                 }
@@ -493,6 +499,51 @@ void AltVsTime::slotClearBoxes() {
     avtUI->epochName->clear();
 }
 
+void AltVsTime::slotComputeAltitudeByTime(){
+    // check if at least one graph exists in the plot
+    if( avtUI->View->graphCount() > 0 ){
+        // get the time from the time spin box
+        QTime timeFormat = avtUI->timeSpin->time();
+        double hours = timeFormat.hour();
+        double minutes = timeFormat.minute();
+        // convert the hours over 24 to correct their values
+        if( hours < 14 )
+            hours += 24;
+        hours -= 2;
+        double timeValue = hours * 3600 + minutes * 60;
+        QCPGraph *selectedGraph;
+        // get the graph's name from the name box
+        QString graphName = avtUI->nameBox->text();
+        // find the graph index
+        int graphIndex = 0;
+        for( int i=0;i<avtUI->View->graphCount();i++ )
+            if( avtUI->View->graph(i)->name().compare(graphName) == 0 ){
+                graphIndex = i;
+                break;
+             }
+        selectedGraph = avtUI->View->graph(graphIndex);
+        // get the data from the selected graph
+        QCPDataMap *dataMap = selectedGraph->data();
+        double averageAltitude = 0;
+        double altitude1 = dataMap->lowerBound(timeValue-899).value().value;
+        double altitude2 = dataMap->lowerBound(timeValue).value().value;
+        double time1 = dataMap->lowerBound(timeValue-899).value().key;
+        averageAltitude = (altitude1+altitude2)/2;
+        // short algorithm to compute the right altitude for a certain time
+        if( timeValue > time1 ){
+            if( timeValue - time1 < 225 )
+                averageAltitude = altitude1;
+            else
+                if( timeValue - time1 < 675 )
+                    averageAltitude = (altitude1+altitude2)/2;
+                else
+                    averageAltitude = altitude2;
+        }
+        // set the altitude in the altitude box
+        avtUI->altitudeBox->setText( QString::number(averageAltitude) );
+    }
+}
+
 void AltVsTime::computeSunRiseSetTimes() {
     //Determine the time of sunset and sunrise for the desired date and location
     //expressed as doubles, the fraction of a full day.
diff --git a/kstars/tools/altvstime.h b/kstars/tools/altvstime.h
index be178a6..b2a3364 100644
--- a/kstars/tools/altvstime.h
+++ b/kstars/tools/altvstime.h
@@ -117,10 +117,18 @@ public slots:
     /** @short Clear the list of displayed objects. */
     void slotClear();
 
+    /** @short Show information from the curve as a tooltip. */
     void plotMousePress(QCPAbstractPlottable *abstractPlottable, QMouseEvent *event);
+
+    /** @short Update the X axis on Zoom and Drag. */
     void onXRangeChanged(const QCPRange &range);
+
+     /** @short Update the Y axis on Zoom and Drag. */
     void onYRangeChanged(const QCPRange &range);
 
+    /** @short Compute the altitude for a certain time. */
+    void slotComputeAltitudeByTime();
+
     /** @short Clear the edit boxes for specifying a new object. */
     void slotClearBoxes();
 
diff --git a/kstars/tools/altvstime.ui b/kstars/tools/altvstime.ui
index 2d77e07..1a91b01 100644
--- a/kstars/tools/altvstime.ui
+++ b/kstars/tools/altvstime.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>607</width>
-    <height>608</height>
+    <width>452</width>
+    <height>529</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -28,9 +28,14 @@
        <height>325</height>
       </size>
      </property>
+     <zorder>tabWidget2</zorder>
+     <zorder>tabWidget2</zorder>
+     <zorder>tabWidget2</zorder>
+     <zorder>tabWidget2</zorder>
+     <zorder>tabWidget2</zorder>
     </widget>
    </item>
-   <item>
+   <item alignment="Qt::AlignTop">
     <widget class="QTabWidget" name="tabWidget2">
      <property name="sizePolicy">
       <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
@@ -102,37 +107,34 @@
           </widget>
          </item>
          <item row="1" column="1" colspan="2">
-          <widget class="dmsBox" name="raBox"/>
-         </item>
-         <item row="1" column="3">
-          <widget class="QPushButton" name="addButton">
+          <widget class="dmsBox" name="raBox">
+           <property name="enabled">
+            <bool>true</bool>
+           </property>
            <property name="sizePolicy">
-            <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
-           <property name="text">
-            <string>Plot</string>
-           </property>
           </widget>
          </item>
-         <item row="2" column="0">
-          <widget class="QLabel" name="textLabel4">
+         <item row="2" column="1" colspan="2">
+          <widget class="dmsBox" name="decBox"/>
+         </item>
+         <item row="1" column="3">
+          <widget class="QPushButton" name="addButton">
            <property name="sizePolicy">
-            <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+            <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
            <property name="text">
-            <string>Dec:</string>
+            <string>Plot</string>
            </property>
           </widget>
          </item>
-         <item row="2" column="1" colspan="2">
-          <widget class="dmsBox" name="decBox"/>
-         </item>
          <item row="2" column="3">
           <widget class="QPushButton" name="clearFieldsButton">
            <property name="sizePolicy">
@@ -152,10 +154,16 @@
            </property>
           </widget>
          </item>
-         <item row="3" column="0">
-          <widget class="QLabel" name="textLabel3">
+         <item row="2" column="0">
+          <widget class="QLabel" name="textLabel4">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
            <property name="text">
-            <string>Equinox:</string>
+            <string>Dec:</string>
            </property>
           </widget>
          </item>
@@ -175,6 +183,26 @@
            </property>
           </widget>
          </item>
+         <item row="3" column="3">
+          <widget class="QPushButton" name="clearButton">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
+           <property name="text">
+            <string>Clear List</string>
+           </property>
+          </widget>
+         </item>
+         <item row="3" column="0">
+          <widget class="QLabel" name="textLabel3">
+           <property name="text">
+            <string>Equinox:     </string>
+           </property>
+          </widget>
+         </item>
          <item row="3" column="2">
           <spacer>
            <property name="orientation">
@@ -188,27 +216,122 @@
            </property>
           </spacer>
          </item>
-         <item row="3" column="3">
-          <widget class="QPushButton" name="clearButton">
+         <item row="0" column="4" rowspan="4">
+          <widget class="QListWidget" name="PlotList">
            <property name="sizePolicy">
-            <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+            <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout">
+         <property name="spacing">
+          <number>6</number>
+         </property>
+         <property name="sizeConstraint">
+          <enum>QLayout::SetNoConstraint</enum>
+         </property>
+         <item>
+          <widget class="QLabel" name="timeLabel">
+           <property name="text">
+            <string>Local Time:</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QDateTimeEdit" name="timeSpin">
+           <property name="minimumDate">
+            <date>
+             <year>2000</year>
+             <month>1</month>
+             <day>1</day>
+            </date>
+           </property>
+           <property name="currentSection">
+            <enum>QDateTimeEdit::HourSection</enum>
+           </property>
+           <property name="displayFormat">
+            <string>HH:mm</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="horizontalSpacer">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeType">
+            <enum>QSizePolicy::Fixed</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>53</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <widget class="QPushButton" name="computeButton">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+             <horstretch>108</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
            <property name="text">
-            <string>Clear List</string>
+            <string>    Compute    </string>
            </property>
           </widget>
          </item>
-         <item row="0" column="4" rowspan="4">
-          <widget class="QListWidget" name="PlotList">
+         <item>
+          <spacer name="horizontalSpacer_2">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>20</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <widget class="QLabel" name="altitudeLabel">
            <property name="sizePolicy">
-            <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+            <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
              <horstretch>0</horstretch>
              <verstretch>0</verstretch>
             </sizepolicy>
            </property>
+           <property name="text">
+            <string>Altitude: </string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QLineEdit" name="altitudeBox">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+             <horstretch>150</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
+           <property name="minimumSize">
+            <size>
+             <width>0</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string>                                            </string>
+           </property>
           </widget>
          </item>
         </layout>


More information about the Kstars-devel mailing list