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:
parent
2235a5d3d8
commit
fedbe60952
|
@ -1487,13 +1487,16 @@ void VToolSeamAllowance::ToggleInLayout(bool checked)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSeamAllowance::ToggleForbidFlipping(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)
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -40,48 +40,35 @@
|
||||||
#include "../vpatterndb/vcontainer.h"
|
#include "../vpatterndb/vcontainer.h"
|
||||||
#include "../vpatterndb/vpiece.h"
|
#include "../vpatterndb/vpiece.h"
|
||||||
#include "vundocommand.h"
|
#include "vundocommand.h"
|
||||||
|
#include "../vtools/tools/vtoolseamallowance.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
TogglePieceState::TogglePieceState(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
||||||
QUndoCommand *parent)
|
QUndoCommand *parent)
|
||||||
: VUndoCommand(QDomElement(), doc, parent),
|
: VUndoCommand(QDomElement(), doc, parent),
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_data(data),
|
m_data(data),
|
||||||
m_oldState(not state),
|
m_oldState(not state),
|
||||||
m_newState(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"));
|
setText(tr("detail in layout list"));
|
||||||
m_oldState = m_data->DataPieces()->value(m_id).IsInLayout();
|
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)
|
void TogglePieceInLayout::Do(bool state)
|
||||||
{
|
{
|
||||||
|
@ -109,52 +96,86 @@ void TogglePieceInLayout::Do(bool state)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
TogglePieceForbidFlipping::TogglePieceForbidFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
TogglePieceForceForbidFlipping::TogglePieceForceForbidFlipping(quint32 id, bool state, ForceForbidFlippingType type,
|
||||||
QUndoCommand *parent)
|
VContainer *data, VAbstractPattern *doc,
|
||||||
: TogglePieceState(id, state, data, doc, parent)
|
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"));
|
setText(tr("piece flipping"));
|
||||||
m_oldState = m_data->DataPieces()->value(m_id).IsForbidFlipping();
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
VPiece det = m_data->DataPieces()->value(m_id);
|
||||||
void TogglePieceForbidFlipping::Do(bool state)
|
|
||||||
{
|
m_oldForceState = det.IsForceFlipping();
|
||||||
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
m_oldForbidState = det.IsForbidFlipping();
|
||||||
if (detail.isElement())
|
|
||||||
|
if (m_type == ForceForbidFlippingType::ForceFlipping)
|
||||||
{
|
{
|
||||||
doc->SetAttribute(detail, AttrForbidFlipping, state);
|
m_newForceState = state;
|
||||||
|
|
||||||
VPiece det = m_data->DataPieces()->value(m_id);
|
|
||||||
det.SetForbidFlipping(state);
|
det.SetForbidFlipping(state);
|
||||||
m_data->UpdatePiece(m_id, det);
|
m_newForbidState = det.IsForbidFlipping();
|
||||||
}
|
}
|
||||||
else
|
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,
|
void TogglePieceForceForbidFlipping::undo()
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
||||||
if (detail.isElement())
|
if (detail.isElement())
|
||||||
{
|
{
|
||||||
doc->SetAttribute(detail, AttrForceFlipping, state);
|
|
||||||
|
|
||||||
VPiece det = m_data->DataPieces()->value(m_id);
|
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);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,87 +37,47 @@
|
||||||
|
|
||||||
#include "vundocommand.h"
|
#include "vundocommand.h"
|
||||||
|
|
||||||
class TogglePieceState : public VUndoCommand
|
class TogglePieceInLayout : 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
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
||||||
QUndoCommand *parent = nullptr);
|
QUndoCommand *parent = nullptr);
|
||||||
virtual ~TogglePieceInLayout() = default;
|
virtual ~TogglePieceInLayout() = default;
|
||||||
|
virtual void undo() override;
|
||||||
protected:
|
virtual void redo() override;
|
||||||
virtual void Do(bool state) override;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void UpdateList();
|
void UpdateList();
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(TogglePieceInLayout)
|
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
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
TogglePieceForbidFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
TogglePieceForceForbidFlipping(quint32 id, bool state, ForceForbidFlippingType type, VContainer *data,
|
||||||
QUndoCommand *parent = nullptr);
|
VAbstractPattern *doc, QUndoCommand *parent = nullptr);
|
||||||
virtual ~TogglePieceForbidFlipping() = default;
|
virtual ~TogglePieceForceForbidFlipping() = default;
|
||||||
|
virtual void undo() override;
|
||||||
protected:
|
virtual void redo() override;
|
||||||
virtual void Do(bool state) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(TogglePieceForbidFlipping)
|
Q_DISABLE_COPY(TogglePieceForceForbidFlipping)
|
||||||
};
|
quint32 m_id;
|
||||||
|
VContainer *m_data;
|
||||||
class TogglePieceForceFlipping : public TogglePieceState
|
ForceForbidFlippingType m_type;
|
||||||
{
|
bool m_oldForceState;
|
||||||
Q_OBJECT
|
bool m_newForceState;
|
||||||
public:
|
bool m_oldForbidState;
|
||||||
TogglePieceForceFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
bool m_newForbidState;
|
||||||
QUndoCommand *parent = nullptr);
|
|
||||||
virtual ~TogglePieceForceFlipping() = default;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void Do(bool state) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Q_DISABLE_COPY(TogglePieceForceFlipping)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOGGLEDETAILINLAYOUT_H
|
#endif // TOGGLEDETAILINLAYOUT_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user