From 9e80bc186d55f200fb68238503a0283123d772b8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 6 Aug 2018 19:38:23 +0300 Subject: [PATCH] Refactoring. Move methods to class MainWindowsNoGUI. --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 89 +--------------------- src/app/valentina/mainwindow.h | 2 - src/app/valentina/mainwindowsnogui.cpp | 100 +++++++++++++++++++++++++ src/app/valentina/mainwindowsnogui.h | 5 ++ 4 files changed, 106 insertions(+), 90 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 019f7679b..4bf6430d3 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -100,6 +100,7 @@ #endif //defined(Q_OS_MAC) QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_INTEL(1418) @@ -404,76 +405,6 @@ void MainWindow::InitScenes() qApp->setSceneView(ui->view); } -//--------------------------------------------------------------------------------------------------------------------- -QSharedPointer MainWindow::OpenMeasurementFile(const QString &path) -{ - QSharedPointer m; - if (path.isEmpty()) - { - return m; - } - - try - { - m = QSharedPointer(new VMeasurements(pattern)); - m->SetSize(VContainer::rsize()); - m->SetHeight(VContainer::rheight()); - m->setXMLContent(path); - - if (m->Type() == MeasurementsType::Unknown) - { - VException e(tr("Measurement file has unknown format.")); - throw e; - } - - if (m->Type() == MeasurementsType::Multisize) - { - VVSTConverter converter(path); - m->setXMLContent(converter.Convert());// Read again after conversion - } - else - { - VVITConverter converter(path); - m->setXMLContent(converter.Convert());// Read again after conversion - } - - if (not m->IsDefinedKnownNamesValid()) - { - VException e(tr("Measurement file contains invalid known measurement(s).")); - throw e; - } - - CheckRequiredMeasurements(m.data()); - - if (m->Type() == MeasurementsType::Multisize) - { - if (m->MUnit() == Unit::Inch) - { - qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")), - qUtf8Printable(tr("Application doesn't support multisize table with inches."))); - m->clear(); - if (not VApplication::IsGUIMode()) - { - qApp->exit(V_EX_DATAERR); - } - return m; - } - } - } - catch (VException &e) - { - qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), - qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); - m->clear(); - if (not VApplication::IsGUIMode()) - { - qApp->exit(V_EX_NOINPUT); - } - return m; - } - return m; -} - //--------------------------------------------------------------------------------------------------------------------- bool MainWindow::LoadMeasurements(const QString &path) { @@ -584,24 +515,6 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) return true; } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindow::CheckRequiredMeasurements(const VMeasurements *m) -{ - const QSet match = doc->ListMeasurements().toSet().subtract(m->ListAll().toSet()); - if (not match.isEmpty()) - { - QList list = match.toList(); - for (int i = 0; i < list.size(); ++i) - { - list[i] = qApp->TrVars()->MToUser(list.at(i)); - } - - VException e(tr("Measurement file doesn't include all required measurements.")); - e.AddMoreInformation(tr("Please, additionally provide: %1").arg(QStringList(list).join(", "))); - throw e; - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetToolButton set tool and show dialog. diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 2fbac38de..498ceacc2 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -356,10 +356,8 @@ private: void InitScenes(); - QSharedPointer OpenMeasurementFile(const QString &path); bool LoadMeasurements(const QString &path); bool UpdateMeasurements(const QString &path, int size, int height); - void CheckRequiredMeasurements(const VMeasurements *m); void ReopenFilesAfterCrash(QStringList &args); bool DoExport(const VCommandLinePtr& expParams); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index af803c630..829b97914 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -35,6 +35,7 @@ #include "../vwidgets/vmaingraphicsscene.h" #include "../vmisc/dialogs/dialogexporttocsv.h" #include "../vmisc/qxtcsvmodel.h" +#include "../vformat/vmeasurements.h" #include "../vlayout/vlayoutgenerator.h" #include "dialogs/dialoglayoutprogress.h" #include "dialogs/dialogsavelayout.h" @@ -46,6 +47,8 @@ #include "../vpatterndb/calculator.h" #include "../vtools/tools/vabstracttool.h" #include "../vtools/tools/vtoolseamallowance.h" +#include "../ifc/xml/vvstconverter.h" +#include "../ifc/xml/vvitconverter.h" #include #include @@ -63,6 +66,15 @@ #include #endif +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Wmissing-prototypes") +QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") +QT_WARNING_DISABLE_INTEL(1418) + +Q_LOGGING_CATEGORY(vMainNoGUIWindow, "v.mainnoguiwindow") + +QT_WARNING_POP + #ifdef Q_OS_WIN # define PDFTOPS "pdftops.exe" #else @@ -1753,6 +1765,94 @@ bool MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, boo return success; } +//--------------------------------------------------------------------------------------------------------------------- +QSharedPointer MainWindowsNoGUI::OpenMeasurementFile(const QString &path) const +{ + QSharedPointer m; + if (path.isEmpty()) + { + return m; + } + + try + { + m = QSharedPointer(new VMeasurements(pattern)); + m->SetSize(VContainer::rsize()); + m->SetHeight(VContainer::rheight()); + m->setXMLContent(path); + + if (m->Type() == MeasurementsType::Unknown) + { + VException e(tr("Measurement file has unknown format.")); + throw e; + } + + if (m->Type() == MeasurementsType::Multisize) + { + VVSTConverter converter(path); + m->setXMLContent(converter.Convert());// Read again after conversion + } + else + { + VVITConverter converter(path); + m->setXMLContent(converter.Convert());// Read again after conversion + } + + if (not m->IsDefinedKnownNamesValid()) + { + VException e(tr("Measurement file contains invalid known measurement(s).")); + throw e; + } + + CheckRequiredMeasurements(m.data()); + + if (m->Type() == MeasurementsType::Multisize) + { + if (m->MUnit() == Unit::Inch) + { + qCCritical(vMainNoGUIWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")), + qUtf8Printable(tr("Application doesn't support multisize table with inches."))); + m->clear(); + if (not VApplication::IsGUIMode()) + { + qApp->exit(V_EX_DATAERR); + } + return m; + } + } + } + catch (VException &e) + { + qCCritical(vMainNoGUIWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + m->clear(); + if (not VApplication::IsGUIMode()) + { + qApp->exit(V_EX_NOINPUT); + } + return m; + } + return m; +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::CheckRequiredMeasurements(const VMeasurements *m) const +{ + const QSet match = doc->ListMeasurements().toSet().subtract(m->ListAll().toSet()); + if (not match.isEmpty()) + { + QList list = match.toList(); + for (int i = 0; i < list.size(); ++i) + { + list[i] = qApp->TrVars()->MToUser(list.at(i)); + } + + VException e(tr("Measurement file doesn't include all required measurements.")); + e.AddMoreInformation(tr("Please, additionally provide: %1").arg(QStringList(list).join(", "))); + throw e; + } +} + //--------------------------------------------------------------------------------------------------------------------- int MainWindowsNoGUI::ContinueIfLayoutStale() { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 635afbb3f..d45ea5bbd 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -41,6 +41,7 @@ class QGraphicsScene; struct PosterData; class QGraphicsRectItem; +class VMeasurements; #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) class QWinTaskbarButton; @@ -116,6 +117,10 @@ protected: bool ExportFMeasurementsToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator) const; + + QSharedPointer OpenMeasurementFile(const QString &path) const; + + void CheckRequiredMeasurements(const VMeasurements *m) const; private slots: void PrintPages (QPrinter *printer); void ErrorConsoleMode(const LayoutErrors &state);