New undo command MoveDetail.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-13 13:29:23 +03:00
parent 2e7e0e92f7
commit 7fed35ad1c
6 changed files with 222 additions and 18 deletions

View file

@ -39,6 +39,7 @@
#include <QMenu>
#include <QGraphicsView>
#include "../undocommands/savedetailoptions.h"
#include "../undocommands/movedetail.h"
const QString VToolDetail::TagName = QStringLiteral("detail");
const QString VToolDetail::TagNode = QStringLiteral("node");
@ -109,7 +110,6 @@ VToolDetail::VToolDetail(VPattern *doc, VContainer *data, const quint32 &id, con
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
RefreshGeometry();
this->setPos(detail.getMx(), detail.getMy());
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
@ -313,20 +313,13 @@ 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();
//qDebug()<<newPos;
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(newPos.x())));
doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(newPos.y())));
QList<QGraphicsView*> list = this->scene()->views();
VAbstractTool::NewSceneRect(this->scene(), list[0]);
doc->haveLiteChange();
}
MoveDetail *moveDet = new MoveDetail(doc, newPos.x(), newPos.y(), id, this->scene());
connect(moveDet, &MoveDetail::NeedLiteParsing, doc, &VPattern::LiteParseTree);
qApp->getUndoStack()->push(moveDet);
}
if (change == QGraphicsItem::ItemSelectedChange)
@ -474,6 +467,10 @@ void VToolDetail::RefreshGeometry()
{
QPainterPath path = VEquidistant().ContourPath(id, this->getData());
this->setPath(path);
VDetail detail = VAbstractTool::data.GetDetail(id);
this->setPos(detail.getMx(), detail.getMy());
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,122 @@
/************************************************************************
**
** @file movedetail.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 13 6, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "movedetail.h"
#include <QGraphicsScene>
#include <QDomElement>
#include "../xml/vpattern.h"
#include "../tools/vabstracttool.h"
#include "../widgets/vapplication.h"
#include "undocommands.h"
//---------------------------------------------------------------------------------------------------------------------
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)
{
setText(QObject::tr("Move detail"));
SCASSERT(scene != nullptr);
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"));
oldY = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMy, "0.0"));
}
else
{
qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO;
}
}
//---------------------------------------------------------------------------------------------------------------------
MoveDetail::~MoveDetail()
{}
//---------------------------------------------------------------------------------------------------------------------
void MoveDetail::undo()
{
QDomElement domElement = doc->elementById(QString().setNum(detId));
if (domElement.isElement())
{
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(oldX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(oldY)));
emit NeedLiteParsing();
QList<QGraphicsView*> list = scene->views();
VAbstractTool::NewSceneRect(scene, list[0]);
}
else
{
qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO;
}
}
//---------------------------------------------------------------------------------------------------------------------
void MoveDetail::redo()
{
QDomElement domElement = doc->elementById(QString().setNum(detId));
if (domElement.isElement())
{
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(newX)));
doc->SetAttribute(domElement, VAbstractTool::AttrMy, QString().setNum(qApp->fromPixel(newY)));
emit NeedLiteParsing();
QList<QGraphicsView*> list = scene->views();
VAbstractTool::NewSceneRect(scene, list[0]);
}
else
{
qDebug()<<"Can't find detail with id ="<< detId << Q_FUNC_INFO;
}
}
//---------------------------------------------------------------------------------------------------------------------
bool MoveDetail::mergeWith(const QUndoCommand *command)
{
const MoveDetail *moveCommand = static_cast<const MoveDetail *>(command);
SCASSERT(moveCommand != nullptr);
const quint32 id = moveCommand->getDetId();
if (id != detId)
{
return false;
}
newX = moveCommand->getNewX();
newY = moveCommand->getNewY();
return true;
}
//---------------------------------------------------------------------------------------------------------------------
int MoveDetail::id() const
{
return static_cast<int>(UndoCommand::MoveDetail);
}

View file

@ -0,0 +1,82 @@
/************************************************************************
**
** @file movedetail.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 13 6, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef MOVEDETAIL_H
#define MOVEDETAIL_H
#include <QUndoCommand>
class VPattern;
class QGraphicsScene;
class MoveDetail : public QObject, public QUndoCommand
{
Q_OBJECT
public:
MoveDetail(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
QUndoCommand *parent = 0);
virtual ~MoveDetail();
virtual void undo();
virtual void redo();
virtual bool mergeWith(const QUndoCommand *command);
virtual int id() const;
quint32 getDetId() const;
double getNewX() const;
double getNewY() const;
signals:
void NeedLiteParsing();
private:
Q_DISABLE_COPY(MoveDetail)
VPattern *doc;
double oldX;
double oldY;
double newX;
double newY;
quint32 detId;
QGraphicsScene *scene;
};
//---------------------------------------------------------------------------------------------------------------------
inline quint32 MoveDetail::getDetId() const
{
return detId;
}
//---------------------------------------------------------------------------------------------------------------------
inline double MoveDetail::getNewX() const
{
return newX;
}
//---------------------------------------------------------------------------------------------------------------------
inline double MoveDetail::getNewY() const
{
return newY;
}
#endif // MOVEDETAIL_H

View file

@ -37,7 +37,7 @@
//---------------------------------------------------------------------------------------------------------------------
MoveSPoint::MoveSPoint(VPattern *doc, const double &x, const double &y, const quint32 &id, QGraphicsScene *scene,
QUndoCommand *parent)
: QObject(), QUndoCommand(parent), doc(doc), oldX(10.0), oldY(10.0), newX(x), newY(y), sPointId(id), scene(scene)
: QObject(), QUndoCommand(parent), doc(doc), oldX(0.0), oldY(0.0), newX(x), newY(y), sPointId(id), scene(scene)
{
setText(tr("Move single point"));
@ -45,8 +45,8 @@ MoveSPoint::MoveSPoint(VPattern *doc, const double &x, const double &y, const qu
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrX, "10.0"));
oldY = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0"));
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrX, "0.0"));
oldY = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrY, "0.0"));
}
else
{

View file

@ -35,7 +35,8 @@ enum class UndoCommand: char { AddPatternPiece,
MoveSplinePath,
MoveSPoint,
SaveToolOptions,
SaveDetailOptions
SaveDetailOptions,
MoveDetail
};
#endif // UNDOCOMMANDS_H

View file

@ -6,7 +6,8 @@ HEADERS += \
undocommands/movesplinepath.h \
undocommands/savetooloptions.h \
undocommands/undocommands.h \
undocommands/savedetailoptions.h
undocommands/savedetailoptions.h \
undocommands/movedetail.h
SOURCES += \
@ -16,5 +17,6 @@ SOURCES += \
undocommands/movespline.cpp \
undocommands/movesplinepath.cpp \
undocommands/savetooloptions.cpp \
undocommands/savedetailoptions.cpp
undocommands/savedetailoptions.cpp \
undocommands/movedetail.cpp