[Kst] branches/work/kst/portto4/kst/src
Barth Netterfield
netterfield at astro.utoronto.ca
Wed Aug 17 17:34:08 UTC 2011
SVN commit 1247868 by netterfield:
The skeleton for timezones in time axis interpretation, and very rudamentary support for them.
-Introduce a timezone class, which gives the offset from gmt for a selected timezone, at a specified time.
-A a static list of timezones (GMT+-X).
-Add support for this feature in plot axis, where this would be used.
It does not support system timezones, as, as far as I can tell, there is no system independent way of
getting them. So we will have to write system dependent code to go from here.
A libkst/ksttimezone.cpp [License: GPL (v2+)]
A libkst/ksttimezone.h [License: GPL (v2+)]
M +20 -0 libkstapp/axistab.cpp
M +4 -0 libkstapp/axistab.h
M +86 -25 libkstapp/axistab.ui
M +30 -2 libkstapp/plotaxis.cpp
M +6 -0 libkstapp/plotaxis.h
M +4 -1 libkstapp/plotitem.cpp
M +5 -0 libkstapp/plotitemdialog.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.cpp #1247867:1247868
@@ -12,6 +12,7 @@
#include "axistab.h"
#include "plotdefines.h"
+#include "ksttimezone.h"
namespace Kst {
@@ -77,6 +78,7 @@
connect(_scaleReverse, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
connect(_scaleDisplayType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
connect(_scaleInterpretType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
+ connect(_timezone, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
connect(_axisMinorTickCount, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
@@ -86,6 +88,8 @@
connect(_significantDigits, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
connect(_rotation, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
+
+ _timezone->addItems(KstTimeZone::tzList());
}
@@ -392,6 +396,21 @@
}
+QString AxisTab::timezone() const {
+ return _timezone->currentText();
+}
+
+
+bool AxisTab::timezoneDirty() const {
+ return _timezone->currentIndex() != -1;
+}
+
+
+void AxisTab::setTimezone(QString timezone) {
+ _timezone->setCurrentIndex(_timezone->findText(timezone));
+}
+
+
AxisInterpretationType AxisTab::axisInterpretation() const {
return AxisInterpretationType(_scaleInterpretType->itemData(_scaleInterpretType->currentIndex()).toInt());
}
@@ -478,6 +497,7 @@
_rotation->clear();
_scaleInterpretType->setCurrentIndex(-1);
_scaleDisplayType->setCurrentIndex(-1);
+ _timezone->setCurrentIndex(-1);
_drawAxisMajorTicks->setCheckState(Qt::PartiallyChecked);
_drawAxisMajorGridLines->setCheckState(Qt::PartiallyChecked);
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.h #1247867:1247868
@@ -108,6 +108,10 @@
bool axisDisplayDirty() const;
void setAxisDisplay(AxisDisplayType display);
+ QString timezone() const;
+ bool timezoneDirty() const;
+ void setTimezone(QString timezone);
+
AxisInterpretationType axisInterpretation() const;
bool axisInterpretationDirty() const;
void setAxisInterpretation(AxisInterpretationType interpretation);
--- branches/work/kst/portto4/kst/src/libkstapp/axistab.ui #1247867:1247868
@@ -61,7 +61,7 @@
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="1" column="1" colspan="3">
<widget class="QComboBox" name="_scaleInterpretType">
<property name="enabled">
<bool>false</bool>
@@ -109,6 +109,35 @@
</property>
</widget>
</item>
+ <item row="2" column="2">
+ <widget class="QLabel" name="label_7">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>TZ:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3">
+ <widget class="QComboBox" name="_timezone">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="toolTip">
+ <string>Time encoding type</string>
+ </property>
+ <property name="whatsThis">
+ <string>The axis represents time, whose encoding is selected here.</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
@@ -613,8 +642,8 @@
<y>299</y>
</hint>
<hint type="destinationlabel">
- <x>136</x>
- <y>396</y>
+ <x>128</x>
+ <y>400</y>
</hint>
</hints>
</connection>
@@ -625,8 +654,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>158</x>
- <y>297</y>
+ <x>247</x>
+ <y>318</y>
</hint>
<hint type="destinationlabel">
<x>254</x>
@@ -641,8 +670,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>473</x>
- <y>294</y>
+ <x>516</x>
+ <y>318</y>
</hint>
<hint type="destinationlabel">
<x>340</x>
@@ -709,7 +738,7 @@
<y>81</y>
</hint>
<hint type="destinationlabel">
- <x>528</x>
+ <x>224</x>
<y>117</y>
</hint>
</hints>
@@ -725,7 +754,7 @@
<y>81</y>
</hint>
<hint type="destinationlabel">
- <x>114</x>
+ <x>109</x>
<y>117</y>
</hint>
</hints>
@@ -737,8 +766,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>114</x>
- <y>81</y>
+ <x>109</x>
+ <y>86</y>
</hint>
<hint type="destinationlabel">
<x>305</x>
@@ -753,12 +782,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>110</x>
- <y>168</y>
+ <x>122</x>
+ <y>189</y>
</hint>
<hint type="destinationlabel">
- <x>276</x>
- <y>209</y>
+ <x>245</x>
+ <y>220</y>
</hint>
</hints>
</connection>
@@ -769,8 +798,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>110</x>
- <y>168</y>
+ <x>122</x>
+ <y>189</y>
</hint>
<hint type="destinationlabel">
<x>340</x>
@@ -785,8 +814,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>190</x>
- <y>285</y>
+ <x>247</x>
+ <y>318</y>
</hint>
<hint type="destinationlabel">
<x>156</x>
@@ -801,8 +830,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>213</x>
- <y>284</y>
+ <x>247</x>
+ <y>318</y>
</hint>
<hint type="destinationlabel">
<x>206</x>
@@ -817,8 +846,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>438</x>
- <y>284</y>
+ <x>516</x>
+ <y>318</y>
</hint>
<hint type="destinationlabel">
<x>424</x>
@@ -833,8 +862,8 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>445</x>
- <y>284</y>
+ <x>516</x>
+ <y>318</y>
</hint>
<hint type="destinationlabel">
<x>487</x>
@@ -842,5 +871,37 @@
</hint>
</hints>
</connection>
+ <connection>
+ <sender>_scaleInterpret</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>_timezone</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>70</x>
+ <y>69</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>291</x>
+ <y>104</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>_scaleInterpret</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>label_7</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>49</x>
+ <y>70</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>237</x>
+ <y>97</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
</ui>
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #1247867:1247868
@@ -91,6 +91,13 @@
}
+double PlotAxis::convertJDtoCTime(double jdIn) {
+ jdIn -= (JD1970);
+ jdIn *= 24.0*3600.0;
+ return (jdIn);
+}
+
+
double PlotAxis::convertTimeValueToJD(double valueIn) {
double value = valueIn;
@@ -145,10 +152,10 @@
}
}
- // utcOffset() is returned in seconds... as it must be since
+ // gmtOffset() is returned in seconds... as it must be since
// some time zones are not an integer number of hours offset
// from UTC...
- //jd += double(Settings::globalSettings()->utcOffset()) / 86400.0;
+ jd += (_timezone.gmtOffset(convertJDtoCTime(jd)))/(3600.0*24.0);
// get the date from the Julian day number
double jd_day = floor(jd);
@@ -526,6 +533,19 @@
}
+QString PlotAxis::timezoneName() const {
+ return _timezone.tzName();
+}
+
+
+void PlotAxis::setTimezoneName(QString timezone) {
+ if (_timezone.tzName() != timezone) {
+ _timezone.setTZ(timezone);
+ _dirty = true;
+ }
+}
+
+
AxisDisplayType PlotAxis::axisDisplay() const {
return _axisDisplay;
}
@@ -1201,6 +1221,7 @@
_dialogDefaults->setValue(group+"Interpret", QVariant(axisInterpret()).toString());
_dialogDefaults->setValue(group+"Interpretation", QVariant(axisInterpretation()).toString());
_dialogDefaults->setValue(group+"Display", QVariant(axisDisplay()).toString());
+ _dialogDefaults->setValue(group+"Timezone", QVariant(timezoneName()));
_dialogDefaults->setValue(group+"MajorTickMode", QVariant(axisMajorTickMode()).toString());
_dialogDefaults->setValue(group+"MinorTickCount", QVariant(axisMinorTickCount()).toString());
_dialogDefaults->setValue(group+"AutoMinorTickCount", QVariant(axisAutoMinorTicks()).toString());
@@ -1246,6 +1267,8 @@
xml.writeAttribute("significantdigits", QVariant(axisSignificantDigits()).toString());
xml.writeAttribute("rotation", QVariant(axisLabelRotation()).toString());
xml.writeAttribute("zoommode", QVariant(axisZoomMode()).toString());
+ xml.writeAttribute("timezonename", _timezone.tzName());
+ xml.writeAttribute("timezoneoffset", QVariant(_timezone.gmtOffset(0)).toString());
_axisPlotMarkers.saveInPlot(xml);
xml.writeEndElement();
}
@@ -1352,6 +1375,11 @@
if (!av.isNull()) {
setAxisZoomMode((PlotAxis::ZoomMode)av.toString().toInt());
}
+ av = attrs.value("timezonename");
+ if (!av.isNull()) {
+ setTimezoneName(av.toString());
+ // fixme: handle unrecognised timezone name by using timezoneoffset
+ }
QString expectedEnd;
while (!(xml.isEndElement() && (xml.name().toString() == primaryTag))) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.h #1247867:1247868
@@ -17,6 +17,7 @@
#include "plotitem.h"
#include "plotmarkers.h"
+#include "ksttimezone.h"
namespace Kst {
@@ -104,6 +105,9 @@
bool axisInterpret() const;
void setAxisInterpret(const bool enabled);
+ QString timezoneName() const;
+ void setTimezoneName(QString timezone);
+
AxisDisplayType axisDisplay() const;
void setAxisDisplay(const AxisDisplayType display);
@@ -142,6 +146,7 @@
private:
double convertTimeValueToJD(double valueIn);
+ double convertJDtoCTime(double jdIn);
double convertJDtoDisplayTime(double T);
QString convertJDToDateString(double jday, double range_jd);
@@ -182,6 +187,7 @@
bool _axisInterpret;
AxisDisplayType _axisDisplay;
AxisInterpretationType _axisInterpretation;
+ KstTimeZone _timezone;
MajorTickMode _axisMajorTickMode;
MajorTickMode _axisOverrideMajorTicks;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1247867:1247868
@@ -217,6 +217,7 @@
xAxis()->setAxisInterpret(_dialogDefaults->value(defaultsGroupName()+"/xAxisInterpret", false).toBool());
xAxis()->setAxisInterpretation((AxisInterpretationType)_dialogDefaults->value(defaultsGroupName()+"/xAxisInterpretation", 1).toInt());
xAxis()->setAxisDisplay((AxisDisplayType)_dialogDefaults->value(defaultsGroupName()+"/xAxisDisplay", 4).toInt());
+ xAxis()->setTimezoneName(_dialogDefaults->value(defaultsGroupName()+"/xAxisTimezone", "GMT").toString());
xAxis()->setAxisMajorTickMode((PlotAxis::MajorTickMode)_dialogDefaults->value(defaultsGroupName()+"/xAxisMajorTickMode", 5).toInt());
xAxis()->setAxisMinorTickCount(_dialogDefaults->value(defaultsGroupName()+"/xAxisMinorTickCount", 5).toInt());
xAxis()->setAxisAutoMinorTicks(_dialogDefaults->value(defaultsGroupName()+"/xAxisautoMinorTickCount", true).toBool());
@@ -247,6 +248,7 @@
yAxis()->setAxisInterpret(_dialogDefaults->value(defaultsGroupName()+"/yAxisInterpret", false).toBool());
yAxis()->setAxisInterpretation((AxisInterpretationType)_dialogDefaults->value(defaultsGroupName()+"/yAxisInterpretation", 1).toInt());
yAxis()->setAxisDisplay((AxisDisplayType)_dialogDefaults->value(defaultsGroupName()+"/yAxisDisplay", 4).toInt());
+ yAxis()->setTimezoneName(_dialogDefaults->value(defaultsGroupName()+"/yAxisTimezone", "GMT").toString());
yAxis()->setAxisMajorTickMode((PlotAxis::MajorTickMode)_dialogDefaults->value(defaultsGroupName()+"/yAxisMajorTickMode", 5).toInt());
yAxis()->setAxisMinorTickCount(_dialogDefaults->value(defaultsGroupName()+"/yAxisMinorTickCount", 5).toInt());
yAxis()->setAxisAutoMinorTicks(_dialogDefaults->value(defaultsGroupName()+"/yAxisautoMinorTickCount", true).toBool());
@@ -2652,7 +2654,8 @@
if (!_legend) {
_legend = new LegendItem(this);
_legend->setVisible(false);
- _legend->setPos(rect().x() + plotRect().width()*0.05, rect().y() + plotRect().height()*0.15);
+ double margin = 0.025*(plotRect().width() + plotRect().height());
+ _legend->setPos(plotRect().x() + margin, plotRect().y() + margin);
_legend->updateRelativeSize();
}
return _legend;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitemdialog.cpp #1247867:1247868
@@ -288,6 +288,7 @@
_xAxisTab->setInterpret(_plotItem->xAxis()->axisInterpret());
_xAxisTab->setAxisDisplay(_plotItem->xAxis()->axisDisplay());
_xAxisTab->setAxisInterpretation(_plotItem->xAxis()->axisInterpretation());
+ _xAxisTab->setTimezone(_plotItem->xAxis()->timezoneName());
_xAxisTab->setHideTopRight(_plotItem->manuallyHideTopAxisLabel());
_xAxisTab->setHideBottomLeft(_plotItem->manuallyHideBottomAxisLabel());
_xAxisTab->setAxisMinorTickCount(_plotItem->xAxis()->axisMinorTickCount());
@@ -314,6 +315,7 @@
_yAxisTab->setInterpret(_plotItem->yAxis()->axisInterpret());
_yAxisTab->setAxisDisplay(_plotItem->yAxis()->axisDisplay());
_yAxisTab->setAxisInterpretation(_plotItem->yAxis()->axisInterpretation());
+ _yAxisTab->setTimezone(_plotItem->yAxis()->timezoneName());
_yAxisTab->setHideTopRight(_plotItem->manuallyHideRightAxisLabel());
_yAxisTab->setHideBottomLeft(_plotItem->manuallyHideLeftAxisLabel());
_yAxisTab->setAxisMinorTickCount(_plotItem->yAxis()->axisMinorTickCount());
@@ -789,6 +791,9 @@
if (axisTab->axisInterpretationDirty()) {
axis->setAxisInterpretation(axisTab->axisInterpretation());
}
+ if (axisTab->timezoneDirty()) {
+ axis->setTimezoneName(axisTab->timezone());
+ }
if (axisTab->isBaseOffsetDirty()) {
axis->setAxisBaseOffset(axisTab->isBaseOffset());
}
More information about the Kst
mailing list