Skip to content

Commit

Permalink
Allow custom plugin to provide its own position source.
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmaphobic committed Mar 30, 2017
1 parent 91ee1a4 commit dac991f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
36 changes: 22 additions & 14 deletions src/PositionManager/PositionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,44 @@
****************************************************************************/

#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()
{
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);
}

Expand Down Expand Up @@ -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();
}
}

2 changes: 2 additions & 0 deletions src/PositionManager/PositionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class QGCPositionManager : public QGCTool {

int updateInterval() const;

void setToolbox(QGCToolbox* toolbox);

private slots:
void positionUpdated(const QGeoPositionInfo &update);

Expand Down
6 changes: 5 additions & 1 deletion src/api/QGCCorePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class QGCOptions;
class QGCSettings;
class QGCCorePlugin_p;
class FactMetaData;
class QGeoPositionInfoSource;

class QGCCorePlugin : public QGCTool
{
Expand Down Expand Up @@ -76,13 +77,16 @@ class QGCCorePlugin : public QGCTool
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);
Expand Down

0 comments on commit dac991f

Please sign in to comment.