Commit 5d91598d authored by Valentin Platzgummer's avatar Valentin Platzgummer

service area depot issue solved.

parent 0397d607
This diff is collapsed.
...@@ -23,10 +23,16 @@ WimaServiceArea &WimaServiceArea::operator=(const WimaServiceArea &other) { ...@@ -23,10 +23,16 @@ WimaServiceArea &WimaServiceArea::operator=(const WimaServiceArea &other) {
return *this; return *this;
} }
const QGeoCoordinate &WimaServiceArea::depot() const { return _depot; }
QGeoCoordinate WimaServiceArea::depotQml() const { return _depot; }
bool WimaServiceArea::setDepot(const QGeoCoordinate &coordinate) { bool WimaServiceArea::setDepot(const QGeoCoordinate &coordinate) {
if (_depot != coordinate) { if (_depot.latitude() != coordinate.latitude() ||
_depot.longitude() != coordinate.longitude()) {
if (this->containsCoordinate(coordinate)) { if (this->containsCoordinate(coordinate)) {
_depot = coordinate; _depot = coordinate;
_depot.setAltitude(0);
emit depotChanged(); emit depotChanged();
return true; return true;
} }
...@@ -90,7 +96,27 @@ void WimaServiceArea::init() { ...@@ -90,7 +96,27 @@ void WimaServiceArea::init() {
this->setObjectName(wimaServiceAreaName); this->setObjectName(wimaServiceAreaName);
connect(this, &WimaArea::pathChanged, [this] { connect(this, &WimaArea::pathChanged, [this] {
if (!this->_depot.isValid() || !this->containsCoordinate(this->_depot)) { if (!this->_depot.isValid() || !this->containsCoordinate(this->_depot)) {
this->setDepot(this->center()); if (this->containsCoordinate(this->center())) {
// Use center.
this->setDepot(this->center());
} else if (this->_depot.isValid()) {
// Use nearest coordinate.
auto minDist = std::numeric_limits<double>::infinity();
auto minIt = this->pathReference().begin();
for (auto it = this->pathReference().begin();
it < this->pathReference().end(); ++it) {
const auto vertex = it->value<QGeoCoordinate>();
auto d = vertex.distanceTo(this->_depot);
if (d < minDist) {
minDist = d;
minIt = it;
}
}
this->setDepot(minIt->value<QGeoCoordinate>());
} else if (this->pathReference().size() > 0) {
// Use first coordinate.
this->setDepot(this->pathReference().value(0).value<QGeoCoordinate>());
}
} }
}); });
} }
...@@ -11,14 +11,16 @@ public: ...@@ -11,14 +11,16 @@ public:
WimaServiceArea(const WimaServiceArea &other, QObject *parent); WimaServiceArea(const WimaServiceArea &other, QObject *parent);
WimaServiceArea &operator=(const WimaServiceArea &other); WimaServiceArea &operator=(const WimaServiceArea &other);
Q_PROPERTY(QGeoCoordinate depot READ depot WRITE setDepot NOTIFY depotChanged) Q_PROPERTY(
QGeoCoordinate depot READ depotQml WRITE setDepot NOTIFY depotChanged)
// Overrides from WimaPolygon // Overrides from WimaPolygon
QString mapVisualQML(void) const { return "WimaServiceAreaMapVisual.qml"; } QString mapVisualQML(void) const { return "WimaServiceAreaMapVisual.qml"; }
QString editorQML(void) const { return "WimaServiceAreaEditor.qml"; } QString editorQML(void) const { return "WimaServiceAreaEditor.qml"; }
// Property acessors // Property acessors
const QGeoCoordinate &depot(void) const { return _depot; } const QGeoCoordinate &depot(void) const;
QGeoCoordinate depotQml(void) const;
// Member Methodes // Member Methodes
void saveToJson(QJsonObject &json); void saveToJson(QJsonObject &json);
......
...@@ -7,12 +7,12 @@ WaypointManager::EmptyManager::EmptyManager(Settings &settings, AreaInterface &) ...@@ -7,12 +7,12 @@ WaypointManager::EmptyManager::EmptyManager(Settings &settings, AreaInterface &)
void WaypointManager::EmptyManager::clear() {} void WaypointManager::EmptyManager::clear() {}
bool WaypointManager::EmptyManager::update() {} bool WaypointManager::EmptyManager::update() { return true; }
bool WaypointManager::EmptyManager::next() {} bool WaypointManager::EmptyManager::next() { return true; }
bool WaypointManager::EmptyManager::previous() {} bool WaypointManager::EmptyManager::previous() { return true; }
bool WaypointManager::EmptyManager::reset() {} bool WaypointManager::EmptyManager::reset() { return true; }
} // namespace WaypointManager } // namespace WaypointManager
...@@ -29,10 +29,8 @@ Item { ...@@ -29,10 +29,8 @@ Item {
property bool checked property bool checked
property string label: "Reference" property string label: "Reference"
property var _itemVisual property var _itemVisual: undefined
property bool _itemVisualShowing: false property var _dragArea: undefined
property var _dragArea
property bool _dragAreaShowing: false
signal clicked() signal clicked()
signal released() signal released()
...@@ -45,31 +43,30 @@ Item { ...@@ -45,31 +43,30 @@ Item {
signal dragReleased() signal dragReleased()
function hideItemVisuals() { function hideItemVisuals() {
if (_itemVisualShowing) { if (_itemVisual) {
map.removeMapItem(_itemVisual)
_itemVisual.destroy() _itemVisual.destroy()
_itemVisualShowing = false _itemVisual = undefined
} }
} }
function showItemVisuals() { function showItemVisuals() {
if (!_itemVisualShowing) { if (!_itemVisual) {
_itemVisual = indicatorComponent.createObject(map) _itemVisual = indicatorComponent.createObject(map)
map.addMapItem(_itemVisual) map.addMapItem(_itemVisual)
_itemVisualShowing = true
} }
} }
function hideDragArea() { function hideDragArea() {
if (_dragAreaShowing) { if (_dragArea) {
_dragArea.destroy() _dragArea.destroy()
_dragAreaShowing = false _dragArea = undefined
} }
} }
function showDragArea() { function showDragArea() {
if (!_dragAreaShowing) { if (!_dragArea) {
_dragArea = dragAreaComponent.createObject(map) _dragArea = dragAreaComponent.createObject(map)
_dragAreaShowing = true
} }
} }
...@@ -102,7 +99,9 @@ Item { ...@@ -102,7 +99,9 @@ Item {
itemIndicator: _itemVisual itemIndicator: _itemVisual
Component.onCompleted: itemCoordinate = _root.coordinate Component.onCompleted: itemCoordinate = _root.coordinate
onItemCoordinateChanged: _root.coordinate = itemCoordinate onItemCoordinateChanged: {
_root.coordinate = itemCoordinate
}
onDragStart: _root.dragStart() onDragStart: _root.dragStart()
onDragStop: _root.dragStop() onDragStop: _root.dragStop()
......
...@@ -26,35 +26,32 @@ Item { ...@@ -26,35 +26,32 @@ Item {
property var areaItem: object property var areaItem: object
property var _polygon: areaItem property var _polygon: areaItem
property var _depot property var _depot: undefined
property bool showDepot: areaItem.interactive || areaItem.borderPolygon.interactive property bool _showDepot: areaItem.interactive || areaItem.borderPolygon.interactive
property bool _depotVisible: false
on_ShowDepotChanged: {
onShowDepotChanged: { if (_showDepot){
if (showDepot){ _addDepot()
if (!_depotVisible){
_addDepot()
}
} else { } else {
if (_depotVisible){ _destroyDepot()
_destroyDepot()
}
} }
} }
signal clicked(int sequenceNumber) signal clicked(int sequenceNumber)
function _addDepot() { function _addDepot() {
_depot = depotPointComponent.createObject(map) if (!_depot){
map.addMapItem(_depot) _depot = depotPointComponent.createObject(_root)
_depotVisible = true map.addMapItem(_depot)
}
} }
function _destroyDepot() { function _destroyDepot() {
if (_depot){ if (_depot){
map.removeMapItem(_depot)
_depot.destroy() _depot.destroy()
_depot = undefined
} }
_depotVisible = false
} }
/// Add an initial 4 sided polygon if there is none /// Add an initial 4 sided polygon if there is none
...@@ -104,7 +101,7 @@ Item { ...@@ -104,7 +101,7 @@ Item {
Component.onCompleted: { Component.onCompleted: {
_addInitialPolygon() _addInitialPolygon()
if (showDepot){ if (_showDepot){
_addDepot() _addDepot()
} }
} }
...@@ -137,21 +134,33 @@ Item { ...@@ -137,21 +134,33 @@ Item {
Component { Component {
id: depotPointComponent id: depotPointComponent
DragCoordinate { DragCoordinate {
property var depot: areaItem.depot property var depot: _root.areaItem.depot
map: _root.map map: _root.map
qgcView: _root.qgcView qgcView: _root.qgcView
z: QGroundControl.zOrderMapItems z: QGroundControl.zOrderMapItems
checked: showDepot checked: _root._showDepot
coordinate: depot coordinate: _root.areaItem.depot
label: "Depot" label: "Depot"
onDragReleased: { function syncAndBind(){
if (areaItem.containsCoordinate(coordinate)){ if (coordinate.latitude !== depot.latitude ||
areaItem.depot = coordinate coordinate.longitude !== depot.longitude){
if (_root.areaItem.containsCoordinate(coordinate)){
_root.areaItem.depot = coordinate
}
} }
coordinate = Qt.binding(function() { return areaItem.depot; }) coordinate = Qt.binding(function(){return _root.areaItem.depot})
} }
onDragReleased: {
syncAndBind()
}
Component.onCompleted: {
syncAndBind()
}
} }
} }
......
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