Resolved issue #860. Valentina allows forbidflipping and forceflipping at the

same time.

Undocommands for context menu were poorly designed.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-07-09 14:17:53 +03:00
parent 2235a5d3d8
commit fedbe60952
3 changed files with 110 additions and 126 deletions

View File

@ -1487,13 +1487,16 @@ void VToolSeamAllowance::ToggleInLayout(bool checked)
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleForbidFlipping(bool checked)
{
qApp->getUndoStack()->push(new TogglePieceForbidFlipping(m_id, checked, &(VAbstractTool::data), doc));
qApp->getUndoStack()->push(new TogglePieceForceForbidFlipping(m_id, checked,
ForceForbidFlippingType::ForbidFlipping,
&(VAbstractTool::data), doc));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleForceFlipping(bool checked)
{
qApp->getUndoStack()->push(new TogglePieceForceFlipping(m_id, checked, &(VAbstractTool::data), doc));
qApp->getUndoStack()->push(new TogglePieceForceForbidFlipping(m_id, checked, ForceForbidFlippingType::ForceFlipping,
&(VAbstractTool::data), doc));
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -40,48 +40,35 @@
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vpiece.h"
#include "vundocommand.h"
#include "../vtools/tools/vtoolseamallowance.h"
//---------------------------------------------------------------------------------------------------------------------
TogglePieceState::TogglePieceState(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_id(id),
m_data(data),
m_oldState(not state),
m_newState(state)
{}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceState::undo()
{
qCDebug(vUndo, "TogglePieceState::undo().");
if (m_newState != m_oldState)
{
Do(m_oldState);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceState::redo()
{
qCDebug(vUndo, "TogglePieceState::redo().");
if (m_newState != m_oldState)
{
Do(m_newState);
}
}
//---------------------------------------------------------------------------------------------------------------------
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: TogglePieceState(id, state, data, doc, parent)
{
setText(tr("detail in layout list"));
m_oldState = m_data->DataPieces()->value(m_id).IsInLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceInLayout::undo()
{
qCDebug(vUndo, "TogglePieceState::undo().");
Do(m_oldState);
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceInLayout::redo()
{
qCDebug(vUndo, "TogglePieceState::redo().");
Do(m_newState);
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceInLayout::Do(bool state)
{
@ -109,52 +96,86 @@ void TogglePieceInLayout::Do(bool state)
}
//---------------------------------------------------------------------------------------------------------------------
TogglePieceForbidFlipping::TogglePieceForbidFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: TogglePieceState(id, state, data, doc, parent)
TogglePieceForceForbidFlipping::TogglePieceForceForbidFlipping(quint32 id, bool state, ForceForbidFlippingType type,
VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_id(id),
m_data(data),
m_type(type),
m_oldForceState(false),
m_newForceState(false),
m_oldForbidState(false),
m_newForbidState(false)
{
setText(tr("forbid flipping"));
m_oldState = m_data->DataPieces()->value(m_id).IsForbidFlipping();
}
setText(tr("piece flipping"));
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceForbidFlipping::Do(bool state)
{
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
if (detail.isElement())
VPiece det = m_data->DataPieces()->value(m_id);
m_oldForceState = det.IsForceFlipping();
m_oldForbidState = det.IsForbidFlipping();
if (m_type == ForceForbidFlippingType::ForceFlipping)
{
doc->SetAttribute(detail, AttrForbidFlipping, state);
VPiece det = m_data->DataPieces()->value(m_id);
m_newForceState = state;
det.SetForbidFlipping(state);
m_data->UpdatePiece(m_id, det);
m_newForbidState = det.IsForbidFlipping();
}
else
{
qDebug("Can't get detail by id = %u.", m_id);
m_newForbidState = state;
det.SetForceFlipping(state);
m_newForceState = det.IsForceFlipping();
}
}
//---------------------------------------------------------------------------------------------------------------------
TogglePieceForceFlipping::TogglePieceForceFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: TogglePieceState(id, state, data, doc, parent)
{
setText(tr("force flipping"));
m_oldState = m_data->DataPieces()->value(m_id).IsForceFlipping();
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceForceFlipping::Do(bool state)
void TogglePieceForceForbidFlipping::undo()
{
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
if (detail.isElement())
{
doc->SetAttribute(detail, AttrForceFlipping, state);
VPiece det = m_data->DataPieces()->value(m_id);
det.SetForceFlipping(state);
if (m_type == ForceForbidFlippingType::ForceFlipping)
{
det.SetForceFlipping(m_oldForceState);
det.SetForbidFlipping(m_oldForbidState);
}
else
{
det.SetForbidFlipping(m_oldForbidState);
det.SetForceFlipping(m_oldForceState);
}
m_data->UpdatePiece(m_id, det);
// Probably overkill, but will help to avoid mistakes
VToolSeamAllowance::AddAttributes(doc, detail, m_id, det);
}
else
{
qDebug("Can't get detail by id = %u.", m_id);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceForceForbidFlipping::redo()
{
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
if (detail.isElement())
{
VPiece det = m_data->DataPieces()->value(m_id);
if (m_type == ForceForbidFlippingType::ForceFlipping)
{
det.SetForceFlipping(m_newForceState);
}
else
{
det.SetForbidFlipping(m_newForbidState);
}
m_data->UpdatePiece(m_id, det);
// Probably overkill, but will help to avoid mistakes
VToolSeamAllowance::AddAttributes(doc, detail, m_id, det);
}
else
{

View File

@ -37,87 +37,47 @@
#include "vundocommand.h"
class TogglePieceState : public VUndoCommand
{
Q_OBJECT
public:
TogglePieceState(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceState() = default;
virtual void undo() override;
virtual void redo() override;
quint32 getDetId() const;
bool getNewState() const;
protected:
quint32 m_id;
VContainer *m_data;
bool m_oldState;
bool m_newState;
virtual void Do(bool state)=0;
private:
Q_DISABLE_COPY(TogglePieceState)
};
//---------------------------------------------------------------------------------------------------------------------
inline quint32 TogglePieceState::getDetId() const
{
return m_id;
}
//---------------------------------------------------------------------------------------------------------------------
inline bool TogglePieceState::getNewState() const
{
return m_newState;
}
class TogglePieceInLayout : public TogglePieceState
class TogglePieceInLayout : public VUndoCommand
{
Q_OBJECT
public:
TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceInLayout() = default;
protected:
virtual void Do(bool state) override;
virtual void undo() override;
virtual void redo() override;
signals:
void UpdateList();
private:
Q_DISABLE_COPY(TogglePieceInLayout)
quint32 m_id;
VContainer *m_data;
bool m_oldState;
bool m_newState;
void Do(bool state);
};
class TogglePieceForbidFlipping : public TogglePieceState
enum class ForceForbidFlippingType : qint8 {ForceFlipping, ForbidFlipping};
class TogglePieceForceForbidFlipping : public VUndoCommand
{
Q_OBJECT
public:
TogglePieceForbidFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceForbidFlipping() = default;
protected:
virtual void Do(bool state) override;
TogglePieceForceForbidFlipping(quint32 id, bool state, ForceForbidFlippingType type, VContainer *data,
VAbstractPattern *doc, QUndoCommand *parent = nullptr);
virtual ~TogglePieceForceForbidFlipping() = default;
virtual void undo() override;
virtual void redo() override;
private:
Q_DISABLE_COPY(TogglePieceForbidFlipping)
};
class TogglePieceForceFlipping : public TogglePieceState
{
Q_OBJECT
public:
TogglePieceForceFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceForceFlipping() = default;
protected:
virtual void Do(bool state) override;
private:
Q_DISABLE_COPY(TogglePieceForceFlipping)
Q_DISABLE_COPY(TogglePieceForceForbidFlipping)
quint32 m_id;
VContainer *m_data;
ForceForbidFlippingType m_type;
bool m_oldForceState;
bool m_newForceState;
bool m_oldForbidState;
bool m_newForbidState;
};
#endif // TOGGLEDETAILINLAYOUT_H