Fix for broken move detail and move single point.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-16 10:52:55 +03:00
parent 01c195fd90
commit 814e414b4b
14 changed files with 37 additions and 22 deletions

View File

@ -154,7 +154,7 @@ void VAbstractSpline::keyReleaseEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
DeleteTool(); DeleteTool(this);
break; break;
default: default:
break; break;

View File

@ -137,7 +137,7 @@ protected:
} }
if (selectedAction == actionRemove) if (selectedAction == actionRemove)
{ {
DeleteTool(); DeleteTool(tool);
} }
} }
} }

View File

@ -349,7 +349,7 @@ void VToolArc::keyReleaseEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
DeleteTool(); DeleteTool(this);
break; break;
default: default:
break; break;

View File

@ -315,7 +315,7 @@ void VToolLine::keyReleaseEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
DeleteTool(); DeleteTool(this);
break; break;
default: default:
break; break;

View File

@ -199,6 +199,7 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
*/ */
void VToolPoint::RefreshPointGeometry(const VPointF &point) void VToolPoint::RefreshPointGeometry(const VPointF &point)
{ {
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor); QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
rec.translate(-rec.center().x(), -rec.center().y()); rec.translate(-rec.center().x(), -rec.center().y());
@ -213,6 +214,7 @@ void VToolPoint::RefreshPointGeometry(const VPointF &point)
namePoint->setPos(QPointF(point.mx(), point.my())); namePoint->setPos(QPointF(point.mx(), point.my()));
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition);
RefreshLine(); RefreshLine();
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -279,7 +281,7 @@ void VToolPoint::keyReleaseEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
DeleteTool(); DeleteTool(this);
break; break;
default: default:
break; break;

View File

@ -161,7 +161,6 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change,
} }
if (change == ItemPositionHasChanged && scene()) if (change == ItemPositionHasChanged && scene())
{ {
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
// value - this is new position. // value - this is new position.
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF();
@ -185,8 +184,9 @@ void VToolSinglePoint::decrementReferens()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::DeleteTool(bool ask) void VToolSinglePoint::DeleteTool(QGraphicsItem *tool, bool ask)
{ {
Q_UNUSED(tool)
if (ask) if (ask)
{ {
QMessageBox msgBox; QMessageBox msgBox;

View File

@ -59,7 +59,7 @@ protected:
virtual void RefreshDataInFile(); virtual void RefreshDataInFile();
QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void decrementReferens(); virtual void decrementReferens();
virtual void DeleteTool(bool ask = true); virtual void DeleteTool(QGraphicsItem *tool, bool ask = true);
virtual void SaveDialog(QDomElement &domElement); virtual void SaveDialog(QDomElement &domElement);
private: private:
QString namePP; QString namePP;

View File

@ -242,8 +242,9 @@ QPointF VAbstractTool::addVector(const QPointF &p, const QPointF &p1, const QPoi
* @brief DeleteTool full delete object form scene and file. * @brief DeleteTool full delete object form scene and file.
* @param tool tool * @param tool tool
*/ */
void VAbstractTool::DeleteTool(bool ask) void VAbstractTool::DeleteTool(QGraphicsItem *tool, bool ask)
{ {
DelTool *delTool = new DelTool(doc, id, tool);
if (ask) if (ask)
{ {
QMessageBox msgBox; QMessageBox msgBox;
@ -256,10 +257,9 @@ void VAbstractTool::DeleteTool(bool ask)
{ {
return; return;
} }
/*Ugly hack. If UnionDetails delete detail no need emit FullParsing */
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
} }
DelTool *delTool = new DelTool(doc, id);
connect(delTool, &DelTool::NeedFullParsing, doc, &VPattern::NeedFullParsing);
qApp->getUndoStack()->push(delTool); qApp->getUndoStack()->push(delTool);
} }

View File

@ -37,6 +37,7 @@ class QLineF;
class QPointF; class QPointF;
class QGraphicsScene; class QGraphicsScene;
class QGraphicsView; class QGraphicsView;
class QGraphicsItem;
class QRectF; class QRectF;
/** /**
@ -145,7 +146,7 @@ protected:
* @brief RemoveReferens decrement value of reference. * @brief RemoveReferens decrement value of reference.
*/ */
virtual void RemoveReferens(){} virtual void RemoveReferens(){}
virtual void DeleteTool(bool ask = true); virtual void DeleteTool(QGraphicsItem *tool, bool ask = true);
Qt::PenStyle LineStyle(); Qt::PenStyle LineStyle();
private: private:
Q_DISABLE_COPY(VAbstractTool) Q_DISABLE_COPY(VAbstractTool)

View File

@ -273,7 +273,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap
*/ */
void VToolDetail::Remove(bool ask) void VToolDetail::Remove(bool ask)
{ {
DeleteTool(ask); DeleteTool(this, ask);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -368,7 +368,6 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
{ {
if (change == ItemPositionHasChanged && scene()) if (change == ItemPositionHasChanged && scene())
{ {
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
// value - this is new position. // value - this is new position.
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF();
@ -403,7 +402,7 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Delete: case Qt::Key_Delete:
DeleteTool(); DeleteTool(this);
break; break;
default: default:
break; break;
@ -457,7 +456,7 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
} }
if (selectedAction == actionRemove) if (selectedAction == actionRemove)
{ {
DeleteTool(); DeleteTool(this);
} }
} }
@ -544,6 +543,7 @@ void VToolDetail::AddNode(VPattern *doc, QDomElement &domElement, const VNodeDet
*/ */
void VToolDetail::RefreshGeometry() void VToolDetail::RefreshGeometry()
{ {
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
QPainterPath path = VEquidistant().ContourPath(id, this->getData()); QPainterPath path = VEquidistant().ContourPath(id, this->getData());
this->setPath(path); this->setPath(path);

View File

@ -28,11 +28,12 @@
#include "deltool.h" #include "deltool.h"
#include "../xml/vpattern.h" #include "../xml/vpattern.h"
#include <QGraphicsItem>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DelTool::DelTool(VPattern *doc, quint32 id, QUndoCommand *parent) DelTool::DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *parent)
: QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), previousNode(QDomNode()), : QObject(), QUndoCommand(parent), xml(QDomElement()), parentNode(QDomNode()), previousNode(QDomNode()),
doc(doc), toolId(id) doc(doc), toolId(id), tool(tool)
{ {
setText(tr("Delete tool")); setText(tr("Delete tool"));
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
@ -67,6 +68,7 @@ void DelTool::redo()
if (domElement.isElement()) if (domElement.isElement())
{ {
parentNode.removeChild(domElement); parentNode.removeChild(domElement);
tool->hide();
emit NeedFullParsing(); emit NeedFullParsing();
} }
else else

View File

@ -33,12 +33,13 @@
#include <QUndoCommand> #include <QUndoCommand>
class VPattern; class VPattern;
class QGraphicsItem;
class DelTool : public QObject, public QUndoCommand class DelTool : public QObject, public QUndoCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
DelTool(VPattern *doc, quint32 id, QUndoCommand *parent = 0); DelTool(VPattern *doc, quint32 id, QGraphicsItem *tool, QUndoCommand *parent = 0);
virtual ~DelTool(); virtual ~DelTool();
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
@ -51,6 +52,7 @@ private:
QDomNode previousNode; QDomNode previousNode;
VPattern *doc; VPattern *doc;
quint32 toolId; quint32 toolId;
QGraphicsItem *tool;
}; };
#endif // DELTOOL_H #endif // DELTOOL_H

View File

@ -37,7 +37,8 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MoveDetail::MoveDetail(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, MoveDetail::MoveDetail(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
QUndoCommand *parent) QUndoCommand *parent)
: QObject(), QUndoCommand(parent), doc(doc), oldX(0.0), oldY(0.0), newX(x), newY(y), detId(id), scene(scene) : QObject(), QUndoCommand(parent), doc(doc), oldX(0.0), oldY(0.0), newX(x), newY(y), detId(id), scene(scene),
redoFlag(false)
{ {
setText(QObject::tr("Move detail")); setText(QObject::tr("Move detail"));
@ -67,6 +68,7 @@ void MoveDetail::undo()
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX))); doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY)));
qDebug()<<"undo move detail"<<oldX<<oldY;
emit NeedLiteParsing(); emit NeedLiteParsing();
@ -88,8 +90,13 @@ void MoveDetail::redo()
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX))); doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY))); doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY)));
qDebug()<<"redo move detail"<<newX<<newY;
emit NeedLiteParsing(); if (redoFlag)
{
emit NeedLiteParsing();
}
redoFlag = true;
QList<QGraphicsView*> list = scene->views(); QList<QGraphicsView*> list = scene->views();
VAbstractTool::NewSceneRect(scene, list[0]); VAbstractTool::NewSceneRect(scene, list[0]);

View File

@ -59,6 +59,7 @@ private:
double newY; double newY;
quint32 detId; quint32 detId;
QGraphicsScene *scene; QGraphicsScene *scene;
bool redoFlag;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------