13#include <QtCore/QJsonArray>
19 , _managerVehicle (masterController->managerVehicle())
20 , _rallyPointManager (masterController->managerVehicle()->rallyPointManager())
33 qCDebug(RallyPointControllerLog) <<
"start flyView" << flyView;
41void RallyPointController::_managerVehicleChanged(
Vehicle* managerVehicle)
43 if (_managerVehicle) {
44 _rallyPointManager->disconnect(
this);
45 _managerVehicle->disconnect(
this);
46 _managerVehicle =
nullptr;
47 _rallyPointManager =
nullptr;
50 _managerVehicle = managerVehicle;
51 if (!_managerVehicle) {
52 qWarning() <<
"RallyPointController::managerVehicleChanged managerVehicle=NULL";
63 Q_UNUSED(capabilityBits);
81 QList<JsonParsing::KeyValidateInfo> keyInfoList = {
83 { _jsonPointsKey, QJsonValue::Array,
true },
90 QString errorMessage = tr(
"Rally: %1");
93 errorString = tr(
"Rally Points supports version %1").arg(_jsonCurrentVersion);
97 QList<QGeoCoordinate> rgPoints;
103 QObjectList pointList;
104 for (
int i=0; i<rgPoints.count(); i++) {
105 pointList.append(
new RallyPoint(rgPoints[i],
this));
110 _setFirstPointCurrent();
120 QJsonValue jsonPoint;
121 for (
int i=0; i<_points.
count(); i++) {
123 rgPoints.append(jsonPoint);
125 json[_jsonPointsKey] = QJsonValue(rgPoints);
138 qCCritical(RallyPointControllerLog) <<
"RallyPointController::removeAllFromVehicle called while offline";
140 qCCritical(RallyPointControllerLog) <<
"RallyPointController::removeAllFromVehicle called while syncInProgress";
149 qCCritical(RallyPointControllerLog) <<
"RallyPointController::loadFromVehicle called while offline";
151 qCCritical(RallyPointControllerLog) <<
"RallyPointController::loadFromVehicle called while syncInProgress";
153 _itemsRequested =
true;
161 qCCritical(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle called while offline";
163 qCCritical(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle called while syncInProgress";
165 qCDebug(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle";
167 QList<QGeoCoordinate> rgPoints;
168 for (
int i=0; i<_points.
count(); i++) {
169 rgPoints.append(qobject_cast<RallyPoint*>(_points[i])->coordinate());
182 if (
dirty != _dirty) {
191void RallyPointController::_pointsDirtyChanged(
bool dirty)
203void RallyPointController::_managerLoadComplete(
void)
211 QObjectList pointList;
212 for (
int i=0; i<_rallyPointManager->
points().count(); i++) {
217 _setFirstPointCurrent();
220 _itemsRequested =
false;
223void RallyPointController::_managerSendComplete(
bool error)
231void RallyPointController::_managerRemoveAllComplete(
bool error)
242 if (_points.
count()) {
243 defaultAlt = qobject_cast<RallyPoint*>(_points[_points.
count() - 1])->coordinate().altitude();
252 point.setAltitude(defaultAlt);
261 return _managerVehicle->
capabilityBits() & MAV_PROTOCOL_CAPABILITY_MISSION_RALLY;
267 for (foundIndex=0; foundIndex<_points.
count(); foundIndex++) {
268 if (_points[foundIndex] == rallyPoint) {
270 rallyPoint->deleteLater();
274 if (_points.
count()) {
275 int newIndex = qMin(foundIndex, _points.
count() - 1);
276 newIndex = qMax(newIndex, 0);
285 if (_currentRallyPoint != rallyPoint) {
286 _currentRallyPoint = rallyPoint;
291void RallyPointController::_setFirstPointCurrent(
void)
298 return _points.
count() > 0;
303 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle _flyView" <<
_flyView;
305 qCCritical(RallyPointControllerLog) <<
"RallyPointController::showPlanFromManagerVehicle called while offline";
310 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: !initialPlanRequestComplete, wait for signal";
314 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: syncInProgress wait for signal";
317 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: sync complete";
318 _itemsRequested =
true;
319 _managerLoadComplete();
327 return _points.
count() == 0;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void dirtyChanged(bool dirty)
void countChanged(int count)
This is the abstract base clas for Plan Element controllers.
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.
void setDirty(bool dirty) override final
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
Q_INVOKABLE void addPoint(QGeoCoordinate point)
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
Q_INVOKABLE 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
This class is used to encapsulate the QGeoCoordinate associated with a Rally Point into a QObject suc...
static double getDefaultFactAltitude()
static SettingsManager * instance()
AppSettings * appSettings() const
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)
Loads a list of QGeoCoordinates (QGC plan format) from a json array.
void saveGeoCoordinate(const QGeoCoordinate &coordinate, bool writeAltitude, QJsonValue &jsonValue)
Saves a QGeoCoordinate as [lat, lon, alt] array (QGC plan format).
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
Validates that all required keys are present and that listed keys have the expected type.
constexpr const char * jsonVersionKey