source: ntrip/trunk/BNC/src/map/bncmapwin.cpp@ 8260

Last change on this file since 8260 was 8260, checked in by stuerze, 6 years ago

see #105: adaptations to allow for QtWebkit or QtWebEngine according to it's availability

File size: 5.4 KB
RevLine 
[5161]1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncMapWin
30 *
[5188]31 * Purpose: Displays the Google Map
[5161]32 *
33 * Author: L. Mervart
34 *
35 * Created: 08-Jun-2013
36 *
[8260]37 * Changes:
[5161]38 *
39 * -----------------------------------------------------------------------*/
40
41#include "map/bncmapwin.h"
[5232]42#include "bncsettings.h"
[5188]43#include "bncutils.h"
[5161]44
45// Constructor
46////////////////////////////////////////////////////////////////////////////
47bncMapWin::bncMapWin(QWidget* parent) : QDialog(parent) {
48
49 const int ww = QFontMetrics(font()).width('w');
50
[5180]51 setWindowTitle("BNC: Map View");
[5161]52
[5229]53 // Current Coordinates
54 // -------------------
55 _currLat = 50.09057949; // BKG latitude
56 _currLon = 8.66496871; // BKG longitude
[5180]57
[8260]58#ifdef QT_WEBENGINE
59 _webView = new QWebEngineView(this);
60#else
[5161]61 _webView = new QWebView(this);
[8260]62#endif
63
[5167]64 connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(slotInitMap(bool)));
65
[6446]66 // Plot Required Station
67 // ---------------------
68 bncSettings settings;
69 _staID = settings.value("PPP/plotCoordinates").toByteArray();
70
[5269]71 // Proxy Settings
72 // --------------
73 QString proxyHost = settings.value("proxyHost").toString();
74 int proxyPort = settings.value("proxyPort").toInt();
75 if (!proxyHost.isEmpty()) {
76 QNetworkProxy proxy(QNetworkProxy::HttpProxy, proxyHost, proxyPort);
77 _webView->page()->networkAccessManager()->setProxy(proxy);
78 }
79
[5166]80 loadHtmlPage();
81
[8260]82 _webView->show();
[5161]83
[5228]84 _statusLabel = new QLabel;
[5161]85
[5180]86 // Layout
87 // ------
[5228]88 QHBoxLayout* statusLayout = new QHBoxLayout;
89 statusLayout->addWidget(_statusLabel);
90
[5180]91 QVBoxLayout* mainLayout = new QVBoxLayout(this);
92 mainLayout->addWidget(_webView);
[5228]93 mainLayout->addLayout(statusLayout);
[5180]94
95 setLayout(mainLayout);
[5161]96 resize(60*ww, 60*ww);
[5180]97
[5161]98 show();
99}
100
101// Destructor
102////////////////////////////////////////////////////////////////////////////
103bncMapWin::~bncMapWin() {
104}
105
[8260]106//
[5166]107////////////////////////////////////////////////////////////////////////////
108void bncMapWin::loadHtmlPage() {
109
[5232]110 bncSettings settings;
111
112 QFile htmlFile;
[5956]113 if (settings.value("PPP/useOpenStreetMap").toBool()) {
[5232]114 htmlFile.setFileName(":/map/map_osm.html");
115 }
116 else {
117 htmlFile.setFileName(":/map/map_gm.html");
118 }
[5166]119 if (!htmlFile.open(QFile::ReadOnly)) {
[5213]120 qDebug() << "bncMapWin:: cannot open html file";
[5166]121 return;
122 }
123
124 QTextStream stream(&htmlFile);
125 QString html = stream.readAll();
126
127 _webView->setHtml(html);
128}
129
[8260]130//
[5167]131////////////////////////////////////////////////////////////////////////////
132void bncMapWin::slotInitMap(bool isOk) {
133 if (!isOk) {
134 return;
135 }
[5246]136 bncSettings settings;
[5956]137 int mapWinDotSize = settings.value("PPP/mapWinDotSize").toInt();
[5305]138 int mapWinDotColor = 1;
[5956]139 if (settings.value("PPP/mapWinDotColor").toString() == "yellow") {
[5305]140 mapWinDotColor = 2;
141 }
142 QString location = QString("%1, %2, %3, %4").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8).arg(mapWinDotSize).arg(mapWinDotColor);
[5167]143 _webView->page()->mainFrame()->evaluateJavaScript(QString("initialize( %1 )").arg(location));
[5177]144}
[5175]145
[8260]146//
[5177]147////////////////////////////////////////////////////////////////////////////
[5187]148void bncMapWin::gotoLocation(double lat, double lon) {
[5180]149 _currLat = lat;
150 _currLon = lon;
[5253]151 //// beg test
152 // _currLat += 0.00001;
153 // _currLon += 0.00001;
154 //// end test
[5230]155
156 int latDeg, latMin;
157 double latSec;
158 deg2DMS(lat, latDeg, latMin, latSec);
159
160 int lonDeg, lonMin;
161 double lonSec;
162 deg2DMS(lon, lonDeg, lonMin, lonSec);
163
164 QString lblStr=QString("Latitude: %1 %2 %3 Longitude: %4 %5 %6")
[5231]165 .arg(latDeg).arg(latMin).arg(latSec,0,'f',4)
166 .arg(lonDeg).arg(lonMin).arg(lonSec,0,'f',4);
[5230]167 _statusLabel->setText(lblStr);
168
[5177]169 QString location = QString("%1, %2").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8);
170 _webView->page()->mainFrame()->evaluateJavaScript(QString("gotoLocation( %1 )").arg(location));
[5180]171}
172
[8260]173//
[5180]174////////////////////////////////////////////////////////////////////////////
[6446]175void bncMapWin::slotNewPosition(QByteArray staID, bncTime /* time */, QVector<double> xx) {
176 if (!_staID.isEmpty() && _staID != staID) {
177 return;
178 }
[5188]179 double ell[3];
[5879]180 xyz2ell(xx.data(), ell);
[5188]181 gotoLocation(ell[0]*180.0/M_PI, ell[1]*180.0/M_PI);
[5187]182}
[5234]183
184// Close Dialog gracefully
185////////////////////////////////////////////////////////////////////////////
186void bncMapWin::closeEvent(QCloseEvent* event) {
187 emit mapClosed();
188 QDialog::closeEvent(event);
189}
Note: See TracBrowser for help on using the repository browser.