1
/***************************************************************************
2
* Copyright (C) 2005 by Robin Gingras *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
27
#include "qgpsdevice.h"
28
#include "qgpssatellitetracker.h"
29
#include "SatelliteStrengthView.h"
33
//#include "Preferences/MerkaartorPreferences.h"
35
QGPS::QGPS(QWidget *parent)
36
: MDockAncestor(parent), gpsDevice(0)
39
setObjectName("GPSMainWindow");
41
int w = fontMetrics().width("360N 60'60\" W");
42
txtLatitude->setFixedWidth(w);
43
txtLongitude->setFixedWidth(w);
44
txtAltitude->setFixedWidth(w);
45
txtSpeed->setFixedWidth(w);
46
txtNumSats->setFixedWidth(w);
47
txtFixType->setFixedWidth(w);
54
// gpsDevice = new QGPSDevice(serialPort);
56
//connect(actStartGps, SIGNAL(activated()), gpsDevice, SLOT(startDevice()));
57
//connect(actStopGps, SIGNAL(activated()), gpsDevice, SLOT(stopDevice()));
59
// The Qt documentation says that using signals and slots between
60
// threaded classes is not recommended! TODO: find a better way!
63
void QGPS::setGpsDevice(QGPSDevice * aDevice)
66
disconnect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
74
connect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
75
gpsDevice->startDevice();
82
gpsDevice->stopDevice();
83
disconnect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
87
void QGPS::resetGpsStatus()
89
txtLatitude->setText("");
90
txtLongitude->setText("");
91
txtAltitude->setText("");
92
txtSpeed->setText("");
93
txtNumSats->setText("");
94
txtFixType->setText(tr("Invalid"));
96
lblFixStatus->setText(tr("No Position Fix"));
97
lblFixTime->setText(tr("No UTC Time"));
99
satTracker->setSatellites(std::vector<Satellite>());
102
void QGPS::updateGpsStatus()
104
QString latCardinal, longCardinal, varCardinal;
106
if(gpsDevice->latCardinal() == QGPSDevice::CardinalNorth)
111
if(gpsDevice->longCardinal() == QGPSDevice::CardinalEast)
116
if(gpsDevice->varCardinal() == QGPSDevice::CardinalEast)
121
txtLatitude->setText(
122
QString("%1 %2\' %3\" %4")
123
.arg(gpsDevice->latDegrees())
124
.arg(gpsDevice->latMinutes())
125
.arg(gpsDevice->latSeconds())
128
txtLongitude->setText(
129
QString("%1 %2\' %3\" %4")
130
.arg(gpsDevice->longDegrees())
131
.arg(gpsDevice->longMinutes())
132
.arg(gpsDevice->longSeconds())
135
txtAltitude->setText(
137
.arg(gpsDevice->altitude())
142
.arg(gpsDevice->speed())
146
QString("%1").arg(gpsDevice->numSatellites()));
148
switch (gpsDevice->fixType()) {
149
case QGPSDevice::FixUnavailable:
150
txtFixType->setText(tr("Unavailable"));
152
case QGPSDevice::FixInvalid:
153
txtFixType->setText(tr("Invalid"));
155
case QGPSDevice::Fix2D:
156
txtFixType->setText(tr("2D"));
158
case QGPSDevice::Fix3D:
159
txtFixType->setText(tr("3D"));
163
switch (gpsDevice->fixStatus()) {
164
case QGPSDevice::StatusActive:
165
lblFixStatus->setText(tr("Position Fix available"));
167
case QGPSDevice::StatusVoid:
168
lblFixStatus->setText(tr("No Position Fix"));
172
if (!gpsDevice->dateTime().isValid())
173
lblFixTime->setText(tr("No UTC Time"));
175
lblFixTime->setText(gpsDevice->dateTime().toString() + " UTC");
177
std::vector<Satellite> List;
178
for(int i = 1; i < 50; i ++)
181
gpsDevice->satInfo(i, b, x, y);
187
S.SignalStrength = y;
192
StrengthView->setSatellites(List);
193
satTracker->setSatellites(List);
194
satTracker->setHeading((int)gpsDevice->heading());
197
void QGPS::showEvent ( QShowEvent * anEvent )
199
QWidget::showEvent(anEvent);
202
connect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
205
void QGPS::hideEvent ( QHideEvent * anEvent )
207
QWidget::hideEvent(anEvent);
210
disconnect(gpsDevice, SIGNAL(updateStatus()), this, SLOT(updateGpsStatus()));
213
void QGPS::changeEvent(QEvent * event)
215
if (event->type() == QEvent::LanguageChange)
217
MDockAncestor::changeEvent(event);
220
void QGPS::retranslateUi()
222
setWindowTitle("GPS");
223
lblFixStatus->setText(tr("No Position Fix"));
224
lblFixTime->setText(tr("No UTC Time"));