Skip to content

Commit

Permalink
Fix point edit when attach point changed
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed May 25, 2019
1 parent 94b167f commit bf38ae9
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 156 deletions.
12 changes: 0 additions & 12 deletions src/Mod/TechDraw/App/DrawLeaderLine.cpp
Expand Up @@ -77,8 +77,6 @@ DrawLeaderLine::~DrawLeaderLine()

void DrawLeaderLine::onChanged(const App::Property* prop)
{
// if (!isRestoring()) {
// }
DrawView::onChanged(prop);
}

Expand Down Expand Up @@ -112,15 +110,6 @@ App::DocumentObjectExecReturn *DrawLeaderLine::execute(void)
return DrawView::execute();
}

//this doesn't really work because LeaderParent is not available?
void DrawLeaderLine::onDocumentRestored(void)
{
// Base::Console().Message("DLL::onDocumentRestored()\n");
requestPaint();
DrawView::onDocumentRestored();
}


DrawView* DrawLeaderLine::getBaseView(void) const
{
DrawView* result = nullptr;
Expand All @@ -134,7 +123,6 @@ DrawView* DrawLeaderLine::getBaseView(void) const
return result;
}


App::DocumentObject* DrawLeaderLine::getBaseObject(void) const
{
App::DocumentObject* result = nullptr;
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/App/DrawLeaderLine.h
Expand Up @@ -51,8 +51,6 @@ class TechDrawExport DrawLeaderLine : public TechDraw::DrawView

virtual short mustExecute() const override;
virtual App::DocumentObjectExecReturn *execute(void) override;
virtual void onDocumentRestored(void) override;


virtual const char* getViewProviderName(void) const override {
return "TechDrawGui::ViewProviderLeader";
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/CommandDecorate.cpp
Expand Up @@ -57,8 +57,8 @@
#include "DrawGuiUtil.h"
#include "MDIViewPage.h"
#include "TaskGeomHatch.h"
#include "TaskLeaderLine.h"
#include "TaskRichAnno.h"
//#include "TaskLeaderLine.h"
//#include "TaskRichAnno.h"
#include "ViewProviderGeomHatch.h"
#include "ViewProviderPage.h"

Expand Down
109 changes: 86 additions & 23 deletions src/Mod/TechDraw/Gui/QGEPath.cpp
Expand Up @@ -94,7 +94,6 @@ void QGMarker::mouseMoveEvent(QGraphicsSceneMouseEvent * event)

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();
m_dragging = false;
Expand All @@ -108,8 +107,6 @@ void QGMarker::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
QPointF mapped = mapToParent(event->pos());
Q_EMIT dragFinished(mapped, getProjIndex());
}
} else {
Base::Console().Message("QGMarker::mouseReleaseEvent - not mouse grabber\n");
}
QGIVertex::mouseReleaseEvent(event);
}
Expand All @@ -124,16 +121,15 @@ void QGMarker::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event)
QGIVertex::mouseDoubleClickEvent(event);
}

//why can markers get the keyPress, but QGTracker can not??
void QGMarker::keyPressEvent(QKeyEvent * event)
{
// Base::Console().Message("QGMarker::keyPressEvent(%d)\n",getProjIndex());
if (event->key() == Qt::Key_Escape) {
Q_EMIT endEdit();
}
QGIVertex::keyPressEvent(event);
}


void QGMarker::setRadius(float r)
{
//TODO:: implement different marker shapes. circle, square, triangle, ???
Expand Down Expand Up @@ -192,6 +188,13 @@ QGEPath::QGEPath() :
if (pView != nullptr) {
m_parentItem = pView;
}
m_ghost = new QGIPrimPath();
m_ghost->setParentItem(this);
m_ghost->setNormalColor(Qt::red);
m_ghost->setStyle(Qt::DashLine);
m_ghost->setPrettyNormal();
m_ghost->hide();

}

QVariant QGEPath::itemChange(GraphicsItemChange change, const QVariant &value)
Expand Down Expand Up @@ -241,9 +244,19 @@ void QGEPath::startPathEdit()
{
// Base::Console().Message("QGEPath::startPathEdit()\n");
inEdit(true);
m_saveDeltas = m_deltas;
showMarkers(m_deltas);
}

void QGEPath::restoreState()
{
// Base::Console().Message("QGEPath::restoreState()\n");
inEdit(false);
m_deltas = m_saveDeltas;
updatePath();
}


void QGEPath::showMarkers(std::vector<QPointF> deltas)
{
// Base::Console().Message("QGEPath::showMarkers()\n");
Expand Down Expand Up @@ -300,6 +313,7 @@ void QGEPath::clearMarkers()
return;
}
for (auto& m: m_markers) {
m->hide();
if (m != nullptr) {
QGraphicsScene* s = m->scene();
if (s != nullptr) {
Expand All @@ -315,8 +329,14 @@ void QGEPath::clearMarkers()
void QGEPath::onDragFinished(QPointF pos, int markerIndex)
{
// Base::Console().Message("QGEPath::onDragFinished()\n");
m_deltas.at(markerIndex) = pos / m_scale;
updatePath();
if ((int) m_points.size() > markerIndex) {
m_points.at(markerIndex) = pos / m_scale;
}
makeDeltasFromPoints(m_points);
if (markerIndex == 0) {
Q_EMIT attachMoved(m_points.front());
}
drawGhost();
}

void QGEPath::onDragging(QPointF pos, int markerIndex)
Expand All @@ -333,18 +353,18 @@ void QGEPath::onDoubleClick(QPointF pos, int markerIndex)
Q_UNUSED(pos);
Q_UNUSED(markerIndex);
// Base::Console().Message("QGEPath::onDoubleClick()\n");
updatePath();
updateFeature();
clearMarkers();
inEdit(false);
onEndEdit();
}

void QGEPath::onEndEdit(void)
{
// Base::Console().Message("QGEPath::onEndEdit()\n");
updatePath();
if (m_ghost != nullptr) {
scene()->removeItem(m_ghost); //stop ghost from messing up brect
}
inEdit(false);
updateFeature();
updatePath();
updateFeature(); //Q_EMIT pointsUpdated(m_deltas) ==> onLineEditComplete <<<1
clearMarkers();
}

Expand All @@ -354,7 +374,7 @@ void QGEPath::updatePath(void)
{
// Base::Console().Message("QGEPath::updatePath() - scale: %.3f\n", m_scale);
if (m_deltas.empty()) {
Base::Console().Log("QGEPath::updatePath - no points\n");
Base::Console().Warning("QGEPath::updatePath - no points\n");
return;
}
QPainterPath result;
Expand All @@ -366,18 +386,24 @@ void QGEPath::updatePath(void)
}
}
setPath(result);
// setPrettyNormal();
}

void QGEPath::makeDeltasFromPoints(std::vector<QPointF> pts)
QPointF QGEPath::makeDeltasFromPoints(void)
{
// Base::Console().Message("QGEPath::makeDeltasFromPoints()\n");
return makeDeltasFromPoints(m_points);
}

QPointF QGEPath::makeDeltasFromPoints(std::vector<QPointF> pts)
{
m_points = pts;
// Base::Console().Message("QGEPath::makeDeltasFromPoints(%d)\n",pts.size());
QPointF firstPt(0.0,0.0);
if (pts.empty()) {
Base::Console().Log("QGEPath::makeDeltasFromPoints - no points\n");
return;
Base::Console().Warning("QGEPath::makeDeltasFromPoints - no points\n");
return firstPt;
}
std::vector<QPointF> deltas;
QPointF firstPt = pts.front();
firstPt = pts.front();
QPointF newStart(0.0,0.0);
deltas.push_back(newStart);
unsigned int i = 1;
Expand All @@ -386,17 +412,34 @@ void QGEPath::makeDeltasFromPoints(std::vector<QPointF> pts)
deltas.push_back(mapped);
}
m_deltas = deltas;
return firstPt;
}

//announce points editing is finished
void QGEPath::updateFeature(void)
{
// Base::Console().Message("QGEPath::updateFeature()\n");
// Base::Console().Message("QGEPath::updateFeature() - inEdit: %d pts: %d\n",inEdit(),m_points.size());
QPointF attach = m_points.front();
if (!inEdit()) {
Q_EMIT pointsUpdated(m_deltas);
Q_EMIT pointsUpdated(attach, m_deltas);
}
}

void QGEPath::drawGhost(void)
{
// Base::Console().Message("QGEPath::drawGhost()\n");
if (m_ghost->scene() == nullptr) {
m_ghost->setParentItem(this);
}
QPainterPath qpp;
qpp.moveTo(m_points.front());
for (int i = 1; i < (int)m_points.size(); i++) {
qpp.lineTo(m_points.at(i));
}
m_ghost->setPath(qpp);
m_ghost->show();
}

QRectF QGEPath::boundingRect() const
{
return shape().controlPointRect();
Expand Down Expand Up @@ -458,7 +501,7 @@ void QGEPath::deletePoint(unsigned int atX)
setDeltas(deltaCopy);
}

void QGEPath::dumpPoints(char* text)
void QGEPath::dumpDeltas(char* text)
{
int idb = 0;
for (auto& d: m_deltas) {
Expand All @@ -468,5 +511,25 @@ void QGEPath::dumpPoints(char* text)
}
}

void QGEPath::dumpPoints(char* text)
{
int idb = 0;
for (auto& d: m_points) {
Base::Console().Message("QGEP - %s - point: %d %s\n", text,
idb,TechDraw::DrawUtil::formatVector(d).c_str());
idb++;
}
}

void QGEPath::dumpMarkerPos(char* text)
{
int idb = 0;
for (auto& m: m_markers) {
Base::Console().Message("QGEP - %s - markerPos: %d %s\n", text,
idb,TechDraw::DrawUtil::formatVector(m->pos()).c_str());
idb++;
}
}

#include <Mod/TechDraw/Gui/moc_QGEPath.cpp>

17 changes: 15 additions & 2 deletions src/Mod/TechDraw/Gui/QGEPath.h
Expand Up @@ -29,6 +29,7 @@
#include <QMouseEvent>
#include <QObject>

#include <Base/Vector3D.h>
#include "QGIVertex.h"
#include "QGIPrimPath.h"

Expand Down Expand Up @@ -107,13 +108,20 @@ class TechDrawGuiExport QGEPath : public QObject, public QGIPrimPath
void setScale(double s) { m_scale = s; }
double getScale(void) { return m_scale; }
void setAttach(QPointF s) { m_attach = s; }
void setAttach(Base::Vector3d v) { m_attach = QPointF(v.x, v.y); }
QPointF getAttach(void) { return m_attach; }

void makeDeltasFromPoints(std::vector<QPointF> pts);
QPointF makeDeltasFromPoints(std::vector<QPointF> pts);
QPointF makeDeltasFromPoints(void);
void setPoints(std::vector<QPointF> pts) { m_points = pts; }
void updatePath();
void updateFeature();
void drawGhost(void);

void dumpDeltas(char* text);
void dumpPoints(char* text);
void dumpMarkerPos(char* text);
void restoreState(void);

public Q_SLOTS:
void onDragFinished(QPointF pos, int index);
Expand All @@ -122,7 +130,9 @@ public Q_SLOTS:
void onEndEdit(void);

Q_SIGNALS:
void pointsUpdated(std::vector<QPointF> pts);
void pointsUpdated(QPointF attach, std::vector<QPointF> deltas);
void attachMoved(QPointF attach);

void hover(bool state);
void selected(bool state);

Expand All @@ -133,13 +143,16 @@ public Q_SLOTS:
double getEdgeFuzz(void) const;

std::vector<QPointF> m_deltas; //deltas between points 1:1 scale, starts at (0,0)
std::vector<QPointF> m_points; //actual pos of markers
std::vector<QPointF> m_saveDeltas;
std::vector<QGMarker*> m_markers;
QPointF m_attach;
double m_scale;

bool m_inEdit;

QGIView* m_parentItem;
QGIPrimPath* m_ghost;
};

}
Expand Down

0 comments on commit bf38ae9

Please sign in to comment.