From 09005ddb63722b38af2a1bb96940113610c99d91 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 8 Sep 2021 11:59:41 +0300 Subject: [PATCH] Show warning before export. --- src/app/puzzle/vpmainwindow.cpp | 126 +++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 4 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index e5ddcbc56..09f9e0f0c 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -3400,6 +3400,69 @@ void VPMainWindow::on_ExportLayout() return; } + if (m_layout->LayoutSettings().GetWarningPiecesOutOfBound() || + m_layout->LayoutSettings().GetWarningSuperpositionOfPieces()) + { + for (const auto &sheet : sheets) + { + bool outOfBoundChecked = false; + bool pieceSuperpositionChecked = false; + + QList pieces = sheet->GetPieces(); + for (const auto& piece :pieces) + { + if (m_layout->LayoutSettings().GetWarningPiecesOutOfBound()) + { + if (not outOfBoundChecked && not piece.isNull() && piece->OutOfBound()) + { + QMessageBox msgBox(this); + msgBox.setIcon(QMessageBox::Question); + msgBox.setWindowTitle(tr("The layout is invalid.")); + msgBox.setText(tr("The layout is invalid. Piece out of bound. Do you want to continue export?")); + msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + const int width = 500; + auto* horizontalSpacer = new QSpacerItem(width, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + auto* layout = qobject_cast(msgBox.layout()); + SCASSERT(layout != nullptr) + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + if (msgBox.exec() == QMessageBox::No) + { + return; + } + + outOfBoundChecked = true; // no need to ask more + } + } + + if (m_layout->LayoutSettings().GetWarningSuperpositionOfPieces()) + { + if (not pieceSuperpositionChecked && not piece.isNull() && piece->HasSuperpositionWithPieces()) + { + QMessageBox msgBox(this); + msgBox.setIcon(QMessageBox::Question); + msgBox.setWindowTitle(tr("The layout is invalid.")); + msgBox.setText(tr("The layout is invalid. Pieces superposition. Do you want to continue " + "export?")); + msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + const int width = 500; + auto* horizontalSpacer = new QSpacerItem(width, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + auto* layout = qobject_cast(msgBox.layout()); + SCASSERT(layout != nullptr) + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + if (msgBox.exec() == QMessageBox::No) + { + return; + } + + pieceSuperpositionChecked = true; // no need to ask more + } + } + } + } + } + DialogSaveManualLayout dialog(sheets.size(), false, m_layout->LayoutSettings().GetTitle(), this); if (dialog.exec() == QDialog::Rejected) @@ -3407,8 +3470,6 @@ void VPMainWindow::on_ExportLayout() return; } - // TODO add checks for out of bound and pieces superpositions - VPExportData data; data.format = dialog.Format(); data.path = dialog.Path(); @@ -3437,6 +3498,65 @@ void VPMainWindow::on_ExportSheet() return; } + if (m_layout->LayoutSettings().GetWarningPiecesOutOfBound() || + m_layout->LayoutSettings().GetWarningSuperpositionOfPieces()) + { + bool outOfBoundChecked = false; + bool pieceSuperpositionChecked = false; + + QList pieces = sheet->GetPieces(); + for (const auto& piece :pieces) + { + if (m_layout->LayoutSettings().GetWarningPiecesOutOfBound()) + { + if (not outOfBoundChecked && not piece.isNull() && piece->OutOfBound()) + { + QMessageBox msgBox(this); + msgBox.setIcon(QMessageBox::Question); + msgBox.setWindowTitle(tr("The layout is invalid.")); + msgBox.setText(tr("The layout is invalid. Piece out of bound. Do you want to continue export?")); + msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + const int width = 500; + auto* horizontalSpacer = new QSpacerItem(width, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + auto* layout = qobject_cast(msgBox.layout()); + SCASSERT(layout != nullptr) + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + if (msgBox.exec() == QMessageBox::No) + { + return; + } + + outOfBoundChecked = true; // no need to ask more + } + } + + if (m_layout->LayoutSettings().GetWarningSuperpositionOfPieces()) + { + if (not pieceSuperpositionChecked && not piece.isNull() && piece->HasSuperpositionWithPieces()) + { + QMessageBox msgBox(this); + msgBox.setIcon(QMessageBox::Question); + msgBox.setWindowTitle(tr("The layout is invalid.")); + msgBox.setText(tr("The layout is invalid. Pieces superposition. Do you want to continue export?")); + msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + const int width = 500; + auto* horizontalSpacer = new QSpacerItem(width, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + auto* layout = qobject_cast(msgBox.layout()); + SCASSERT(layout != nullptr) + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + if (msgBox.exec() == QMessageBox::No) + { + return; + } + + pieceSuperpositionChecked = true; // no need to ask more + } + } + } + } + DialogSaveManualLayout dialog(1, false, sheet->GetName(), this); if (dialog.exec() == QDialog::Rejected) @@ -3444,8 +3564,6 @@ void VPMainWindow::on_ExportSheet() return; } - // TODO add checks for out of bound and pieces superpositions - VPExportData data; data.format = dialog.Format(); data.path = dialog.Path();