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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
#include "togglepieceinlayout.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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
TogglePieceInLayout::TogglePieceInLayout(quint32 id, bool state, VContainer *data, VAbstractPattern *doc,
|
2016-06-26 13:36:12 +02:00
|
|
|
QUndoCommand *parent)
|
|
|
|
: VUndoCommand(QDomElement(), doc, parent),
|
|
|
|
m_id(id),
|
|
|
|
m_data(data),
|
2016-11-09 14:53:22 +01:00
|
|
|
m_oldState(m_data->DataPieces()->value(m_id).IsInLayout()),
|
2016-06-26 13:36:12 +02:00
|
|
|
m_newState(state)
|
|
|
|
{
|
|
|
|
setText(tr("detail in layout list"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
TogglePieceInLayout::~TogglePieceInLayout()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
void TogglePieceInLayout::undo()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
|
|
|
qCDebug(vUndo, "ToggleDetailInLayout::undo().");
|
|
|
|
|
|
|
|
if (m_newState != m_oldState)
|
|
|
|
{
|
|
|
|
Do(m_oldState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
void TogglePieceInLayout::redo()
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
|
|
|
qCDebug(vUndo, "ToggleDetailInLayout::redo().");
|
|
|
|
|
|
|
|
if (m_newState != m_oldState)
|
|
|
|
{
|
|
|
|
Do(m_newState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
int TogglePieceInLayout::id() const
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
2016-11-09 14:53:22 +01:00
|
|
|
return static_cast<int>(UndoCommand::TogglePieceInLayout);
|
2016-06-26 13:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
quint32 TogglePieceInLayout::getDetId() const
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-11-09 14:53:22 +01:00
|
|
|
bool TogglePieceInLayout::getNewState() const
|
2016-06-26 13:36:12 +02:00
|
|
|
{
|
|
|
|
return m_newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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);
|
|
|
|
}
|
|
|
|
}
|