Correct update measurements.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-10-07 16:58:00 +03:00
parent 8aea332cda
commit afce2cb0ba
2 changed files with 258 additions and 65 deletions

View File

@ -230,17 +230,17 @@ void MainWindow::InitScenes()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool MainWindow::LoadMeasurements(const QString &path) QSharedPointer<VMeasurements> MainWindow::OpenMeasurementFile(const QString &path)
{ {
QSharedPointer<VMeasurements> m;
if (path.isEmpty()) if (path.isEmpty())
{ {
return false; return m;
} }
VMeasurements *m = nullptr;
try try
{ {
m = new VMeasurements(pattern); m = QSharedPointer<VMeasurements>(new VMeasurements(pattern));
m->setXMLContent(path); m->setXMLContent(path);
if (m->Type() == MeasurementsType::Unknown) if (m->Type() == MeasurementsType::Unknown)
@ -289,6 +289,87 @@ bool MainWindow::LoadMeasurements(const QString &path)
{ {
qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")), qCCritical(vMainWindow, "%s\n\n%s", qUtf8Printable(tr("Wrong units.")),
qUtf8Printable(tr("Application doesn't support standard table with inches."))); qUtf8Printable(tr("Application doesn't support standard table with inches.")));
m->clear();
if (VApplication::CheckGUI())
{
return m;
}
else
{
std::exit(V_EX_DATAERR);
}
}
}
}
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 (VApplication::CheckGUI())
{
return m;
}
else
{
std::exit(V_EX_NOINPUT);
}
}
return m;
}
//---------------------------------------------------------------------------------------------------------------------
bool MainWindow::LoadMeasurements(const QString &path)
{
QSharedPointer<VMeasurements> m = OpenMeasurementFile(path);
if (m->isNull())
{
return false;
}
if (m->Type() == MeasurementsType::Standard)
{
m->SetDataSize();
m->SetDataHeight();
}
try
{
qApp->setPatternType(m->Type());
ToolBarOption();
pattern->ClearVariables(VarType::Measurement);
m->ReadMeasurements();
}
catch (VExceptionEmptyParameter &e)
{
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
if (VApplication::CheckGUI())
{
return false;
}
else
{
std::exit(V_EX_NOINPUT);
}
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
bool MainWindow::UpdateMeasurements(const QString &path, int size, int height)
{
QSharedPointer<VMeasurements> m = OpenMeasurementFile(path);
if (m->isNull())
{
return false;
}
if (qApp->patternType() != m->Type())
{
qCCritical(vMainWindow, "%s", qUtf8Printable(tr("Measurement files types have not match.")));
if (VApplication::CheckGUI()) if (VApplication::CheckGUI())
{ {
return false; return false;
@ -298,21 +379,22 @@ bool MainWindow::LoadMeasurements(const QString &path)
std::exit(V_EX_DATAERR); std::exit(V_EX_DATAERR);
} }
} }
m->SetDataSize();
m->SetDataHeight(); if (m->Type() == MeasurementsType::Standard)
{
pattern->SetSize(size);
pattern->SetHeight(height);
} }
qApp->setPatternType(m->Type()); try
ToolBarOption(); {
pattern->ClearVariables(VarType::Measurement); pattern->ClearVariables(VarType::Measurement);
m->ReadMeasurements(); m->ReadMeasurements();
delete m;
} }
catch (VException &e) catch (VExceptionEmptyParameter &e)
{ {
qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
delete m;
if (VApplication::CheckGUI()) if (VApplication::CheckGUI())
{ {
return false; return false;
@ -1172,18 +1254,23 @@ void MainWindow::SyncMeasurements()
if (mChanges) if (mChanges)
{ {
const QString path = AbsoluteMPath(curFile, doc->MPath()); const QString path = AbsoluteMPath(curFile, doc->MPath());
if(LoadMeasurements(path)) if(UpdateMeasurements(path, static_cast<int>(pattern->size()), static_cast<int>(pattern->height())))
{ {
if (not watcher->files().contains(path)) if (not watcher->files().contains(path))
{ {
watcher->addPath(path); watcher->addPath(path);
} }
const QString msg = tr("Measurements was updated"); const QString msg = tr("Measurements was synced");
qCDebug(vMainWindow, "%s", qUtf8Printable(msg));
helpLabel->setText(msg); helpLabel->setText(msg);
VWidgetPopup::PopupMessage(this, msg); VWidgetPopup::PopupMessage(this, msg);
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
mChanges = false; mChanges = false;
} }
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't sync measurements.")));
}
} }
ToggleMSync(false); ToggleMSync(false);
@ -1224,14 +1311,40 @@ void MainWindow::ToolBarOption()
gradationHeightsLabel = new QLabel(tr("Height: "), this); gradationHeightsLabel = new QLabel(tr("Height: "), this);
gradationHeights = SetGradationList(gradationHeightsLabel, listHeights); gradationHeights = SetGradationList(gradationHeightsLabel, listHeights);
SetDefaultHeight(static_cast<int>(pattern->height()));
// set default height
{
const qint32 index = gradationHeights->findText(QString("%1").arg(static_cast<int>(pattern->height())));
if (index != -1)
{
gradationHeights->setCurrentIndex(index);
}
else
{
pattern->SetHeight(gradationHeights->currentText().toInt());
}
}
connect(gradationHeights.data(), connect(gradationHeights.data(),
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedHeight); this, &MainWindow::ChangedHeight);
gradationSizesLabel = new QLabel(tr("Size: "), this); gradationSizesLabel = new QLabel(tr("Size: "), this);
gradationSizes = SetGradationList(gradationSizesLabel, listSizes); gradationSizes = SetGradationList(gradationSizesLabel, listSizes);
SetDefaultSize(static_cast<int>(pattern->size()));
// set default size
{
const qint32 index = gradationSizes->findText(QString("%1").arg(static_cast<int>(pattern->size())));
if (index != -1)
{
gradationSizes->setCurrentIndex(index);
}
else
{
pattern->SetSize(gradationSizes->currentText().toInt());
}
}
connect(gradationSizes.data(), connect(gradationSizes.data(),
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize); this, &MainWindow::ChangedSize);
@ -1255,42 +1368,6 @@ QComboBox *MainWindow::SetGradationList(QLabel *label, const QStringList &list)
return comboBox; return comboBox;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetDefaultHeight set base height in combobox.
* @param value [in] height value in pattern units.
*/
void MainWindow::SetDefaultHeight(int value)
{
const qint32 index = gradationHeights->findText(QString("%1").arg(value));
if (index != -1)
{
gradationHeights->setCurrentIndex(index);
}
else
{
pattern->SetHeight(gradationHeights->currentText().toInt());
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetDefaultSize set base size in combobox.
* @param value [in] size value in pattern units.
*/
void MainWindow::SetDefaultSize(int value)
{
const qint32 index = gradationSizes->findText(QString("%1").arg(value));
if (index != -1)
{
gradationSizes->setCurrentIndex(index);
}
else
{
pattern->SetSize(gradationSizes->currentText().toInt());
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MainWindow::ToolBarStages() void MainWindow::ToolBarStages()
{ {
@ -2481,9 +2558,26 @@ void MainWindow::PatternWasModified(bool saved)
*/ */
void MainWindow::ChangedSize(const QString & text) void MainWindow::ChangedSize(const QString & text)
{ {
pattern->SetSize(text.toInt()); const int size = static_cast<int>(pattern->size());
if (UpdateMeasurements(AbsoluteMPath(curFile, doc->MPath()), text.toInt(), static_cast<int>(pattern->height())))
{
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
} }
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't update measurements.")));
const qint32 index = gradationSizes->findText(QString().setNum(size));
if (index != -1)
{
gradationSizes->setCurrentIndex(index);
}
else
{
qCDebug(vMainWindow, "Couldn't restore size value.");
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -2492,9 +2586,26 @@ void MainWindow::ChangedSize(const QString & text)
*/ */
void MainWindow::ChangedHeight(const QString &text) void MainWindow::ChangedHeight(const QString &text)
{ {
pattern->SetHeight(text.toInt()); const int height = static_cast<int>(pattern->height());
if (UpdateMeasurements(AbsoluteMPath(curFile, doc->MPath()), static_cast<int>(pattern->size()), text.toInt()))
{
doc->LiteParseTree(Document::LiteParse); doc->LiteParseTree(Document::LiteParse);
} }
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't update measurements.")));
const qint32 index = gradationHeights->findText(QString().setNum(height));
if (index != -1)
{
gradationHeights->setCurrentIndex(index);
}
else
{
qCDebug(vMainWindow, "Couldn't restore height value.");
}
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -3659,3 +3770,79 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams)
dialog.SelectFormate(expParams->OptExportType()); dialog.SelectFormate(expParams->OptExportType());
ExportLayout(dialog); ExportLayout(dialog);
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetSize(const QString &text)
{
if (not qApp->CheckGUI())
{
if (this->isWindowModified() || not curFile.isEmpty())
{
if (qApp->patternType() == MeasurementsType::Standard)
{
const int size = static_cast<int>(UnitConvertor(text.toInt(), Unit::Cm, *pattern->GetPatternUnit()));
const qint32 index = gradationSizes->findText(QString().setNum(size));
if (index != -1)
{
gradationSizes->setCurrentIndex(index);
}
else
{
qCWarning(vMainWindow, "%s",
qUtf8Printable(tr("Not supported size value '%1' for this pattern file.").arg(text)));
}
}
else
{
qCWarning(vMainWindow, "%s",
qUtf8Printable(tr("Couldn't set size. Need a file with standard measurements.")));
}
}
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't set size. File wasn't opened.")));
}
}
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("The method %1 does nothing in GUI mode").arg(Q_FUNC_INFO)));
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::SetHeight(const QString &text)
{
if (not qApp->CheckGUI())
{
if (this->isWindowModified() || not curFile.isEmpty())
{
if (qApp->patternType() == MeasurementsType::Standard)
{
const int height = static_cast<int>(UnitConvertor(text.toInt(), Unit::Cm, *pattern->GetPatternUnit()));
const qint32 index = gradationHeights->findText(QString().setNum(height));
if (index != -1)
{
gradationHeights->setCurrentIndex(index);
}
else
{
qCWarning(vMainWindow, "%s",
qUtf8Printable(tr("Not supported height value '%1' for this pattern file.").arg(text)));
}
}
else
{
qCWarning(vMainWindow, "%s",
qUtf8Printable(tr("Couldn't set height. Need a file with standard measurements.")));
}
}
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("Couldn't set height. File wasn't opened.")));
}
}
else
{
qCWarning(vMainWindow, "%s", qUtf8Printable(tr("The method %1 does nothing in GUI mode").arg(Q_FUNC_INFO)));
}
}

View File

@ -48,6 +48,7 @@ namespace Ui
} }
class VToolOptionsPropertyBrowser; class VToolOptionsPropertyBrowser;
class VMeasurements;
/** /**
* @brief The MainWindow class main windows. * @brief The MainWindow class main windows.
@ -58,10 +59,14 @@ class MainWindow : public MainWindowsNoGUI
public: public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
virtual ~MainWindow() Q_DECL_OVERRIDE; virtual ~MainWindow() Q_DECL_OVERRIDE;
bool LoadPattern(const QString &curFile, const QString &customMeasureFile = QString()); bool LoadPattern(const QString &curFile, const QString &customMeasureFile = QString());
void ReopenFilesAfterCrash(QStringList &args); void ReopenFilesAfterCrash(QStringList &args);
void DoExport(const VCommandLinePtr& expParams); void DoExport(const VCommandLinePtr& expParams);
void SetSize(const QString &text);
void SetHeight(const QString & text);
public slots: public slots:
void mouseMove(const QPointF &scenePos); void mouseMove(const QPointF &scenePos);
void ArrowTool(); void ArrowTool();
@ -97,9 +102,6 @@ public slots:
void currentPPChanged(int index); void currentPPChanged(int index);
void ChangedSize(const QString &text);
void ChangedHeight(const QString & text);
void PatternWasModified(bool saved); void PatternWasModified(bool saved);
void ToolEndLine(bool checked); void ToolEndLine(bool checked);
@ -170,6 +172,10 @@ private slots:
void ShowMeasurements(); void ShowMeasurements();
void MeasurementsChanged(const QString &path); void MeasurementsChanged(const QString &path);
void SyncMeasurements(); void SyncMeasurements();
void ChangedSize(const QString &text);
void ChangedHeight(const QString & text);
private: private:
Q_DISABLE_COPY(MainWindow) Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */ /** @brief ui keeps information about user interface */
@ -283,8 +289,6 @@ private:
void ZoomFirstShow(); void ZoomFirstShow();
void UpdateHeightsList(const QStringList &list); void UpdateHeightsList(const QStringList &list);
void UpdateSizesList(const QStringList &list); void UpdateSizesList(const QStringList &list);
void SetDefaultHeight(int value);
void SetDefaultSize(int value);
void AddDocks(); void AddDocks();
void PropertyBrowser(); void PropertyBrowser();
@ -297,7 +301,9 @@ 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);
void ToggleMSync(bool toggle); void ToggleMSync(bool toggle);