Commit fe004f8b authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #4889 from dogmaphobic/positionSource

Allow custom plugin to provide its own position source.
parents 91ee1a46 dac991f7
......@@ -8,22 +8,15 @@
****************************************************************************/
#include "PositionManager.h"
#include "QGCApplication.h"
#include "QGCCorePlugin.h"
QGCPositionManager::QGCPositionManager(QGCApplication* app) :
QGCTool(app),
_updateInterval(0),
_currentSource(nullptr)
{
_defaultSource = QGeoPositionInfoSource::createDefaultSource(this);
_simulatedSource = new SimulatedPosition();
// Enable this to get a simulated target on desktop
// if (_defaultSource == nullptr) {
// _defaultSource = _simulatedSource;
// }
setPositionSource(QGCPositionSource::GPS);
}
QGCPositionManager::~QGCPositionManager()
......@@ -31,12 +24,28 @@ QGCPositionManager::~QGCPositionManager()
delete(_simulatedSource);
}
void QGCPositionManager::positionUpdated(const QGeoPositionInfo &update)
void QGCPositionManager::setToolbox(QGCToolbox *toolbox)
{
QGCTool::setToolbox(toolbox);
//-- First see if plugin provides a position source
_defaultSource = toolbox->corePlugin()->createPositionSource(this);
if(!_defaultSource) {
//-- Otherwise, create a default one
_defaultSource = QGeoPositionInfoSource::createDefaultSource(this);
}
_simulatedSource = new SimulatedPosition();
QGeoCoordinate position(update.coordinate().latitude(), update.coordinate().longitude());
// Enable this to get a simulated target on desktop
// if (_defaultSource == nullptr) {
// _defaultSource = _simulatedSource;
// }
setPositionSource(QGCPositionSource::GPS);
}
emit lastPositionUpdated(update.isValid(), QVariant::fromValue(position));
void QGCPositionManager::positionUpdated(const QGeoPositionInfo &update)
{
emit lastPositionUpdated(update.isValid(), QVariant::fromValue(update.coordinate()));
emit positionInfoUpdated(update);
}
......@@ -68,9 +77,8 @@ void QGCPositionManager::setPositionSource(QGCPositionManager::QGCPositionSource
_updateInterval = _currentSource->minimumUpdateInterval();
_currentSource->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
_currentSource->setUpdateInterval(_updateInterval);
_currentSource->startUpdates();
connect(_currentSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
_currentSource->startUpdates();
}
}
......@@ -34,6 +34,8 @@ public:
int updateInterval() const;
void setToolbox(QGCToolbox* toolbox);
private slots:
void positionUpdated(const QGeoPositionInfo &update);
......
......@@ -25,6 +25,7 @@ class QGCOptions;
class QGCSettings;
class QGCCorePlugin_p;
class FactMetaData;
class QGeoPositionInfoSource;
class QGCCorePlugin : public QGCTool
{
......@@ -76,13 +77,16 @@ public:
virtual QString showAdvancedUIMessage(void) const { return tr("WARNING: You are about to enter Advanced Mode. This may expose features which may cause your vehicle to malfunction. "
"You should do so only if instructed by customer support. Are you sure you want to enable Advanced Mode?"); }
/// @return An instance of an alternate postion source (or NULL if not available)
virtual QGeoPositionInfoSource* createPositionSource (QObject* parent) { Q_UNUSED(parent); return NULL; }
bool showTouchAreas(void) const { return _showTouchAreas; }
bool showAdvancedUI(void) const { return _showAdvancedUI; }
void setShowTouchAreas(bool show);
void setShowAdvancedUI(bool show);
// Override from QGCTool
void setToolbox (QGCToolbox *toolbox);
void setToolbox (QGCToolbox* toolbox);
signals:
void settingsPagesChanged (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment