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())
{
case Qt::Key_Delete:
DeleteTool();
DeleteTool(this);
break;
default:
break;

View File

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

View File

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

View File

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

View File

@ -199,6 +199,7 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
*/
void VToolPoint::RefreshPointGeometry(const VPointF &point)
{
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor));
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
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()));
connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, &VToolPoint::NameChangePosition);
RefreshLine();
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
//---------------------------------------------------------------------------------------------------------------------
@ -279,7 +281,7 @@ void VToolPoint::keyReleaseEvent(QKeyEvent *event)
switch (event->key())
{
case Qt::Key_Delete:
DeleteTool();
DeleteTool(this);
break;
default:
break;

View File

@ -161,7 +161,6 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change,
}
if (change == ItemPositionHasChanged && scene())
{
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
// value - this is new position.
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)
{
QMessageBox msgBox;

View File

@ -59,7 +59,7 @@ protected:
virtual void RefreshDataInFile();
QVariant itemChange ( GraphicsItemChange change, const QVariant &value );
virtual void decrementReferens();
virtual void DeleteTool(bool ask = true);
virtual void DeleteTool(QGraphicsItem *tool, bool ask = true);
virtual void SaveDialog(QDomElement &domElement);
private:
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.
* @param tool tool
*/
void VAbstractTool::DeleteTool(bool ask)
void VAbstractTool::DeleteTool(QGraphicsItem *tool, bool ask)
{
DelTool *delTool = new DelTool(doc, id, tool);
if (ask)
{
QMessageBox msgBox;
@ -256,10 +257,9 @@ void VAbstractTool::DeleteTool(bool ask)
{
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);
}

View File

@ -37,6 +37,7 @@ class QLineF;
class QPointF;
class QGraphicsScene;
class QGraphicsView;
class QGraphicsItem;
class QRectF;
/**
@ -145,7 +146,7 @@ protected:
* @brief RemoveReferens decrement value of reference.
*/
virtual void RemoveReferens(){}
virtual void DeleteTool(bool ask = true);
virtual void DeleteTool(QGraphicsItem *tool, bool ask = true);
Qt::PenStyle LineStyle();
private:
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)
{
DeleteTool(ask);
DeleteTool(this, ask);
}
//---------------------------------------------------------------------------------------------------------------------
@ -368,7 +368,6 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
{
if (change == ItemPositionHasChanged && scene())
{
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
// value - this is new position.
QPointF newPos = value.toPointF();
@ -403,7 +402,7 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event)
switch (event->key())
{
case Qt::Key_Delete:
DeleteTool();
DeleteTool(this);
break;
default:
break;
@ -457,7 +456,7 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}
if (selectedAction == actionRemove)
{
DeleteTool();
DeleteTool(this);
}
}
@ -544,6 +543,7 @@ void VToolDetail::AddNode(VPattern *doc, QDomElement &domElement, const VNodeDet
*/
void VToolDetail::RefreshGeometry()
{
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
QPainterPath path = VEquidistant().ContourPath(id, this->getData());
this->setPath(path);

View File

@ -28,11 +28,12 @@
#include "deltool.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()),
doc(doc), toolId(id)
doc(doc), toolId(id), tool(tool)
{
setText(tr("Delete tool"));
QDomElement domElement = doc->elementById(QString().setNum(id));
@ -67,6 +68,7 @@ void DelTool::redo()
if (domElement.isElement())
{
parentNode.removeChild(domElement);
tool->hide();
emit NeedFullParsing();
}
else

View File

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

View File

@ -37,7 +37,8 @@
//---------------------------------------------------------------------------------------------------------------------
MoveDetail::MoveDetail(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
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"));
@ -67,6 +68,7 @@ void MoveDetail::undo()
{
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY)));
qDebug()<<"undo move detail"<<oldX<<oldY;
emit NeedLiteParsing();
@ -88,8 +90,13 @@ void MoveDetail::redo()
{
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX)));
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();
VAbstractTool::NewSceneRect(scene, list[0]);

View File

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