2020-04-13 18:58:16 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 15:34:11 +02:00
|
|
|
** @file vplayout.cpp
|
2020-04-13 18:58:16 +02:00
|
|
|
** @author Ronan Le Tiec
|
|
|
|
** @date 13 4, 2020
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2020 Valentina project
|
|
|
|
** <https://gitlab.com/smart-pattern/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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
2021-07-29 16:11:18 +02:00
|
|
|
|
2020-05-23 15:34:11 +02:00
|
|
|
#include "vplayout.h"
|
2020-05-23 15:42:51 +02:00
|
|
|
#include "vppiece.h"
|
2020-05-23 17:47:04 +02:00
|
|
|
#include "vpsheet.h"
|
2020-04-13 18:58:16 +02:00
|
|
|
|
2020-05-24 19:53:51 +02:00
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(pLayout, "p.layout")
|
|
|
|
|
2020-04-13 18:58:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
VPLayout::VPLayout(QObject *parent) :
|
|
|
|
QObject(parent),
|
|
|
|
m_trashSheet(new VPSheet(this))
|
|
|
|
{}
|
2020-04-13 18:58:16 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:34:11 +02:00
|
|
|
VPLayout::~VPLayout()
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
qDeleteAll(m_pieces);
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:40:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
void VPLayout::AddPiece(VPPiece *piece)
|
2020-05-05 17:40:36 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
if ((piece != nullptr) && not m_pieces.contains(piece))
|
2020-05-23 17:47:04 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
piece->SetLayout(this);
|
|
|
|
m_pieces.append(piece);
|
2020-05-23 17:47:04 +02:00
|
|
|
}
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::GetPieces() const -> QList<VPPiece *>
|
2020-04-13 18:58:16 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return m_pieces;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
|
|
|
|
2020-11-11 19:14:06 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::GetUnplacedPieces() const -> QList<VPPiece *>
|
2020-11-11 19:14:06 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return PiecesForSheet(nullptr);
|
2020-11-11 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::GetTrashedPieces() const -> QList<VPPiece *>
|
2020-11-11 19:14:06 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return PiecesForSheet(m_trashSheet);
|
2020-11-11 19:14:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::AddSheet() -> VPSheet*
|
2020-11-11 19:14:06 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
auto *newSheet = new VPSheet(this);
|
|
|
|
m_sheets.append(newSheet);
|
|
|
|
return newSheet;
|
2020-04-13 18:58:16 +02:00
|
|
|
}
|
2020-05-06 15:05:01 +02:00
|
|
|
|
2020-05-24 19:53:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::AddSheet(VPSheet *sheet) -> VPSheet*
|
2020-05-24 19:53:51 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
if ((sheet != nullptr) && not m_sheets.contains(sheet))
|
2020-05-24 19:53:51 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
sheet->setParent(this);
|
|
|
|
m_sheets.append(sheet);
|
2020-05-24 19:53:51 +02:00
|
|
|
}
|
2021-07-29 16:11:18 +02:00
|
|
|
return sheet;
|
2020-05-24 19:53:51 +02:00
|
|
|
}
|
|
|
|
|
2020-05-06 15:05:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::GetSheets() -> QList<VPSheet *>
|
2020-05-06 15:05:01 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return m_sheets;
|
2020-05-06 15:05:01 +02:00
|
|
|
}
|
2020-05-08 23:49:41 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 17:47:04 +02:00
|
|
|
void VPLayout::SetFocusedSheet(VPSheet *focusedSheet)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
if (m_sheets.isEmpty())
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
m_focusedSheet = nullptr;
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
m_focusedSheet = focusedSheet == nullptr ? m_sheets.first() : focusedSheet;
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::GetFocusedSheet() -> VPSheet*
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 17:47:04 +02:00
|
|
|
return m_focusedSheet;
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
2020-11-14 15:58:42 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::GetTrashSheet() -> VPSheet*
|
2020-11-14 15:58:42 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return m_trashSheet;
|
2020-11-14 15:58:42 +01:00
|
|
|
}
|
|
|
|
|
2020-11-15 12:30:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::LayoutSettings() -> VPLayoutSettings &
|
2020-11-15 12:30:29 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
return m_layoutSettings;
|
2020-11-15 12:30:29 +01:00
|
|
|
}
|
|
|
|
|
2020-11-14 15:58:42 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-07-29 16:11:18 +02:00
|
|
|
auto VPLayout::PiecesForSheet(const VPSheet *sheet) const -> QList<VPPiece *>
|
2020-11-14 15:58:42 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
QList<VPPiece *> list;
|
|
|
|
list.reserve(m_pieces.size());
|
2020-11-14 15:58:42 +01:00
|
|
|
|
2021-07-29 16:11:18 +02:00
|
|
|
for (auto *piece : m_pieces)
|
2020-11-14 15:58:42 +01:00
|
|
|
{
|
2021-07-29 16:11:18 +02:00
|
|
|
if ((piece != nullptr) && piece->Sheet() == sheet)
|
|
|
|
{
|
|
|
|
list.append(piece);
|
|
|
|
}
|
2020-11-14 15:58:42 +01:00
|
|
|
}
|
|
|
|
|
2021-07-29 16:11:18 +02:00
|
|
|
return list;
|
2020-11-14 15:58:42 +01:00
|
|
|
}
|