File: DialogUnits.cpp

package info (click to toggle)
xygrib 1.2.6.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,024 kB
  • sloc: cpp: 28,210; ansic: 2,636; sh: 158; xml: 144; makefile: 12
file content (325 lines) | stat: -rw-r--r-- 12,248 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**********************************************************************
XyGrib: meteorological GRIB file viewer
Copyright (C) 2008-2012 - Jacques Zaninetti - http://www.zygrib.org

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/

#include <QMessageBox>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <ctime>

#include "DialogUnits.h"
#include "Util.h"


//-------------------------------------------------------------------------------
DialogUnits::DialogUnits (QWidget *parent) : DialogBoxBase (parent)
{
    setWindowTitle(tr("Units"));
    QFrame *ftmp;
    QLabel *label;
    frameGui = createFrameGui(this);
    
    layout = new QGridLayout(this);
    int lig=0;
    //-------------------------
    lig ++;
    QFont font;
    font.setBold(true);
    label = new QLabel(tr("Units"), this);
    label->setFont(font);
    layout->addWidget( label,    lig,0, 1,-1, Qt::AlignCenter);
    lig ++;
    ftmp = new QFrame(this); ftmp->setFrameShape(QFrame::HLine); layout->addWidget( ftmp, lig,0, 1, -1);
    //-------------------------
    lig ++;
    layout->addWidget( frameGui,  lig,0,   1, 2);
    //-------------------------
    lig ++;
    ftmp = new QFrame(this); ftmp->setFrameShape(QFrame::HLine); layout->addWidget( ftmp, lig,0, 1, -1);
    //-------------------------
    lig ++;
    btOK     = new QPushButton(tr("Ok"), this);
    btCancel = new QPushButton(tr("Cancel"), this);
    layout->addWidget( btOK,    lig,0);
    layout->addWidget( btCancel, lig,1);
    
    //===============================================================
    // restaure les valeurs enregistrées dans les settings
    QString tunit;
    int ind;

    tunit = Util::getSetting("unitsWindSpeed", "").toString();
    ind = (tunit=="") ? 0 : cbWindSpeedUnit->findData(tunit);
    cbWindSpeedUnit->setCurrentIndex( ind );

    tunit = Util::getSetting("unitsCurrentSpeed", "").toString();
    ind = (tunit=="") ? 0 : cbCurrentSpeedUnit->findData(tunit);
    cbCurrentSpeedUnit->setCurrentIndex( ind );

    tunit = Util::getSetting("unitsTemp",   "").toString();
    ind = (tunit=="") ? 0 : cbTempUnit->findData(tunit);
    cbTempUnit->setCurrentIndex( ind );

    tunit = Util::getSetting("unitsPosition", "").toString();
    ind = (tunit=="") ? 0 : cbPositionUnit->findData(tunit);
    cbPositionUnit->setCurrentIndex( ind );
    
    tunit = Util::getSetting("unitsDistance", "").toString();
    ind = (tunit=="") ? 0 : cbDistanceUnit->findData(tunit);
    cbDistanceUnit->setCurrentIndex( ind );
    
    tunit = Util::getSetting("longitudeDirection", "").toString();
    ind = (tunit=="") ? 0 : cbLongitude->findData(tunit);
    cbLongitude->setCurrentIndex( ind );
    
    tunit = Util::getSetting("latitudeDirection", "").toString();
    ind = (tunit=="") ? 0 : cbLatitude->findData(tunit);
    cbLatitude->setCurrentIndex( ind );
    
    tunit = Util::getSetting("timeZone", "UTC").toString();
    ind = (tunit=="") ? 0 : cbTimeZone->findData(tunit);
    cbTimeZone->setCurrentIndex( ind );
	isTimeZoneChanged = false;    
    
    tunit = Util::getSetting("geopotAltitudeUnit", "").toString();
    ind = (tunit=="") ? 0 : cbAltitude->findData(tunit);
    cbAltitude->setCurrentIndex( ind );
    
    tunit = Util::getSetting("isotherm0Unit", "").toString();
    ind = (tunit=="") ? 0 : cbIsotherme0->findData(tunit);
    cbIsotherme0->setCurrentIndex( ind );

    //===============================================================
    connect(btCancel, SIGNAL(clicked()), this, SLOT(slotBtCancel()));
    connect(btOK, SIGNAL(clicked()), this, SLOT(slotBtOK()));
}

//-------------------------------------------------------------------------------
void DialogUnits::slotBtOK()
{
	QComboBox *cb;
	
	cb = cbWindSpeedUnit;
    Util::setSetting("unitsWindSpeed", cb->itemData(cb->currentIndex()).toString(), false);
    cb = cbCurrentSpeedUnit;
    Util::setSetting("unitsCurrentSpeed", cb->itemData(cb->currentIndex()).toString(), false);
    cb = cbTempUnit;
    Util::setSetting("unitsTemp",      cb->itemData(cb->currentIndex()).toString(), false);
    cb = cbPositionUnit;
    Util::setSetting("unitsPosition",  cb->itemData(cb->currentIndex()).toString(), false);
    cb = cbDistanceUnit;
    Util::setSetting("unitsDistance",  cb->itemData(cb->currentIndex()).toString(), false);

    cb = cbAltitude;
    Util::setSetting("geopotAltitudeUnit",  cb->itemData(cb->currentIndex()).toString(), false);
    cb = cbIsotherme0;
    Util::setSetting("isotherm0Unit",  cb->itemData(cb->currentIndex()).toString(), false);

 	cb = cbLongitude;
    Util::setSetting("longitudeDirection", cb->itemData(cb->currentIndex()).toString(), false);
    cb = cbLatitude;
    Util::setSetting("latitudeDirection",  cb->itemData(cb->currentIndex()).toString(), false);

 	cb = cbTimeZone;
    Util::setSetting("timeZone",  cb->itemData(cb->currentIndex()).toString());
	if	(isTimeZoneChanged)
	{
		isTimeZoneChanged = false;
		emit signalTimeZoneChanged();
    }
    accept();
}
//-------------------------------------------------------------------------------
void DialogUnits::slotBtCancel()
{
	isTimeZoneChanged = false;
    reject();
}

//=============================================================================
// GUI
//=============================================================================
QFrame *DialogUnits::createFrameGui(QWidget *parent)
{
    QFrame * frm = new QFrame(parent);
    QLabel * label;
    QGridLayout  *lay = new QGridLayout(frm);
    int lig=0;
    int sizemin = 160;
    //-------------------------
    lig ++;
    label = new QLabel(tr("Wind speed :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbWindSpeedUnit = new QComboBox(this);
    cbWindSpeedUnit->addItem( tr("m/s") ,  "m/s");
    cbWindSpeedUnit->addItem( tr("km/h"),  "km/h");
    cbWindSpeedUnit->addItem( tr("kts"), "kts");
    cbWindSpeedUnit->setMinimumWidth (sizemin);
    lay->addWidget( cbWindSpeedUnit, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Current speed :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbCurrentSpeedUnit = new QComboBox(this);
    cbCurrentSpeedUnit->addItem( tr("m/s") ,  "m/s");
    cbCurrentSpeedUnit->addItem( tr("km/h"),  "km/h");
    cbCurrentSpeedUnit->addItem( tr("kts"), "kts");
    cbCurrentSpeedUnit->setMinimumWidth (sizemin);
    lay->addWidget( cbCurrentSpeedUnit, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Temperature :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbTempUnit = new QComboBox(this);
    cbTempUnit->addItem( tr("°C"),  "°C");
    cbTempUnit->addItem( tr("°F"),  "°F");
    cbTempUnit->addItem( tr("°K"),  "°K");
    cbTempUnit->setMinimumWidth (sizemin);
    lay->addWidget( cbTempUnit, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Distances :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbDistanceUnit = new QComboBox(this);
    cbDistanceUnit->addItem( tr("Nautical Mile"), "mille marin");
    cbDistanceUnit->addItem( tr("km"), "km");
    cbDistanceUnit->setMinimumWidth (sizemin);
    lay->addWidget( cbDistanceUnit, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Coordinates :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbPositionUnit = new QComboBox(this);
    cbPositionUnit->addItem( tr("dd°mm'ss\""), "dd°mm'ss\"");
    cbPositionUnit->addItem( tr("dd°mm,mm'"), "dd°mm,mm'");
    cbPositionUnit->addItem( tr("dd,dd°"), "dd,dd°");
    cbPositionUnit->setMinimumWidth (sizemin);
    lay->addWidget( cbPositionUnit, lig,1, Qt::AlignLeft);
    
    //-------------------------
    lig ++;
    label = new QLabel(tr("Longitudes :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbLongitude = new QComboBox(this);
    cbLongitude->addItem( tr("Auto"), "Auto");
    cbLongitude->addItem( tr("East positive"),   "East+");
    cbLongitude->addItem( tr("West positive"), "West+");
    cbLongitude->setMinimumWidth (sizemin);
    lay->addWidget( cbLongitude, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Latitudes :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbLatitude = new QComboBox(this);
    cbLatitude->addItem( tr("Auto"), "Auto");
    cbLatitude->addItem( tr("North positive"), "North+");
    cbLatitude->addItem( tr("South positive"),  "South+");
    cbLatitude->setMinimumWidth (sizemin);
    lay->addWidget( cbLatitude, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Time zone :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbTimeZone = new QComboBox(this);
    cbTimeZone->addItem( tr("UTC time"),    "UTC");
    cbTimeZone->addItem( tr("Local time"), "LOC");
	for (int i=-12; i<=14; i++)
	{	// UTC-12 UTC-11 ... UTC+1 UTC+2 UTC+3 ... UTC+14
		QString stz;
		if (i != 0)
			stz.sprintf("UTC%+d", i);
		else
			stz = "UTC";
    	cbTimeZone->addItem( tr("Fixed time ")+stz, stz);
	}
    cbTimeZone->setMinimumWidth (sizemin);
    lay->addWidget( cbTimeZone, lig,1, Qt::AlignLeft);
    connect(cbTimeZone, SIGNAL(activated(int)), this, SLOT(slotTimeZoneChanged(int)));
    //-------------------------
    lig ++;
    label = new QLabel(tr("Geopotential altitudes:"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbAltitude = new QComboBox(this);
    cbAltitude->addItem( tr("gm (≈ meter)"), "gpm");
    cbAltitude->addItem( tr("gdm (≈ decameter)"), "gpdm");
    cbAltitude->addItem( tr("gft (≈ foot)"), "gpft");
    cbAltitude->setMinimumWidth (sizemin);
    lay->addWidget( cbAltitude, lig,1, Qt::AlignLeft);
    //-------------------------
    lig ++;
    label = new QLabel(tr("Isotherm 0°C :"), frm);
    lay->addWidget( label,    lig,0, Qt::AlignRight);
    cbIsotherme0 = new QComboBox(this);
    cbIsotherme0->addItem( tr("meter (m)"), "m");
    cbIsotherme0->addItem( tr("decameter (dam)"), "dam");
    cbIsotherme0->addItem( tr("foot (ft)"), "ft");
    cbIsotherme0->setMinimumWidth (sizemin);
    lay->addWidget( cbIsotherme0, lig,1, Qt::AlignLeft);
    
    return frm;
}

//---------------------------------------------------
void DialogUnits::slotTimeZoneChanged(int index)
{
	isTimeZoneChanged = true;
	QString val = cbTimeZone->itemData(index).toString();
	if (val == "LOC")
	{
		time_t locnow = QDateTime::currentDateTime().toTime_t();
    	
    	QString saveTimeZone = Util::getSetting("timeZone", "UTC").toString();
		Util::setSetting("timeZone",  "UTC", false);
		QString tutc = Util::formatDateTimeLong (locnow);
		Util::setSetting("timeZone",  "LOC", false);
		QString tloc = Util::formatDateTimeLong (locnow);
    	Util::setSetting("timeZone",  saveTimeZone);

        QMessageBox::warning (this,
		tr("Local time"),
		tr("WARNING: You have choose local time.")+"\n"
		  + "\n"
		  + tr("The local time is the time of your computer, it's not")+"\n"
		  + tr("the time of a point on the map.")+"\n"
		  + "\n"
		  + tr("Conversion UTC/Local time depends of the parameters ") +"\n"
		  + tr("of your computer. ")
		  +"\n"
          + tr("Current hour seen by xygrib with those parameters :")+"\n"
		  + "      " + tutc + tr(" : UTC")+"\n"
		  + "      " + tloc + tr(" : Local")+"\n"
		  + "\n"
		  + tr("If these values are bad, you must update the ")+"\n"
		  + tr("configuration of your computeur (time zone),")+"\n"
		  + tr("or choose display in UTC time zone.")+"\n"
		  + "\n"
		);
	}
//exit(1);
}