dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
gpsdisplaywidget.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
27 #include "gpsdisplaywidget.h"
30 
31 #include <iostream>
32 
33 // The following is needed to workaround the problem here:
34 // https://bugreports.qt-project.org/browse/QTBUG-26000
35 #undef B0
36 
37 #include <QtGui>
38 #include <QDebug>
39 
40 /*
41  * Initialize the widget
42  */
44  : QWidget(parent)
45 {
46  setupUi(this);
47 
48  // Not elegant, just load the image for now
49  QGraphicsScene *fescene = new QGraphicsScene(this);
50  QPixmap earthpix(":/gpsgadget/images/flatEarth.png");
51  fescene->addPixmap(earthpix);
52  flatEarth->setScene(fescene);
53  marker = new QGraphicsSvgItem();
54  QSvgRenderer *renderer = new QSvgRenderer();
55  renderer->load(QString(":/gpsgadget/images/marker.svg"));
56  marker->setSharedRenderer(renderer);
57  fescene->addItem(marker);
58  double scale = earthpix.width() / (marker->boundingRect().width() * 20);
59  marker->setScale(scale);
60 }
61 
63 {
64 }
65 
66 void GpsDisplayWidget::setSpeedHeading(double speed, double heading)
67 {
68  QString str;
69 
70  speed_value->setText(str.sprintf("%.02f m/s", speed));
71  bear_value->setText(str.sprintf("%.02f deg", heading));
72 }
73 
74 void GpsDisplayWidget::setDateTime(double date, double time)
75 {
76  QString dstring1, dstring2;
77 
78  dstring1.sprintf("%06.0f", date);
79  dstring1.insert(dstring1.length() - 2, ".");
80  dstring1.insert(dstring1.length() - 5, ".");
81  dstring2.sprintf("%06.0f", time);
82  dstring2.insert(dstring2.length() - 2, ":");
83  dstring2.insert(dstring2.length() - 5, ":");
84  time_value->setText(dstring1 + " " + dstring2 + " GMT");
85 }
86 
87 void GpsDisplayWidget::setFixType(const QString &fixtype)
88 {
89  if (fixtype == "NoGPS") {
90  fix_value->setText("No GPS");
91  } else if (fixtype == "NoFix") {
92  fix_value->setText("Fix not available");
93  } else if (fixtype == "Fix2D") {
94  fix_value->setText("2D");
95  } else if (fixtype == "Fix3D") {
96  fix_value->setText("3D");
97  } else {
98  fix_value->setText("Unknown");
99  }
100 }
101 
102 void GpsDisplayWidget::setSVs(int sv)
103 {
104  QString temp;
105 
106  temp.append(QString::number(sv));
107  status_value->setText(temp);
108  status_value->adjustSize();
109 }
110 
111 void GpsDisplayWidget::setDOP(double hdop, double vdop, double pdop)
112 {
113  QString str;
114 
115  str.sprintf("%.2f / %.2f / %.2f", hdop, vdop, pdop);
116  dop_value->setText(str);
117 }
118 
119 void GpsDisplayWidget::setPosition(double lat, double lon, double alt)
120 {
121  // lat *= 1E-7;
122  // lon *= 1E-7;
123  double deg = floor(fabs(lat));
124  double min = (fabs(lat) - deg) * 60;
125  QString str1;
126 
127  str1.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
128  if (lat > 0) {
129  str1.append("N");
130  } else {
131  str1.append("S");
132  }
133  coord_value->setText(str1);
134  deg = floor(fabs(lon));
135  min = (fabs(lon) - deg) * 60;
136  QString str2;
137  str2.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
138  if (lon > 0) {
139  str2.append("E");
140  } else {
141  str2.append("W");
142  }
143  coord_value_2->setText(str2);
144  QString str3;
145  str3.sprintf("%.2f m", alt);
146  coord_value_3->setText(str3);
147 
148  // Now place the marker:
149  double wscale = flatEarth->sceneRect().width() / 360;
150  double hscale = flatEarth->sceneRect().height() / 180;
151  QPointF opd =
152  QPointF((lon + 180) * wscale - marker->boundingRect().width() * marker->scale() / 2,
153  (90 - lat) * hscale - marker->boundingRect().height() * marker->scale() / 2);
154  marker->setTransform(QTransform::fromTranslate(opd.x(), opd.y()), false);
155 }
GpsDisplayWidget(QWidget *parent=nullptr)