valentina/src/app/puzzle/vpiececarrousellayer.cpp

84 lines
3.0 KiB
C++
Raw Normal View History

2020-04-26 12:09:28 +02:00
/************************************************************************
**
** @file vpiececarrousellayer.cpp
** @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/>.
**
*************************************************************************/
#include "vpiececarrousellayer.h"
#include <QVBoxLayout>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer")
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselLayer::VPieceCarrouselLayer(VPuzzleLayer *layer, QWidget *parent) : QWidget(parent), m_layer(layer)
{
Init();
}
//---------------------------------------------------------------------------------------------------------------------
VPieceCarrouselLayer::~VPieceCarrouselLayer()
{
// TODO
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselLayer::Init()
{
// initiales the structure
QVBoxLayout *layoutPiecesLayout = new QVBoxLayout();
layoutPiecesLayout->setMargin(0);
setLayout(layoutPiecesLayout);
// then refresh the content
Refresh();
}
//---------------------------------------------------------------------------------------------------------------------
void VPieceCarrouselLayer::Refresh()
{
// remove the existing carrousel pieces
// TODO
// Updates the carrousel pieces from the pieces list
QList<VPuzzlePiece*> pieces = m_layer->GetPieces();
2020-04-26 14:03:43 +02:00
// sort the pieces in alphabetical order
std::sort(pieces.begin(), pieces.end(),
[](const VPuzzlePiece* a, const VPuzzlePiece* b) -> bool { return a->GetName() < b->GetName();});
// create the corresponding carrousel pieces
2020-04-26 12:09:28 +02:00
for (auto piece : pieces)
{
2020-04-26 14:03:43 +02:00
// qCDebug(pCarrouselLayer, "piece name : %s", piece->GetName().toStdString().c_str());
2020-04-26 12:09:28 +02:00
VPieceCarrouselPiece *carrouselPiece = new VPieceCarrouselPiece(piece);
m_carrouselPieces.append(carrouselPiece);
layout()->addWidget(carrouselPiece);
}
}