From 54ee9e062947fdfd1a846ada7361f0dba4f7f3d0 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 6 Apr 2024 12:09:38 +0300 Subject: [PATCH] Refactoring. --- src/app/puzzle/vpmainwindow.cpp | 194 +++++++++++++++++--------------- src/app/puzzle/vpmainwindow.h | 7 +- 2 files changed, 109 insertions(+), 92 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index ab2a1469b..051d06573 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include "../ifc/exception/vexception.h" #include "../ifc/xml/vlayoutconverter.h" @@ -323,10 +324,10 @@ struct VPExportData }; //--------------------------------------------------------------------------------------------------------------------- -VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) +VPMainWindow::VPMainWindow(VPCommandLinePtr cmd, QWidget *parent) : VAbstractMainWindow(parent), ui(std::make_unique()), - m_cmd(cmd), + m_cmd(std::move(cmd)), m_undoStack(new QUndoStack(this)), m_layout{VPLayout::CreateLayout(m_undoStack)}, m_statusLabel(new QLabel(this)), @@ -769,101 +770,111 @@ void VPMainWindow::InitProperties() InitPropertyTabLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::CurrentPieceShowSeamLineToggled(bool checked) +{ + QList const selectedPieces = SelectedPieces(); + if (selectedPieces.size() == 1) + { + const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); + if (not selectedPiece.isNull()) + { + selectedPiece->SetHideMainPath(not checked); + LayoutWasSaved(false); + // nothing changed, but will force redraw + emit m_layout->PieceTransformationChanged(selectedPiece); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::ShowFullPieceToggled(bool checked) +{ + + QList const selectedPieces = SelectedPieces(); + if (selectedPieces.size() == 1) + { + const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); + if (not selectedPiece.isNull()) + { + if (selectedPiece->IsShowFullPiece() != checked) + { + selectedPiece->SetShowFullPiece(checked); + LayoutWasSaved(false); + emit m_layout->PieceTransformationChanged(selectedPiece); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::ShowMirrorLineToggled(bool checked) +{ + QList const selectedPieces = SelectedPieces(); + if (selectedPieces.size() == 1) + { + const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); + if (not selectedPiece.isNull()) + { + if (selectedPiece->IsShowMirrorLine() != checked) + { + selectedPiece->SetShowMirrorLine(checked); + LayoutWasSaved(false); + emit m_layout->PieceTransformationChanged(selectedPiece); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::CurrentPieceVerticallyFlippedToggled(bool checked) +{ + QList const selectedPieces = SelectedPieces(); + if (selectedPieces.size() == 1) + { + const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); + if (not selectedPiece.isNull()) + { + if (selectedPiece->IsVerticallyFlipped() != checked) + { + selectedPiece->FlipVertically(); + LayoutWasSaved(false); + emit m_layout->PieceTransformationChanged(selectedPiece); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::CurrentPieceHorizontallyFlippedToggled(bool checked) +{ + QList const selectedPieces = SelectedPieces(); + if (selectedPieces.size() == 1) + { + const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); + if (not selectedPiece.isNull()) + { + if (selectedPiece->IsHorizontallyFlipped() != checked) + { + selectedPiece->FlipHorizontally(); + LayoutWasSaved(false); + emit m_layout->PieceTransformationChanged(selectedPiece); + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitPropertyTabCurrentPiece() { connect(ui->checkBoxCurrentPieceShowSeamline, &QCheckBox::toggled, this, - [this](bool checked) - { - QList const selectedPieces = SelectedPieces(); - if (selectedPieces.size() == 1) - { - const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); - if (not selectedPiece.isNull()) - { - selectedPiece->SetHideMainPath(not checked); - LayoutWasSaved(false); - // nothing changed, but will force redraw - emit m_layout->PieceTransformationChanged(selectedPiece); - } - } - }); - - connect(ui->checkBoxShowFullPiece, &QCheckBox::toggled, this, - [this](bool checked) - { - QList const selectedPieces = SelectedPieces(); - if (selectedPieces.size() == 1) - { - const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); - if (not selectedPiece.isNull()) - { - if (selectedPiece->IsShowFullPiece() != checked) - { - selectedPiece->SetShowFullPiece(checked); - LayoutWasSaved(false); - emit m_layout->PieceTransformationChanged(selectedPiece); - } - } - } - }); - - connect(ui->checkBoxShowMirrorLine, &QCheckBox::toggled, this, - [this](bool checked) - { - QList const selectedPieces = SelectedPieces(); - if (selectedPieces.size() == 1) - { - const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); - if (not selectedPiece.isNull()) - { - if (selectedPiece->IsShowMirrorLine() != checked) - { - selectedPiece->SetShowMirrorLine(checked); - LayoutWasSaved(false); - emit m_layout->PieceTransformationChanged(selectedPiece); - } - } - } - }); - + &VPMainWindow::CurrentPieceShowSeamLineToggled); + connect(ui->checkBoxShowFullPiece, &QCheckBox::toggled, this, &VPMainWindow::ShowFullPieceToggled); + connect(ui->checkBoxShowMirrorLine, &QCheckBox::toggled, this, &VPMainWindow::ShowMirrorLineToggled); connect(ui->checkBoxCurrentPieceVerticallyFlipped, &QCheckBox::toggled, this, - [this](bool checked) - { - QList const selectedPieces = SelectedPieces(); - if (selectedPieces.size() == 1) - { - const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); - if (not selectedPiece.isNull()) - { - if (selectedPiece->IsVerticallyFlipped() != checked) - { - selectedPiece->FlipVertically(); - LayoutWasSaved(false); - emit m_layout->PieceTransformationChanged(selectedPiece); - } - } - } - }); - + &VPMainWindow::CurrentPieceVerticallyFlippedToggled); connect(ui->checkBoxCurrentPieceHorizontallyFlipped, &QCheckBox::toggled, this, - [this](bool checked) - { - QList const selectedPieces = SelectedPieces(); - if (selectedPieces.size() == 1) - { - const VPPiecePtr &selectedPiece = selectedPieces.constFirst(); - if (not selectedPiece.isNull()) - { - if (selectedPiece->IsHorizontallyFlipped() != checked) - { - selectedPiece->FlipHorizontally(); - LayoutWasSaved(false); - emit m_layout->PieceTransformationChanged(selectedPiece); - } - } - } - }); + &VPMainWindow::CurrentPieceHorizontallyFlippedToggled); // Translate ui->comboBoxTranslateUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); @@ -2174,6 +2185,7 @@ void VPMainWindow::FindTemplate(QComboBox *box, qreal width, qreal height) const QSizeF tmplSize = VAbstractLayoutDialog::GetTemplateSize(static_cast(i), paperUnit); if (VAbstractLayoutDialog::RoundTemplateSize(width, height, paperUnit) == tmplSize || + // NOLINTNEXTLINE(readability-suspicious-call-argument) VAbstractLayoutDialog::RoundTemplateSize(height, width, paperUnit) == tmplSize) { box->blockSignals(true); diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index a52514f61..19a8ccc2d 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -61,7 +61,7 @@ class VPMainWindow : public VAbstractMainWindow Q_OBJECT // NOLINT public: - explicit VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent = nullptr); + explicit VPMainWindow(VPCommandLinePtr cmd, QWidget *parent = nullptr); ~VPMainWindow() override; auto CurrentFile() const -> QString; @@ -300,6 +300,11 @@ private slots: void UpdateShortcuts(); void TogetherWithNotchesChanged(bool checked); + void CurrentPieceShowSeamLineToggled(bool checked); + void ShowFullPieceToggled(bool checked); + void ShowMirrorLineToggled(bool checked); + void CurrentPieceVerticallyFlippedToggled(bool checked); + void CurrentPieceHorizontallyFlippedToggled(bool checked); private: Q_DISABLE_COPY_MOVE(VPMainWindow) // NOLINT