Returned undocommand "Move piece".

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-09 13:06:05 +02:00
parent b88663dcb4
commit 8601b2ae2a
8 changed files with 120 additions and 48 deletions

View File

@ -135,7 +135,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI); connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI);
connect(doc, &VPattern::CheckLayout, [this]() connect(doc, &VPattern::CheckLayout, [this]()
{ {
if (pattern->DataDetails()->count() == 0) if (pattern->DataPieces()->count() == 0)
{ {
if(not ui->actionDraw->isChecked()) if(not ui->actionDraw->isChecked())
{ {

View File

@ -1698,8 +1698,6 @@ void VPatternConverter::TagDetailToV0_4_0()
dom.removeAttribute(strSupplement); dom.removeAttribute(strSupplement);
dom.removeAttribute(strClosed); dom.removeAttribute(strClosed);
dom.removeAttribute(strWidth); dom.removeAttribute(strWidth);
dom.removeAttribute(strMx);
dom.removeAttribute(strMy);
dom.removeAttribute(strForbidFlipping); dom.removeAttribute(strForbidFlipping);
dom.removeAttribute(strInLayout); dom.removeAttribute(strInLayout);

View File

@ -74,7 +74,7 @@
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../undocommands/adddet.h" #include "../undocommands/adddet.h"
#include "../undocommands/deletedetail.h" #include "../undocommands/deletedetail.h"
#include "../undocommands/movedetail.h" #include "../undocommands/movepiece.h"
#include "../undocommands/savedetailoptions.h" #include "../undocommands/savedetailoptions.h"
#include "../undocommands/toggledetailinlayout.h" #include "../undocommands/toggledetailinlayout.h"
#include "../vgeometry/varc.h" #include "../vgeometry/varc.h"
@ -620,8 +620,8 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
// value - this is new position. // value - this is new position.
const QPointF newPos = value.toPointF(); const QPointF newPos = value.toPointF();
MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id, scene()); MovePiece *moveDet = new MovePiece(doc, newPos.x(), newPos.y(), id, scene());
connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); connect(moveDet, &MovePiece::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveDet); qApp->getUndoStack()->push(moveDet);
const QList<QGraphicsView *> viewList = scene()->views(); const QList<QGraphicsView *> viewList = scene()->views();

View File

@ -42,11 +42,13 @@
#include "../ifc/xml/vpatternconverter.h" #include "../ifc/xml/vpatternconverter.h"
#include "../undocommands/addpiece.h" #include "../undocommands/addpiece.h"
#include "../undocommands/deletepiece.h" #include "../undocommands/deletepiece.h"
//#include "../undocommands/movepiece.h" #include "../undocommands/movepiece.h"
//#include "../undocommands/savepieceoptions.h" //#include "../undocommands/savepieceoptions.h"
//#include "../undocommands/togglepieceinlayout.h" //#include "../undocommands/togglepieceinlayout.h"
#include "../vwidgets/vmaingraphicsview.h"
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
@ -260,7 +262,9 @@ void VToolSeamAllowance::GroupVisibility(quint32 object, bool visible)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::FullUpdateFromFile() void VToolSeamAllowance::FullUpdateFromFile()
{} {
RefreshGeometry();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::FullUpdateFromGuiOk(int result) void VToolSeamAllowance::FullUpdateFromGuiOk(int result)
@ -329,6 +333,68 @@ void VToolSeamAllowance::RefreshDataInFile()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant VToolSeamAllowance::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if (change == ItemPositionChange && scene())
{
// Each time we move something we call recalculation scene rect. In some cases this can cause moving
// objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move.
static bool changeFinished = true;
if (changeFinished)
{
changeFinished = false;
// value - this is new position.
const QPointF newPos = value.toPointF();
MovePiece *moveDet = new MovePiece(doc, newPos.x(), newPos.y(), id, scene());
connect(moveDet, &MovePiece::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveDet);
const QList<QGraphicsView *> viewList = scene()->views();
if (not viewList.isEmpty())
{
if (QGraphicsView *view = viewList.at(0))
{
const int xmargin = 50;
const int ymargin = 50;
const QRectF viewRect = VMainGraphicsView::SceneVisibleArea(view);
const QRectF itemRect = mapToScene(boundingRect()|childrenBoundingRect()).boundingRect();
// If item's rect is bigger than view's rect ensureVisible works very unstable.
if (itemRect.height() + 2*ymargin < viewRect.height() &&
itemRect.width() + 2*xmargin < viewRect.width())
{
view->ensureVisible(itemRect, xmargin, ymargin);
}
else
{
// Ensure visible only small rect around a cursor
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(scene());
SCASSERT(currentScene);
const QPointF cursorPosition = currentScene->getScenePos();
view->ensureVisible(QRectF(cursorPosition.x()-5, cursorPosition.y()-5, 10, 10));
}
}
}
// Don't forget to update geometry, because first change never call full parse
RefreshGeometry();
changeFinished = true;
}
}
if (change == QGraphicsItem::ItemSelectedChange)
{
if (value == true)
{
// do stuff if selected
this->setFocus();
}
else
{
// do stuff if not selected
}
}
return VNoBrushScalePathItem::itemChange(change, value); return VNoBrushScalePathItem::itemChange(change, value);
} }

View File

@ -26,7 +26,7 @@
** **
*************************************************************************/ *************************************************************************/
#include "movedetail.h" #include "movepiece.h"
#include <QDomElement> #include <QDomElement>
@ -42,9 +42,14 @@ class QDomElement;
class QUndoCommand; class QUndoCommand;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MoveDetail::MoveDetail(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, MovePiece::MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id,
QGraphicsScene *scene, QUndoCommand *parent) QGraphicsScene *scene, QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent), oldX(0.0), oldY(0.0), newX(x), newY(y), scene(scene) : VUndoCommand(QDomElement(), doc, parent),
m_oldX(0.0),
m_oldY(0.0),
m_newX(x),
m_newY(y),
m_scene(scene)
{ {
setText(QObject::tr("move detail")); setText(QObject::tr("move detail"));
nodeId = id; nodeId = id;
@ -53,8 +58,8 @@ MoveDetail::MoveDetail(VAbstractPattern *doc, const double &x, const double &y,
QDomElement domElement = doc->elementById(id); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0")); m_oldX = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0"));
oldY = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0")); m_oldY = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0"));
} }
else else
{ {
@ -64,18 +69,18 @@ MoveDetail::MoveDetail(VAbstractPattern *doc, const double &x, const double &y,
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MoveDetail::~MoveDetail() MovePiece::~MovePiece()
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MoveDetail::undo() void MovePiece::undo()
{ {
qCDebug(vUndo, "Undo."); qCDebug(vUndo, "Undo.");
QDomElement domElement = doc->elementById(nodeId); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveCoordinates(domElement, oldX, oldY); SaveCoordinates(domElement, m_oldX, m_oldY);
emit NeedLiteParsing(Document::LiteParse); emit NeedLiteParsing(Document::LiteParse);
} }
@ -87,14 +92,14 @@ void MoveDetail::undo()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MoveDetail::redo() void MovePiece::redo()
{ {
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
QDomElement domElement = doc->elementById(nodeId); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveCoordinates(domElement, newX, newY); SaveCoordinates(domElement, m_newX, m_newY);
if (redoFlag) if (redoFlag)
{ {
@ -102,7 +107,7 @@ void MoveDetail::redo()
} }
else else
{ {
VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }
redoFlag = true; redoFlag = true;
} }
@ -115,9 +120,9 @@ void MoveDetail::redo()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
bool MoveDetail::mergeWith(const QUndoCommand *command) bool MovePiece::mergeWith(const QUndoCommand *command)
{ {
const MoveDetail *moveCommand = static_cast<const MoveDetail *>(command); const MovePiece *moveCommand = static_cast<const MovePiece *>(command);
SCASSERT(moveCommand != nullptr); SCASSERT(moveCommand != nullptr);
const quint32 id = moveCommand->getDetId(); const quint32 id = moveCommand->getDetId();
@ -126,19 +131,19 @@ bool MoveDetail::mergeWith(const QUndoCommand *command)
return false; return false;
} }
newX = moveCommand->getNewX(); m_newX = moveCommand->getNewX();
newY = moveCommand->getNewY(); m_newY = moveCommand->getNewY();
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int MoveDetail::id() const int MovePiece::id() const
{ {
return static_cast<int>(UndoCommand::MoveDetail); return static_cast<int>(UndoCommand::MovePiece);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MoveDetail::SaveCoordinates(QDomElement &domElement, double x, double y) void MovePiece::SaveCoordinates(QDomElement &domElement, double x, double y)
{ {
doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(x))); doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(x)));
doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(y))); doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(y)));

View File

@ -42,13 +42,14 @@ class QGraphicsScene;
class QUndoCommand; class QUndoCommand;
class VAbstractPattern; class VAbstractPattern;
class MoveDetail : public VUndoCommand class MovePiece : public VUndoCommand
{ {
Q_OBJECT Q_OBJECT
public: public:
MoveDetail(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene, MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
QUndoCommand *parent = 0); QUndoCommand *parent = nullptr);
virtual ~MoveDetail() Q_DECL_OVERRIDE; virtual ~MovePiece();
virtual void undo() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE;
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
@ -58,31 +59,33 @@ public:
double getNewX() const; double getNewX() const;
double getNewY() const; double getNewY() const;
private: private:
Q_DISABLE_COPY(MoveDetail) Q_DISABLE_COPY(MovePiece)
double oldX;
double oldY; double m_oldX;
double newX; double m_oldY;
double newY; double m_newX;
QGraphicsScene *scene; double m_newY;
void SaveCoordinates(QDomElement &domElement, double x, double y); QGraphicsScene *m_scene;
void SaveCoordinates(QDomElement &domElement, double x, double y);
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline quint32 MoveDetail::getDetId() const inline quint32 MovePiece::getDetId() const
{ {
return nodeId; return nodeId;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline double MoveDetail::getNewX() const inline double MovePiece::getNewX() const
{ {
return newX; return m_newX;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline double MoveDetail::getNewY() const inline double MovePiece::getNewY() const
{ {
return newY; return m_newY;
} }
#endif // MOVEDETAIL_H #endif // MOVEDETAIL_H

View File

@ -9,7 +9,6 @@ HEADERS += \
$$PWD/movesplinepath.h \ $$PWD/movesplinepath.h \
$$PWD/savetooloptions.h \ $$PWD/savetooloptions.h \
$$PWD/savedetailoptions.h \ $$PWD/savedetailoptions.h \
$$PWD/movedetail.h \
$$PWD/deltool.h \ $$PWD/deltool.h \
$$PWD/deletepatternpiece.h \ $$PWD/deletepatternpiece.h \
$$PWD/adddetnode.h \ $$PWD/adddetnode.h \
@ -25,7 +24,8 @@ HEADERS += \
$$PWD/toggledetailinlayout.h \ $$PWD/toggledetailinlayout.h \
$$PWD/label/operationmovelabel.h \ $$PWD/label/operationmovelabel.h \
$$PWD/addpiece.h \ $$PWD/addpiece.h \
$$PWD/deletepiece.h $$PWD/deletepiece.h \
$$PWD/movepiece.h
SOURCES += \ SOURCES += \
$$PWD/addtocalc.cpp \ $$PWD/addtocalc.cpp \
@ -35,7 +35,6 @@ SOURCES += \
$$PWD/movesplinepath.cpp \ $$PWD/movesplinepath.cpp \
$$PWD/savetooloptions.cpp \ $$PWD/savetooloptions.cpp \
$$PWD/savedetailoptions.cpp \ $$PWD/savedetailoptions.cpp \
$$PWD/movedetail.cpp \
$$PWD/deltool.cpp \ $$PWD/deltool.cpp \
$$PWD/deletepatternpiece.cpp \ $$PWD/deletepatternpiece.cpp \
$$PWD/adddetnode.cpp \ $$PWD/adddetnode.cpp \
@ -51,4 +50,5 @@ SOURCES += \
$$PWD/toggledetailinlayout.cpp \ $$PWD/toggledetailinlayout.cpp \
$$PWD/label/operationmovelabel.cpp \ $$PWD/label/operationmovelabel.cpp \
$$PWD/addpiece.cpp \ $$PWD/addpiece.cpp \
$$PWD/deletepiece.cpp $$PWD/deletepiece.cpp \
$$PWD/movepiece.cpp

View File

@ -54,7 +54,7 @@ enum class UndoCommand: char { AddPatternPiece,
MoveSPoint, MoveSPoint,
SaveToolOptions, SaveToolOptions,
SaveDetailOptions, SaveDetailOptions,
MoveDetail, MovePiece,
DeleteTool, DeleteTool,
DeletePatternPiece, DeletePatternPiece,
RenamePP, RenamePP,