20 , _interactive (false)
28 , _interactive (false)
44 QVariantList vertices = other.
path();
45 for (
int i=0; i<vertices.count(); i++) {
54void QGCMapPolyline::_init(
void)
68 _polylinePath.clear();
71 _polylineModel.clearAndDeleteContents();
80 _polylinePath[vertexIndex] = QVariant::fromValue(coordinate);
82 if (!_deferredPathChanged) {
83 _deferredPathChanged =
true;
86 QTimer::singleShot(0,
this, [
this]() {
88 _deferredPathChanged =
false;
91 QTimer::singleShot(0,
this, [
this]() {
93 _deferredPathChanged =
false;
102 if (_dirty !=
dirty) {
105 _polylineModel.setDirty(
false);
110QGeoCoordinate QGCMapPolyline::_coordFromPointF(
const QPointF& point)
const
112 QGeoCoordinate coord;
114 if (_polylinePath.count() > 0) {
115 QGeoCoordinate tangentOrigin = _polylinePath[0].value<QGeoCoordinate>();
122QPointF QGCMapPolyline::_pointFFromCoord(
const QGeoCoordinate& coordinate)
const
124 if (_polylinePath.count() > 0) {
126 QGeoCoordinate tangentOrigin = _polylinePath[0].value<QGeoCoordinate>();
129 return QPointF(x, -y);
139 _polylinePath.clear();
140 _polylineModel.clearAndDeleteContents();
141 for (
const QGeoCoordinate& coord:
path) {
142 _polylinePath.append(QVariant::fromValue(coord));
155 _polylinePath =
path;
156 _polylineModel.clearAndDeleteContents();
157 for (
int i=0; i<_polylinePath.count(); i++) {
158 _polylineModel.append(
new QGCQGeoCoordinate(_polylinePath[i].value<QGeoCoordinate>(),
this));
168 QJsonValue jsonValue;
192 for (
int i=0; i<_polylinePath.count(); i++) {
193 _polylineModel.append(
new QGCQGeoCoordinate(_polylinePath[i].value<QGeoCoordinate>(),
this));
204 QList<QGeoCoordinate> coords;
206 for (
int i=0; i<_polylinePath.count(); i++) {
207 coords.append(_polylinePath[i].value<QGeoCoordinate>());
215 int nextIndex = vertexIndex + 1;
216 if (nextIndex > _polylinePath.length() - 1) {
220 QGeoCoordinate firstVertex = _polylinePath[vertexIndex].value<QGeoCoordinate>();
221 QGeoCoordinate nextVertex = _polylinePath[nextIndex].value<QGeoCoordinate>();
223 double distance = firstVertex.distanceTo(nextVertex);
224 double azimuth = firstVertex.azimuthTo(nextVertex);
225 QGeoCoordinate newVertex = firstVertex.atDistanceAndAzimuth(distance / 2, azimuth);
227 if (nextIndex == 0) {
231 _polylinePath.insert(nextIndex, QVariant::fromValue(newVertex));
238 _polylinePath.append(QVariant::fromValue(coordinate));
245 if (vertexIndex < 0 || vertexIndex > _polylinePath.length() - 1) {
246 qCWarning(QGCMapPolylineLog) <<
"Call to removeVertex with bad vertexIndex:count" << vertexIndex << _polylinePath.length();
250 if (_polylinePath.length() <= 2) {
255 QObject* coordObj = _polylineModel.removeAt(vertexIndex);
256 coordObj->deleteLater();
257 if(vertexIndex == _selectedVertexIndex) {
259 }
else if (vertexIndex < _selectedVertexIndex) {
263 _polylinePath.removeAt(vertexIndex);
289 if (vertex >= 0 && vertex < _polylinePath.count()) {
290 return _polylinePath[vertex].value<QGeoCoordinate>();
292 qCWarning(QGCMapPolylineLog) <<
"QGCMapPolyline::vertexCoordinate bad vertex requested";
293 return QGeoCoordinate();
304 for (
int i=0; i<_polylinePath.count(); i++) {
323 if (offsetPoints.isEmpty()) {
328 QList<QGeoCoordinate> result;
329 result.reserve(offsetPoints.size());
330 for (
const QPointF& point : offsetPoints) {
331 QGeoCoordinate coordinate;
333 result.append(coordinate);
341 QList<QList<QGeoCoordinate>> polylines;
346 if (polylines.isEmpty()) {
350 const QList<QGeoCoordinate>& rgCoords = polylines.first();
360void QGCMapPolyline::_polylineModelDirtyChanged(
bool dirty)
367void QGCMapPolyline::_polylineModelCountChanged(
int count)
377 for (
int i=0; i<_polylinePath.count() - 1; i++) {
378 QGeoCoordinate from = _polylinePath[i].value<QGeoCoordinate>();
379 QGeoCoordinate to = _polylinePath[i+1].value<QGeoCoordinate>();
380 length += from.distanceTo(to);
390 QList<QObject*> objects;
391 for (
const QGeoCoordinate& coordinate: coordinates) {
393 _polylinePath.append(QVariant::fromValue(coordinate));
395 _polylineModel.append(objects);
404 _polylineModel.beginResetModel();
409 _polylineModel.endResetModel();
422 if(index == _selectedVertexIndex)
return;
424 if(-1 <= index && index <
count()) {
425 _selectedVertexIndex = index;
427 qCWarning(QGCMapPolylineLog) << QStringLiteral(
"QGCMapPolyline: Selected vertex index (%1) is out of bounds! "
428 "Polyline vertices indexes range is [%2..%3].").arg(index).arg(0).arg(
count()-1);
429 _selectedVertexIndex = -1;
Geographic coordinate conversion utilities using GeographicLib.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void dirtyChanged(bool dirty)
void countChanged(int count)
Q_INVOKABLE void beginReset(void)
QList< QGeoCoordinate > offsetPolyline(double distance)
void dirtyChanged(bool dirty)
static constexpr const char * jsonPolylineKey
QList< QPointF > nedPolyline(void)
Convert polyline to NED and return (D is ignored).
Q_INVOKABLE void clear(void)
Q_INVOKABLE bool loadKMLOrSHPFile(const QString &file)
Q_INVOKABLE void splitSegment(int vertexIndex)
Splits the line segment comprised of vertexIndex -> vertexIndex + 1.
Q_INVOKABLE void removeVertex(int vertexIndex)
void interactiveChanged(bool interactive)
void traceModeChanged(bool traceMode)
Q_INVOKABLE void adjustVertex(int vertexIndex, const QGeoCoordinate coordinate)
void dragPathChanged(void)
void setTraceMode(bool traceMode)
void isEmptyChanged(void)
Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const
Returns the QGeoCoordinate for the vertex specified.
void selectVertex(int index)
void setPath(const QList< QGeoCoordinate > &path)
void setDirty(bool dirty)
bool interactive(void) const
Q_INVOKABLE void appendVertex(const QGeoCoordinate &coordinate)
~QGCMapPolyline() override
void vertexDragChanged(bool vertexDrag)
bool vertexDrag(void) const
void saveToJson(QJsonObject &json)
QList< QGeoCoordinate > coordinateList(void) const
Returns the path in a list of QGeoCoordinate's format.
const QGCMapPolyline & operator=(const QGCMapPolyline &other)
Q_INVOKABLE void endReset(void)
Q_INVOKABLE void appendVertices(const QList< QGeoCoordinate > &coordinates)
QVariantList path(void) const
void isValidChanged(void)
bool loadFromJson(const QJsonObject &json, bool required, QString &errorString)
QGCMapPolyline(QObject *parent=nullptr)
double length(void) const
Returns the length of the polyline in meters.
void countChanged(int count)
void setVertexDrag(bool vertexDrag)
bool traceMode(void) const
void selectedVertexChanged(int index)
void setInteractive(bool interactive)
This is a QGeoCoordinate within a QObject such that it can be used on a QmlObjectListModel.
static bool loadPolylinesFromFile(const QString &file, QList< QList< QGeoCoordinate > > &polylines, QString &errorString, double filterMeters=kDefaultVertexFilterMeters)
bool loadGeoCoordinateArray(const QJsonValue &jsonValue, bool altitudeRequired, QVariantList &rgVarPoints, QString &errorString)
Loads a list of QGeoCoordinates (QGC plan format) from a json array.
void saveGeoCoordinateArray(const QVariantList &rgVarPoints, bool writeAltitude, QJsonValue &jsonValue)
Saves a list of QGeoCoordinates (QGC plan format) to a json array.
bool validateRequiredKeys(const QJsonObject &jsonObject, const QStringList &keys, QString &errorString)
Validates that all listed keys are present in the object.
void convertGeoToNed(const QGeoCoordinate &coord, const QGeoCoordinate &origin, double &x, double &y, double &z)
void convertNedToGeo(double x, double y, double z, const QGeoCoordinate &origin, QGeoCoordinate &coord)
QList< QPointF > offsetPolyline(const QList< QPointF > &polyline, double distance)
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.