Commit f9a43531 authored by Lorenz Meier's avatar Lorenz Meier

Merge branch 'master' of github.com:mavlink/qgroundcontrol

parents 160e0014 b0103c8f
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
#include <QShowEvent> #include <QShowEvent>
#include <QSettings> #include <QSettings>
#include <QInputDialog> #include <QInputDialog>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include "UASManager.h" #include "UASManager.h"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <QWebFrame> #include <QWebFrame>
#include <QWebPage> #include <QWebPage>
#include <QWebElement> #include <QWebElement>
#include "QGCWebPage.h" #include "QGCWebPage.h"
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#include <QAxObject> #include <QAxObject>
#include <QUuid> #include <QUuid>
#include <mshtml.h> #include <mshtml.h>
#include <comdef.h> #include <comdef.h>
#include <qaxtypes.h> #include <qaxtypes.h>
#endif #endif
#include "QGC.h" #include "QGC.h"
#include "ui_QGCGoogleEarthView.h" #include "ui_QGCGoogleEarthView.h"
#include "QGCGoogleEarthView.h" #include "QGCGoogleEarthView.h"
#include "UASWaypointManager.h" #include "UASWaypointManager.h"
#define QGCGOOGLEEARTHVIEWSETTINGS QString("GoogleEarthViewSettings_") #define QGCGOOGLEEARTHVIEWSETTINGS QString("GoogleEarthViewSettings_")
QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) : QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) :
QWidget(parent), QWidget(parent),
updateTimer(new QTimer(this)), updateTimer(new QTimer(this)),
refreshRateMs(100), refreshRateMs(100),
mav(NULL), mav(NULL),
followCamera(true), followCamera(true),
trailEnabled(true), trailEnabled(true),
webViewInitialized(false), webViewInitialized(false),
jScriptInitialized(false), jScriptInitialized(false),
gEarthInitialized(false), gEarthInitialized(false),
currentViewMode(QGCGoogleEarthView::VIEW_MODE_SIDE), currentViewMode(QGCGoogleEarthView::VIEW_MODE_SIDE),
#if (defined Q_OS_MAC) #if (defined Q_OS_MAC)
webViewMac(new QWebView(this)), webViewMac(new QWebView(this)),
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
webViewWin(new QGCWebAxWidget(this)), webViewWin(new QGCWebAxWidget(this)),
documentWin(NULL), documentWin(NULL),
#endif #endif
ui(new Ui::QGCGoogleEarthView) ui(new Ui::QGCGoogleEarthView)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
// Create layout and attach webViewWin // Create layout and attach webViewWin
// QFile file("doc.html"); // QFile file("doc.html");
// if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) // if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
// qDebug() << __FILE__ << __LINE__ << "Could not open log file"; // qDebug() << __FILE__ << __LINE__ << "Could not open log file";
// QTextStream out(&file); // QTextStream out(&file);
// out << webViewWin->generateDocumentation(); // out << webViewWin->generateDocumentation();
// out.flush(); // out.flush();
// file.flush(); // file.flush();
// file.close(); // file.close();
#else #else
#endif #endif
// Load settings // Load settings
QSettings settings; QSettings settings;
followCamera = settings.value(QGCGOOGLEEARTHVIEWSETTINGS + "follow", followCamera).toBool(); followCamera = settings.value(QGCGOOGLEEARTHVIEWSETTINGS + "follow", followCamera).toBool();
trailEnabled = settings.value(QGCGOOGLEEARTHVIEWSETTINGS + "trail", trailEnabled).toBool(); trailEnabled = settings.value(QGCGOOGLEEARTHVIEWSETTINGS + "trail", trailEnabled).toBool();
ui->setupUi(this); ui->setupUi(this);
#if (defined Q_OS_MAC) #if (defined Q_OS_MAC)
ui->webViewLayout->addWidget(webViewMac); ui->webViewLayout->addWidget(webViewMac);
//connect(webViewMac, SIGNAL(loadFinished(bool)), this, SLOT(initializeGoogleEarth(bool))); //connect(webViewMac, SIGNAL(loadFinished(bool)), this, SLOT(initializeGoogleEarth(bool)));
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
ui->webViewLayout->addWidget(webViewWin); ui->webViewLayout->addWidget(webViewWin);
#endif #endif
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState())); connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState()));
connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(reloadHTML())); connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(reloadHTML()));
connect(ui->changeViewButton, SIGNAL(clicked()), this, SLOT(toggleViewMode())); connect(ui->changeViewButton, SIGNAL(clicked()), this, SLOT(toggleViewMode()));
connect(ui->clearTrailsButton, SIGNAL(clicked()), this, SLOT(clearTrails())); connect(ui->clearTrailsButton, SIGNAL(clicked()), this, SLOT(clearTrails()));
connect(ui->atmosphereCheckBox, SIGNAL(clicked(bool)), this, SLOT(enableAtmosphere(bool))); connect(ui->atmosphereCheckBox, SIGNAL(clicked(bool)), this, SLOT(enableAtmosphere(bool)));
connect(ui->daylightCheckBox, SIGNAL(clicked(bool)), this, SLOT(enableDaylight(bool))); connect(ui->daylightCheckBox, SIGNAL(clicked(bool)), this, SLOT(enableDaylight(bool)));
connect(UASManager::instance(), SIGNAL(homePositionChanged(double,double,double)), this, SLOT(setHome(double,double,double))); connect(UASManager::instance(), SIGNAL(homePositionChanged(double,double,double)), this, SLOT(setHome(double,double,double)));
} }
QGCGoogleEarthView::~QGCGoogleEarthView() QGCGoogleEarthView::~QGCGoogleEarthView()
{ {
QSettings settings; QSettings settings;
settings.setValue(QGCGOOGLEEARTHVIEWSETTINGS + "follow", followCamera); settings.setValue(QGCGOOGLEEARTHVIEWSETTINGS + "follow", followCamera);
settings.setValue(QGCGOOGLEEARTHVIEWSETTINGS + "trail", trailEnabled); settings.setValue(QGCGOOGLEEARTHVIEWSETTINGS + "trail", trailEnabled);
settings.sync(); settings.sync();
#if (defined Q_OS_MAC) #if (defined Q_OS_MAC)
delete webViewMac; delete webViewMac;
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
delete webViewWin; delete webViewWin;
#endif #endif
delete ui; delete ui;
} }
/** /**
* @param range in centimeters * @param range in centimeters
*/ */
void QGCGoogleEarthView::setViewRangeScaledInt(int range) void QGCGoogleEarthView::setViewRangeScaledInt(int range)
{ {
setViewRange(range/100.0f); setViewRange(range/100.0f);
} }
void QGCGoogleEarthView::reloadHTML() void QGCGoogleEarthView::reloadHTML()
{ {
hide(); hide();
webViewInitialized = false; webViewInitialized = false;
jScriptInitialized = false; jScriptInitialized = false;
gEarthInitialized = false; gEarthInitialized = false;
show(); show();
} }
void QGCGoogleEarthView::enableEditMode(bool mode) void QGCGoogleEarthView::enableEditMode(bool mode)
{ {
javaScript(QString("setDraggingAllowed(%1);").arg(mode)); javaScript(QString("setDraggingAllowed(%1);").arg(mode));
} }
void QGCGoogleEarthView::enableDaylight(bool enable) void QGCGoogleEarthView::enableDaylight(bool enable)
{ {
javaScript(QString("enableDaylight(%1);").arg(enable)); javaScript(QString("enableDaylight(%1);").arg(enable));
} }
void QGCGoogleEarthView::enableAtmosphere(bool enable) void QGCGoogleEarthView::enableAtmosphere(bool enable)
{ {
javaScript(QString("enableAtmosphere(%1);").arg(enable)); javaScript(QString("enableAtmosphere(%1);").arg(enable));
} }
/** /**
* @param range in meters (SI-units) * @param range in meters (SI-units)
*/ */
void QGCGoogleEarthView::setViewRange(float range) void QGCGoogleEarthView::setViewRange(float range)
{ {
javaScript(QString("setViewRange(%1);").arg(range, 0, 'f', 5)); javaScript(QString("setViewRange(%1);").arg(range, 0, 'f', 5));
} }
void QGCGoogleEarthView::setDistanceMode(int mode) void QGCGoogleEarthView::setDistanceMode(int mode)
{ {
javaScript(QString("setDistanceMode(%1);").arg(mode)); javaScript(QString("setDistanceMode(%1);").arg(mode));
} }
void QGCGoogleEarthView::toggleViewMode() void QGCGoogleEarthView::toggleViewMode()
{ {
switch (currentViewMode) { switch (currentViewMode) {
case VIEW_MODE_MAP: case VIEW_MODE_MAP:
setViewMode(VIEW_MODE_SIDE); setViewMode(VIEW_MODE_SIDE);
break; break;
case VIEW_MODE_SIDE: case VIEW_MODE_SIDE:
setViewMode(VIEW_MODE_MAP); setViewMode(VIEW_MODE_MAP);
break; break;
case VIEW_MODE_CHASE_LOCKED: case VIEW_MODE_CHASE_LOCKED:
setViewMode(VIEW_MODE_CHASE_FREE); setViewMode(VIEW_MODE_CHASE_FREE);
break; break;
case VIEW_MODE_CHASE_FREE: case VIEW_MODE_CHASE_FREE:
setViewMode(VIEW_MODE_CHASE_LOCKED); setViewMode(VIEW_MODE_CHASE_LOCKED);
break; break;
} }
} }
void QGCGoogleEarthView::setViewMode(QGCGoogleEarthView::VIEW_MODE mode) void QGCGoogleEarthView::setViewMode(QGCGoogleEarthView::VIEW_MODE mode)
{ {
switch (mode) { switch (mode) {
case VIEW_MODE_MAP: case VIEW_MODE_MAP:
ui->changeViewButton->setText("Free View"); ui->changeViewButton->setText("Free View");
break; break;
case VIEW_MODE_SIDE: case VIEW_MODE_SIDE:
ui->changeViewButton->setText("Map View"); ui->changeViewButton->setText("Map View");
break; break;
case VIEW_MODE_CHASE_LOCKED: case VIEW_MODE_CHASE_LOCKED:
ui->changeViewButton->setText("Free Chase"); ui->changeViewButton->setText("Free Chase");
break; break;
case VIEW_MODE_CHASE_FREE: case VIEW_MODE_CHASE_FREE:
ui->changeViewButton->setText("Fixed Chase"); ui->changeViewButton->setText("Fixed Chase");
break; break;
} }
currentViewMode = mode; currentViewMode = mode;
javaScript(QString("setViewMode(%1);").arg(mode)); javaScript(QString("setViewMode(%1);").arg(mode));
} }
void QGCGoogleEarthView::addUAS(UASInterface* uas) void QGCGoogleEarthView::addUAS(UASInterface* uas)
{ {
// uasid, type, color (in #rrbbgg format) // uasid, type, color (in #rrbbgg format)
QString uasColor = uas->getColor().name().remove(0, 1); QString uasColor = uas->getColor().name().remove(0, 1);
// Convert to bbggrr format // Convert to bbggrr format
QString rChannel = uasColor.mid(0, 2); QString rChannel = uasColor.mid(0, 2);
uasColor.remove(0, 2); uasColor.remove(0, 2);
uasColor.prepend(rChannel); uasColor.prepend(rChannel);
// Set alpha value to 0x66, append JavaScript quotes ('') // Set alpha value to 0x66, append JavaScript quotes ('')
uasColor.prepend("'66").append("'"); uasColor.prepend("'66").append("'");
javaScript(QString("createAircraft(%1, %2, %3);").arg(uas->getUASID()).arg(uas->getSystemType()).arg(uasColor)); javaScript(QString("createAircraft(%1, %2, %3);").arg(uas->getUASID()).arg(uas->getSystemType()).arg(uasColor));
if (trailEnabled) javaScript(QString("showTrail(%1);").arg(uas->getUASID())); if (trailEnabled) javaScript(QString("showTrail(%1);").arg(uas->getUASID()));
// Automatically receive further position updates // Automatically receive further position updates
connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64))); connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64)));
// Receive waypoint updates // Receive waypoint updates
// Connect the waypoint manager / data storage to the UI // Connect the waypoint manager / data storage to the UI
connect(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged(int)), this, SLOT(updateWaypointList(int))); connect(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(uas->getWaypointManager(), SIGNAL(waypointEditableChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*))); connect(uas->getWaypointManager(), SIGNAL(waypointEditableChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
//connect(this, SIGNAL(waypointCreated(Waypoint*)), uas->getWaypointManager(), SLOT(addWaypointEditable(Waypoint*))); //connect(this, SIGNAL(waypointCreated(Waypoint*)), uas->getWaypointManager(), SLOT(addWaypointEditable(Waypoint*)));
// TODO Update waypoint list on UI changes here // TODO Update waypoint list on UI changes here
} }
void QGCGoogleEarthView::setActiveUAS(UASInterface* uas) void QGCGoogleEarthView::setActiveUAS(UASInterface* uas)
{ {
if (uas) if (uas)
{ {
mav = uas; mav = uas;
javaScript(QString("setCurrAircraft(%1);").arg(uas->getUASID())); javaScript(QString("setCurrAircraft(%1);").arg(uas->getUASID()));
updateWaypointList(uas->getUASID()); updateWaypointList(uas->getUASID());
} }
} }
/** /**
* This function is called if a a single waypoint is updated and * This function is called if a a single waypoint is updated and
* also if the whole list changes. * also if the whole list changes.
*/ */
void QGCGoogleEarthView::updateWaypoint(int uas, Waypoint* wp) void QGCGoogleEarthView::updateWaypoint(int uas, Waypoint* wp)
{ {
// Only accept waypoints in global coordinate frame // Only accept waypoints in global coordinate frame
if ((wp->getFrame() == MAV_FRAME_GLOBAL || wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT) && wp->isNavigationType()) if ((wp->getFrame() == MAV_FRAME_GLOBAL || wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT) && wp->isNavigationType())
{ {
// We're good, this is a global waypoint // We're good, this is a global waypoint
// Get the index of this waypoint // Get the index of this waypoint
// note the call to getGlobalFrameAndNavTypeIndexOf() // note the call to getGlobalFrameAndNavTypeIndexOf()
// as we're only handling global waypoints // as we're only handling global waypoints
int wpindex = UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameAndNavTypeIndexOf(wp); int wpindex = UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameAndNavTypeIndexOf(wp);
// If not found, return (this should never happen, but helps safety) // If not found, return (this should never happen, but helps safety)
if (wpindex == -1) if (wpindex == -1)
{ {
return; return;
} }
else else
{ {
javaScript(QString("updateWaypoint(%1,%2,%3,%4,%5,%6);").arg(uas).arg(wpindex).arg(wp->getLatitude(), 0, 'f', 22).arg(wp->getLongitude(), 0, 'f', 22).arg(wp->getAltitude(), 0, 'f', 22).arg(wp->getAction())); javaScript(QString("updateWaypoint(%1,%2,%3,%4,%5,%6);").arg(uas).arg(wpindex).arg(wp->getLatitude(), 0, 'f', 22).arg(wp->getLongitude(), 0, 'f', 22).arg(wp->getAltitude(), 0, 'f', 22).arg(wp->getAction()));
//qDebug() << QString("updateWaypoint(%1,%2,%3,%4,%5,%6);").arg(uas).arg(wpindex).arg(wp->getLatitude(), 0, 'f', 18).arg(wp->getLongitude(), 0, 'f', 18).arg(wp->getAltitude(), 0, 'f', 18).arg(wp->getAction()); //qDebug() << QString("updateWaypoint(%1,%2,%3,%4,%5,%6);").arg(uas).arg(wpindex).arg(wp->getLatitude(), 0, 'f', 18).arg(wp->getLongitude(), 0, 'f', 18).arg(wp->getAltitude(), 0, 'f', 18).arg(wp->getAction());
} }
} }
} }
/** /**
* Update the whole list of waypoints. This is e.g. necessary if the list order changed. * Update the whole list of waypoints. This is e.g. necessary if the list order changed.
* The UAS manager will emit the appropriate signal whenever updating the list * The UAS manager will emit the appropriate signal whenever updating the list
* is necessary. * is necessary.
*/ */
void QGCGoogleEarthView::updateWaypointList(int uas) void QGCGoogleEarthView::updateWaypointList(int uas)
{ {
// Get already existing waypoints // Get already existing waypoints
UASInterface* uasInstance = UASManager::instance()->getUASForId(uas); UASInterface* uasInstance = UASManager::instance()->getUASForId(uas);
if (uasInstance) if (uasInstance)
{ {
// Get all waypoints, including non-global waypoints // Get all waypoints, including non-global waypoints
QVector<Waypoint*> wpList = uasInstance->getWaypointManager()->getGlobalFrameAndNavTypeWaypointList(); QVector<Waypoint*> wpList = uasInstance->getWaypointManager()->getGlobalFrameAndNavTypeWaypointList();
// Trim internal list to number of global waypoints in the waypoint manager list // Trim internal list to number of global waypoints in the waypoint manager list
javaScript(QString("updateWaypointListLength(%1,%2);").arg(uas).arg(wpList.count())); javaScript(QString("updateWaypointListLength(%1,%2);").arg(uas).arg(wpList.count()));
qDebug() << QString("updateWaypointListLength(%1,%2);").arg(uas).arg(wpList.count()); qDebug() << QString("updateWaypointListLength(%1,%2);").arg(uas).arg(wpList.count());
// Load all existing waypoints into map view // Load all existing waypoints into map view
foreach (Waypoint* wp, wpList) foreach (Waypoint* wp, wpList)
{ {
updateWaypoint(uas, wp); updateWaypoint(uas, wp);
} }
} }
} }
void QGCGoogleEarthView::updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec) void QGCGoogleEarthView::updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec)
{ {
Q_UNUSED(usec); Q_UNUSED(usec);
javaScript(QString("addTrailPosition(%1, %2, %3, %4);").arg(uas->getUASID()).arg(lat, 0, 'f', 22).arg(lon, 0, 'f', 22).arg(alt, 0, 'f', 22)); javaScript(QString("addTrailPosition(%1, %2, %3, %4);").arg(uas->getUASID()).arg(lat, 0, 'f', 22).arg(lon, 0, 'f', 22).arg(alt, 0, 'f', 22));
} }
void QGCGoogleEarthView::clearTrails() void QGCGoogleEarthView::clearTrails()
{ {
QList<UASInterface*> mavs = UASManager::instance()->getUASList(); QList<UASInterface*> mavs = UASManager::instance()->getUASList();
foreach (UASInterface* currMav, mavs) foreach (UASInterface* currMav, mavs)
{ {
javaScript(QString("clearTrail(%1);").arg(currMav->getUASID())); javaScript(QString("clearTrail(%1);").arg(currMav->getUASID()));
} }
} }
void QGCGoogleEarthView::showTrail(bool state) void QGCGoogleEarthView::showTrail(bool state)
{ {
// Check if the current trail has to be hidden // Check if the current trail has to be hidden
if (trailEnabled && !state) if (trailEnabled && !state)
{ {
QList<UASInterface*> mavs = UASManager::instance()->getUASList(); QList<UASInterface*> mavs = UASManager::instance()->getUASList();
foreach (UASInterface* currMav, mavs) foreach (UASInterface* currMav, mavs)
{ {
javaScript(QString("hideTrail(%1);").arg(currMav->getUASID())); javaScript(QString("hideTrail(%1);").arg(currMav->getUASID()));
} }
} }
// Check if the current trail has to be shown // Check if the current trail has to be shown
if (!trailEnabled && state) if (!trailEnabled && state)
{ {
QList<UASInterface*> mavs = UASManager::instance()->getUASList(); QList<UASInterface*> mavs = UASManager::instance()->getUASList();
foreach (UASInterface* currMav, mavs) foreach (UASInterface* currMav, mavs)
{ {
javaScript(QString("showTrail(%1);").arg(currMav->getUASID())); javaScript(QString("showTrail(%1);").arg(currMav->getUASID()));
} }
} }
trailEnabled = state; trailEnabled = state;
ui->trailCheckbox->setChecked(state); ui->trailCheckbox->setChecked(state);
} }
void QGCGoogleEarthView::showWaypoints(bool state) void QGCGoogleEarthView::showWaypoints(bool state)
{ {
waypointsEnabled = state; waypointsEnabled = state;
} }
void QGCGoogleEarthView::follow(bool follow) void QGCGoogleEarthView::follow(bool follow)
{ {
ui->followAirplaneCheckbox->setChecked(follow); ui->followAirplaneCheckbox->setChecked(follow);
if (follow != followCamera) if (follow != followCamera)
{ {
if (follow) if (follow)
{ {
setViewMode(VIEW_MODE_CHASE_LOCKED); setViewMode(VIEW_MODE_CHASE_LOCKED);
} }
else else
{ {
setViewMode(VIEW_MODE_SIDE); setViewMode(VIEW_MODE_SIDE);
} }
} }
followCamera = follow; followCamera = follow;
javaScript(QString("setFollowEnabled(%1)").arg(follow)); javaScript(QString("setFollowEnabled(%1)").arg(follow));
} }
void QGCGoogleEarthView::goHome() void QGCGoogleEarthView::goHome()
{ {
// Disable follow and update // Disable follow and update
follow(false); follow(false);
updateState(); updateState();
// Go to home location // Go to home location
javaScript("goHome();"); javaScript("goHome();");
} }
void QGCGoogleEarthView::setHome(double lat, double lon, double alt) void QGCGoogleEarthView::setHome(double lat, double lon, double alt)
{ {
qDebug() << "SETTING GCS HOME IN GOOGLE MAPS" << lat << lon << alt; qDebug() << "SETTING GCS HOME IN GOOGLE MAPS" << lat << lon << alt;
javaScript(QString("setGCSHome(%1,%2,%3);").arg(lat, 0, 'f', 15).arg(lon, 0, 'f', 15).arg(alt, 0, 'f', 15)); javaScript(QString("setGCSHome(%1,%2,%3);").arg(lat, 0, 'f', 15).arg(lon, 0, 'f', 15).arg(alt, 0, 'f', 15));
} }
void QGCGoogleEarthView::setHome() void QGCGoogleEarthView::setHome()
{ {
javaScript(QString("enableSetHomeMode();")); javaScript(QString("enableSetHomeMode();"));
} }
void QGCGoogleEarthView::moveToPosition() void QGCGoogleEarthView::moveToPosition()
{ {
bool ok; bool ok;
javaScript("sampleCurrentPosition();"); javaScript("sampleCurrentPosition();");
double latitude = documentElement("currentCameraLatitude").toDouble(); double latitude = documentElement("currentCameraLatitude").toDouble();
double longitude = documentElement("currentCameraLongitude").toDouble(); double longitude = documentElement("currentCameraLongitude").toDouble();
QString text = QInputDialog::getText(this, tr("Please enter coordinates"), QString text = QInputDialog::getText(this, tr("Please enter coordinates"),
tr("Coordinates (Lat,Lon):"), QLineEdit::Normal, tr("Coordinates (Lat,Lon):"), QLineEdit::Normal,
QString("%1,%2").arg(latitude).arg(longitude), &ok); QString("%1,%2").arg(latitude).arg(longitude), &ok);
if (ok && !text.isEmpty()) { if (ok && !text.isEmpty()) {
QStringList split = text.split(","); QStringList split = text.split(",");
if (split.length() == 2) { if (split.length() == 2) {
bool convert; bool convert;
double latitude = split.first().toDouble(&convert); double latitude = split.first().toDouble(&convert);
ok &= convert; ok &= convert;
double longitude = split.last().toDouble(&convert); double longitude = split.last().toDouble(&convert);
ok &= convert; ok &= convert;
if (ok) { if (ok) {
javaScript(QString("setLookAtLatLon(%1,%2);").arg(latitude, 0, 'f', 15).arg(longitude, 0, 'f', 15)); javaScript(QString("setLookAtLatLon(%1,%2);").arg(latitude, 0, 'f', 15).arg(longitude, 0, 'f', 15));
} }
} }
} }
} }
void QGCGoogleEarthView::hideEvent(QHideEvent* event) void QGCGoogleEarthView::hideEvent(QHideEvent* event)
{ {
updateTimer->stop(); updateTimer->stop();
QWidget::hideEvent(event); QWidget::hideEvent(event);
emit visibilityChanged(false); emit visibilityChanged(false);
} }