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"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-06-26 13:36:12 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-02-03 13:18:32 +01:00
|
|
|
TogglePieceState::TogglePieceState(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-02-03 13:18:32 +01:00
|
|
|
{}
|
2016-06-26 13:36:12 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-02-03 13:18:32 +01:00
|
|
|
void TogglePieceState::undo()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2018-02-03 13:18:32 +01:00
|
|
|
qCDebug(vUndo, "TogglePieceState::undo().");
|
2016-06-26 13:36:12 +02:00
|
|
|
|
|
|
|
if (m_newState != m_oldState)
|
|
|
|
{
|
|
|
|
Do(m_oldState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-02-03 13:18:32 +01:00
|
|
|
void TogglePieceState::redo()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2018-02-03 13:18:32 +01:00
|
|
|
qCDebug(vUndo, "TogglePieceState::redo().");
|
2016-06-26 13:36:12 +02:00
|
|
|
|
|
|
|
if (m_newState != m_oldState)
|
|
|
|
{
|
|
|
|
Do(m_newState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-02-03 13:18:32 +01:00
|
|
|
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
|
|
|
QUndoCommand *parent)
|
|
|
|
: TogglePieceState(id, state, data, doc, parent)
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2018-02-03 13:18:32 +01:00
|
|
|
setText(tr("detail in layout list"));
|
|
|
|
m_oldState = m_data->DataPieces()->value(m_id).IsInLayout();
|
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);
|
2016-10-14 16:11:15 +02:00
|
|
|
emit UpdateList();
|
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
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|