diff --git a/src/MissionManager/MissionManager.h b/src/MissionManager/MissionManager.h index e34d6e37dc69239ff7f09882fdc69bf10a35c6b0..a333678f700af0121eac22855ddfbd824c9229f6 100644 --- a/src/MissionManager/MissionManager.h +++ b/src/MissionManager/MissionManager.h @@ -38,10 +38,6 @@ public: /// from mission start to resumeIndex in the generate mission. void generateResumeMission(int resumeIndex); -signals: - void currentIndexChanged (int currentIndex); - void lastCurrentIndexChanged (int lastCurrentIndex); - private slots: void _mavlinkMessageReceived(const mavlink_message_t& message); diff --git a/src/MissionManager/QGCMapPolygon.cc b/src/MissionManager/QGCMapPolygon.cc index 3803e203ed08495ae8d2d3cb62dd9728999a143b..6b607e3862eb5c7333ab4e6441f612e3d57dc67f 100644 --- a/src/MissionManager/QGCMapPolygon.cc +++ b/src/MissionManager/QGCMapPolygon.cc @@ -258,6 +258,19 @@ void QGCMapPolygon::appendVertex(const QGeoCoordinate& coordinate) emit pathChanged(); } +void QGCMapPolygon::appendVertices(const QList& coordinates) +{ + QList objects; + + foreach (const QGeoCoordinate& coordinate, coordinates) { + objects.append(new QGCQGeoCoordinate(coordinate, this)); + _polygonPath.append(QVariant::fromValue(coordinate)); + } + _polygonModel.append(objects); + emit pathChanged(); +} + + void QGCMapPolygon::_polygonModelDirtyChanged(bool dirty) { if (dirty) { @@ -509,9 +522,7 @@ bool QGCMapPolygon::loadKMLFile(const QString& kmlFile) } clear(); - for (int i=0; i& coordinates); /// Adjust the value for the specified coordinate /// @param vertexIndex Polygon point index to modify (0-based) diff --git a/src/MissionManager/SurveyMissionItem.cc b/src/MissionManager/SurveyMissionItem.cc index 1e8b5e9f4590bde163effb055a5212090f76e4b0..c7c4d76c4c8f421e541e1171243e82b7b24867a8 100644 --- a/src/MissionManager/SurveyMissionItem.cc +++ b/src/MissionManager/SurveyMissionItem.cc @@ -554,53 +554,6 @@ void SurveyMissionItem::_swapPoints(QList& points, int index1, int inde points[index2] = temp; } -QList SurveyMissionItem::_convexPolygon(const QList& polygon) -{ - // We use the Graham scan algorithem to convert the possibly concave polygon to a convex polygon - // https://en.wikipedia.org/wiki/Graham_scan - - QList workPolygon(polygon); - - // First point must be lowest y-coordinate point - for (int i=1; i angle) { - _swapPoints(workPolygon, i, j); - angle = _dp(workPolygon[0], workPolygon[j]); - } - } - } - - // Perform the the Graham scan - - workPolygon.insert(0, workPolygon.last()); // Sentinel for algo stop - int convexCount = 1; // Number of points on the convex hull. - - for (int i=2; i<=polygon.count(); i++) { - while (_ccw(workPolygon[convexCount-1], workPolygon[convexCount], workPolygon[i]) <= 0) { - if (convexCount > 1) { - convexCount -= 1; - } else if (i == polygon.count()) { - break; - } else { - i++; - } - } - convexCount++; - _swapPoints(workPolygon, convexCount, i); - } - - return workPolygon.mid(1, convexCount); -} - /// Returns true if the current grid angle generates north/south oriented transects bool SurveyMissionItem::_gridAngleIsNorthSouthTransects() { @@ -695,8 +648,6 @@ void SurveyMissionItem::_generateGrid(void) qCDebug(SurveyMissionItemLog) << "vertex:x:y" << vertex << polygonPoints.last().x() << polygonPoints.last().y(); } - polygonPoints = _convexPolygon(polygonPoints); - double coveredArea = 0.0; for (int i=0; i& lineList, c void SurveyMissionItem::_intersectLinesWithPolygon(const QList& lineList, const QPolygonF& polygon, QList& resultLines) { resultLines.clear(); + for (int i=0; i intersections; + // Intersect the line with all the polygon edges for (int j=0; j 1) { + QPointF firstPoint; + QPointF secondPoint; + double currentMaxDistance = 0; + + for (int i=0; i currentMaxDistance) { + firstPoint = intersections[i]; + secondPoint = intersections[j]; + currentMaxDistance = newMaxDistance; + } + } + } + + resultLines += QLineF(firstPoint, secondPoint); } } } diff --git a/src/MissionManager/SurveyMissionItem.h b/src/MissionManager/SurveyMissionItem.h index 307042c77dd03af635e917cfca7a3a8bce214f61..92b084f47de1b5e8289952921d73b6b1cb561031 100644 --- a/src/MissionManager/SurveyMissionItem.h +++ b/src/MissionManager/SurveyMissionItem.h @@ -217,7 +217,6 @@ private: qreal _ccw(QPointF pt1, QPointF pt2, QPointF pt3); qreal _dp(QPointF pt1, QPointF pt2); void _swapPoints(QList& points, int index1, int index2); - QList _convexPolygon(const QList& polygon); void _reverseTransectOrder(QList>& transects); void _reverseInternalTransectPoints(QList>& transects); void _adjustTransectsToEntryPointLocation(QList>& transects); diff --git a/src/PlanView/SurveyItemEditor.qml b/src/PlanView/SurveyItemEditor.qml index ad47d11ebe470df2c7fc302f299d25c37763517c..58579e36586f985334c1d68c25b6bcd204a80326 100644 --- a/src/PlanView/SurveyItemEditor.qml +++ b/src/PlanView/SurveyItemEditor.qml @@ -63,6 +63,7 @@ Rectangle { } } } + recalcFromCameraValues() } function recalcFromCameraValues() { diff --git a/src/QmlControls/QmlObjectListModel.cc b/src/QmlControls/QmlObjectListModel.cc index 1db22e6e8e1955eebbb2c33abe3c1ff59258a093..f45a6e996c7b59c88a5d8f1c4d9ad4893d2e116e 100644 --- a/src/QmlControls/QmlObjectListModel.cc +++ b/src/QmlControls/QmlObjectListModel.cc @@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object) setDirty(true); } +void QmlObjectListModel::insert(int i, QList objects) +{ + if (i < 0 || i > _objectList.count()) { + qWarning() << "Invalid index index:count" << i << _objectList.count(); + } + + int j = i; + foreach (QObject* object, objects) { + QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); + + // Look for a dirtyChanged signal on the object + if (object->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("dirtyChanged(bool)")) != -1) { + if (!_skipDirtyFirstItem || j != 0) { + QObject::connect(object, SIGNAL(dirtyChanged(bool)), this, SLOT(_childDirtyChanged(bool))); + } + } + j++; + + _objectList.insert(i, object); + } + + insertRows(i, objects.count()); + + setDirty(true); +} + void QmlObjectListModel::append(QObject* object) { insert(_objectList.count(), object); } +void QmlObjectListModel::append(QList objects) +{ + insert(_objectList.count(), objects); +} + QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist) { QObjectList oldlist(_objectList); diff --git a/src/QmlControls/QmlObjectListModel.h b/src/QmlControls/QmlObjectListModel.h index 78a202dd0db9054179ea3e83aa217552a6f76def..976405ee5794118ae6bca4c8bf2d2d9fc7830aba 100644 --- a/src/QmlControls/QmlObjectListModel.h +++ b/src/QmlControls/QmlObjectListModel.h @@ -37,11 +37,13 @@ public: void setDirty(bool dirty); void append(QObject* object); + void append(QList objects); QObjectList swapObjectList(const QObjectList& newlist); void clear(void); QObject* removeAt(int i); QObject* removeOne(QObject* object) { return removeAt(indexOf(object)); } void insert(int i, QObject* object); + void insert(int i, QList objects); QObject* operator[](int i); const QObject* operator[](int i) const; bool contains(QObject* object) { return _objectList.indexOf(object) != -1; } @@ -63,12 +65,12 @@ private slots: private: // Overrides from QAbstractListModel - virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; - virtual QHash roleNames(void) const; - virtual bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); - virtual bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + int rowCount(const QModelIndex & parent = QModelIndex()) const override; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; + QHash roleNames(void) const override; + bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override; + bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; private: QList _objectList;