13#include <QtCore/QJsonArray>
19 , _managerVehicle (masterController->managerVehicle())
20 , _rallyPointManager (masterController->managerVehicle()->rallyPointManager())
32 qCDebug(RallyPointControllerLog) <<
"start flyView" << flyView;
40void RallyPointController::_managerVehicleChanged(
Vehicle* managerVehicle)
42 if (_managerVehicle) {
43 _rallyPointManager->disconnect(
this);
44 _managerVehicle->disconnect(
this);
45 _managerVehicle =
nullptr;
46 _rallyPointManager =
nullptr;
49 _managerVehicle = managerVehicle;
50 if (!_managerVehicle) {
51 qWarning() <<
"RallyPointController::managerVehicleChanged managerVehicle=NULL";
62 Q_UNUSED(capabilityBits);
80 QList<JsonParsing::KeyValidateInfo> keyInfoList = {
82 { _jsonPointsKey, QJsonValue::Array,
true },
89 QString errorMessage = tr(
"Rally: %1");
92 errorString = tr(
"Rally Points supports version %1").arg(_jsonCurrentVersion);
96 QList<QGeoCoordinate> rgPoints;
102 QObjectList pointList;
103 for (
int i=0; i<rgPoints.count(); i++) {
104 pointList.append(
new RallyPoint(rgPoints[i],
this));
109 _setFirstPointCurrent();
119 QJsonValue jsonPoint;
120 for (
int i=0; i<_points.
count(); i++) {
122 rgPoints.append(jsonPoint);
124 json[_jsonPointsKey] = QJsonValue(rgPoints);
137 qCCritical(RallyPointControllerLog) <<
"RallyPointController::removeAllFromVehicle called while offline";
139 qCCritical(RallyPointControllerLog) <<
"RallyPointController::removeAllFromVehicle called while syncInProgress";
148 qCCritical(RallyPointControllerLog) <<
"RallyPointController::loadFromVehicle called while offline";
150 qCCritical(RallyPointControllerLog) <<
"RallyPointController::loadFromVehicle called while syncInProgress";
152 _itemsRequested =
true;
160 qCCritical(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle called while offline";
162 qCCritical(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle called while syncInProgress";
164 qCDebug(RallyPointControllerLog) <<
"RallyPointController::sendToVehicle";
166 QList<QGeoCoordinate> rgPoints;
167 for (
int i=0; i<_points.
count(); i++) {
168 rgPoints.append(qobject_cast<RallyPoint*>(_points[i])->coordinate());
181 if (
dirty != _dirty) {
192void RallyPointController::_managerLoadComplete(
void)
200 QObjectList pointList;
201 for (
int i=0; i<_rallyPointManager->
points().count(); i++) {
206 _setFirstPointCurrent();
209 _itemsRequested =
false;
212void RallyPointController::_managerSendComplete(
bool error)
220void RallyPointController::_managerRemoveAllComplete(
bool error)
231 if (_points.
count()) {
232 defaultAlt = qobject_cast<RallyPoint*>(_points[_points.
count() - 1])->coordinate().altitude();
241 point.setAltitude(defaultAlt);
250 return _managerVehicle->
capabilityBits() & MAV_PROTOCOL_CAPABILITY_MISSION_RALLY;
256 for (foundIndex=0; foundIndex<_points.
count(); foundIndex++) {
257 if (_points[foundIndex] == rallyPoint) {
259 rallyPoint->deleteLater();
263 if (_points.
count()) {
264 int newIndex = qMin(foundIndex, _points.
count() - 1);
265 newIndex = qMax(newIndex, 0);
274 if (_currentRallyPoint != rallyPoint) {
275 _currentRallyPoint = rallyPoint;
280void RallyPointController::_setFirstPointCurrent(
void)
287 return _points.
count() > 0;
292 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle _flyView" <<
_flyView;
294 qCCritical(RallyPointControllerLog) <<
"RallyPointController::showPlanFromManagerVehicle called while offline";
299 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: !initialPlanRequestComplete, wait for signal";
303 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: syncInProgress wait for signal";
306 qCDebug(RallyPointControllerLog) <<
"showPlanFromManagerVehicle: sync complete";
307 _itemsRequested =
true;
308 _managerLoadComplete();
316 return _points.
count() == 0;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
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.
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