Browse Source

* Add support for showing rotation on QGCMapCircle.


			
			
				QGC4.4
			
			
		
Don Gagne 6 years ago
parent
commit
20485a4692
  1. 13
      src/FlightDisplay/FlightDisplayViewMap.qml
  2. 2
      src/FlightDisplay/GuidedActionsController.qml
  3. 2
      src/MissionManager/QGCFenceCircle.cc
  4. 53
      src/MissionManager/QGCMapCircle.cc
  5. 39
      src/MissionManager/QGCMapCircle.h
  6. 78
      src/MissionManager/QGCMapCircleVisuals.qml

13
src/FlightDisplay/FlightDisplayViewMap.qml

@ -319,12 +319,13 @@ FlightMap {
} }
QGCMapCircleVisuals { QGCMapCircleVisuals {
id: orbitMapCircle id: orbitMapCircle
mapControl: parent mapControl: parent
mapCircle: _mapCircle mapCircle: _mapCircle
visible: false visible: false
property alias center: _mapCircle.center property alias center: _mapCircle.center
property alias clockwiseRotation: _mapCircle.clockwiseRotation
readonly property real defaultRadius: 30 readonly property real defaultRadius: 30
@ -348,6 +349,8 @@ FlightMap {
id: _mapCircle id: _mapCircle
interactive: true interactive: true
radius.rawValue: 30 radius.rawValue: 30
showRotation: true
clockwiseRotation: true
} }
} }

2
src/FlightDisplay/GuidedActionsController.qml

@ -384,7 +384,7 @@ Item {
_activeVehicle.setCurrentMissionSequence(actionData) _activeVehicle.setCurrentMissionSequence(actionData)
break break
case actionOrbit: case actionOrbit:
_activeVehicle.guidedModeOrbit(orbitMapCircle.center, orbitMapCircle.radius(), _activeVehicle.altitudeAMSL.rawValue + actionAltitudeChange) _activeVehicle.guidedModeOrbit(orbitMapCircle.center, orbitMapCircle.radius() * (orbitMapCircle.clockWiseRotation ? 1 : -1), _activeVehicle.altitudeAMSL.rawValue + actionAltitudeChange)
orbitMapCircle.hide() orbitMapCircle.hide()
break break
case actionLandAbort: case actionLandAbort:

2
src/MissionManager/QGCFenceCircle.cc

@ -20,7 +20,7 @@ QGCFenceCircle::QGCFenceCircle(QObject* parent)
} }
QGCFenceCircle::QGCFenceCircle(const QGeoCoordinate& center, double radius, bool inclusion, QObject* parent) QGCFenceCircle::QGCFenceCircle(const QGeoCoordinate& center, double radius, bool inclusion, QObject* parent)
: QGCMapCircle (center, radius, parent) : QGCMapCircle (center, radius, false /* showRotation */, true /* clockwiseRotation */, parent)
, _inclusion (inclusion) , _inclusion (inclusion)
{ {
_init(); _init();

53
src/MissionManager/QGCMapCircle.cc

@ -22,30 +22,36 @@ const char* QGCMapCircle::_jsonRadiusKey = "radius";
const char* QGCMapCircle::_radiusFactName = "Radius"; const char* QGCMapCircle::_radiusFactName = "Radius";
QGCMapCircle::QGCMapCircle(QObject* parent) QGCMapCircle::QGCMapCircle(QObject* parent)
: QObject (parent) : QObject (parent)
, _dirty (false) , _dirty (false)
, _interactive (false) , _interactive (false)
, _showRotation (false)
, _clockwiseRotation(true)
{ {
_init(); _init();
} }
QGCMapCircle::QGCMapCircle(const QGeoCoordinate& center, double radius, QObject* parent) QGCMapCircle::QGCMapCircle(const QGeoCoordinate& center, double radius, bool showRotation, bool clockwiseRotation, QObject* parent)
: QObject (parent) : QObject (parent)
, _dirty (false) , _dirty (false)
, _center (center) , _center (center)
, _radius (FactSystem::defaultComponentId, _radiusFactName, FactMetaData::valueTypeDouble) , _radius (FactSystem::defaultComponentId, _radiusFactName, FactMetaData::valueTypeDouble)
, _interactive (false) , _interactive (false)
, _showRotation (showRotation)
, _clockwiseRotation(clockwiseRotation)
{ {
_radius.setRawValue(radius); _radius.setRawValue(radius);
_init(); _init();
} }
QGCMapCircle::QGCMapCircle(const QGCMapCircle& other, QObject* parent) QGCMapCircle::QGCMapCircle(const QGCMapCircle& other, QObject* parent)
: QObject (parent) : QObject (parent)
, _dirty (false) , _dirty (false)
, _center (other._center) , _center (other._center)
, _radius (FactSystem::defaultComponentId, _radiusFactName, FactMetaData::valueTypeDouble) , _radius (FactSystem::defaultComponentId, _radiusFactName, FactMetaData::valueTypeDouble)
, _interactive (false) , _interactive (false)
, _showRotation (other._showRotation)
, _clockwiseRotation(other._clockwiseRotation)
{ {
_radius.setRawValue(other._radius.rawValue()); _radius.setRawValue(other._radius.rawValue());
_init(); _init();
@ -117,6 +123,10 @@ bool QGCMapCircle::loadFromJson(const QJsonObject& json, QString& errorString)
setCenter(center); setCenter(center);
_radius.setRawValue(circleObject[_jsonRadiusKey].toDouble()); _radius.setRawValue(circleObject[_jsonRadiusKey].toDouble());
_interactive = false;
_showRotation = false;
_clockwiseRotation = true;
return true; return true;
} }
@ -142,3 +152,18 @@ void QGCMapCircle::setInteractive(bool interactive)
} }
} }
void QGCMapCircle::setShowRotation(bool showRotation)
{
if (showRotation != _showRotation) {
_showRotation = showRotation;
emit showRotationChanged(showRotation);
}
}
void QGCMapCircle::setClockwiseRotation(bool clockwiseRotation)
{
if (clockwiseRotation != _clockwiseRotation) {
_clockwiseRotation = clockwiseRotation;
emit clockwiseRotationChanged(clockwiseRotation);
}
}

39
src/MissionManager/QGCMapCircle.h

@ -25,14 +25,17 @@ class QGCMapCircle : public QObject
public: public:
QGCMapCircle(QObject* parent = nullptr); QGCMapCircle(QObject* parent = nullptr);
QGCMapCircle(const QGeoCoordinate& center, double radius, QObject* parent = nullptr); QGCMapCircle(const QGeoCoordinate& center, double radius, QObject* parent = nullptr);
QGCMapCircle(const QGeoCoordinate& center, double radius, bool showRotation, bool clockwiseRotation, QObject* parent = nullptr);
QGCMapCircle(const QGCMapCircle& other, QObject* parent = nullptr); QGCMapCircle(const QGCMapCircle& other, QObject* parent = nullptr);
const QGCMapCircle& operator=(const QGCMapCircle& other); const QGCMapCircle& operator=(const QGCMapCircle& other);
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
Q_PROPERTY(Fact* radius READ radius CONSTANT) Q_PROPERTY(Fact* radius READ radius CONSTANT)
Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged) Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
Q_PROPERTY(bool showRotation READ showRotation WRITE setShowRotation NOTIFY showRotationChanged)
Q_PROPERTY(bool clockwiseRotation READ clockwiseRotation WRITE setClockwiseRotation NOTIFY clockwiseRotationChanged)
/// Saves the polygon to the json object. /// Saves the polygon to the json object.
/// @param json Json object to save to /// @param json Json object to save to
@ -46,21 +49,27 @@ public:
// Property methods // Property methods
bool dirty (void) const { return _dirty; } bool dirty (void) const { return _dirty; }
QGeoCoordinate center (void) const { return _center; } QGeoCoordinate center (void) const { return _center; }
Fact* radius (void) { return &_radius; } Fact* radius (void) { return &_radius; }
bool interactive (void) const { return _interactive; } bool interactive (void) const { return _interactive; }
bool showRotation (void) const { return _showRotation; }
bool clockwiseRotation (void) const { return _clockwiseRotation; }
void setDirty (bool dirty); void setDirty (bool dirty);
void setCenter (QGeoCoordinate newCenter); void setCenter (QGeoCoordinate newCenter);
void setInteractive (bool interactive); void setInteractive (bool interactive);
void setShowRotation (bool showRotation);
void setClockwiseRotation (bool clockwiseRotation);
static const char* jsonCircleKey; static const char* jsonCircleKey;
signals: signals:
void dirtyChanged (bool dirty); void dirtyChanged (bool dirty);
void centerChanged (QGeoCoordinate center); void centerChanged (QGeoCoordinate center);
void interactiveChanged (bool interactive); void interactiveChanged (bool interactive);
void showRotationChanged (bool showRotation);
void clockwiseRotationChanged (bool clockwiseRotation);
private slots: private slots:
void _setDirty(void); void _setDirty(void);
@ -72,6 +81,8 @@ private:
QGeoCoordinate _center; QGeoCoordinate _center;
Fact _radius; Fact _radius;
bool _interactive; bool _interactive;
bool _showRotation;
bool _clockwiseRotation;
QMap<QString, FactMetaData*> _nameToMetaDataMap; QMap<QString, FactMetaData*> _nameToMetaDataMap;

78
src/MissionManager/QGCMapCircleVisuals.qml

@ -30,14 +30,23 @@ Item {
property int borderWidth: 2 property int borderWidth: 2
property color borderColor: "orange" property color borderColor: "orange"
property var _circleComponent property var _circleComponent
property var _dragHandlesComponent property var _topRotationIndicatorComponent
property var _bottomRotationIndicatorComponent
property var _dragHandlesComponent
property real _radius: mapCircle.radius.rawValue
function addVisuals() { function addVisuals() {
if (!_circleComponent) { if (!_circleComponent) {
_circleComponent = circleComponent.createObject(mapControl) _circleComponent = circleComponent.createObject(mapControl)
mapControl.addMapItem(_circleComponent) mapControl.addMapItem(_circleComponent)
} }
if (!_topRotationIndicatorComponent) {
_topRotationIndicatorComponent = rotationIndicatorComponent.createObject(mapControl, { "topIndicator": true })
_bottomRotationIndicatorComponent = rotationIndicatorComponent.createObject(mapControl, { "topIndicator": false })
mapControl.addMapItem(_topRotationIndicatorComponent)
mapControl.addMapItem(_bottomRotationIndicatorComponent)
}
} }
function removeVisuals() { function removeVisuals() {
@ -45,6 +54,12 @@ Item {
_circleComponent.destroy() _circleComponent.destroy()
_circleComponent = undefined _circleComponent = undefined
} }
if (_topRotationIndicatorComponent) {
_topRotationIndicatorComponent.destroy()
_bottomRotationIndicatorComponent.destroy()
_topRotationIndicatorComponent = undefined
_bottomRotationIndicatorComponent = undefined
}
} }
function addDragHandles() { function addDragHandles() {
@ -74,15 +89,64 @@ Item {
} }
} }
Component.onCompleted: updateInternalComponents() Component.onCompleted: {
onInteractiveChanged: updateInternalComponents() updateInternalComponents()
onVisibleChanged: updateInternalComponents() }
Component.onDestruction: { Component.onDestruction: {
removeVisuals() removeVisuals()
removeDragHandles() removeDragHandles()
} }
onInteractiveChanged: updateInternalComponents()
onVisibleChanged: updateInternalComponents()
Component {
id: rotationIndicatorComponent
MapQuickItem {
z: QGroundControl.zOrderMapItems + 2
visible: mapCircle.showRotation
property bool topIndicator: true
property real _rotationRadius: _radius
function updateCoordinate() {
coordinate = mapCircle.center.atDistanceAndAzimuth(_radius, topIndicator ? 0 : 180)
}
Component.onCompleted: updateCoordinate()
on_RotationRadiusChanged: updateCoordinate()
Connections {
target: mapCircle
onCenterChanged: updateCoordinate()
}
sourceItem: QGCColoredImage {
anchors.centerIn: parent
width: ScreenTools.defaultFontPixelHeight / 2
height: ScreenTools.defaultFontPixelHeight
source: "/qmlimages/arrow-down.png"
color: borderColor
transform: Rotation {
origin.x: width / 2
origin.y: height / 2
angle: (mapCircle.clockwiseRotation ? 1 : -1) * (topIndicator ? -90 : 90)
}
QGCMouseArea {
fillItem: parent
onClicked: mapCircle.clockwiseRotation = !mapCircle.clockwiseRotation
visible: mapCircle.interactive
}
}
}
}
Component { Component {
id: circleComponent id: circleComponent
@ -92,7 +156,7 @@ Item {
border.color: borderColor border.color: borderColor
border.width: borderWidth border.width: borderWidth
center: mapCircle.center center: mapCircle.center
radius: mapCircle.radius.rawValue radius: _radius
} }
} }
@ -146,7 +210,7 @@ Item {
property var radiusDragArea property var radiusDragArea
property var radiusDragCoord: QtPositioning.coordinate() property var radiusDragCoord: QtPositioning.coordinate()
property var circleCenterCoord: mapCircle.center property var circleCenterCoord: mapCircle.center
property real circleRadius: mapCircle.radius.rawValue property real circleRadius: _radius
function calcRadiusDragCoord() { function calcRadiusDragCoord() {
radiusDragCoord = mapCircle.center.atDistanceAndAzimuth(circleRadius, 90) radiusDragCoord = mapCircle.center.atDistanceAndAzimuth(circleRadius, 90)

Loading…
Cancel
Save