Browse Source

Merge pull request #2607 from DonLakeFlyer/InitialMapPosition

Initial map position changes, plus GCS position on map
QGC4.4
Don Gagne 9 years ago
parent
commit
8290009d45
  1. 4
      src/FlightDisplay/FlightDisplayView.qml
  2. 17
      src/FlightDisplay/FlightDisplayViewMap.qml
  3. 33
      src/FlightMap/FlightMap.qml
  4. 45
      src/MissionEditor/MissionEditor.qml
  5. 15
      src/QGCApplication.cc
  6. 19
      src/QGCApplication.h
  7. 1
      src/QmlControls/QGroundControlQmlGlobal.cc
  8. 5
      src/QmlControls/QGroundControlQmlGlobal.h
  9. 1
      src/Vehicle/Vehicle.cc
  10. 18
      src/ui/MainWindowInner.qml

4
src/FlightDisplay/FlightDisplayView.qml

@ -50,7 +50,6 @@ Item { @@ -50,7 +50,6 @@ Item {
property var _activeVehicle: multiVehicleManager.activeVehicle
readonly property var _defaultVehicleCoordinate: mainWindow.tabletPosition
readonly property real _defaultRoll: 0
readonly property real _defaultPitch: 0
readonly property real _defaultHeading: 0
@ -71,8 +70,6 @@ Item { @@ -71,8 +70,6 @@ Item {
property real _pitch: _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch
property real _heading: _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading
property var _vehicleCoordinate: _activeVehicle ? (_activeVehicle.coordinateValid ? _activeVehicle.coordinate : _defaultVehicleCoordinate) : _defaultVehicleCoordinate
property real _altitudeWGS84: _activeVehicle ? _activeVehicle.altitudeWGS84 : _defaultAltitudeWGS84
property real _groundSpeed: _activeVehicle ? _activeVehicle.groundSpeed : _defaultGroundSpeed
property real _airSpeed: _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed
@ -120,7 +117,6 @@ Item { @@ -120,7 +117,6 @@ Item {
_flightMap.zoomLevel = _savedZoomLevel
else
_savedZoomLevel = _flightMap.zoomLevel
_flightMap.updateMapPosition(true /* force */)
} else {
_flightVideo = item
}

17
src/FlightDisplay/FlightDisplayViewMap.qml

@ -39,18 +39,15 @@ FlightMap { @@ -39,18 +39,15 @@ FlightMap {
id: flightMap
anchors.fill: parent
mapName: _mapName
latitude: mainWindow.tabletPosition.latitude
longitude: mainWindow.tabletPosition.longitude
property var rootVehicleCoordinate: _vehicleCoordinate
property bool _followVehicle: true
property bool _followVehicle: true
property bool _activeVehicleCoordinateValid: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.coordinateValid : false
property var activeVehicleCoordinate: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.coordinate : QtPositioning.coordinate()
onRootVehicleCoordinateChanged: updateMapPosition(false /* force */)
function updateMapPosition(force) {
if (_followVehicle || force) {
flightMap.latitude = root._vehicleCoordinate.latitude
flightMap.longitude = root._vehicleCoordinate.longitude
onActiveVehicleCoordinateChanged: {
if (_followVehicle && activeVehicleCoordinate.isValid) {
_initialMapPositionSet = true
flightMap.center = activeVehicleCoordinate
}
}

33
src/FlightMap/FlightMap.qml

@ -43,22 +43,16 @@ import QGroundControl.Mavlink 1.0 @@ -43,22 +43,16 @@ import QGroundControl.Mavlink 1.0
Map {
id: _map
property real latitude: 64.154549 //-- If you find yourself here on startup, something went wrong :)
property real longitude: -22.023540
property real heading: 0
property bool interactive: true
property string mapName: 'defaultMap'
property string mapType: QGroundControl.flightMapSettings.mapTypeForMapName(mapName)
// property alias mapWidgets: controlWidgets
property bool isSatelliteMap: mapType == "Satellite Map" || mapType == "Hybrid Map"
property real lon: (longitude >= -180 && longitude <= 180) ? longitude : 0
property real lat: (latitude >= -90 && latitude <= 90) ? latitude : 0
readonly property real maxZoomLevel: 20
zoomLevel: 18
center: QtPositioning.coordinate(lat, lon)
center: QGroundControl.defaultMapPosition
gesture.flickDeceleration: 3000
gesture.enabled: interactive
gesture.activeGestures: MapGestureArea.ZoomGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture
@ -69,6 +63,18 @@ Map { @@ -69,6 +63,18 @@ Map {
Component.onCompleted: onMapTypeChanged
property bool _initialMapPositionSet: false
Connections {
target: mainWindow
onGcsPositionChanged: {
if (!_initialMapPositionSet) {
_initialMapPositionSet = true
flightMap.center = mainWindow.gcsPosition
}
}
}
onMapTypeChanged: {
QGroundControl.flightMapSettings.setMapTypeForMapName(mapName, mapType)
var fullMapName = QGroundControl.flightMapSettings.mapProvider + " " + mapType
@ -80,7 +86,18 @@ Map { @@ -80,7 +86,18 @@ Map {
}
}
/*********************************************
MapQuickItem {
anchorPoint.x: sourceItem.width / 2
anchorPoint.y: sourceItem.height / 2
visible: mainWindow.gcsPosition.isValid
coordinate: mainWindow.gcsPosition
sourceItem: MissionItemIndexLabel {
label: "Q"
}
}
/*********************************************
/// Map control widgets
Column {
id: controlWidgets

45
src/MissionEditor/MissionEditor.qml

@ -62,13 +62,8 @@ QGCView { @@ -62,13 +62,8 @@ QGCView {
property var _missionItems: controller.missionItems
property var _currentMissionItem
property bool gpsLock: _activeVehicle ? _activeVehicle.coordinateValid : false
property bool _firstGpsLock: true
//property var _homePositionManager: QGroundControl.homePositionManager
//property string _homePositionName: _homePositionManager.homePositions.get(0).name
//property var offlineHomePosition: _homePositionManager.homePositions.get(0).coordinate
property bool _firstVehiclePosition: true
property var activeVehiclePosition: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
property var liveHomePosition: controller.liveHomePosition
property var liveHomePositionAvailable: controller.liveHomePositionAvailable
@ -76,17 +71,23 @@ QGCView { @@ -76,17 +71,23 @@ QGCView {
property bool _syncInProgress: _activeVehicle ? _activeVehicle.missionManager.inProgress : false
onGpsLockChanged: updateMapToVehiclePosition()
Component.onCompleted: updateMapToVehiclePosition()
onActiveVehiclePositionChanged: updateMapToVehiclePosition()
Component.onCompleted: {
updateMapToVehiclePosition()
Connections {
target: multiVehicleManager
onActiveVehicleChanged: {
// When the active vehicle changes we need to allow the first vehicle position to move the map again
_firstVehiclePosition = true
updateMapToVehiclePosition()
}
}
function updateMapToVehiclePosition() {
if (gpsLock && _firstGpsLock) {
_firstGpsLock = false
editorMap.latitude = _activeVehicle.latitude
editorMap.longitude = _activeVehicle.longitude
if (_activeVehicle && _activeVehicle.coordinateValid && _firstVehiclePosition) {
_firstVehiclePosition = false
editorMap.center = _activeVehicle.coordinate
}
}
@ -178,8 +179,6 @@ QGCView { @@ -178,8 +179,6 @@ QGCView {
id: editorMap
anchors.fill: parent
mapName: "MissionEditor"
latitude: mainWindow.tabletPosition.latitude
longitude: mainWindow.tabletPosition.longitude
readonly property real animationDuration: 500
@ -190,20 +189,6 @@ QGCView { @@ -190,20 +189,6 @@ QGCView {
}
}
Behavior on latitude {
NumberAnimation {
duration: editorMap.animationDuration
easing.type: Easing.InOutQuad
}
}
Behavior on longitude {
NumberAnimation {
duration: editorMap.animationDuration
easing.type: Easing.InOutQuad
}
}
MouseArea {
anchors.fill: parent

15
src/QGCApplication.cc

@ -121,6 +121,8 @@ const char* QGCApplication::_settingsVersionKey = "SettingsVersion"; @@ -121,6 +121,8 @@ const char* QGCApplication::_settingsVersionKey = "SettingsVersion";
const char* QGCApplication::_promptFlightDataSave = "PromptFLightDataSave";
const char* QGCApplication::_promptFlightDataSaveNotArmed = "PromptFLightDataSaveNotArmed";
const char* QGCApplication::_styleKey = "StyleIsDark";
const char* QGCApplication::_defaultMapPositionLatKey = "DefaultMapPositionLat";
const char* QGCApplication::_defaultMapPositionLonKey = "DefaultMapPositionLon";
const char* QGCApplication::_darkStyleFile = ":/res/styles/style-dark.css";
const char* QGCApplication::_lightStyleFile = ":/res/styles/style-light.css";
@ -176,6 +178,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) @@ -176,6 +178,7 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
#endif
, _toolbox(NULL)
, _bluetoothAvailable(false)
, _defaultMapPosition(37.803784, -122.462276)
{
Q_ASSERT(_app == NULL);
_app = this;
@ -318,6 +321,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) @@ -318,6 +321,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
settings.setValue(_settingsVersionKey, QGC_SETTINGS_VERSION);
}
_defaultMapPosition.setLatitude(settings.value(_defaultMapPositionLatKey, 37.803784).toDouble());
_defaultMapPosition.setLongitude(settings.value(_defaultMapPositionLonKey, -122.462276).toDouble());
// Initialize Bluetooth
#ifdef QGC_ENABLE_BLUETOOTH
QBluetoothLocalDevice localDevice;
@ -711,3 +717,12 @@ void QGCApplication::_showSetupVehicleComponent(VehicleComponent* vehicleCompone @@ -711,3 +717,12 @@ void QGCApplication::_showSetupVehicleComponent(VehicleComponent* vehicleCompone
QMetaObject::invokeMethod(_rootQmlObject(), "showSetupVehicleComponent", Q_RETURN_ARG(QVariant, varReturn), Q_ARG(QVariant, varComponent));
}
void QGCApplication::setDefaultMapPosition(QGeoCoordinate& defaultMapPosition)
{
QSettings settings;
settings.setValue(_defaultMapPositionLatKey, defaultMapPosition.latitude());
settings.setValue(_defaultMapPositionLonKey, defaultMapPosition.longitude());
_defaultMapPosition = defaultMapPosition;
}

19
src/QGCApplication.h

@ -121,6 +121,9 @@ public: @@ -121,6 +121,9 @@ public:
/// Do we have Bluetooth Support?
bool isBluetoothAvailable() { return _bluetoothAvailable; }
QGeoCoordinate defaultMapPosition(void) { return _defaultMapPosition; }
void setDefaultMapPosition(QGeoCoordinate& defaultMapPosition);
public slots:
/// You can connect to this slot to show an information message box from a different thread.
void informationMessageBoxOnMainThread(const QString& title, const QString& msg);
@ -184,12 +187,6 @@ private: @@ -184,12 +187,6 @@ private:
QQmlApplicationEngine* _qmlAppEngine;
#endif
static const char* _settingsVersionKey; ///< Settings key which hold settings version
static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
static const char* _promptFlightDataSave; ///< Settings key for promptFlightDataSave
static const char* _promptFlightDataSaveNotArmed; ///< Settings key for promptFlightDataSaveNotArmed
static const char* _styleKey; ///< Settings key for UI style
bool _runningUnitTests; ///< true: running unit tests, false: normal app
static const char* _darkStyleFile;
@ -210,6 +207,16 @@ private: @@ -210,6 +207,16 @@ private:
bool _bluetoothAvailable;
QGeoCoordinate _defaultMapPosition; ///< Map position when all other sources fail
static const char* _settingsVersionKey; ///< Settings key which hold settings version
static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
static const char* _promptFlightDataSave; ///< Settings key for promptFlightDataSave
static const char* _promptFlightDataSaveNotArmed; ///< Settings key for promptFlightDataSaveNotArmed
static const char* _styleKey; ///< Settings key for UI style
static const char* _defaultMapPositionLatKey; ///< Settings key for default map location
static const char* _defaultMapPositionLonKey; ///< Settings key for default map location
/// Unit Test have access to creating and destroying singletons
friend class UnitTest;
};

1
src/QmlControls/QGroundControlQmlGlobal.cc

@ -42,7 +42,6 @@ QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app) @@ -42,7 +42,6 @@ QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
, _virtualTabletJoystick(false)
, _offlineEditingFirmwareTypeFact(QString(), "OfflineEditingFirmwareType", FactMetaData::valueTypeUint32, (uint32_t)MAV_AUTOPILOT_ARDUPILOTMEGA)
, _offlineEditingFirmwareTypeMetaData(FactMetaData::valueTypeUint32)
{
QSettings settings;
_virtualTabletJoystick = settings.value(_virtualTabletJoystickKey, false). toBool();

5
src/QmlControls/QGroundControlQmlGlobal.h

@ -76,6 +76,8 @@ public: @@ -76,6 +76,8 @@ public:
Q_PROPERTY(Fact* offlineEditingFirmwareType READ offlineEditingFirmwareType CONSTANT)
Q_PROPERTY(QGeoCoordinate defaultMapPosition READ defaultMapPosition CONSTANT)
Q_INVOKABLE void saveGlobalSetting (const QString& key, const QString& value);
Q_INVOKABLE QString loadGlobalSetting (const QString& key, const QString& defaultValue);
Q_INVOKABLE void saveBoolGlobalSetting (const QString& key, bool value);
@ -113,6 +115,8 @@ public: @@ -113,6 +115,8 @@ public:
bool isVersionCheckEnabled () { return _toolbox->mavlinkProtocol()->versionCheckEnabled(); }
int mavlinkSystemID () { return _toolbox->mavlinkProtocol()->getSystemId(); }
QGeoCoordinate defaultMapPosition() { return qgcApp()->defaultMapPosition(); }
Fact* offlineEditingFirmwareType () { return &_offlineEditingFirmwareTypeFact; }
//-- TODO: Make this into an actual preference.
@ -144,7 +148,6 @@ signals: @@ -144,7 +148,6 @@ signals:
void mavlinkSystemIDChanged (int id);
private:
FlightMapSettings* _flightMapSettings;
HomePositionManager* _homePositionManager;
LinkManager* _linkManager;

1
src/Vehicle/Vehicle.cc

@ -281,6 +281,7 @@ void Vehicle::_handleHomePosition(mavlink_message_t& message) @@ -281,6 +281,7 @@ void Vehicle::_handleHomePosition(mavlink_message_t& message)
if (emitHomePositionChanged) {
qCDebug(VehicleLog) << "New home position" << newHomePosition;
qgcApp()->setDefaultMapPosition(_homePosition);
emit homePositionChanged(_homePosition);
}
if (emitHomePositionAvailableChanged) {

18
src/ui/MainWindowInner.qml

@ -33,9 +33,9 @@ import QGroundControl.FlightDisplay 1.0 @@ -33,9 +33,9 @@ import QGroundControl.FlightDisplay 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.MultiVehicleManager 1.0
/// Inner common QML for MainWindow
/// Inner common QML for mainWindow
Item {
id: mainWindow
id: mainWindow
signal reallyClose
@ -50,10 +50,7 @@ Item { @@ -50,10 +50,7 @@ Item {
property real tbButtonWidth: tbCellHeight * 1.35
property real availableHeight: height - tbHeight
property real menuButtonWidth: (tbButtonWidth * 2) + (tbSpacing * 4) + 1
property var defaultPosition: QtPositioning.coordinate(37.803784, -122.462276)
property var tabletPosition: defaultPosition
property var gcsPosition: QtPositioning.coordinate() // Starts as invalid coordinate
property var currentPopUp: null
property real currentCenterX: 0
property var activeVehicle: multiVehicleManager.activeVehicle
@ -179,20 +176,20 @@ Item { @@ -179,20 +176,20 @@ Item {
PositionSource {
id: positionSource
updateInterval: 1000
active: false
active: true
onPositionChanged: {
if(positionSource.valid) {
if(positionSource.position.coordinate.latitude) {
if(Math.abs(positionSource.position.coordinate.latitude) > 0.001) {
if(positionSource.position.coordinate.longitude) {
if(Math.abs(positionSource.position.coordinate.longitude) > 0.001) {
tabletPosition = positionSource.position.coordinate
gcsPosition = positionSource.position.coordinate
}
}
}
}
}
positionSource.stop()
}
}
@ -299,9 +296,6 @@ Item { @@ -299,9 +296,6 @@ Item {
anchors.fill: parent
availableHeight: mainWindow.availableHeight
visible: true
Component.onCompleted: {
positionSource.start()
}
}
Loader {

Loading…
Cancel
Save