diff --git a/src/MissionManager/MissionController.cc b/src/MissionManager/MissionController.cc index 257a2a7231aabf77f8de5b5024e5f13b4be8e0f9..a11afb3317e70bf6a2a32d068025d06bba9b30f0 100644 --- a/src/MissionManager/MissionController.cc +++ b/src/MissionManager/MissionController.cc @@ -1110,9 +1110,14 @@ void MissionController::_recalcWaypointLines(void) qCDebug(MissionControllerLog) << "_recalcWaypointLines homePositionValid" << homePositionValid; CoordVectHashTable old_table = _linesTable; + _linesTable.clear(); - _waypointLines.clear(); _waypointPath.clear(); + + _waypointLines.beginReset(); + _directionArrows.beginReset(); + + _waypointLines.clear(); _directionArrows.clear(); bool linkEndToHome; @@ -1150,7 +1155,10 @@ void MissionController::_recalcWaypointLines(void) lastSegmentVisualItemPair = VisualItemPair(lastCoordinateItem, item); if (!_flyView || addDirectionArrow) { - _directionArrows.append(_addWaypointLineSegment(old_table, lastSegmentVisualItemPair)); + CoordinateVector* coordVector = _addWaypointLineSegment(old_table, lastSegmentVisualItemPair); + if (addDirectionArrow) { + _directionArrows.append(coordVector); + } } } firstCoordinateItem = false; @@ -1205,6 +1213,9 @@ void MissionController::_recalcWaypointLines(void) _waypointLines.swapObjectList(objs); } + _waypointLines.endReset(); + _directionArrows.endReset(); + // Anything left in the old table is an obsolete line object that can go qDeleteAll(old_table); @@ -1218,7 +1229,6 @@ void MissionController::_recalcWaypointLines(void) _waypointPath.append(QVariant::fromValue(QGeoCoordinate(0, 0))); } - emit waypointLinesChanged(); emit waypointPathChanged(); } diff --git a/src/MissionManager/MissionController.h b/src/MissionManager/MissionController.h index 16d2c549cfcff22eb98b6f6443b4e999d0695ad0..62b4235ec26b74c160022d7a93262207bc76ed8d 100644 --- a/src/MissionManager/MissionController.h +++ b/src/MissionManager/MissionController.h @@ -68,7 +68,7 @@ public: } MissionFlightStatus_t; Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged) - Q_PROPERTY(QmlObjectListModel* waypointLines READ waypointLines NOTIFY waypointLinesChanged) ///< Used by Plan view only for interactive editing + Q_PROPERTY(QmlObjectListModel* waypointLines READ waypointLines CONSTANT) ///< Used by Plan view only for interactive editing Q_PROPERTY(QVariantList waypointPath READ waypointPath NOTIFY waypointPathChanged) ///< Used by Fly view only for static display Q_PROPERTY(QmlObjectListModel* directionArrows READ directionArrows CONSTANT) Q_PROPERTY(QStringList complexMissionItemNames READ complexMissionItemNames NOTIFY complexMissionItemNamesChanged) @@ -206,7 +206,6 @@ public: signals: void visualItemsChanged (void); - void waypointLinesChanged (void); void waypointPathChanged (void); void newItemsFromVehicle (void); void missionDistanceChanged (double missionDistance); diff --git a/src/MissionManager/MissionControllerTest.cc b/src/MissionManager/MissionControllerTest.cc index 29d3f2c9c75ca5731933e1eb108ab9893991b797..effced1e7205cc95445fca08cdb2a483815ffc32 100644 --- a/src/MissionManager/MissionControllerTest.cc +++ b/src/MissionManager/MissionControllerTest.cc @@ -48,7 +48,6 @@ void MissionControllerTest::_initForFirmwareType(MAV_AUTOPILOT firmwareType) // MissionController signals _rgMissionControllerSignals[visualItemsChangedSignalIndex] = SIGNAL(visualItemsChanged()); - _rgMissionControllerSignals[waypointLinesChangedSignalIndex] = SIGNAL(waypointLinesChanged()); // Master controller pulls offline vehicle info from settings qgcApp()->toolbox()->settingsManager()->appSettings()->offlineEditingFirmwareType()->setRawValue(firmwareType); @@ -62,7 +61,7 @@ void MissionControllerTest::_initForFirmwareType(MAV_AUTOPILOT firmwareType) _masterController->start(false /* flyView */); // All signals should some through on start - QCOMPARE(_multiSpyMissionController->checkOnlySignalsByMask(visualItemsChangedSignalMask | waypointLinesChangedSignalMask), true); + QCOMPARE(_multiSpyMissionController->checkOnlySignalsByMask(visualItemsChangedSignalMask), true); _multiSpyMissionController->clearAllSignals(); QmlObjectListModel* visualItems = _missionController->visualItems(); @@ -120,8 +119,6 @@ void MissionControllerTest::_testAddWaypointWorker(MAV_AUTOPILOT firmwareType) _missionController->insertSimpleMissionItem(coordinate, _missionController->visualItems()->count()); - QCOMPARE(_multiSpyMissionController->checkOnlySignalsByMask(waypointLinesChangedSignalMask), true); - QmlObjectListModel* visualItems = _missionController->visualItems(); QVERIFY(visualItems); diff --git a/src/MissionManager/MissionControllerTest.h b/src/MissionManager/MissionControllerTest.h index 101c20482dc9841926c97cd2a804bc96aa69323a..88a4ec6e034a87a334591d3c04ce3c641093d3be 100644 --- a/src/MissionManager/MissionControllerTest.h +++ b/src/MissionManager/MissionControllerTest.h @@ -70,13 +70,11 @@ private: enum { visualItemsChangedSignalIndex = 0, - waypointLinesChangedSignalIndex, missionControllerMaxSignalIndex }; enum { visualItemsChangedSignalMask = 1 << visualItemsChangedSignalIndex, - waypointLinesChangedSignalMask = 1 << waypointLinesChangedSignalIndex, }; MultiSignalSpy* _multiSpyMissionController; diff --git a/src/QmlControls/QmlObjectListModel.cc b/src/QmlControls/QmlObjectListModel.cc index e06e61db8c673df02c731751b8dd2f22f5a7edf2..1395fa862143f0162fb58da0f5dd87f9728ea64d 100644 --- a/src/QmlControls/QmlObjectListModel.cc +++ b/src/QmlControls/QmlObjectListModel.cc @@ -20,9 +20,10 @@ const int QmlObjectListModel::ObjectRole = Qt::UserRole; const int QmlObjectListModel::TextRole = Qt::UserRole + 1; QmlObjectListModel::QmlObjectListModel(QObject* parent) - : QAbstractListModel(parent) - , _dirty(false) - , _skipDirtyFirstItem(false) + : QAbstractListModel (parent) + , _dirty (false) + , _skipDirtyFirstItem (false) + , _externalBeginResetModel (false) { } @@ -142,8 +143,13 @@ const QObject* QmlObjectListModel::operator[](int index) const void QmlObjectListModel::clear() { - while (rowCount()) { - removeAt(0); + if (!_externalBeginResetModel) { + beginResetModel(); + } + _objectList.clear(); + if (!_externalBeginResetModel) { + endResetModel(); + emit countChanged(count()); } } @@ -221,10 +227,14 @@ void QmlObjectListModel::append(QList objects) QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist) { QObjectList oldlist(_objectList); - beginResetModel(); + if (!_externalBeginResetModel) { + beginResetModel(); + } _objectList = newlist; - endResetModel(); - emit countChanged(count()); + if (!_externalBeginResetModel) { + endResetModel(); + emit countChanged(count()); + } return oldlist; } @@ -274,3 +284,21 @@ void QmlObjectListModel::clearAndDeleteContents() clear(); endResetModel(); } + +void QmlObjectListModel::beginReset(void) +{ + if (_externalBeginResetModel) { + qWarning() << "QmlObjectListModel::beginReset already set"; + } + _externalBeginResetModel = true; + beginResetModel(); +} + +void QmlObjectListModel::endReset(void) +{ + if (!_externalBeginResetModel) { + qWarning() << "QmlObjectListModel::endReset begin not set"; + } + _externalBeginResetModel = false; + endResetModel(); +} diff --git a/src/QmlControls/QmlObjectListModel.h b/src/QmlControls/QmlObjectListModel.h index dd04d6d01eb04bfffd4cf8b93f846243c0fc8354..49c2dd9d3acbc73493dd7d527c6bafe1007b4ee8 100644 --- a/src/QmlControls/QmlObjectListModel.h +++ b/src/QmlControls/QmlObjectListModel.h @@ -33,6 +33,7 @@ public: int count () const; bool dirty () const { return _dirty; } + void setDirty (bool dirty); void append (QObject* object); void append (QList objects); @@ -56,8 +57,8 @@ public: /// Clears the list and calls deleteLater on each entry void clearAndDeleteContents (); - void beginReset () { beginResetModel(); } - void endReset () { endResetModel(); } + void beginReset (); + void endReset (); signals: void countChanged (int count); @@ -80,6 +81,7 @@ private: bool _dirty; bool _skipDirtyFirstItem; + bool _externalBeginResetModel; static const int ObjectRole; static const int TextRole;