diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 6945564a7..c7f6aa65e 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -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()) { diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index e4bbe71d7..1f004335e 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -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); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 912f81f7e..a2b4a9d05 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -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 viewList = scene()->views(); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index c6a283037..a722a31dc 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -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 +#include #include #include #include @@ -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 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(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); } diff --git a/src/libs/vtools/undocommands/movedetail.cpp b/src/libs/vtools/undocommands/movepiece.cpp similarity index 77% rename from src/libs/vtools/undocommands/movedetail.cpp rename to src/libs/vtools/undocommands/movepiece.cpp index f06fd568d..46726ec9c 100644 --- a/src/libs/vtools/undocommands/movedetail.cpp +++ b/src/libs/vtools/undocommands/movepiece.cpp @@ -26,7 +26,7 @@ ** *************************************************************************/ -#include "movedetail.h" +#include "movepiece.h" #include @@ -42,9 +42,14 @@ class QDomElement; class QUndoCommand; //--------------------------------------------------------------------------------------------------------------------- -MoveDetail::MoveDetail(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) +MovePiece::MovePiece(VAbstractPattern *doc, const double &x, const double &y, const quint32 &id, + QGraphicsScene *scene, QUndoCommand *parent) + : 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(command); + const MovePiece *moveCommand = static_cast(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(UndoCommand::MoveDetail); + return static_cast(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))); diff --git a/src/libs/vtools/undocommands/movedetail.h b/src/libs/vtools/undocommands/movepiece.h similarity index 78% rename from src/libs/vtools/undocommands/movedetail.h rename to src/libs/vtools/undocommands/movepiece.h index 37c0d1db2..95d0b5535 100644 --- a/src/libs/vtools/undocommands/movedetail.h +++ b/src/libs/vtools/undocommands/movepiece.h @@ -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; - void SaveCoordinates(QDomElement &domElement, double x, double y); + 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 diff --git a/src/libs/vtools/undocommands/undocommands.pri b/src/libs/vtools/undocommands/undocommands.pri index 5bdcf4b90..d031daf32 100644 --- a/src/libs/vtools/undocommands/undocommands.pri +++ b/src/libs/vtools/undocommands/undocommands.pri @@ -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 diff --git a/src/libs/vtools/undocommands/vundocommand.h b/src/libs/vtools/undocommands/vundocommand.h index 9d92a1f0e..b8ae606ea 100644 --- a/src/libs/vtools/undocommands/vundocommand.h +++ b/src/libs/vtools/undocommands/vundocommand.h @@ -54,7 +54,7 @@ enum class UndoCommand: char { AddPatternPiece, MoveSPoint, SaveToolOptions, SaveDetailOptions, - MoveDetail, + MovePiece, DeleteTool, DeletePatternPiece, RenamePP,