Commit 5ceb1d24 authored by DonLakeFlyer's avatar DonLakeFlyer

Fix drag visual glitches

parent 09bde0c7
...@@ -29,6 +29,8 @@ Rectangle { ...@@ -29,6 +29,8 @@ Rectangle {
property var itemCoordinate ///< Coordinate we are updating during drag property var itemCoordinate ///< Coordinate we are updating during drag
signal clicked signal clicked
signal dragStart
signal dragStop
property bool _preventCoordinateBindingLoop: false property bool _preventCoordinateBindingLoop: false
...@@ -37,6 +39,7 @@ Rectangle { ...@@ -37,6 +39,7 @@ Rectangle {
property real _touchHeight: Math.max(itemIndicator.height, ScreenTools.minTouchPixels) property real _touchHeight: Math.max(itemIndicator.height, ScreenTools.minTouchPixels)
property real _touchMarginHorizontal: _mobile ? (_touchWidth - itemIndicator.width) / 2 : 0 property real _touchMarginHorizontal: _mobile ? (_touchWidth - itemIndicator.width) / 2 : 0
property real _touchMarginVertical: _mobile ? (_touchHeight - itemIndicator.height) / 2 : 0 property real _touchMarginVertical: _mobile ? (_touchHeight - itemIndicator.height) / 2 : 0
property bool _dragStartSignalled: false
onXChanged: liveDrag() onXChanged: liveDrag()
onYChanged: liveDrag() onYChanged: liveDrag()
...@@ -65,13 +68,18 @@ Rectangle { ...@@ -65,13 +68,18 @@ Rectangle {
preventStealing: true preventStealing: true
onClicked: itemDragger.clicked() onClicked: itemDragger.clicked()
}
Item {
id: fakeItemIndicator
Item { property bool dragActive: drag.active
id: anchorPoint onDragActiveChanged: {
if (dragActive) {
if (!_dragStartSignalled) {
_dragStartSignalled = true
dragStart()
}
} else {
_dragStartSignalled = false
dragStop()
}
} }
} }
} }
...@@ -22,6 +22,7 @@ QGCMapPolygon::QGCMapPolygon(QObject* newCoordParent, QObject* parent) ...@@ -22,6 +22,7 @@ QGCMapPolygon::QGCMapPolygon(QObject* newCoordParent, QObject* parent)
: QObject(parent) : QObject(parent)
, _newCoordParent(newCoordParent) , _newCoordParent(newCoordParent)
, _dirty(false) , _dirty(false)
, _centerDrag(false)
, _ignoreCenterUpdates(false) , _ignoreCenterUpdates(false)
{ {
connect(&_polygonModel, &QmlObjectListModel::dirtyChanged, this, &QGCMapPolygon::_polygonModelDirtyChanged); connect(&_polygonModel, &QmlObjectListModel::dirtyChanged, this, &QGCMapPolygon::_polygonModelDirtyChanged);
...@@ -53,7 +54,10 @@ void QGCMapPolygon::clear(void) ...@@ -53,7 +54,10 @@ void QGCMapPolygon::clear(void)
void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinate) void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinate)
{ {
_polygonPath[vertexIndex] = QVariant::fromValue(coordinate); _polygonPath[vertexIndex] = QVariant::fromValue(coordinate);
emit pathChanged(); if (!_centerDrag) {
// When dragging center we don't signal path changed until add vertices are updated
emit pathChanged();
}
_polygonModel.value<QGCQGeoCoordinate*>(vertexIndex)->setCoordinate(coordinate); _polygonModel.value<QGCQGeoCoordinate*>(vertexIndex)->setCoordinate(coordinate);
...@@ -278,7 +282,22 @@ void QGCMapPolygon::setCenter(QGeoCoordinate newCenter) ...@@ -278,7 +282,22 @@ void QGCMapPolygon::setCenter(QGeoCoordinate newCenter)
adjustVertex(i, newVertex); adjustVertex(i, newVertex);
} }
if (_centerDrag) {
// When center dragging signals are delayed until all vertices are updated
emit pathChanged();
}
_ignoreCenterUpdates = false; _ignoreCenterUpdates = false;
_updateCenter();
_center = newCenter;
emit centerChanged(newCenter);
}
}
void QGCMapPolygon::setCenterDrag(bool centerDrag)
{
if (centerDrag != _centerDrag) {
_centerDrag = centerDrag;
emit centerDragChanged(centerDrag);
} }
} }
...@@ -26,11 +26,12 @@ class QGCMapPolygon : public QObject ...@@ -26,11 +26,12 @@ class QGCMapPolygon : public QObject
public: public:
QGCMapPolygon(QObject* newCoordParent, QObject* parent = NULL); QGCMapPolygon(QObject* newCoordParent, QObject* parent = NULL);
Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged) Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged)
Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT) Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT)
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
Q_PROPERTY(bool centerDrag READ centerDrag WRITE setCenterDrag NOTIFY centerDragChanged)
Q_INVOKABLE void clear(void); Q_INVOKABLE void clear(void);
Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate); Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
...@@ -63,28 +64,30 @@ public: ...@@ -63,28 +64,30 @@ public:
// Property methods // Property methods
int count (void) const { return _polygonPath.count(); } int count (void) const { return _polygonPath.count(); }
bool dirty (void) const { return _dirty; } bool dirty (void) const { return _dirty; }
void setDirty(bool dirty); void setDirty (bool dirty);
QGeoCoordinate center (void) const { return _center; } QGeoCoordinate center (void) const { return _center; }
bool centerDrag (void) const { return _centerDrag; }
QVariantList path (void) const { return _polygonPath; } QVariantList path (void) const { return _polygonPath; }
QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; } QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; }
QmlObjectListModel& pathModel (void) { return _polygonModel; } QmlObjectListModel& pathModel (void) { return _polygonModel; }
void setPath(const QList<QGeoCoordinate>& path); void setPath (const QList<QGeoCoordinate>& path);
void setPath(const QVariantList& path); void setPath (const QVariantList& path);
void setCenter(QGeoCoordinate newCenter); void setCenter (QGeoCoordinate newCenter);
void setCenterDrag (bool centerDrag);
static const char* jsonPolygonKey; static const char* jsonPolygonKey;
signals: signals:
void countChanged (int count); void countChanged (int count);
void pathChanged (void); void pathChanged (void);
void dirtyChanged (bool dirty); void dirtyChanged (bool dirty);
void cleared (void); void cleared (void);
void centerChanged (QGeoCoordinate center); void centerChanged (QGeoCoordinate center);
void centerDragChanged (bool centerDrag);
private slots: private slots:
void _polygonModelCountChanged(int count); void _polygonModelCountChanged(int count);
...@@ -101,6 +104,7 @@ private: ...@@ -101,6 +104,7 @@ private:
QmlObjectListModel _polygonModel; QmlObjectListModel _polygonModel;
bool _dirty; bool _dirty;
QGeoCoordinate _center; QGeoCoordinate _center;
bool _centerDrag;
bool _ignoreCenterUpdates; bool _ignoreCenterUpdates;
}; };
......
...@@ -222,7 +222,9 @@ Item { ...@@ -222,7 +222,9 @@ Item {
id: centerDragAreaComponent id: centerDragAreaComponent
MissionItemIndicatorDrag { MissionItemIndicatorDrag {
onItemCoordinateChanged: mapPolygon.center = itemCoordinate onItemCoordinateChanged: mapPolygon.center = itemCoordinate
onDragStart: mapPolygon.centerDrag = true
onDragStop: mapPolygon.centerDrag = false
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment