LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / gpsdisplay / gpsdisplaywidget.cpp
blobe8b5df611b53468ef9c22be5dcceb017fbd03360
1 /**
2 ******************************************************************************
4 * @file gpsdisplaywidget.cpp
5 * @author Edouard Lafargue Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup GPSGadgetPlugin GPS Gadget Plugin
9 * @{
10 * @brief A gadget that displays GPS status and enables basic configuration
11 *****************************************************************************/
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.
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.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "gpsdisplaywidget.h"
29 #include "extensionsystem/pluginmanager.h"
30 #include "uavobjectmanager.h"
33 #include <iostream>
35 // The following is needed to workaround the problem here:
36 // https://bugreports.qt-project.org/browse/QTBUG-26000
37 #undef B0
39 #include <QtGui>
40 #include <QDebug>
43 * Initialize the widget
45 GpsDisplayWidget::GpsDisplayWidget(QWidget *parent) : QWidget(parent)
47 setupUi(this);
49 // Not elegant, just load the image for now
50 QGraphicsScene *fescene = new QGraphicsScene(this);
51 QPixmap earthpix(":/gpsgadget/images/flatEarth.png");
52 fescene->addPixmap(earthpix);
53 flatEarth->setScene(fescene);
54 marker = new QGraphicsSvgItem();
55 QSvgRenderer *renderer = new QSvgRenderer();
56 renderer->load(QString(":/gpsgadget/images/marker.svg"));
57 marker->setSharedRenderer(renderer);
58 fescene->addItem(marker);
59 double scale = earthpix.width() / (marker->boundingRect().width() * 20);
60 marker->setScale(scale);
63 GpsDisplayWidget::~GpsDisplayWidget()
66 void GpsDisplayWidget::setSpeedHeading(double speed, double heading)
68 QString str;
70 speed_value->setText(str.sprintf("%.02f m/s", speed));
71 bear_value->setText(str.sprintf("%.02f deg", heading));
74 void GpsDisplayWidget::setDateTime(double date, double time)
76 QString dstring1, dstring2;
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");
87 void GpsDisplayWidget::setFixType(const QString &fixtype)
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");
102 void GpsDisplayWidget::dumpPacket(const QString &packet)
104 textBrowser->append(packet);
105 if (textBrowser->document()->lineCount() > 200) {
106 QTextCursor tc = textBrowser->textCursor();
107 tc.movePosition(QTextCursor::Start);
108 tc.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
109 tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
110 tc.removeSelectedText();
114 void GpsDisplayWidget::setSVs(int sv)
116 QString temp;
118 temp.append(QString::number(sv));
119 status_value->setText(temp);
120 status_value->adjustSize();
123 void GpsDisplayWidget::setDOP(double hdop, double vdop, double pdop)
125 QString str;
127 str.sprintf("%.2f / %.2f / %.2f", hdop, vdop, pdop);
128 dop_value->setText(str);
131 void GpsDisplayWidget::setPosition(double lat, double lon, double alt)
133 // lat *= 1E-7;
134 // lon *= 1E-7;
135 double deg = floor(fabs(lat));
136 double min = (fabs(lat) - deg) * 60;
137 QString str1;
139 str1.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
140 if (lat > 0) {
141 str1.append("N");
142 } else {
143 str1.append("S");
145 coord_value->setText(str1);
146 deg = floor(fabs(lon));
147 min = (fabs(lon) - deg) * 60;
148 QString str2;
149 str2.sprintf("%.0f%c%.3f' ", deg, 0x00b0, min);
150 if (lon > 0) {
151 str2.append("E");
152 } else {
153 str2.append("W");
155 coord_value_2->setText(str2);
156 QString str3;
157 str3.sprintf("%.2f m", alt);
158 coord_value_3->setText(str3);
160 // Now place the marker:
161 double wscale = flatEarth->sceneRect().width() / 360;
162 double hscale = flatEarth->sceneRect().height() / 180;
163 QPointF opd = QPointF((lon + 180) * wscale - marker->boundingRect().width() * marker->scale() / 2,
164 (90 - lat) * hscale - marker->boundingRect().height() * marker->scale() / 2);
165 marker->setTransform(QTransform::fromTranslate(opd.x(), opd.y()), false);