2016-06-26 13:36:12 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file toggledetailinlayout.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 25 6, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-06-26 13:36:12 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2018-02-03 13:18:32 +01:00
|
|
|
#include "togglepiecestate.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QDomElement>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "../vmisc/logging.h"
|
2016-06-26 13:36:12 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-11-09 14:53:22 +01:00
|
|
|
#include "../vpatterndb/vpiece.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "vundocommand.h"
|
2018-07-09 13:17:53 +02:00
|
|
|
#include "../vtools/tools/vtoolseamallowance.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-06-26 13:36:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-07-09 13:17:53 +02:00
|
|
|
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
|
|
|
QUndoCommand *parent)
|
2016-06-26 13:36:12 +02:00
|
|
|
: VUndoCommand(QDomElement(), doc, parent),
|
|
|
|
m_id(id),
|
|
|
|
m_data(data),
|
2018-02-03 13:18:32 +01:00
|
|
|
m_oldState(not state),
|
2016-06-26 13:36:12 +02:00
|
|
|
m_newState(state)
|
|
|
|
{
|
2018-07-09 13:17:53 +02:00
|
|
|
setText(tr("detail in layout list"));
|
|
|
|
m_oldState = m_data->DataPieces()->value(m_id).IsInLayout();
|
2016-06-26 13:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-07-09 13:17:53 +02:00
|
|
|
void TogglePieceInLayout::undo()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2018-07-09 13:17:53 +02:00
|
|
|
qCDebug(vUndo, "TogglePieceState::undo().");
|
|
|
|
Do(m_oldState);
|
2016-06-26 13:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-07-09 13:17:53 +02:00
|
|
|
void TogglePieceInLayout::redo()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2018-07-09 13:17:53 +02:00
|
|
|
qCDebug(vUndo, "TogglePieceState::redo().");
|
|
|
|
Do(m_newState);
|
2016-06-26 13:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
void TogglePieceInLayout::Do(bool state)
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2017-08-02 13:10:10 +02:00
|
|
|
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
2016-06-26 13:36:12 +02:00
|
|
|
if (detail.isElement())
|
|
|
|
{
|
|
|
|
if (state == false)
|
|
|
|
{
|
|
|
|
doc->SetAttribute(detail, AttrInLayout, state);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
detail.removeAttribute(AttrInLayout);
|
|
|
|
}
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
VPiece det = m_data->DataPieces()->value(m_id);
|
2016-06-26 13:36:12 +02:00
|
|
|
det.SetInLayout(state);
|
2016-11-09 14:53:22 +01:00
|
|
|
m_data->UpdatePiece(m_id, det);
|
2019-01-16 18:13:23 +01:00
|
|
|
emit Toggled(m_id);
|
2016-06-26 13:36:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get detail by id = %u.", m_id);
|
|
|
|
}
|
|
|
|
}
|
2018-02-03 13:18:32 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-07-09 13:17:53 +02:00
|
|
|
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)
|
2018-02-03 13:18:32 +01:00
|
|
|
{
|
2018-07-09 13:17:53 +02:00
|
|
|
setText(tr("piece flipping"));
|
|
|
|
|
|
|
|
VPiece det = m_data->DataPieces()->value(m_id);
|
|
|
|
|
|
|
|
m_oldForceState = det.IsForceFlipping();
|
|
|
|
m_oldForbidState = det.IsForbidFlipping();
|
|
|
|
|
|
|
|
if (m_type == ForceForbidFlippingType::ForceFlipping)
|
|
|
|
{
|
|
|
|
m_newForceState = state;
|
|
|
|
det.SetForbidFlipping(state);
|
|
|
|
m_newForbidState = det.IsForbidFlipping();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_newForbidState = state;
|
|
|
|
det.SetForceFlipping(state);
|
|
|
|
m_newForceState = det.IsForceFlipping();
|
|
|
|
}
|
2018-02-03 13:18:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-07-09 13:17:53 +02:00
|
|
|
void TogglePieceForceForbidFlipping::undo()
|
2018-02-03 13:18:32 +01:00
|
|
|
{
|
|
|
|
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
|
|
|
if (detail.isElement())
|
|
|
|
{
|
|
|
|
VPiece det = m_data->DataPieces()->value(m_id);
|
2018-07-09 13:17:53 +02:00
|
|
|
if (m_type == ForceForbidFlippingType::ForceFlipping)
|
|
|
|
{
|
|
|
|
det.SetForceFlipping(m_oldForceState);
|
|
|
|
det.SetForbidFlipping(m_oldForbidState);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
det.SetForbidFlipping(m_oldForbidState);
|
|
|
|
det.SetForceFlipping(m_oldForceState);
|
|
|
|
}
|
2018-02-03 13:18:32 +01:00
|
|
|
m_data->UpdatePiece(m_id, det);
|
2018-07-09 13:17:53 +02:00
|
|
|
|
|
|
|
// Probably overkill, but will help to avoid mistakes
|
|
|
|
VToolSeamAllowance::AddAttributes(doc, detail, m_id, det);
|
2018-02-03 13:18:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get detail by id = %u.", m_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-07-09 13:17:53 +02:00
|
|
|
void TogglePieceForceForbidFlipping::redo()
|
2018-02-03 13:18:32 +01:00
|
|
|
{
|
|
|
|
QDomElement detail = doc->elementById(m_id, VAbstractPattern::TagDetail);
|
|
|
|
if (detail.isElement())
|
|
|
|
{
|
|
|
|
VPiece det = m_data->DataPieces()->value(m_id);
|
2018-07-09 13:17:53 +02:00
|
|
|
if (m_type == ForceForbidFlippingType::ForceFlipping)
|
|
|
|
{
|
|
|
|
det.SetForceFlipping(m_newForceState);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
det.SetForbidFlipping(m_newForbidState);
|
|
|
|
}
|
2018-02-03 13:18:32 +01:00
|
|
|
m_data->UpdatePiece(m_id, det);
|
2018-07-09 13:17:53 +02:00
|
|
|
|
|
|
|
// Probably overkill, but will help to avoid mistakes
|
|
|
|
VToolSeamAllowance::AddAttributes(doc, detail, m_id, det);
|
2018-02-03 13:18:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("Can't get detail by id = %u.", m_id);
|
|
|
|
}
|
|
|
|
}
|