From a79e9bb6096b2eb7693db6258562da3dbc524aaa Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 14 Feb 2021 19:30:06 +0100 Subject: [PATCH] TD: fix undo/redo for balloon objects * inside mouseReleaseEvent() check if the mouse has been moved and only if yes emit the dragFinished() signal * improve error handling in mouseDoubleClickEvent * in mouseDoubleClickEvent start to edit the view provider --- src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 22 ++++++++++++++-------- src/Mod/TechDraw/Gui/ViewProviderBalloon.h | 4 +--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index fb094498ce..e5fee48d14 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -31,6 +31,7 @@ # include # include + # include # include # include # include @@ -48,7 +49,6 @@ #include #include #include -#include #include #include @@ -74,7 +74,6 @@ #include "QGIViewDimension.h" #include "QGVPage.h" #include "MDIViewPage.h" -#include "TaskBalloon.h" //TODO: hide the Qt coord system (+y down). @@ -140,8 +139,11 @@ void QGIBalloonLabel::mouseMoveEvent(QGraphicsSceneMouseEvent * event) void QGIBalloonLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { - if(scene() && this == scene()->mouseGrabberItem()) { - Q_EMIT dragFinished(); + if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)) + .length() > 0) { + if (scene() && this == scene()->mouseGrabberItem()) { + Q_EMIT dragFinished(); + } } m_ctrl = false; m_drag = false; @@ -152,13 +154,17 @@ void QGIBalloonLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) { QGIViewBalloon* qgivBalloon = dynamic_cast(parentItem()); if (qgivBalloon == nullptr) { + qWarning() << "QGIBalloonLabel::mouseDoubleClickEvent: No parent item"; return; } - auto ViewProvider = static_cast(qgivBalloon->getViewProvider(qgivBalloon->getViewObject())); + + auto ViewProvider = dynamic_cast(qgivBalloon->getViewProvider(qgivBalloon->getViewObject())); if (ViewProvider == nullptr) { + qWarning() << "QGIBalloonLabel::mouseDoubleClickEvent: No valid view provider"; return; } - Gui::Control().showDialog(new TaskDlgBalloon(qgivBalloon, ViewProvider)); + + ViewProvider->startDefaultEditMode(); QGraphicsItem::mouseDoubleClickEvent(event); } @@ -482,7 +488,7 @@ void QGIViewBalloon::balloonLabelDragged(bool ctrl) m_saveOffset = dvb->getOriginOffset(); } } - + double scale = 1.0; DrawView* balloonParent = getSourceView(); if (balloonParent != nullptr) { @@ -499,7 +505,7 @@ void QGIViewBalloon::balloonLabelDragged(bool ctrl) if (ctrl) { Base::Vector3d pos(x, -y, 0.0); Base::Vector3d newOrg = pos - m_saveOffset; - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.OriginX = %f", + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.OriginX = %f", dvb->getNameInDocument(), newOrg.x); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.OriginY = %f", dvb->getNameInDocument(), newOrg.y); diff --git a/src/Mod/TechDraw/Gui/ViewProviderBalloon.h b/src/Mod/TechDraw/Gui/ViewProviderBalloon.h index 3dcc7580fb..9dcef1b50f 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderBalloon.h +++ b/src/Mod/TechDraw/Gui/ViewProviderBalloon.h @@ -63,14 +63,12 @@ public: virtual void unsetEdit(int ModNum); virtual bool doubleClicked(void); virtual bool canDelete(App::DocumentObject* obj) const; + void startDefaultEditMode(); virtual TechDraw::DrawViewBalloon* getViewObject() const; protected: virtual void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop); - -private: - void startDefaultEditMode(); }; } // namespace TechDrawGui