2020-04-26 12:09:28 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
2020-05-23 14:33:02 +02:00
|
|
|
** @file vpcarrouselpiecelist.cpp
|
2020-04-26 12:09:28 +02:00
|
|
|
** @author Ronan Le Tiec
|
|
|
|
** @date 25 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2020-05-23 14:33:02 +02:00
|
|
|
#include "vpcarrouselpiecelist.h"
|
2020-05-23 14:29:18 +02:00
|
|
|
#include "vpcarrousel.h"
|
2020-05-09 12:57:42 +02:00
|
|
|
#include "../vmisc/backport/qoverload.h"
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
2020-05-23 15:29:57 +02:00
|
|
|
Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:29:57 +02:00
|
|
|
VPCarrouselPieceList::VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel) :
|
|
|
|
m_pieceList(pieceList),
|
2020-05-06 15:05:01 +02:00
|
|
|
m_carrousel(carrousel),
|
2020-05-23 14:36:35 +02:00
|
|
|
m_carrouselPieces(QList<VPCarrouselPiece*>())
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
VPCarrouselPieceList::~VPCarrouselPieceList()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
2020-05-08 23:49:41 +02:00
|
|
|
Clear();
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::Init()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
|
|
|
// initiales the structure
|
|
|
|
QVBoxLayout *layoutPiecesLayout = new QVBoxLayout();
|
|
|
|
layoutPiecesLayout->setMargin(0);
|
|
|
|
setLayout(layoutPiecesLayout);
|
|
|
|
|
|
|
|
// then refresh the content
|
|
|
|
Refresh();
|
2020-05-08 23:49:41 +02:00
|
|
|
|
|
|
|
// add the connections
|
2020-05-23 15:29:57 +02:00
|
|
|
connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
|
|
|
|
connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::Refresh()
|
2020-04-26 12:09:28 +02:00
|
|
|
{
|
2020-05-08 23:49:41 +02:00
|
|
|
Clear();
|
2020-04-26 12:09:28 +02:00
|
|
|
|
|
|
|
// Updates the carrousel pieces from the pieces list
|
2020-05-23 15:42:51 +02:00
|
|
|
QList<VPPiece*> pieces = m_pieceList->GetPieces();
|
2020-04-26 12:09:28 +02:00
|
|
|
|
2020-04-26 14:03:43 +02:00
|
|
|
// sort the pieces in alphabetical order
|
|
|
|
std::sort(pieces.begin(), pieces.end(),
|
2020-05-23 15:42:51 +02:00
|
|
|
[](const VPPiece* a, const VPPiece* b) -> bool { return a->GetName() < b->GetName();});
|
2020-04-26 14:03:43 +02:00
|
|
|
|
|
|
|
// create the corresponding carrousel pieces
|
2020-04-26 22:32:08 +02:00
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
bool _isVisible = isVisible();
|
|
|
|
setVisible(true);
|
2020-04-26 12:09:28 +02:00
|
|
|
for (auto piece : pieces)
|
|
|
|
{
|
2020-05-23 14:36:35 +02:00
|
|
|
VPCarrouselPiece *carrouselPiece = new VPCarrouselPiece(piece, this);
|
2020-04-26 12:09:28 +02:00
|
|
|
m_carrouselPieces.append(carrouselPiece);
|
|
|
|
layout()->addWidget(carrouselPiece);
|
2020-05-08 23:49:41 +02:00
|
|
|
carrouselPiece->CleanPreview(); // fitInView only works if the widget is displayed.
|
|
|
|
}
|
|
|
|
setVisible(_isVisible);
|
|
|
|
}
|
2020-04-26 22:32:08 +02:00
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
void VPCarrouselPieceList::Clear()
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
// Removes and deletes the carrousel pieces from the piece list
|
2020-05-08 23:49:41 +02:00
|
|
|
while (!m_carrouselPieces.isEmpty())
|
|
|
|
{
|
2020-05-23 14:36:35 +02:00
|
|
|
VPCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast();
|
2020-05-08 23:49:41 +02:00
|
|
|
|
|
|
|
if(carrouselPiece != nullptr)
|
|
|
|
{
|
|
|
|
layout()->removeWidget(carrouselPiece);
|
|
|
|
delete carrouselPiece;
|
|
|
|
}
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
2020-05-08 23:49:41 +02:00
|
|
|
|
2020-04-26 12:09:28 +02:00
|
|
|
}
|
2020-05-01 18:26:02 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:36:35 +02:00
|
|
|
QList<VPCarrouselPiece*> VPCarrouselPieceList::GetCarrouselPieces()
|
2020-05-01 18:26:02 +02:00
|
|
|
{
|
|
|
|
return m_carrouselPieces;
|
|
|
|
}
|
|
|
|
|
2020-05-06 15:05:01 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 14:33:02 +02:00
|
|
|
VPCarrousel* VPCarrouselPieceList::GetCarrousel()
|
2020-05-06 15:05:01 +02:00
|
|
|
{
|
|
|
|
return m_carrousel;
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:49:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:29:57 +02:00
|
|
|
VPPieceList* VPCarrouselPieceList::GetPieceList()
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
2020-05-23 15:29:57 +02:00
|
|
|
return m_pieceList;
|
2020-05-08 23:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:42:51 +02:00
|
|
|
void VPCarrouselPieceList::on_PieceAdded(VPPiece* piece)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(piece)
|
|
|
|
|
|
|
|
// TODO/ FIXME: see if we find a solution more efficient refreshing the complete layout everytime.
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-05-23 15:42:51 +02:00
|
|
|
void VPCarrouselPieceList::on_PieceRemoved(VPPiece* piece)
|
2020-05-08 23:49:41 +02:00
|
|
|
{
|
|
|
|
for (auto carrouselPiece : m_carrouselPieces)
|
|
|
|
{
|
|
|
|
if(carrouselPiece->GetPiece() == piece)
|
|
|
|
{
|
|
|
|
m_carrouselPieces.removeAll(carrouselPiece);
|
|
|
|
layout()->removeWidget(carrouselPiece);
|
|
|
|
delete carrouselPiece;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|