[kstars] kstars: QDateTime setUtcOffset is deprecated since Qt v5.2 so ought to move away from it and we are now using timespec instead. I made the necessary changes where I can find them, please investigate if I missed other places within the code as well.

Jasem Mutlaq null at kde.org
Fri Aug 11 16:42:00 UTC 2017


Git commit 8d85c265b9e143cd3de171179c9c92762a663bb2 by Jasem Mutlaq.
Committed on 11/08/2017 at 16:39.
Pushed by mutlaqja into branch 'master'.

QDateTime setUtcOffset is deprecated since Qt v5.2 so ought to move away from it and we are now using timespec instead. I made the necessary changes where I can find them, please investigate if I missed other places within the code as well.

CCMAIL:kstars-devel at kde.org

M  +6    -2    kstars/auxiliary/geolocation.cpp
M  +8    -1    kstars/ekos/scheduler/scheduler.cpp
M  +16   -12   kstars/time/kstarsdatetime.cpp
M  +1    -1    kstars/time/kstarsdatetime.h

https://commits.kde.org/kstars/8d85c265b9e143cd3de171179c9c92762a663bb2

diff --git a/kstars/auxiliary/geolocation.cpp b/kstars/auxiliary/geolocation.cpp
index 6375e2b91..ef142f88a 100644
--- a/kstars/auxiliary/geolocation.cpp
+++ b/kstars/auxiliary/geolocation.cpp
@@ -202,7 +202,9 @@ void GeoLocation::setReadOnly(bool value)
 KStarsDateTime GeoLocation::UTtoLT(const KStarsDateTime &ut) const
 {
     KStarsDateTime lt = ut.addSecs(int(3600. * TZ()));
-    lt.setUtcOffset(int(3600. * TZ()));
+    // 2017-08-11 (Jasem): setUtcOffset is deprecated
+    //lt.setUtcOffset(int(3600. * TZ()));
+    lt.setTimeSpec(Qt::LocalTime);
 
     return lt;
 }
@@ -210,7 +212,9 @@ KStarsDateTime GeoLocation::UTtoLT(const KStarsDateTime &ut) const
 KStarsDateTime GeoLocation::LTtoUT(const KStarsDateTime &lt) const
 {
     KStarsDateTime ut = lt.addSecs(int(-3600. * TZ()));
-    ut.setUtcOffset(0);
+    ut.setTimeSpec(Qt::UTC);
+    // 2017-08-11 (Jasem): setUtcOffset is deprecated
+    //ut.setUtcOffset(0);
 
     return ut;
 }
diff --git a/kstars/ekos/scheduler/scheduler.cpp b/kstars/ekos/scheduler/scheduler.cpp
index 451416736..388c31587 100644
--- a/kstars/ekos/scheduler/scheduler.cpp
+++ b/kstars/ekos/scheduler/scheduler.cpp
@@ -1491,7 +1491,7 @@ void Scheduler::wakeUpScheduler()
 double Scheduler::findAltitude(const SkyPoint &target, const QDateTime &when)
 {
     // Make a copy
-    SkyPoint p = target;
+    /*SkyPoint p = target;
     QDateTime lt(when.date(), QTime());
     KStarsDateTime ut = KStarsData::Instance()->geo()->LTtoUT(KStarsDateTime(lt));
 
@@ -1500,6 +1500,13 @@ double Scheduler::findAltitude(const SkyPoint &target, const QDateTime &when)
     CachingDms LST = KStarsData::Instance()->geo()->GSTtoLST(myUT.gst());
     p.EquatorialToHorizontal(&LST, KStarsData::Instance()->geo()->lat());
 
+    return p.alt().Degrees();*/
+
+    SkyPoint p = target;
+    KStarsDateTime lt(when);
+    CachingDms LST = KStarsData::Instance()->geo()->GSTtoLST(lt.gst());
+    p.EquatorialToHorizontal(&LST, KStarsData::Instance()->geo()->lat());
+
     return p.alt().Degrees();
 }
 
diff --git a/kstars/time/kstarsdatetime.cpp b/kstars/time/kstarsdatetime.cpp
index 3b6a20f63..d48e18e71 100644
--- a/kstars/time/kstarsdatetime.cpp
+++ b/kstars/time/kstarsdatetime.cpp
@@ -22,7 +22,7 @@
 
 #include <KLocalizedString>
 
-#include <QDebug>
+#include <kstars_debug.h>
 
 KStarsDateTime::KStarsDateTime() : QDateTime()
 {
@@ -32,7 +32,9 @@ KStarsDateTime::KStarsDateTime() : QDateTime()
 KStarsDateTime::KStarsDateTime(const KStarsDateTime &kdt) : QDateTime()
 {
     setDJD(kdt.djd());
-    setUtcOffset(kdt.utcOffset());
+    setTimeSpec(kdt.timeSpec());
+    //utcoffset deprecated
+    //setUtcOffset(kdt.utcOffset());
 }
 
 /*KStarsDateTime::KStarsDateTime( const QDateTime &kdt ) :
@@ -52,12 +54,13 @@ KStarsDateTime::KStarsDateTime(const QDateTime &qdt) : QDateTime(qdt) //, QDateT
     QDate _d           = qdt.date();
     long double jdFrac = (_t.hour() - 12 + (_t.minute() + (_t.second() + _t.msec() / 1000.) / 60.) / 60.) / 24.;
     DJD                = (long double)(_d.toJulianDay()) + jdFrac;
-    setUtcOffset(qdt.utcOffset());
+    setTimeSpec(qdt.timeSpec());
+    //setUtcOffset(qdt.utcOffset());
 }
 
-KStarsDateTime::KStarsDateTime(const QDate &_d, const QTime &_t)
+KStarsDateTime::KStarsDateTime(const QDate &_d, const QTime &_t, Qt::TimeSpec timeSpec)
     : //QDateTime( _d, _t, QDateTime::Spec::UTC() )
-      QDateTime(_d, _t, Qt::UTC)
+      QDateTime(_d, _t, timeSpec)
 {
     //don't call setDJD() because we don't need to compute the time; just set DJD directly
     long double jdFrac = (_t.hour() - 12 + (_t.minute() + (_t.second() + _t.msec() / 1000.) / 60.) / 60.) / 24.;
@@ -67,6 +70,7 @@ KStarsDateTime::KStarsDateTime(const QDate &_d, const QTime &_t)
 KStarsDateTime::KStarsDateTime(long double _jd) : QDateTime()
 {
     setDJD(_jd);
+    setTimeSpec(Qt::UTC);
 }
 
 //KStarsDateTime KStarsDateTime::currentDateTime( QDateTime::Spec spec ) {
@@ -91,7 +95,7 @@ KStarsDateTime KStarsDateTime::currentDateTimeUtc()
 KStarsDateTime KStarsDateTime::fromString(const QString &s)
 {
     //DEBUG
-    qDebug() << "Date string: " << s;
+    qCDebug(KSTARS) << "Date string: " << s;
 
     KStarsDateTime dtResult(QDateTime::fromString(s, Qt::TextDate));
 
@@ -107,11 +111,11 @@ KStarsDateTime KStarsDateTime::fromString(const QString &s)
     if (dtResult.isValid())
         return dtResult;
 
-    qWarning() << i18n("Could not parse Date/Time string: ") << s;
-    qWarning() << i18n("Valid date formats: ");
-    qWarning() << "  1950-02-25   ;  1950-02-25T05:30:00";
-    qWarning() << "  25 Feb 1950  ;  25 Feb 1950 05:30:00";
-    qWarning() << "  Sat Feb 25 1950  ;  Sat Feb 25 05:30:00 1950";
+    qCWarning(KSTARS) << i18n("Could not parse Date/Time string: ") << s;
+    qCWarning(KSTARS) << i18n("Valid date formats: ");
+    qCWarning(KSTARS) << "  1950-02-25   ;  1950-02-25T05:30:00";
+    qCWarning(KSTARS) << "  25 Feb 1950  ;  25 Feb 1950 05:30:00";
+    qCWarning(KSTARS) << "  Sat Feb 25 1950  ;  Sat Feb 25 05:30:00 1950";
     return KStarsDateTime(QDateTime()); //invalid
 }
 
@@ -167,7 +171,7 @@ dms KStarsDateTime::gst() const
 {
     dms gst0 = GSTat0hUT();
 
-    double hr = double(time().hour());
+    double hr = double(time().hour() - offsetFromUtc()/3600.0);
     double mn = double(time().minute());
     double sc = double(time().second()) + double(0.001 * time().msec());
     double st = (hr + (mn + sc / 60.0) / 60.0) * SIDEREALSECOND;
diff --git a/kstars/time/kstarsdatetime.h b/kstars/time/kstarsdatetime.h
index f32205d66..9f0dd2240 100644
--- a/kstars/time/kstarsdatetime.h
+++ b/kstars/time/kstarsdatetime.h
@@ -75,7 +75,7 @@ class KStarsDateTime : public QDateTime
          *@p _d The QDate to assign
          *@p _t The QTime to assign
          */
-    KStarsDateTime(const QDate &_d, const QTime &_t);
+    KStarsDateTime(const QDate &_d, const QTime &_t, Qt::TimeSpec timeSpec = Qt::UTC);
 
     /**
          *Assign the (long double) Julian Day value, which includes the time of day



More information about the Kstars-devel mailing list