Refactoring. Move methods to class MainWindowsNoGUI.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-08-06 19:38:23 +03:00
parent ed5ac37256
commit 9e80bc186d
4 changed files with 106 additions and 90 deletions

View File

@ -100,6 +100,7 @@
#endif //defined(Q_OS_MAC) #endif //defined(Q_OS_MAC)
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmissing-prototypes")
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
QT_WARNING_DISABLE_INTEL(1418) QT_WARNING_DISABLE_INTEL(1418)
@ -404,76 +405,6 @@ void MainWindow::InitScenes()
qApp->setSceneView(ui->view); qApp->setSceneView(ui->view);
} }
//---------------------------------------------------------------------------------------------------------------------
QSharedPointer<VMeasurements> MainWindow::OpenMeasurementFile(const QString &path)
{
QSharedPointer<VMeasurements> m;
if (path.isEmpty())
{
return m;
}
try
{
m = QSharedPointer<VMeasurements>(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) bool MainWindow::LoadMeasurements(const QString &path)
{ {
@ -584,24 +515,6 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height)
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::CheckRequiredMeasurements(const VMeasurements *m)
{
const QSet<QString> match = doc->ListMeasurements().toSet().subtract(m->ListAll().toSet());
if (not match.isEmpty())
{
QList<QString> 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. * @brief SetToolButton set tool and show dialog.

View File

@ -356,10 +356,8 @@ private:
void InitScenes(); void InitScenes();
QSharedPointer<VMeasurements> OpenMeasurementFile(const QString &path);
bool LoadMeasurements(const QString &path); bool LoadMeasurements(const QString &path);
bool UpdateMeasurements(const QString &path, int size, int height); bool UpdateMeasurements(const QString &path, int size, int height);
void CheckRequiredMeasurements(const VMeasurements *m);
void ReopenFilesAfterCrash(QStringList &args); void ReopenFilesAfterCrash(QStringList &args);
bool DoExport(const VCommandLinePtr& expParams); bool DoExport(const VCommandLinePtr& expParams);

View File

@ -35,6 +35,7 @@
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include "../vmisc/dialogs/dialogexporttocsv.h" #include "../vmisc/dialogs/dialogexporttocsv.h"
#include "../vmisc/qxtcsvmodel.h" #include "../vmisc/qxtcsvmodel.h"
#include "../vformat/vmeasurements.h"
#include "../vlayout/vlayoutgenerator.h" #include "../vlayout/vlayoutgenerator.h"
#include "dialogs/dialoglayoutprogress.h" #include "dialogs/dialoglayoutprogress.h"
#include "dialogs/dialogsavelayout.h" #include "dialogs/dialogsavelayout.h"
@ -46,6 +47,8 @@
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"
#include "../vtools/tools/vabstracttool.h" #include "../vtools/tools/vabstracttool.h"
#include "../vtools/tools/vtoolseamallowance.h" #include "../vtools/tools/vtoolseamallowance.h"
#include "../ifc/xml/vvstconverter.h"
#include "../ifc/xml/vvitconverter.h"
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
@ -63,6 +66,15 @@
#include <QWinTaskbarProgress> #include <QWinTaskbarProgress>
#endif #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 #ifdef Q_OS_WIN
# define PDFTOPS "pdftops.exe" # define PDFTOPS "pdftops.exe"
#else #else
@ -1753,6 +1765,94 @@ bool MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, boo
return success; return success;
} }
//---------------------------------------------------------------------------------------------------------------------
QSharedPointer<VMeasurements> MainWindowsNoGUI::OpenMeasurementFile(const QString &path) const
{
QSharedPointer<VMeasurements> m;
if (path.isEmpty())
{
return m;
}
try
{
m = QSharedPointer<VMeasurements>(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<QString> match = doc->ListMeasurements().toSet().subtract(m->ListAll().toSet());
if (not match.isEmpty())
{
QList<QString> 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() int MainWindowsNoGUI::ContinueIfLayoutStale()
{ {

View File

@ -41,6 +41,7 @@
class QGraphicsScene; class QGraphicsScene;
struct PosterData; struct PosterData;
class QGraphicsRectItem; class QGraphicsRectItem;
class VMeasurements;
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
class QWinTaskbarButton; class QWinTaskbarButton;
@ -116,6 +117,10 @@ protected:
bool ExportFMeasurementsToCSVData(const QString &fileName, bool ExportFMeasurementsToCSVData(const QString &fileName,
bool withHeader, int mib, const QChar &separator) const; bool withHeader, int mib, const QChar &separator) const;
QSharedPointer<VMeasurements> OpenMeasurementFile(const QString &path) const;
void CheckRequiredMeasurements(const VMeasurements *m) const;
private slots: private slots:
void PrintPages (QPrinter *printer); void PrintPages (QPrinter *printer);
void ErrorConsoleMode(const LayoutErrors &state); void ErrorConsoleMode(const LayoutErrors &state);