Returned undocommand "Move piece".
--HG-- branch : feature
This commit is contained in:
parent
b88663dcb4
commit
8601b2ae2a
|
@ -135,7 +135,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI);
|
||||
connect(doc, &VPattern::CheckLayout, [this]()
|
||||
{
|
||||
if (pattern->DataDetails()->count() == 0)
|
||||
if (pattern->DataPieces()->count() == 0)
|
||||
{
|
||||
if(not ui->actionDraw->isChecked())
|
||||
{
|
||||
|
|
|
@ -1698,8 +1698,6 @@ void VPatternConverter::TagDetailToV0_4_0()
|
|||
dom.removeAttribute(strSupplement);
|
||||
dom.removeAttribute(strClosed);
|
||||
dom.removeAttribute(strWidth);
|
||||
dom.removeAttribute(strMx);
|
||||
dom.removeAttribute(strMy);
|
||||
dom.removeAttribute(strForbidFlipping);
|
||||
dom.removeAttribute(strInLayout);
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
#include "../ifc/ifcdef.h"
|
||||
#include "../undocommands/adddet.h"
|
||||
#include "../undocommands/deletedetail.h"
|
||||
#include "../undocommands/movedetail.h"
|
||||
#include "../undocommands/movepiece.h"
|
||||
#include "../undocommands/savedetailoptions.h"
|
||||
#include "../undocommands/toggledetailinlayout.h"
|
||||
#include "../vgeometry/varc.h"
|
||||
|
@ -620,8 +620,8 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
|
|||
// value - this is new position.
|
||||
const QPointF newPos = value.toPointF();
|
||||
|
||||
MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id, scene());
|
||||
connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
||||
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();
|
||||
|
|
|
@ -42,11 +42,13 @@
|
|||
#include "../ifc/xml/vpatternconverter.h"
|
||||
#include "../undocommands/addpiece.h"
|
||||
#include "../undocommands/deletepiece.h"
|
||||
//#include "../undocommands/movepiece.h"
|
||||
#include "../undocommands/movepiece.h"
|
||||
//#include "../undocommands/savepieceoptions.h"
|
||||
//#include "../undocommands/togglepieceinlayout.h"
|
||||
#include "../vwidgets/vmaingraphicsview.h"
|
||||
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
@ -260,7 +262,9 @@ void VToolSeamAllowance::GroupVisibility(quint32 object, bool visible)
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::FullUpdateFromFile()
|
||||
{}
|
||||
{
|
||||
RefreshGeometry();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VToolSeamAllowance::FullUpdateFromGuiOk(int result)
|
||||
|
@ -329,6 +333,68 @@ void VToolSeamAllowance::RefreshDataInFile()
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "movedetail.h"
|
||||
#include "movepiece.h"
|
||||
|
||||
#include <QDomElement>
|
||||
|
||||
|
@ -42,9 +42,14 @@ class QDomElement;
|
|||
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)
|
||||
: 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"));
|
||||
nodeId = id;
|
||||
|
@ -53,8 +58,8 @@ MoveDetail::MoveDetail(VAbstractPattern *doc, const double &x, const double &y,
|
|||
QDomElement domElement = doc->elementById(id);
|
||||
if (domElement.isElement())
|
||||
{
|
||||
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0"));
|
||||
oldY = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0"));
|
||||
m_oldX = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMx, "0.0"));
|
||||
m_oldY = qApp->toPixel(doc->GetParametrDouble(domElement, AttrMy, "0.0"));
|
||||
}
|
||||
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.");
|
||||
|
||||
QDomElement domElement = doc->elementById(nodeId);
|
||||
if (domElement.isElement())
|
||||
{
|
||||
SaveCoordinates(domElement, oldX, oldY);
|
||||
SaveCoordinates(domElement, m_oldX, m_oldY);
|
||||
|
||||
emit NeedLiteParsing(Document::LiteParse);
|
||||
}
|
||||
|
@ -87,14 +92,14 @@ void MoveDetail::undo()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void MoveDetail::redo()
|
||||
void MovePiece::redo()
|
||||
{
|
||||
qCDebug(vUndo, "Redo.");
|
||||
|
||||
QDomElement domElement = doc->elementById(nodeId);
|
||||
if (domElement.isElement())
|
||||
{
|
||||
SaveCoordinates(domElement, newX, newY);
|
||||
SaveCoordinates(domElement, m_newX, m_newY);
|
||||
|
||||
if (redoFlag)
|
||||
{
|
||||
|
@ -102,7 +107,7 @@ void MoveDetail::redo()
|
|||
}
|
||||
else
|
||||
{
|
||||
VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
|
||||
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
|
||||
}
|
||||
redoFlag = true;
|
||||
}
|
||||
|
@ -115,9 +120,9 @@ void MoveDetail::redo()
|
|||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// 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);
|
||||
const quint32 id = moveCommand->getDetId();
|
||||
|
||||
|
@ -126,19 +131,19 @@ bool MoveDetail::mergeWith(const QUndoCommand *command)
|
|||
return false;
|
||||
}
|
||||
|
||||
newX = moveCommand->getNewX();
|
||||
newY = moveCommand->getNewY();
|
||||
m_newX = moveCommand->getNewX();
|
||||
m_newY = moveCommand->getNewY();
|
||||
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, AttrMy, QString().setNum(qApp->fromPixel(y)));
|
|
@ -42,13 +42,14 @@ class QGraphicsScene;
|
|||
class QUndoCommand;
|
||||
class VAbstractPattern;
|
||||
|
||||
class MoveDetail : public VUndoCommand
|
||||
class MovePiece : public VUndoCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MoveDetail(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
|
||||
QUndoCommand *parent = 0);
|
||||
virtual ~MoveDetail() Q_DECL_OVERRIDE;
|
||||
MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
|
||||
QUndoCommand *parent = nullptr);
|
||||
virtual ~MovePiece();
|
||||
|
||||
virtual void undo() Q_DECL_OVERRIDE;
|
||||
virtual void redo() Q_DECL_OVERRIDE;
|
||||
// cppcheck-suppress unusedFunction
|
||||
|
@ -58,31 +59,33 @@ public:
|
|||
double getNewX() const;
|
||||
double getNewY() const;
|
||||
private:
|
||||
Q_DISABLE_COPY(MoveDetail)
|
||||
double oldX;
|
||||
double oldY;
|
||||
double newX;
|
||||
double newY;
|
||||
QGraphicsScene *scene;
|
||||
Q_DISABLE_COPY(MovePiece)
|
||||
|
||||
double m_oldX;
|
||||
double m_oldY;
|
||||
double m_newX;
|
||||
double m_newY;
|
||||
QGraphicsScene *m_scene;
|
||||
|
||||
void SaveCoordinates(QDomElement &domElement, double x, double y);
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline quint32 MoveDetail::getDetId() const
|
||||
inline quint32 MovePiece::getDetId() const
|
||||
{
|
||||
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
|
|
@ -9,7 +9,6 @@ HEADERS += \
|
|||
$$PWD/movesplinepath.h \
|
||||
$$PWD/savetooloptions.h \
|
||||
$$PWD/savedetailoptions.h \
|
||||
$$PWD/movedetail.h \
|
||||
$$PWD/deltool.h \
|
||||
$$PWD/deletepatternpiece.h \
|
||||
$$PWD/adddetnode.h \
|
||||
|
@ -25,7 +24,8 @@ HEADERS += \
|
|||
$$PWD/toggledetailinlayout.h \
|
||||
$$PWD/label/operationmovelabel.h \
|
||||
$$PWD/addpiece.h \
|
||||
$$PWD/deletepiece.h
|
||||
$$PWD/deletepiece.h \
|
||||
$$PWD/movepiece.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/addtocalc.cpp \
|
||||
|
@ -35,7 +35,6 @@ SOURCES += \
|
|||
$$PWD/movesplinepath.cpp \
|
||||
$$PWD/savetooloptions.cpp \
|
||||
$$PWD/savedetailoptions.cpp \
|
||||
$$PWD/movedetail.cpp \
|
||||
$$PWD/deltool.cpp \
|
||||
$$PWD/deletepatternpiece.cpp \
|
||||
$$PWD/adddetnode.cpp \
|
||||
|
@ -51,4 +50,5 @@ SOURCES += \
|
|||
$$PWD/toggledetailinlayout.cpp \
|
||||
$$PWD/label/operationmovelabel.cpp \
|
||||
$$PWD/addpiece.cpp \
|
||||
$$PWD/deletepiece.cpp
|
||||
$$PWD/deletepiece.cpp \
|
||||
$$PWD/movepiece.cpp
|
||||
|
|
|
@ -54,7 +54,7 @@ enum class UndoCommand: char { AddPatternPiece,
|
|||
MoveSPoint,
|
||||
SaveToolOptions,
|
||||
SaveDetailOptions,
|
||||
MoveDetail,
|
||||
MovePiece,
|
||||
DeleteTool,
|
||||
DeletePatternPiece,
|
||||
RenamePP,
|
||||
|
|
Loading…
Reference in New Issue
Block a user