From e555e8d97dac396bc3b8bb222ede29111f92a5d7 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 15 May 2019 20:12:52 -0400 Subject: [PATCH] Fix Leader point edit --- src/Mod/TechDraw/Gui/QGEPath.cpp | 22 ++++++++++------ src/Mod/TechDraw/Gui/QGEPath.h | 1 + src/Mod/TechDraw/Gui/QGILeaderLine.cpp | 29 ++++++++++++++++++--- src/Mod/TechDraw/Gui/TaskLeaderLine.cpp | 34 +++++++++++++++---------- src/Mod/TechDraw/Gui/TaskLeaderLine.h | 4 +-- 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGEPath.cpp b/src/Mod/TechDraw/Gui/QGEPath.cpp index a191157c68..b74a36c42e 100644 --- a/src/Mod/TechDraw/Gui/QGEPath.cpp +++ b/src/Mod/TechDraw/Gui/QGEPath.cpp @@ -43,7 +43,8 @@ using namespace TechDrawGui; -QGMarker::QGMarker(int idx) : QGIVertex(idx) +QGMarker::QGMarker(int idx) : QGIVertex(idx), + m_dragging(false) { // Base::Console().Message("QGMarker::QGMarker(%d)\n", idx); setFlag(QGraphicsItem::ItemIsMovable, true); @@ -77,6 +78,8 @@ void QGMarker::mousePressEvent(QGraphicsSceneMouseEvent * event) event->accept(); return; } else if(scene() && this == scene()->mouseGrabberItem()) { + //start dragging + m_dragging = true; QPointF mapped = mapToParent(event->pos()); Q_EMIT dragging(mapped, getProjIndex()); } @@ -94,16 +97,20 @@ void QGMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) // Base::Console().Message("QGMarker::mouseReleaseEvent(%d) - focus: %d\n", getProjIndex(), hasFocus()); if (event->button() == Qt::RightButton) { //we're done Q_EMIT endEdit(); - event->accept(); //this is mine! + m_dragging = false; return; } if(this->scene() && this == this->scene()->mouseGrabberItem()) { - QPointF mapped = mapToParent(event->pos()); - Q_EMIT dragFinished(mapped, getProjIndex()); - event->accept(); + if (m_dragging) { + m_dragging = false; + setSelected(false); + QPointF mapped = mapToParent(event->pos()); + Q_EMIT dragFinished(mapped, getProjIndex()); + } + } else { + Base::Console().Message("QGMarker::mouseReleaseEvent - not mouse grabber\n"); } - QGIVertex::mouseReleaseEvent(event); } @@ -112,7 +119,6 @@ void QGMarker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event) // Base::Console().Message("QGMarker::mouseDoubleClickEvent(%d)\n",getProjIndex()); if (event->button() == Qt::RightButton) { //we're done Q_EMIT endEdit(); - event->accept(); //this is mine! return; } QGIVertex::mouseDoubleClickEvent(event); @@ -382,7 +388,7 @@ void QGEPath::makeDeltasFromPoints(std::vector pts) m_deltas = deltas; } -//tell parent points editing is finished +//announce points editing is finished void QGEPath::updateFeature(void) { // Base::Console().Message("QGEPath::updateFeature()\n"); diff --git a/src/Mod/TechDraw/Gui/QGEPath.h b/src/Mod/TechDraw/Gui/QGEPath.h index cb36fa52ba..7a0d6bd38a 100644 --- a/src/Mod/TechDraw/Gui/QGEPath.h +++ b/src/Mod/TechDraw/Gui/QGEPath.h @@ -72,6 +72,7 @@ protected: virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; private: + bool m_dragging; }; diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index 34b8444b38..821d0b9291 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -160,19 +160,37 @@ void QGILeaderLine::hover(bool state) void QGILeaderLine::onLineEditFinished(std::vector pts) { -// Base::Console().Message("QGIVL::onLineEditFinished(%d)\n",pts.size()); +// Base::Console().Message("QGILL::onLineEditFinished(%d)\n",pts.size()); + QPointF p0 = pts.front(); + if ( !(TechDraw::DrawUtil::fpCompare(p0.x(),0.0) && + TechDraw::DrawUtil::fpCompare(p0.y(),0.0)) ) { + //p0 was moved. need to change AttachPoint and intervals from p0 + QPointF mapped = m_parentItem->mapFromItem(this,p0); + Base::Vector3d attachPoint = Base::Vector3d(mapped.x(),mapped.y(),0.0); + for (auto& p : pts) { + p -= p0; + } + pts.at(0) = QPointF(0.0,0.0); + getFeature()->setPosition(Rez::appX(attachPoint.x),Rez::appX(- attachPoint.y), true); + } + std::vector waypoints; for (auto& p: pts) { Base::Vector3d v(p.x(),p.y(),0.0); waypoints.push_back(v); } + getFeature()->WayPoints.setValues(waypoints); + if (getFeature()->AutoHorizontal.getValue()) { + getFeature()->adjustLastSegment(); + } + if (m_parentItem == nullptr) { Base::Console().Log("QGILL::onLineEditFinished - m_parentItem is NULL\n"); } else { QGIView* qgiv = dynamic_cast(m_parentItem); if (qgiv != nullptr) { - Q_EMIT editComplete(pts, qgiv); //leader's parent if QGIView + Q_EMIT editComplete(pts, qgiv); } } } @@ -230,6 +248,11 @@ void QGILeaderLine::draw() return; } + if (m_line->inEdit()) { + Base::Console().Log("QGIL::draw - m_line is in edit\n"); + return; + } + if (leadFeat->isLocked()) { setFlag(QGraphicsItem::ItemIsMovable, false); } else { @@ -264,7 +287,7 @@ void QGILeaderLine::draw() m_line->setNormalColor(m_lineColor); scale = getScale(); m_line->setScale(scale); - m_line->makeDeltasFromPoints(qPoints); + m_line->makeDeltasFromPoints(qPoints); //this is what messes up edit!?? m_line->setPos(0,0); m_line->updatePath(); m_line->show(); diff --git a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp index e019ac74ba..6bdbe4e748 100644 --- a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp @@ -247,7 +247,13 @@ void TaskLeaderLine::createLeaderFeature(std::vector converted) } if (obj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) { m_lineFeat = static_cast(obj); - commonFeatureUpdate(converted); + if (!converted.empty()) { + m_lineFeat->WayPoints.setValues(converted); + if (m_lineFeat->AutoHorizontal.getValue()) { + m_lineFeat->adjustLastSegment(); + } + } + commonFeatureUpdate(); } Gui::Command::updateActive(); @@ -255,11 +261,12 @@ void TaskLeaderLine::createLeaderFeature(std::vector converted) m_lineFeat->requestPaint(); } -void TaskLeaderLine::updateLeaderFeature(std::vector converted) +void TaskLeaderLine::updateLeaderFeature(void) { // Base::Console().Message("TTL::updateLeaderFeature(%d)\n",converted.size()); Gui::Command::openCommand("Edit Leader"); - commonFeatureUpdate(converted); + //waypoints & x,y are updated by QGILeaderLine + commonFeatureUpdate(); App::Color ac; ac.setValue(ui->cpLineColor->color()); m_lineVP->Color.setValue(ac); @@ -270,16 +277,16 @@ void TaskLeaderLine::updateLeaderFeature(std::vector converted) m_lineFeat->requestPaint(); } -void TaskLeaderLine::commonFeatureUpdate(std::vector converted) +void TaskLeaderLine::commonFeatureUpdate(void) { // Base::Console().Message("TTL::commonFeatureUpdate()\n"); - m_lineFeat->setPosition(Rez::appX(m_attachPoint.x),Rez::appX(- m_attachPoint.y), true); - if (!converted.empty()) { - m_lineFeat->WayPoints.setValues(converted); - if (m_lineFeat->AutoHorizontal.getValue()) { - m_lineFeat->adjustLastSegment(); - } - } +// m_lineFeat->setPosition(Rez::appX(m_attachPoint.x),Rez::appX(- m_attachPoint.y), true); +// if (!converted.empty()) { +// m_lineFeat->WayPoints.setValues(converted); +// if (m_lineFeat->AutoHorizontal.getValue()) { +// m_lineFeat->adjustLastSegment(); +// } +// } int start = ui->cboxStartSym->currentIndex() - 1; int end = ui->cboxEndSym->currentIndex() - 1; m_lineFeat->StartSymbol.setValue(start); @@ -524,13 +531,14 @@ void TaskLeaderLine::convertTrackerPoints(std::vector pts) void TaskLeaderLine::onPointEditComplete(std::vector pts, QGIView* parent) { // Base::Console().Message("TTL::onPointEditComplete(%d)\n", pts.size()); + if (pts.empty()) { return; } QPointF p0 = pts.front(); if (parent == nullptr) { -// Base::Console().Message("TTL::onPointEditComplete - passed parent is NULL!\n"); + Base::Console().Message("TTL::onPointEditComplete - passed parent is NULL!\n"); } else { m_qgParent = parent; // double scale = m_qgParent->getScale(); @@ -608,7 +616,7 @@ bool TaskLeaderLine::accept() if (!doc) return false; if (!getCreateMode()) { - updateLeaderFeature(m_trackerPoints); + updateLeaderFeature(); } else { removeTracker(); createLeaderFeature(m_trackerPoints); diff --git a/src/Mod/TechDraw/Gui/TaskLeaderLine.h b/src/Mod/TechDraw/Gui/TaskLeaderLine.h index 7b41df059c..491c2c586c 100644 --- a/src/Mod/TechDraw/Gui/TaskLeaderLine.h +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.h @@ -103,8 +103,8 @@ protected: void abandonEditSession(void); void createLeaderFeature(std::vector converted); - void updateLeaderFeature(std::vector converted); - void commonFeatureUpdate(std::vector converted); + void updateLeaderFeature(); + void commonFeatureUpdate(void); void removeFeature(void); /* QPointF calcTextStartPos(double scale);*/