12#include <QtCore/QJsonArray>
18 , _managerVehicle (masterController->managerVehicle())
19 , _rallyPointManager (masterController->managerVehicle()->rallyPointManager())
31 qCDebug(GeoFenceControllerLog) <<
"start flyView" << flyView;
39void RallyPointController::_managerVehicleChanged(
Vehicle* managerVehicle)
41 if (_managerVehicle) {
42 _rallyPointManager->disconnect(
this);
43 _managerVehicle->disconnect(
this);
44 _managerVehicle =
nullptr;
45 _rallyPointManager =
nullptr;
48 _managerVehicle = managerVehicle;
49 if (!_managerVehicle) {
50 qWarning() <<
"RallyPointController::managerVehicleChanged managerVehicle=NULL";
61 Q_UNUSED(capabilityBits);
79 QList<JsonHelper::KeyValidateInfo> keyInfoList = {
81 { _jsonPointsKey, QJsonValue::Array,
true },
88 QString errorMessage = tr(
"Rally: %1");
91 errorString = tr(
"Rally Points supports version %1").arg(_jsonCurrentVersion);
95 QList<QGeoCoordinate> rgPoints;
101 QObjectList pointList;
102 for (
int i=0; i<rgPoints.count(); i++) {
103 pointList.append(
new RallyPoint(rgPoints[i],
this));
108 _setFirstPointCurrent();
118 QJsonValue jsonPoint;
119 for (
int i=0; i<_points.
count(); i++) {
121 rgPoints.append(jsonPoint);
123 json[_jsonPointsKey] = QJsonValue(rgPoints);
136 qCCritical(RallyPointControllerLog) <<
"RallyPointController::removeAllFromVehicle called while offline";
138 qCCritical(RallyPointControllerLog) <<
"RallyPointController::removeAllFromVehicle called while syncInProgress";
147 qCCritical(RallyPointControllerLog) <<
"RallyPointController::loadFromVehicle called while offline";
149 qCCritical(RallyPointControllerLog) <<
"RallyPointController::loadFromVehicle called while syncInProgress";
151 _itemsRequested =
true;
159 qCCritical(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle called while offline";
161 qCCritical(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle called while syncInProgress";
163 qCDebug(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle";
165 QList<QGeoCoordinate> rgPoints;
166 for (
int i=0; i<_points.
count(); i++) {
167 rgPoints.append(qobject_cast<RallyPoint*>(_points[i])->coordinate());
180 if (
dirty != _dirty) {
191void RallyPointController::_managerLoadComplete(
void)
199 QObjectList pointList;
200 for (
int i=0; i<_rallyPointManager->
points().count(); i++) {
205 _setFirstPointCurrent();
208 _itemsRequested =
false;
211void RallyPointController::_managerSendComplete(
bool error)
219void RallyPointController::_managerRemoveAllComplete(
bool error)
227void RallyPointController::addPoint(QGeoCoordinate point)
230 if (_points.
count()) {
231 defaultAlt = qobject_cast<RallyPoint*>(_points[_points.
count() - 1])->coordinate().altitude();
240 point.setAltitude(defaultAlt);
249 return _managerVehicle->
capabilityBits() & MAV_PROTOCOL_CAPABILITY_MISSION_RALLY;
255 for (foundIndex=0; foundIndex<_points.
count(); foundIndex++) {
256 if (_points[foundIndex] == rallyPoint) {
258 rallyPoint->deleteLater();
262 if (_points.
count()) {
263 int newIndex = qMin(foundIndex, _points.
count() - 1);
264 newIndex = qMax(newIndex, 0);
273 if (_currentRallyPoint != rallyPoint) {
274 _currentRallyPoint = rallyPoint;
279void RallyPointController::_setFirstPointCurrent(
void)
286 return _points.
count() > 0;
291 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle _flyView" <<
_flyView;
293 qCCritical(RallyPointControllerLog) <<
"RallyPointController::showPlanFromManagerVehicle called while offline";
298 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: !initialPlanRequestComplete, wait for signal";
302 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: syncInProgress wait for signal";
305 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: sync complete";
306 _itemsRequested =
true;
307 _managerLoadComplete();
315 return _points.
count() == 0;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Fact *defaultMissionItemAltitude READ defaultMissionItemAltitude CONSTANT Fact * defaultMissionItemAltitude()
int count READ count NOTIFY countChanged(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) bool dirty() const
void supportedChanged(bool supported)
void syncInProgressChanged(bool syncInProgress)
PlanMasterController * _masterController
virtual void start(bool flyView)
Should be called immediately upon Component.onCompleted.
void containsItemsChanged()
void dirtyChanged(bool dirty)
void loadFromVehicle(void)
bool inProgress(void) const
Master controller for mission, fence, rally.
Vehicle * controllerVehicle(void)
void managerVehicleChanged(Vehicle *managerVehicle)
Vehicle * managerVehicle(void)
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
QObject * removeOne(const QObject *object) override final
int count() const override final
void clearAndDeleteContents() override final
Clears the list and calls deleteLater on each entry.
QObjectList swapObjectList(const QObjectList &newlist)
bool containsItems(void) const final
void save(QJsonObject &json) final
bool supported(void) const final
true: controller is waiting for the current load to complete
void setDirty(bool dirty) final
QString editorQml(void) const
bool showPlanFromManagerVehicle(void) final
bool syncInProgress(void) const final
void setCurrentRallyPoint(QObject *rallyPoint)
bool dirty(void) const final
void start(bool flyView) final
Should be called immediately upon Component.onCompleted.
void removeAllFromVehicle(void) final
bool load(const QJsonObject &json, QString &errorString) final
void removePoint(QObject *rallyPoint)
void removeAll(void) final
Removes all from controller only.
void currentRallyPointChanged(QObject *rallyPoint)
void loadFromVehicle(void) final
void sendToVehicle(void) final
void inProgressChanged(bool inProgress)
void sendToVehicle(const QList< QGeoCoordinate > &rgPoints)
void sendComplete(bool error)
QList< QGeoCoordinate > points(void) const
void removeAllComplete(bool error)
QString editorQml(void) const
static double getDefaultFactAltitude()
void capabilityBitsChanged(uint64_t capabilityBits)
uint64_t capabilityBits() const
RallyPointManager * rallyPointManager()
bool initialPlanRequestComplete() const
bool loadGeoCoordinateArray(const QJsonValue &jsonValue, bool altitudeRequired, QVariantList &rgVarPoints, QString &errorString)
returned error string if load failure
constexpr const char * jsonVersionKey
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
void saveGeoCoordinate(const QGeoCoordinate &coordinate, bool writeAltitude, QJsonValue &jsonValue, bool geoJsonFormat=false)