Show Forbid flipping and Force flipping options in piece context menu.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-02-03 14:18:32 +02:00
parent 63fd000443
commit 8b7494fb08
12 changed files with 208 additions and 58 deletions

View File

@ -31,7 +31,7 @@
#include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vcontainer.h"
#include "../vmisc/vabstractapplication.h"
#include "../vtools/undocommands/togglepieceinlayout.h"
#include "../vtools/undocommands/togglepiecestate.h"
#include <QMenu>
#include <QUndoStack>

View File

@ -876,9 +876,9 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
initData.detail.SetSeamAllowanceBuiltIn(GetParametrBool(domElement,
VToolSeamAllowance::AttrSeamAllowanceBuiltIn,
falseStr));
initData.detail.SetForbidFlipping(GetParametrBool(domElement, VToolSeamAllowance::AttrForbidFlipping,
initData.detail.SetForbidFlipping(GetParametrBool(domElement, AttrForbidFlipping,
QString().setNum(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping())));
initData.detail.SetForceFlipping(GetParametrBool(domElement, VToolSeamAllowance::AttrForceFlipping,
initData.detail.SetForceFlipping(GetParametrBool(domElement, AttrForceFlipping,
QString().setNum(qApp->ValentinaSettings()->GetForceWorkpieceFlipping())));
initData.detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr));
initData.detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr));

View File

@ -119,6 +119,8 @@ const QString AttrArc = QStringLiteral("arc");
const QString AttrSuffix = QStringLiteral("suffix");
const QString AttrIdObject = QStringLiteral("idObject");
const QString AttrInLayout = QStringLiteral("inLayout");
const QString AttrForbidFlipping = QStringLiteral("forbidFlipping");
const QString AttrForceFlipping = QStringLiteral("forceFlipping");
const QString AttrRotationAngle = QStringLiteral("rotationAngle");
const QString AttrClosed = QStringLiteral("closed");
const QString AttrShowLabel = QStringLiteral("showLabel");

View File

@ -141,6 +141,8 @@ extern const QString AttrArc;
extern const QString AttrSuffix;
extern const QString AttrIdObject;
extern const QString AttrInLayout;
extern const QString AttrForbidFlipping;
extern const QString AttrForceFlipping;
extern const QString AttrClosed;
extern const QString AttrShowLabel;
extern const QString AttrShowLabel1;

View File

@ -288,11 +288,20 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
const VPiece detail = VAbstractTool::data.GetPiece(piece->getId());
QAction *inLayoutOption = menu.addAction(tr("In layout"));
inLayoutOption->setCheckable(true);
const VPiece detail = VAbstractTool::data.GetPiece(piece->getId());
inLayoutOption->setChecked(detail.IsInLayout());
QAction *forbidFlippingOption = menu.addAction(tr("Forbid flipping"));
forbidFlippingOption->setCheckable(true);
forbidFlippingOption->setChecked(detail.IsForbidFlipping());
QAction *forceFlippingOption = menu.addAction(tr("Force flipping"));
forceFlippingOption->setCheckable(true);
forceFlippingOption->setChecked(detail.IsForceFlipping());
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
piece->referens() > 1 ? actionRemove->setEnabled(false) : actionRemove->setEnabled(true);
@ -305,6 +314,14 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
emit ToggleInLayout(selectedAction->isChecked());
}
else if (selectedAction == forbidFlippingOption)
{
emit ToggleForbidFlipping(selectedAction->isChecked());
}
else if (selectedAction == forceFlippingOption)
{
emit ToggleForceFlipping(selectedAction->isChecked());
}
else if (selectedAction == actionRemove)
{
try

View File

@ -62,6 +62,8 @@ public:
signals:
void ShowOptions();
void ToggleInLayout(bool checked);
void ToggleForbidFlipping(bool checked);
void ToggleForceFlipping(bool checked);
void Delete();
void ToggleExcludeState(quint32 id);
public slots:

View File

@ -48,7 +48,7 @@
#include "../undocommands/deletepiece.h"
#include "../undocommands/movepiece.h"
#include "../undocommands/savepieceoptions.h"
#include "../undocommands/togglepieceinlayout.h"
#include "../undocommands/togglepiecestate.h"
#include "../vwidgets/vmaingraphicsview.h"
#include "../vwidgets/vnobrushscalepathitem.h"
#include "../qmuparser/qmutokenparser.h"
@ -70,8 +70,6 @@ const QString VToolSeamAllowance::TagIPaths = QStringLiteral("iPaths");
const QString VToolSeamAllowance::TagPins = QStringLiteral("pins");
const QString VToolSeamAllowance::TagPlaceLabels = QStringLiteral("placeLabels");
const QString VToolSeamAllowance::AttrForbidFlipping = QStringLiteral("forbidFlipping");
const QString VToolSeamAllowance::AttrForceFlipping = QStringLiteral("forceFlipping");
const QString VToolSeamAllowance::AttrSeamAllowance = QStringLiteral("seamAllowance");
const QString VToolSeamAllowance::AttrHideMainPath = QStringLiteral("hideMainPath");
const QString VToolSeamAllowance::AttrSeamAllowanceBuiltIn = QStringLiteral("seamAllowanceBuiltIn");
@ -1177,11 +1175,20 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QMenu menu;
QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options"));
const VPiece detail = VAbstractTool::data.GetPiece(m_id);
QAction *inLayoutOption = menu.addAction(tr("In layout"));
inLayoutOption->setCheckable(true);
const VPiece detail = VAbstractTool::data.GetPiece(m_id);
inLayoutOption->setChecked(detail.IsInLayout());
QAction *forbidFlippingOption = menu.addAction(tr("Forbid flipping"));
forbidFlippingOption->setCheckable(true);
forbidFlippingOption->setChecked(detail.IsForbidFlipping());
QAction *forceFlippingOption = menu.addAction(tr("Force flipping"));
forceFlippingOption->setCheckable(true);
forceFlippingOption->setChecked(detail.IsForceFlipping());
QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
_referens > 1 ? actionRemove->setEnabled(false) : actionRemove->setEnabled(true);
@ -1194,6 +1201,14 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ToggleInLayout(selectedAction->isChecked());
}
else if (selectedAction == forbidFlippingOption)
{
ToggleForbidFlipping(selectedAction->isChecked());
}
else if (selectedAction == forceFlippingOption)
{
ToggleForceFlipping(selectedAction->isChecked());
}
else if (selectedAction == actionRemove)
{
try
@ -1462,6 +1477,18 @@ void VToolSeamAllowance::ToggleInLayout(bool checked)
qApp->getUndoStack()->push(togglePrint);
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleForbidFlipping(bool checked)
{
qApp->getUndoStack()->push(new TogglePieceForbidFlipping(m_id, checked, &(VAbstractTool::data), doc));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ToggleForceFlipping(bool checked)
{
qApp->getUndoStack()->push(new TogglePieceForceFlipping(m_id, checked, &(VAbstractTool::data), doc));
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::DeleteFromMenu()
{
@ -1706,6 +1733,10 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
connect(tool, &VNodePoint::ShowOptions, parent, &VToolSeamAllowance::ShowOptions, Qt::UniqueConnection);
connect(tool, &VNodePoint::ToggleInLayout, parent, &VToolSeamAllowance::ToggleInLayout,
Qt::UniqueConnection);
connect(tool, &VNodePoint::ToggleForbidFlipping, parent, &VToolSeamAllowance::ToggleForbidFlipping,
Qt::UniqueConnection);
connect(tool, &VNodePoint::ToggleForceFlipping, parent, &VToolSeamAllowance::ToggleForceFlipping,
Qt::UniqueConnection);
connect(tool, &VNodePoint::Delete, parent, &VToolSeamAllowance::DeleteFromMenu, Qt::UniqueConnection);
connect(tool, &VNodePoint::ToggleExcludeState, parent, &VToolSeamAllowance::ToggleExcludeState,
Qt::UniqueConnection);

View File

@ -76,8 +76,7 @@ public:
static const QString TagPins;
static const QString TagPlaceLabels;
static const QString AttrForbidFlipping;
static const QString AttrForceFlipping;
static const QString AttrSeamAllowance;
static const QString AttrHideMainPath;
static const QString AttrSeamAllowanceBuiltIn;
@ -163,6 +162,8 @@ protected:
private slots:
void ShowOptions();
void ToggleInLayout(bool checked);
void ToggleForbidFlipping(bool checked);
void ToggleForceFlipping(bool checked);
void DeleteFromMenu();
void ToggleExcludeState(quint32 id);

View File

@ -26,7 +26,7 @@
**
*************************************************************************/
#include "togglepieceinlayout.h"
#include "togglepiecestate.h"
#include <QDomElement>
#include <QHash>
@ -42,26 +42,19 @@
#include "vundocommand.h"
//---------------------------------------------------------------------------------------------------------------------
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
TogglePieceState::TogglePieceState(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: VUndoCommand(QDomElement(), doc, parent),
m_id(id),
m_data(data),
m_oldState(m_data->DataPieces()->value(m_id).IsInLayout()),
m_oldState(not state),
m_newState(state)
{
setText(tr("detail in layout list"));
}
{}
//---------------------------------------------------------------------------------------------------------------------
TogglePieceInLayout::~TogglePieceInLayout()
void TogglePieceState::undo()
{
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceInLayout::undo()
{
qCDebug(vUndo, "ToggleDetailInLayout::undo().");
qCDebug(vUndo, "TogglePieceState::undo().");
if (m_newState != m_oldState)
{
@ -70,9 +63,9 @@ void TogglePieceInLayout::undo()
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceInLayout::redo()
void TogglePieceState::redo()
{
qCDebug(vUndo, "ToggleDetailInLayout::redo().");
qCDebug(vUndo, "TogglePieceState::redo().");
if (m_newState != m_oldState)
{
@ -81,21 +74,12 @@ void TogglePieceInLayout::redo()
}
//---------------------------------------------------------------------------------------------------------------------
int TogglePieceInLayout::id() const
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: TogglePieceState(id, state, data, doc, parent)
{
return static_cast<int>(UndoCommand::TogglePieceInLayout);
}
//---------------------------------------------------------------------------------------------------------------------
quint32 TogglePieceInLayout::getDetId() const
{
return m_id;
}
//---------------------------------------------------------------------------------------------------------------------
bool TogglePieceInLayout::getNewState() const
{
return m_newState;
setText(tr("detail in layout list"));
m_oldState = m_data->DataPieces()->value(m_id).IsInLayout();
}
//---------------------------------------------------------------------------------------------------------------------
@ -123,3 +107,57 @@ void TogglePieceInLayout::Do(bool state)
qDebug("Can't get detail by id = %u.", m_id);
}
}
//---------------------------------------------------------------------------------------------------------------------
TogglePieceForbidFlipping::TogglePieceForbidFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent)
: TogglePieceState(id, state, data, doc, parent)
{
setText(tr("forbid flipping"));
m_oldState = m_data->DataPieces()->value(m_id).IsForbidFlipping();
}
//---------------------------------------------------------------------------------------------------------------------
void TogglePieceForbidFlipping::Do(bool state)
{
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
if (detail.isElement())
{
doc->SetAttribute(detail, AttrForbidFlipping, state);
VPiece det = m_data->DataPieces()->value(m_id);
det.SetForbidFlipping(state);
m_data->UpdatePiece(m_id, det);
}
else
{
qDebug("Can't get detail by id = %u.", m_id);
}
}
//---------------------------------------------------------------------------------------------------------------------
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)
{
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);
m_data->UpdatePiece(m_id, det);
}
else
{
qDebug("Can't get detail by id = %u.", m_id);
}
}

View File

@ -37,29 +37,87 @@
#include "vundocommand.h"
class TogglePieceInLayout : public VUndoCommand
class TogglePieceState : public VUndoCommand
{
Q_OBJECT
public:
TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
TogglePieceState(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceInLayout();
virtual ~TogglePieceState() = default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
virtual int id() const Q_DECL_OVERRIDE;
quint32 getDetId() const;
bool getNewState() const;
signals:
void UpdateList();
private:
Q_DISABLE_COPY(TogglePieceInLayout)
protected:
quint32 m_id;
VContainer *m_data;
bool m_oldState;
bool m_newState;
void Do(bool state);
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
public:
TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceInLayout() = default;
protected:
virtual void Do(bool state) Q_DECL_OVERRIDE;
signals:
void UpdateList();
private:
Q_DISABLE_COPY(TogglePieceInLayout)
};
class TogglePieceForbidFlipping : public TogglePieceState
{
Q_OBJECT
public:
TogglePieceForbidFlipping(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
QUndoCommand *parent = nullptr);
virtual ~TogglePieceForbidFlipping() = default;
protected:
virtual void Do(bool state) Q_DECL_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) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(TogglePieceForceFlipping)
};
#endif // TOGGLEDETAILINLAYOUT_H

View File

@ -22,12 +22,12 @@ HEADERS += \
$$PWD/deletepiece.h \
$$PWD/movepiece.h \
$$PWD/savepieceoptions.h \
$$PWD/togglepieceinlayout.h \
$$PWD/savepiecepathoptions.h \
$$PWD/label/showlabel.h \
$$PWD/label/showdoublelabel.h \
$$PWD/label/operationshowlabel.h \
$$PWD/saveplacelabeloptions.h
$$PWD/saveplacelabeloptions.h \
$$PWD/togglepiecestate.h
SOURCES += \
$$PWD/addtocalc.cpp \
@ -50,9 +50,9 @@ SOURCES += \
$$PWD/deletepiece.cpp \
$$PWD/movepiece.cpp \
$$PWD/savepieceoptions.cpp \
$$PWD/togglepieceinlayout.cpp \
$$PWD/savepiecepathoptions.cpp \
$$PWD/label/showlabel.cpp \
$$PWD/label/showdoublelabel.cpp \
$$PWD/label/operationshowlabel.cpp \
$$PWD/saveplacelabeloptions.cpp
$$PWD/saveplacelabeloptions.cpp \
$$PWD/togglepiecestate.cpp

View File

@ -59,8 +59,7 @@ enum class UndoCommand: char { AddPatternPiece,
RenamePP,
MoveLabel,
MoveDoubleLabel,
RotationMoveLabel,
TogglePieceInLayout
RotationMoveLabel
};
class VPattern;