Fix point edit when attach point changed

This commit is contained in:
wandererfan
2019-05-21 20:02:28 -04:00
parent 94b167f3a2
commit bf38ae958f
13 changed files with 401 additions and 156 deletions

View File

@@ -77,8 +77,6 @@ DrawLeaderLine::~DrawLeaderLine()
void DrawLeaderLine::onChanged(const App::Property* prop)
{
// if (!isRestoring()) {
// }
DrawView::onChanged(prop);
}
@@ -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;
@@ -134,7 +123,6 @@ DrawView* DrawLeaderLine::getBaseView(void) const
return result;
}
App::DocumentObject* DrawLeaderLine::getBaseObject(void) const
{
App::DocumentObject* result = nullptr;

View File

@@ -51,8 +51,6 @@ public:
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";

View File

@@ -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"

View File

@@ -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;
@@ -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);
}
@@ -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, ???
@@ -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)
@@ -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");
@@ -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) {
@@ -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)
@@ -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();
}
@@ -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;
@@ -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;
@@ -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();
@@ -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) {
@@ -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>

View File

@@ -29,6 +29,7 @@
#include <QMouseEvent>
#include <QObject>
#include <Base/Vector3D.h>
#include "QGIVertex.h"
#include "QGIPrimPath.h"
@@ -107,13 +108,20 @@ public:
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);
@@ -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);
@@ -133,6 +143,8 @@ protected:
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;
@@ -140,6 +152,7 @@ protected:
bool m_inEdit;
QGIView* m_parentItem;
QGIPrimPath* m_ghost;
};
}

View File

@@ -75,7 +75,8 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent,
m_parentItem(myParent),
m_lineWidth(0.0),
m_lineColor(Qt::black),
m_hasHover(false)
m_hasHover(false),
m_blockDraw(false)
{
setHandlesChildEvents(false);
@@ -113,8 +114,12 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent,
setZValue(ZVALUE::DIMENSION);
QObject::connect(
m_line, SIGNAL(pointsUpdated(std::vector<QPointF>)),
this , SLOT (onLineEditFinished(std::vector<QPointF>))
m_line, SIGNAL(pointsUpdated(QPointF, std::vector<QPointF>)),
this , SLOT (onLineEditFinished(QPointF, std::vector<QPointF>))
);
QObject::connect(
m_line, SIGNAL(attachMoved(QPointF)),
this , SLOT (onAttachMoved(QPointF))
);
QObject::connect(
m_line, SIGNAL(selected(bool)),
@@ -146,6 +151,36 @@ QVariant QGILeaderLine::itemChange(GraphicsItemChange change, const QVariant &va
return QGIView::itemChange(change, value);
}
void QGILeaderLine::onSourceChange(TechDraw::DrawView* newParent)
{
// Base::Console().Message("QGILL::onSoureChange(%s)\n",newParent->getNameInDocument());
std::string parentName = newParent->getNameInDocument();
QGIView* qgiParent = getQGIVByName(parentName);
if (qgiParent != nullptr) {
m_parentItem = qgiParent;
setParentItem(m_parentItem);
draw();
} else {
Base::Console().Warning("QGILL::onSourceChange - new parent %s has no QGIView\n",parentName.c_str());
}
}
void QGILeaderLine::onAttachMoved(QPointF attach)
{
auto leadFeat( dynamic_cast<TechDraw::DrawLeaderLine*>(getViewObject()) );
TechDraw::DrawView* parent = leadFeat->getBaseView();
double pScale = 1.0;
if (parent != nullptr) {
pScale = parent->getScale();
}
QPointF mapped = m_parentItem->mapFromItem(this,attach); //map point to baseView
Base::Vector3d attachPoint = Base::Vector3d(mapped.x(),mapped.y(),0.0);
getFeature()->setPosition(Rez::appX(attachPoint.x / pScale), //attach point must scale with parent.
Rez::appX(- attachPoint.y / pScale),
true);
}
void QGILeaderLine::select(bool state)
{
setSelected(state);
@@ -158,24 +193,45 @@ void QGILeaderLine::hover(bool state)
draw();
}
void QGILeaderLine::onLineEditFinished(std::vector<QPointF> pts)
void QGILeaderLine::closeEdit(void)
{
// 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)) ) {
// Base::Console().Message("QGIL::closeEdit()\n");
if (m_line != nullptr) {
m_line->onEndEdit(); //to QGEPath
}
}
//from QGEPath
void QGILeaderLine::onLineEditFinished(QPointF attach, std::vector<QPointF> deltas)
{
// Base::Console().Message("QGILL::onLineEditFinished(%s, %d)\n",
// TechDraw::DrawUtil::formatVector(attach).c_str(),
// deltas.size());
m_blockDraw = true;
double pScale = 1.0;
auto leadFeat( dynamic_cast<TechDraw::DrawLeaderLine*>(getViewObject()) );
TechDraw::DrawView* parent = leadFeat->getBaseView();
if (parent != nullptr) {
pScale = parent->getScale();
}
QPointF p0 = deltas.front();
if ( !(TechDraw::DrawUtil::fpCompare(attach.x(),0.0) &&
TechDraw::DrawUtil::fpCompare(attach.y(),0.0)) ) {
//p0 was moved. need to change AttachPoint and intervals from p0
QPointF mapped = m_parentItem->mapFromItem(this,p0);
QPointF mapped = m_parentItem->mapFromItem(this,attach); //map point to baseView
Base::Vector3d attachPoint = Base::Vector3d(mapped.x(),mapped.y(),0.0);
for (auto& p : pts) {
for (auto& p : deltas) {
p -= p0;
}
pts.at(0) = QPointF(0.0,0.0);
getFeature()->setPosition(Rez::appX(attachPoint.x),Rez::appX(- attachPoint.y), true);
deltas.at(0) = QPointF(0.0,0.0);
getFeature()->setPosition(Rez::appX(attachPoint.x / pScale), //attach point must scale with parent.
Rez::appX(- attachPoint.y / pScale),
true);
}
std::vector<Base::Vector3d> waypoints;
for (auto& p: pts) {
for (auto& p: deltas) {
Base::Vector3d v(p.x(),p.y(),0.0);
waypoints.push_back(v);
}
@@ -186,30 +242,54 @@ void QGILeaderLine::onLineEditFinished(std::vector<QPointF> pts)
}
if (m_parentItem == nullptr) {
Base::Console().Log("QGILL::onLineEditFinished - m_parentItem is NULL\n");
Base::Console().Warning("QGILL::onLineEditFinished - m_parentItem is NULL\n");
} else {
QGIView* qgiv = dynamic_cast<QGIView*>(m_parentItem);
if (qgiv != nullptr) {
Q_EMIT editComplete(pts, qgiv);
Q_EMIT editComplete(); //to task
}
}
m_blockDraw = false;
draw();
}
void QGILeaderLine::startPathEdit(void)
{
saveState();
double scale = getScale();
m_line->setScale(scale);
m_line->inEdit(true);
m_line->startPathEdit();
}
void QGILeaderLine::saveState(void)
{
auto leadFeat = getFeature();
if (leadFeat != nullptr) {
m_savePoints = leadFeat->WayPoints.getValues();
m_saveX = leadFeat->X.getValue();
m_saveY = leadFeat->Y.getValue();
}
}
void QGILeaderLine::restoreState(void)
{
auto leadFeat = getFeature();
if (leadFeat != nullptr) {
leadFeat->WayPoints.setValues(m_savePoints);
leadFeat->X.setValue(m_saveX);
leadFeat->Y.setValue(m_saveY);
}
}
void QGILeaderLine::updateView(bool update)
{
// Base::Console().Message("QGIL::updateView() %s\n",getViewObject()->getNameInDocument());
Q_UNUSED(update);
auto leadFeat( dynamic_cast<TechDraw::DrawLeaderLine*>(getViewObject()) );
if ( leadFeat == nullptr ) {
Base::Console().Log("QGILL::updateView - no feature!\n");
Base::Console().Warning("QGILL::updateView - no feature!\n");
return;
}
@@ -217,39 +297,43 @@ void QGILeaderLine::updateView(bool update)
if ( vp == nullptr ) {
return;
}
draw();
}
void QGILeaderLine::draw()
{
// Base::Console().Message("QGILL::draw()- %s\n", getViewObject()->getNameInDocument());
if (m_blockDraw) {
// Base::Console().Message("QGIL::draw - block draw\n");
return;
}
if (!isVisible()) {
Base::Console().Log("QGIL::draw - not visible\n");
// Base::Console().Message("QGIL::draw - not visible\n");
return;
}
TechDraw::DrawLeaderLine* leadFeat = getFeature();
if((!leadFeat) ) {
Base::Console().Log("QGIL::draw - no feature\n");
// Base::Console().Message("QGIL::draw - no feature\n");
return;
}
auto vp = static_cast<ViewProviderLeader*>(getViewProvider(getViewObject()));
if ( vp == nullptr ) {
Base::Console().Log("QGIL::draw - no viewprovider\n");
// Base::Console().Message("QGIL::draw - no viewprovider\n");
return;
}
TechDraw::DrawView* parent = leadFeat->getBaseView();
QGVPage* view = QGIView::getGraphicsView(parent);
if (view == nullptr) {
Base::Console().Log("QGIL::draw - no graphcisView for parent!! - setup?\n");
// Base::Console().Message("QGIL::draw - no graphcisView for parent!! - setup?\n");
return;
}
if (m_line->inEdit()) {
Base::Console().Log("QGIL::draw - m_line is in edit\n");
// Base::Console().Message("QGIL::draw - m_line in edit\n");
return;
}
@@ -275,11 +359,12 @@ void QGILeaderLine::draw()
// if (leadFeat->Scalable.getValue()) {
// ptScale = scale;
// }
std::vector<QPointF> qPoints = convertWaypoints();
std::vector<QPointF> qPoints = waypointsToQPoints();
if (qPoints.empty()) {
Base::Console().Log("QGIL::draw - no points\n");
// Base::Console().Warning("QGIL::draw - no points\n");
return;
}
m_line->setStyle(m_lineStyle);
double scaler = 1.0;
m_line->setWidth(scaler * m_lineWidth);
@@ -287,7 +372,7 @@ void QGILeaderLine::draw()
m_line->setNormalColor(m_lineColor);
scale = getScale();
m_line->setScale(scale);
m_line->makeDeltasFromPoints(qPoints); //this is what messes up edit!??
m_line->makeDeltasFromPoints(qPoints);
m_line->setPos(0,0);
m_line->updatePath();
m_line->show();
@@ -307,6 +392,7 @@ void QGILeaderLine::draw()
m_arrow2->setPrettyNormal();
m_line->setPrettyNormal();
}
// Base::Console().Message("QGIL::draw - exits\n");
}
void QGILeaderLine::drawBorder()
@@ -316,24 +402,32 @@ void QGILeaderLine::drawBorder()
}
//waypoints converted to QPointF
std::vector<QPointF> QGILeaderLine::convertWaypoints()
std::vector<QPointF> QGILeaderLine::waypointsToQPoints()
{
// Base::Console().Message("QGIL::convertWaypoints()\n");
// Base::Console().Message("QGIL::waypointsToQPoints - #1 ()\n");
TechDraw::DrawLeaderLine* featLine = getFeature();
std::vector<QPointF> result;
std::vector<Base::Vector3d> vPts = featLine->WayPoints.getValues();
if (vPts.empty()) {
Base::Console().Log("QGIL::convertWaypoints - no points from feature!\n");
Base::Console().Warning("QGIL::waypointsToQPoints - no points from feature!\n");
return result;
}
QGraphicsItem* myParent = parentItem();
if (myParent != nullptr) {
for (auto& p: vPts) {
QPointF pConvert(p.x, p.y);
result.push_back(pConvert);
}
}
for (auto& p: vPts) {
QPointF pConvert(p.x, p.y);
result.push_back(pConvert);
}
return result;
}
std::vector<QPointF> QGILeaderLine::waypointsToQPoints(std::vector<Base::Vector3d> pts)
{
// Base::Console().Message("QGIL::waypointsToQPoints(%d) - #2\n", pts.size());
std::vector<QPointF> result;
for (auto& p: pts) {
QPointF pConvert(p.x, p.y);
result.push_back(pConvert);
}
return result;
}
@@ -393,7 +487,9 @@ void QGILeaderLine::setArrows(std::vector<QPointF> pathPoints)
void QGILeaderLine::abandonEdit(void)
{
//// Base::Console().Message("QGIL::abandonEdit()\n");
m_line->clearMarkers();
m_line->restoreState();
}
double QGILeaderLine::getScale(void)

View File

@@ -38,6 +38,7 @@
namespace TechDraw {
class DrawLeaderLine;
class DrawView;
}
namespace TechDrawGui
@@ -73,20 +74,25 @@ public:
virtual TechDraw::DrawLeaderLine* getFeature(void);
QGEPath* getLeaderLine(void) { return m_line; }
std::vector<QPointF> convertWaypoints(void);
std::vector<QPointF> waypointsToQPoints(void);
std::vector<QPointF> waypointsToQPoints(std::vector<Base::Vector3d> pts);
void startPathEdit(void);
void setArrows(std::vector<QPointF> pathPoints);
void abandonEdit(void);
void closeEdit(void);
double getScale(void);
public Q_SLOTS:
void onLineEditFinished(std::vector<QPointF> pts); //QGEPath is finished editing points
void onLineEditFinished(QPointF attach, std::vector<QPointF> deltas); //QGEPath is finished editing points
void onAttachMoved(QPointF attach);
void select(bool state);
void hover(bool state);
virtual void onSourceChange(TechDraw::DrawView* newParent) override;
Q_SIGNALS:
void editComplete(std::vector<QPointF> pts, QGIView* parent); //tell caller that edit session is finished
void editComplete(void); //tell caller that edit session is finished
protected:
virtual void draw() override;
@@ -94,11 +100,14 @@ protected:
const QVariant &value ) override;
std::vector<QPointF> m_pathPoints;
Base::Vector3d m_attachPoint;
void saveState(void);
void restoreState(void);
protected:
QColor getNormalColor() override;
QGraphicsItem* m_parentItem;
QGraphicsItem* m_parentItem; //<<< this never changes!
QGEPath* m_line;
QGIArrow* m_arrow1;
QGIArrow* m_arrow2;
@@ -106,6 +115,12 @@ protected:
QColor m_lineColor;
Qt::PenStyle m_lineStyle;
bool m_hasHover;
double m_saveX;
double m_saveY;
std::vector<Base::Vector3d> m_savePoints;
bool m_blockDraw; //prevent redraws while updating.
};
}

View File

@@ -125,6 +125,11 @@ QGIView::~QGIView()
signalSelectPoint.disconnect_all_slots();
}
void QGIView::onSourceChange(TechDraw::DrawView* newParent)
{
Q_UNUSED(newParent);
}
void QGIView::isVisible(bool state)
{
auto feat = getViewObject();

View File

@@ -116,6 +116,9 @@ public:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
boost::signals2::signal<void (QGIView*, QPointF)> signalSelectPoint;
public Q_SLOTS:
virtual void onSourceChange(TechDraw::DrawView* newParent);
protected:
QGIView* getQGIVByName(std::string name);

View File

@@ -116,7 +116,12 @@ TaskLeaderLine::TaskLeaderLine(TechDrawGui::ViewProviderLeader* leadVP) :
connect(ui->pbTracker, SIGNAL(clicked(bool)),
this, SLOT(onTrackerClicked(bool)));
connect(ui->pbCancelEdit, SIGNAL(clicked(bool)),
this, SLOT(onCancelEditClicked(bool)));
ui->pbCancelEdit->setEnabled(false);
saveState();
m_trackerMode = QGTracker::TrackerMode::Line;
}
@@ -155,6 +160,9 @@ TaskLeaderLine::TaskLeaderLine(TechDraw::DrawView* baseFeat,
connect(ui->pbTracker, SIGNAL(clicked(bool)),
this, SLOT(onTrackerClicked(bool)));
connect(ui->pbCancelEdit, SIGNAL(clicked(bool)),
this, SLOT(onCancelEditClicked(bool)));
ui->pbCancelEdit->setEnabled(false);
m_trackerMode = QGTracker::TrackerMode::Line;
}
@@ -164,6 +172,24 @@ TaskLeaderLine::~TaskLeaderLine()
delete ui;
}
void TaskLeaderLine::saveState()
{
if (m_lineFeat != nullptr) {
m_savePoints = m_lineFeat->WayPoints.getValues();
m_saveX = m_lineFeat->X.getValue();
m_saveY = m_lineFeat->Y.getValue();
}
}
void TaskLeaderLine::restoreState()
{
if (m_lineFeat != nullptr) {
m_lineFeat->WayPoints.setValues(m_savePoints);
m_lineFeat->X.setValue(m_saveX);
m_lineFeat->Y.setValue(m_saveY);
}
}
void TaskLeaderLine::updateTask()
{
// blockUpdate = true;
@@ -190,7 +216,8 @@ void TaskLeaderLine::setUiPrimary()
}
ui->pbTracker->setText(QString::fromUtf8("Pick points"));
ui->pbTracker->setEnabled(true);
int aSize = getPrefArrowStyle() + 1;
ui->pbCancelEdit->setEnabled(true);
int aSize = getPrefArrowStyle() + 1;
ui->cboxStartSym->setCurrentIndex(aSize);
}
@@ -214,6 +241,7 @@ void TaskLeaderLine::setUiEdit()
ui->cboxEndSym->setCurrentIndex(m_lineFeat->EndSymbol.getValue() + 1);
ui->pbTracker->setText(QString::fromUtf8("Edit points"));
ui->pbTracker->setEnabled(true);
ui->pbCancelEdit->setEnabled(true);
}
if (m_lineVP != nullptr) {
@@ -264,7 +292,7 @@ void TaskLeaderLine::createLeaderFeature(std::vector<Base::Vector3d> converted)
void TaskLeaderLine::updateLeaderFeature(void)
{
// Base::Console().Message("TTL::updateLeaderFeature(%d)\n",converted.size());
// Base::Console().Message("TTL::updateLeaderFeature()\n");
Gui::Command::openCommand("Edit Leader");
//waypoints & x,y are updated by QGILeaderLine (for edits only!)
commonFeatureUpdate();
@@ -280,14 +308,6 @@ void TaskLeaderLine::updateLeaderFeature(void)
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();
// }
// }
int start = ui->cboxStartSym->currentIndex() - 1;
int end = ui->cboxEndSym->currentIndex() - 1;
m_lineFeat->StartSymbol.setValue(start);
@@ -327,26 +347,35 @@ void TaskLeaderLine::onTrackerClicked(bool b)
Q_UNUSED(b);
// Base::Console().Message("TTL::onTrackerClicked() m_pbTrackerState: %d\n",
// m_pbTrackerState);
if (m_pbTrackerState == TRACKERCANCEL) {
removeTracker();
if ( (m_pbTrackerState == TRACKERSAVE) &&
(getCreateMode()) ){
if (m_tracker != nullptr) {
m_tracker->terminateDrawing();
}
m_pbTrackerState = TRACKERPICK;
ui->pbTracker->setText(QString::fromUtf8("Pick Points"));
ui->pbCancelEdit->setEnabled(false);
enableTaskButtons(true);
setEditCursor(Qt::ArrowCursor);
return;
} else if (m_pbTrackerState == TRACKERCANCELEDIT) {
abandonEditSession();
} else if ( (m_pbTrackerState == TRACKERSAVE) &&
(!getCreateMode()) ) {
if (m_qgLine != nullptr) {
m_qgLine->closeEdit();
}
m_pbTrackerState = TRACKEREDIT;
ui->pbTracker->setText(QString::fromUtf8("Edit points"));
m_pbTrackerState = TRACKERPICK;
ui->pbTracker->setText(QString::fromUtf8("Pick Points"));
ui->pbCancelEdit->setEnabled(false);
enableTaskButtons(true);
setEditCursor(Qt::ArrowCursor);
return;
}
//TRACKERPICK or TRACKEREDIT
if (getCreateMode()) {
m_inProgressLock = true;
m_saveContextPolicy = m_mdi->contextMenuPolicy();
@@ -358,9 +387,10 @@ void TaskLeaderLine::onTrackerClicked(bool b)
QString msg = tr("Pick a starting point for leader line");
getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,3000);
ui->pbTracker->setText(QString::fromUtf8("Escape picking"));
ui->pbTracker->setText(QString::fromUtf8("Save Points"));
ui->pbTracker->setEnabled(true);
m_pbTrackerState = TRACKERCANCEL;
ui->pbCancelEdit->setEnabled(true);
m_pbTrackerState = TRACKERSAVE;
enableTaskButtons(false);
} else { //edit mode
m_trackerPoints = m_lineFeat->WayPoints.getValues();
@@ -378,26 +408,19 @@ void TaskLeaderLine::onTrackerClicked(bool b)
//now what? throw will generate "unknown unhandled exception"
} else {
m_qgLine = qgLead;
connect(qgLead, SIGNAL(editComplete(std::vector<QPointF>, QGIView*)),
this, SLOT(onPointEditComplete(std::vector<QPointF>, QGIView*)));
m_attachPoint = Rez::guiX(Base::Vector3d(m_lineFeat->X.getValue(), //don't need this?
-m_lineFeat->Y.getValue(),
0.0));
connect(qgLead, SIGNAL(editComplete()),
this, SLOT(onPointEditComplete()));
qgLead->startPathEdit();
QString msg = tr("Click and drag markers to adjust leader line");
getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,3000);
msg = tr("ESC or RMB to exit");
getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,3000);
ui->pbTracker->setText(QString::fromUtf8("Escape edit"));
ui->pbTracker->setText(QString::fromUtf8("Save changes"));
ui->pbTracker->setEnabled(true);
m_pbTrackerState = TRACKERCANCELEDIT;
ui->pbCancelEdit->setEnabled(true);
m_pbTrackerState = TRACKERSAVE;
enableTaskButtons(false);
}
} else { // need to recreate leaderline
// same as create mode??
m_inProgressLock = true;
m_saveContextPolicy = m_mdi->contextMenuPolicy();
m_mdi->setContextMenuPolicy(Qt::PreventContextMenu);
@@ -408,12 +431,13 @@ void TaskLeaderLine::onTrackerClicked(bool b)
QString msg = tr("Pick a starting point for leader line");
getMainWindow()->statusBar()->show();
Gui::getMainWindow()->showMessage(msg,3000);
ui->pbTracker->setText(QString::fromUtf8("Escape picking"));
ui->pbTracker->setText(QString::fromUtf8("Save changes"));
ui->pbTracker->setEnabled(true);
m_pbTrackerState = TRACKERCANCEL;
ui->pbCancelEdit->setEnabled(true);
m_pbTrackerState = TRACKERSAVE;
enableTaskButtons(false);
}
} //end edit mode
}
}
void TaskLeaderLine::startTracker(void)
@@ -446,7 +470,7 @@ void TaskLeaderLine::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgPare
Base::Console().Error("TaskLeaderLine - no points available\n");
return;
}
if (qgParent == nullptr) {
//do something;
m_qgParent = findParentQGIV();
@@ -465,7 +489,7 @@ void TaskLeaderLine::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgPare
double scale = m_qgParent->getScale();
QPointF mapped = m_qgParent->mapFromScene(pts.front()) / scale;
m_attachPoint = Base::Vector3d(mapped.x(), mapped.y(), 0.0);
convertTrackerPoints(pts);
trackerPointsFromQPoints(pts);
} else {
Base::Console().Message("TTL::onTrackerFinished - can't find parent graphic!\n");
//blow up!?
@@ -480,6 +504,7 @@ void TaskLeaderLine::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgPare
m_tracker->sleep(true);
m_inProgressLock = false;
ui->pbTracker->setEnabled(false);
ui->pbCancelEdit->setEnabled(false);
enableTaskButtons(true);
setEditCursor(Qt::ArrowCursor);
}
@@ -495,6 +520,25 @@ void TaskLeaderLine::removeTracker(void)
}
}
void TaskLeaderLine::onCancelEditClicked(bool b)
{
Q_UNUSED(b);
// Base::Console().Message("TTL::onCancelEditClicked() m_pbTrackerState: %d\n",
// m_pbTrackerState);
abandonEditSession();
if (m_lineFeat != nullptr) {
m_lineFeat->requestPaint();
}
m_pbTrackerState = TRACKEREDIT;
ui->pbTracker->setText(QString::fromUtf8("Edit points"));
ui->pbCancelEdit->setEnabled(false);
enableTaskButtons(true);
m_inProgressLock = false;
setEditCursor(Qt::ArrowCursor);
}
QGIView* TaskLeaderLine::findParentQGIV()
{
QGIView* result = nullptr;
@@ -517,9 +561,9 @@ void TaskLeaderLine::setEditCursor(QCursor c)
}
//from 1:1 scale scene QPointF to zero origin Vector3d points
void TaskLeaderLine::convertTrackerPoints(std::vector<QPointF> pts)
void TaskLeaderLine::trackerPointsFromQPoints(std::vector<QPointF> pts)
{
// Base::Console().Message("TTL::convertTrackerPoints(%d)\n", pts.size());
// Base::Console().Message("TTL::trackerPointsFromQPoints(%d)\n", pts.size());
m_trackerPoints.clear();
for (auto& p: pts) {
QPointF mapped = p - pts.front();
@@ -529,43 +573,22 @@ void TaskLeaderLine::convertTrackerPoints(std::vector<QPointF> pts)
}
//******************************************************************************
void TaskLeaderLine::onPointEditComplete(std::vector<QPointF> pts, QGIView* parent)
//void TaskLeaderLine::onPointEditComplete(std::vector<QPointF> pts, QGIView* parent)
void TaskLeaderLine::onPointEditComplete(void)
{
// 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");
} else {
m_qgParent = parent;
// double scale = m_qgParent->getScale();
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_qgParent->mapFromItem(m_qgLine,p0);
m_attachPoint = Base::Vector3d(mapped.x(),mapped.y(),0.0);
for (auto& p : pts) {
p -= p0;
}
pts.at(0) = QPointF(0.0,0.0);
}
convertTrackerPoints(pts);
}
// Base::Console().Message("TTL::onPointEditComplete()\n");
m_inProgressLock = false;
m_pbTrackerState = TRACKEREDIT;
ui->pbTracker->setText(QString::fromUtf8("Edit points"));
ui->pbTracker->setEnabled(true);
ui->pbCancelEdit->setEnabled(true);
enableTaskButtons(true);
}
void TaskLeaderLine::abandonEditSession(void)
{
// Base::Console().Message("TTL::abandonEditSession()\n");
if (m_qgLine != nullptr) {
m_qgLine->abandonEdit();
}
@@ -577,6 +600,7 @@ void TaskLeaderLine::abandonEditSession(void)
ui->pbTracker->setText(QString::fromUtf8("Edit points"));
enableTaskButtons(true);
ui->pbTracker->setEnabled(true);
ui->pbCancelEdit->setEnabled(false);
setEditCursor(Qt::ArrowCursor);
}
@@ -608,7 +632,6 @@ bool TaskLeaderLine::accept()
{
// Base::Console().Message("TTL::accept()\n");
if (m_inProgressLock) {
// Base::Console().Message("TTL::accept - edit in progress!!\n");
abandonEditSession();
return true;
}
@@ -648,6 +671,12 @@ bool TaskLeaderLine::reject()
(m_lineFeat != nullptr) ) {
removeFeature();
}
if (!getCreateMode() &&
(m_lineFeat != nullptr) ) {
restoreState();
}
m_trackerMode = QGTracker::TrackerMode::None;
//make sure any dangling objects are cleaned up

View File

@@ -37,6 +37,8 @@
#define TRACKEREDIT 1
#define TRACKERCANCEL 2
#define TRACKERCANCELEDIT 3
#define TRACKERFINISHED 4
#define TRACKERSAVE 5
class Ui_TaskLeaderLine;
@@ -75,9 +77,8 @@ public:
public Q_SLOTS:
void onTrackerClicked(bool b);
void onCancelEditClicked(bool b);
void onTrackerFinished(std::vector<QPointF> pts, QGIView* qgParent);
/* void onEditorClicked(bool b);*/
/* void onViewPicked(QPointF pos, QGIView* qgParent);*/
public:
virtual bool accept();
@@ -91,12 +92,10 @@ public:
protected Q_SLOTS:
void convertTrackerPoints(std::vector<QPointF> pts);
void onPointEditComplete(std::vector<QPointF> pts, QGIView* parent);
/* void onSaveAndExit(QString);*/
/* void onEditorExit(void);*/
void onPointEditComplete(void);
protected:
void trackerPointsFromQPoints(std::vector<QPointF> pts);
void changeEvent(QEvent *e);
void startTracker(void);
void removeTracker(void);
@@ -107,8 +106,6 @@ protected:
void commonFeatureUpdate(void);
void removeFeature(void);
/* QPointF calcTextStartPos(double scale);*/
void blockButtons(bool b);
void setUiPrimary(void);
void setUiEdit(void);
@@ -119,6 +116,8 @@ protected:
QGIView* findParentQGIV();
int getPrefArrowStyle();
void saveState(void);
void restoreState(void);
private:
Ui_TaskLeaderLine * ui;
@@ -153,6 +152,10 @@ private:
QPushButton* m_btnCancel;
int m_pbTrackerState;
std::vector<Base::Vector3d> m_savePoints;
double m_saveX;
double m_saveY;
};
class TaskDlgLeaderLine : public Gui::TaskView::TaskDialog

View File

@@ -76,6 +76,26 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbCancelEdit">
<property name="text">
<string>Discard Changes</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -92,12 +112,12 @@
<item>
<widget class="QPushButton" name="pbTracker">
<property name="text">
<string>Select Line Points</string>
<string>Pick Points</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>

View File

@@ -120,6 +120,18 @@ bool ViewProviderLeader::doubleClicked(void)
void ViewProviderLeader::updateData(const App::Property* p)
{
if (!getFeature()->isRestoring()) {
if (p == &getFeature()->LeaderParent) {
App::DocumentObject* docObj = getFeature()->LeaderParent.getValue();
TechDraw::DrawView* dv = dynamic_cast<TechDraw::DrawView*>(docObj);
if (dv != nullptr) {
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->onSourceChange(dv);
}
}
}
}
ViewProviderDrawingView::updateData(p);
}