Improvements for VPCarrousel.

This commit is contained in:
Roman Telezhynskyi 2021-05-27 15:55:25 +03:00
parent f233e7dcba
commit 82935a1f03
3 changed files with 100 additions and 34 deletions

View file

@ -62,36 +62,69 @@ VPCarrousel::VPCarrousel(VPLayout *layout, QWidget *parent) :
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::Refresh()
{
const int index = ui->comboBoxPieceList->currentIndex();
// --- clears the content of the carrousel
Clear();
// --- add the content saved in the layout to the carrousel.
// Do not rely on m_layout because we do not control it.
m_pieceLists = QList<VPPieceList*>();
m_pieceLists.append(m_layout->GetUnplacedPieceList());
m_pieceLists.append(m_layout->GetFocusedSheet()->GetPieceList());
m_pieceLists = QList<VPCarrouselSheet>();
ui->comboBoxPieceList->blockSignals(true);
if (m_layout != nullptr)
{
{
VPCarrouselSheet carrouselSheet;
carrouselSheet.unplaced = true;
carrouselSheet.name = tr("Unplaced pieces");
carrouselSheet.pieces = m_layout->GetUnplacedPieceList();
ui->comboBoxPieceList->addItem(m_layout->GetUnplacedPieceList()->GetName());
ui->comboBoxPieceList->addItem(tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName());
m_pieceLists.append(carrouselSheet);
}
ui->comboBoxPieceList->blockSignals(false);
QList<VPSheet *> sheets = m_layout->GetSheets();
for (auto *sheet : sheets)
{
VPCarrouselSheet carrouselSheet;
carrouselSheet.unplaced = false;
carrouselSheet.name = sheet->GetName();
carrouselSheet.pieces = sheet->GetPieceList();
on_ActivePieceListChanged(0);
m_pieceLists.append(carrouselSheet);
}
ui->comboBoxPieceList->blockSignals(true);
for (const auto& sheet: m_pieceLists)
{
ui->comboBoxPieceList->addItem(GetSheetName(sheet));
}
ui->comboBoxPieceList->blockSignals(false);
}
on_ActivePieceListChanged(index != -1 ? index: 0);
RefreshOrientation();
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::RefreshFocusedSheetName()
void VPCarrousel::RefreshSheetNames()
{
// FIXME : This implementation will need a refactoring when we have multiple sheets, now it's not very nice!!
// Here we assume that order and number of sheets are the same in layout and here
QList<VPSheet *> sheets = m_layout->GetSheets();
if (m_pieceLists.size() != sheets.size()+1)
{
return;
}
ui->comboBoxPieceList->setItemText(1, tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName());
for (int i=0; i < sheets.size(); ++i)
{
m_pieceLists[i+1].name = sheets.at(i)->GetName();
ui->comboBoxPieceList->setItemText(i+1, GetSheetName(m_pieceLists.at(i+1)));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::Clear()
{
@ -106,11 +139,13 @@ void VPCarrousel::on_ActivePieceListChanged(int index)
{
qCDebug(pCarrousel, "index changed %i", index);
if (index >= 0 && index < m_pieceLists.size())
if (not m_pieceLists.isEmpty() && index >= 0 && index < m_pieceLists.size())
{
VPPieceList *pieceList = m_pieceLists.at(index);
ui->listWidget->SetCurrentPieceList(pieceList);
ui->listWidget->SetCurrentPieceList(m_pieceLists.at(index).pieces);
}
else
{
ui->listWidget->SetCurrentPieceList(nullptr);
}
}
@ -150,10 +185,12 @@ void VPCarrousel::RefreshOrientation()
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::ClearSelection()
{
m_layout->ClearSelection();
if (m_layout != nullptr)
{
m_layout->ClearSelection();
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::ClearSelectionExceptForCurrentPieceList()
{
@ -162,3 +199,25 @@ void VPCarrousel::ClearSelectionExceptForCurrentPieceList()
m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList());
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
{
// retranslate designer form (single inheritance approach)
ui->retranslateUi(this);
RefreshSheetNames();
on_ActivePieceListChanged(ui->comboBoxPieceList->currentIndex());
}
// remember to call base class implementation
QWidget::changeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
auto VPCarrousel::GetSheetName(const VPCarrouselSheet &sheet) -> QString
{
return sheet.unplaced ? sheet.name : tr("Pieces of ") + sheet.name;
}

View file

@ -40,6 +40,13 @@ namespace Ui
class VPCarrousel;
}
struct VPCarrouselSheet
{
bool unplaced{true};
QString name{};
VPPieceList* pieces{nullptr};
};
class VPCarrousel : public QWidget
{
Q_OBJECT
@ -65,10 +72,7 @@ public:
*/
void Refresh();
/**
* @brief RefreshFocusedSheetName refreshes the name of the focused sheet
*/
void RefreshFocusedSheetName();
void RefreshSheetNames();
/**
* @brief Clear Clears the carrousel (removes everything)
@ -86,16 +90,8 @@ public:
*/
void ClearSelectionExceptForCurrentPieceList();
private:
Q_DISABLE_COPY(VPCarrousel)
Ui::VPCarrousel *ui;
VPLayout *m_layout{nullptr};
QList<VPPieceList*> m_pieceLists{};
Qt::Orientation m_orientation{Qt::Vertical};
protected:
virtual void changeEvent(QEvent* event) override;
private slots:
@ -104,6 +100,18 @@ private slots:
* @param index piece index
*/
void on_ActivePieceListChanged(int index);
private:
Q_DISABLE_COPY(VPCarrousel)
Ui::VPCarrousel *ui;
VPLayout *m_layout{nullptr};
QList<VPCarrouselSheet> m_pieceLists{};
Qt::Orientation m_orientation{Qt::Vertical};
static QString GetSheetName(const VPCarrouselSheet &sheet);
};
#endif // VPCARROUSEL_H

View file

@ -569,7 +569,6 @@ void VPMainWindow::InitCarrousel()
&VPMainWindow::on_CarrouselLocationChanged);
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::SetPropertiesData()
{
@ -1376,7 +1375,7 @@ void VPMainWindow::on_lineEditSheetName_textChanged(const QString &text)
if(m_carrousel != nullptr)
{
m_carrousel->RefreshFocusedSheetName();
m_carrousel->RefreshSheetNames();
}
}