Refactoring.

This commit is contained in:
Roman Telezhynskyi 2024-04-06 12:09:38 +03:00
parent a4e2e1f1bf
commit 54ee9e0629
2 changed files with 109 additions and 92 deletions

View File

@ -43,6 +43,7 @@
#include <QtMath> #include <QtMath>
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <utility>
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "../ifc/xml/vlayoutconverter.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), : VAbstractMainWindow(parent),
ui(std::make_unique<Ui::VPMainWindow>()), ui(std::make_unique<Ui::VPMainWindow>()),
m_cmd(cmd), m_cmd(std::move(cmd)),
m_undoStack(new QUndoStack(this)), m_undoStack(new QUndoStack(this)),
m_layout{VPLayout::CreateLayout(m_undoStack)}, m_layout{VPLayout::CreateLayout(m_undoStack)},
m_statusLabel(new QLabel(this)), m_statusLabel(new QLabel(this)),
@ -769,101 +770,111 @@ void VPMainWindow::InitProperties()
InitPropertyTabLayout(); InitPropertyTabLayout();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::CurrentPieceShowSeamLineToggled(bool checked)
{
QList<VPPiecePtr> 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<VPPiecePtr> 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<VPPiecePtr> 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<VPPiecePtr> 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<VPPiecePtr> 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() void VPMainWindow::InitPropertyTabCurrentPiece()
{ {
connect(ui->checkBoxCurrentPieceShowSeamline, &QCheckBox::toggled, this, connect(ui->checkBoxCurrentPieceShowSeamline, &QCheckBox::toggled, this,
[this](bool checked) &VPMainWindow::CurrentPieceShowSeamLineToggled);
{ connect(ui->checkBoxShowFullPiece, &QCheckBox::toggled, this, &VPMainWindow::ShowFullPieceToggled);
QList<VPPiecePtr> const selectedPieces = SelectedPieces(); connect(ui->checkBoxShowMirrorLine, &QCheckBox::toggled, this, &VPMainWindow::ShowMirrorLineToggled);
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<VPPiecePtr> 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<VPPiecePtr> 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);
}
}
}
});
connect(ui->checkBoxCurrentPieceVerticallyFlipped, &QCheckBox::toggled, this, connect(ui->checkBoxCurrentPieceVerticallyFlipped, &QCheckBox::toggled, this,
[this](bool checked) &VPMainWindow::CurrentPieceVerticallyFlippedToggled);
{
QList<VPPiecePtr> 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);
}
}
}
});
connect(ui->checkBoxCurrentPieceHorizontallyFlipped, &QCheckBox::toggled, this, connect(ui->checkBoxCurrentPieceHorizontallyFlipped, &QCheckBox::toggled, this,
[this](bool checked) &VPMainWindow::CurrentPieceHorizontallyFlippedToggled);
{
QList<VPPiecePtr> 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);
}
}
}
});
// Translate // Translate
ui->comboBoxTranslateUnit->addItem(tr("Millimiters"), QVariant(UnitsToStr(Unit::Mm))); 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 = const QSizeF tmplSize =
VAbstractLayoutDialog::GetTemplateSize(static_cast<VAbstractLayoutDialog::PaperSizeTemplate>(i), paperUnit); VAbstractLayoutDialog::GetTemplateSize(static_cast<VAbstractLayoutDialog::PaperSizeTemplate>(i), paperUnit);
if (VAbstractLayoutDialog::RoundTemplateSize(width, height, paperUnit) == tmplSize || if (VAbstractLayoutDialog::RoundTemplateSize(width, height, paperUnit) == tmplSize ||
// NOLINTNEXTLINE(readability-suspicious-call-argument)
VAbstractLayoutDialog::RoundTemplateSize(height, width, paperUnit) == tmplSize) VAbstractLayoutDialog::RoundTemplateSize(height, width, paperUnit) == tmplSize)
{ {
box->blockSignals(true); box->blockSignals(true);

View File

@ -61,7 +61,7 @@ class VPMainWindow : public VAbstractMainWindow
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
explicit VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent = nullptr); explicit VPMainWindow(VPCommandLinePtr cmd, QWidget *parent = nullptr);
~VPMainWindow() override; ~VPMainWindow() override;
auto CurrentFile() const -> QString; auto CurrentFile() const -> QString;
@ -300,6 +300,11 @@ private slots:
void UpdateShortcuts(); void UpdateShortcuts();
void TogetherWithNotchesChanged(bool checked); 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: private:
Q_DISABLE_COPY_MOVE(VPMainWindow) // NOLINT Q_DISABLE_COPY_MOVE(VPMainWindow) // NOLINT