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() void VPCarrousel::Refresh()
{ {
const int index = ui->comboBoxPieceList->currentIndex();
// --- clears the content of the carrousel // --- clears the content of the carrousel
Clear(); Clear();
// --- add the content saved in the layout to the carrousel. // --- add the content saved in the layout to the carrousel.
// Do not rely on m_layout because we do not control it. // Do not rely on m_layout because we do not control it.
m_pieceLists = QList<VPPieceList*>(); m_pieceLists = QList<VPCarrouselSheet>();
m_pieceLists.append(m_layout->GetUnplacedPieceList());
m_pieceLists.append(m_layout->GetFocusedSheet()->GetPieceList()); if (m_layout != nullptr)
{
{
VPCarrouselSheet carrouselSheet;
carrouselSheet.unplaced = true;
carrouselSheet.name = tr("Unplaced pieces");
carrouselSheet.pieces = m_layout->GetUnplacedPieceList();
m_pieceLists.append(carrouselSheet);
}
QList<VPSheet *> sheets = m_layout->GetSheets();
for (auto *sheet : sheets)
{
VPCarrouselSheet carrouselSheet;
carrouselSheet.unplaced = false;
carrouselSheet.name = sheet->GetName();
carrouselSheet.pieces = sheet->GetPieceList();
m_pieceLists.append(carrouselSheet);
}
ui->comboBoxPieceList->blockSignals(true); ui->comboBoxPieceList->blockSignals(true);
ui->comboBoxPieceList->addItem(m_layout->GetUnplacedPieceList()->GetName()); for (const auto& sheet: m_pieceLists)
ui->comboBoxPieceList->addItem(tr("Pieces of ") + m_layout->GetFocusedSheet()->GetName()); {
ui->comboBoxPieceList->addItem(GetSheetName(sheet));
}
ui->comboBoxPieceList->blockSignals(false); ui->comboBoxPieceList->blockSignals(false);
}
on_ActivePieceListChanged(0); on_ActivePieceListChanged(index != -1 ? index: 0);
RefreshOrientation(); 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() void VPCarrousel::Clear()
{ {
@ -106,11 +139,13 @@ void VPCarrousel::on_ActivePieceListChanged(int index)
{ {
qCDebug(pCarrousel, "index changed %i", 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(m_pieceLists.at(index).pieces);
}
ui->listWidget->SetCurrentPieceList(pieceList); else
{
ui->listWidget->SetCurrentPieceList(nullptr);
} }
} }
@ -150,10 +185,12 @@ void VPCarrousel::RefreshOrientation()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::ClearSelection() void VPCarrousel::ClearSelection()
{ {
if (m_layout != nullptr)
{
m_layout->ClearSelection(); m_layout->ClearSelection();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::ClearSelectionExceptForCurrentPieceList() void VPCarrousel::ClearSelectionExceptForCurrentPieceList()
{ {
@ -162,3 +199,25 @@ void VPCarrousel::ClearSelectionExceptForCurrentPieceList()
m_layout->ClearSelectionExceptForGivenPieceList(ui->listWidget->GetCurrentPieceList()); 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; class VPCarrousel;
} }
struct VPCarrouselSheet
{
bool unplaced{true};
QString name{};
VPPieceList* pieces{nullptr};
};
class VPCarrousel : public QWidget class VPCarrousel : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -65,10 +72,7 @@ public:
*/ */
void Refresh(); void Refresh();
/** void RefreshSheetNames();
* @brief RefreshFocusedSheetName refreshes the name of the focused sheet
*/
void RefreshFocusedSheetName();
/** /**
* @brief Clear Clears the carrousel (removes everything) * @brief Clear Clears the carrousel (removes everything)
@ -86,16 +90,8 @@ public:
*/ */
void ClearSelectionExceptForCurrentPieceList(); void ClearSelectionExceptForCurrentPieceList();
private: protected:
Q_DISABLE_COPY(VPCarrousel) virtual void changeEvent(QEvent* event) override;
Ui::VPCarrousel *ui;
VPLayout *m_layout{nullptr};
QList<VPPieceList*> m_pieceLists{};
Qt::Orientation m_orientation{Qt::Vertical};
private slots: private slots:
@ -104,6 +100,18 @@ private slots:
* @param index piece index * @param index piece index
*/ */
void on_ActivePieceListChanged(int 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 #endif // VPCARROUSEL_H

View File

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