From 8e8422c5fdbad8260465e8a2ca5fd06e25c469d7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 11 Jun 2015 15:40:43 +0300 Subject: [PATCH] Refactoring. VContainer is more independent now. --HG-- branch : feature --- src/app/container/vcontainer.cpp | 12 ++++++------ src/app/container/vcontainer.h | 15 ++++++++++----- src/app/dialogs/app/dialogincrements.cpp | 5 +++-- src/app/dialogs/tools/dialogeditwrongformula.cpp | 6 ++++-- src/app/mainwindowsnogui.cpp | 2 +- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index bfc72a4ea..928d03c9a 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -27,10 +27,10 @@ *************************************************************************/ #include "vcontainer.h" -#include "../core/vapplication.h" #include "../libs/vgeometry/varc.h" #include "../libs/vgeometry/vsplinepath.h" #include "../../utils/logging.h" +#include "vtranslatevars.h" #include #include @@ -47,8 +47,8 @@ QSet VContainer::uniqueNames = QSet(); /** * @brief VContainer create empty container */ -VContainer::VContainer() - :d(new VContainerData) +VContainer::VContainer(const VTranslateVars *trVars) + :d(new VContainerData(trVars)) {} //--------------------------------------------------------------------------------------------------------------------- @@ -384,10 +384,10 @@ void VContainer::UpdateDetail(quint32 id, const VDetail &detail) } //--------------------------------------------------------------------------------------------------------------------- -qreal VContainer::GetTableValue(const QString &name) const +qreal VContainer::GetTableValue(const QString &name, MeasurementsType patternType) const { QSharedPointer m = GetVariable(name); - if (qApp->patternType() == MeasurementsType::Standard) + if (patternType == MeasurementsType::Standard) { m->SetValue(size(), height()); } @@ -489,7 +489,7 @@ const QMap > VContainer::DataVar(const VarType &type) if (i.value()->GetType() == type) { QSharedPointer var = GetVariable(i.key()); - map.insert(qApp->TrVars()->VarToUser(i.key()), var); + map.insert(d->trVars->VarToUser(i.key()), var); } } return map; diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index d0caf76c6..2ec693afd 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -40,6 +40,8 @@ #include #include +class VTranslateVars; + #ifdef Q_CC_GNU #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" @@ -49,14 +51,15 @@ class VContainerData : public QSharedData { public: - VContainerData() + VContainerData(const VTranslateVars *trVars) :sizeName(size_M), heightName(height_M), gObjects(QHash >()), - variables(QHash > ()), details(QHash()) + variables(QHash > ()), details(QHash()), + trVars(trVars) {} VContainerData(const VContainerData &data) :QSharedData(data), sizeName(data.sizeName), heightName(data.heightName), gObjects(data.gObjects), - variables(data.variables), details(data.details) + variables(data.variables), details(data.details), trVars(data.trVars) {} virtual ~VContainerData(); @@ -76,6 +79,8 @@ public: * @brief details container of details */ QHash details; + + const VTranslateVars *trVars; }; #ifdef Q_CC_GNU @@ -89,7 +94,7 @@ class VContainer { Q_DECLARE_TR_FUNCTIONS(VContainer) public: - VContainer(); + VContainer(const VTranslateVars *trVars); VContainer &operator=(const VContainer &data); VContainer(const VContainer &data); ~VContainer(); @@ -98,7 +103,7 @@ public: const QSharedPointer GeometricObject(const quint32 &id) const; const QSharedPointer GetGObject(quint32 id) const; const VDetail GetDetail(quint32 id) const; - qreal GetTableValue(const QString& name) const; + qreal GetTableValue(const QString& name, MeasurementsType patternType) const; template QSharedPointer GetVariable(QString name) const; static quint32 getId(); diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index d88e9e1bf..e1c0ae2ac 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -214,7 +214,8 @@ void DialogIncrements::FillMeasurements() if (qApp->patternType() == MeasurementsType::Standard) { QTableWidgetItem *item = new QTableWidgetItem(qApp->LocaleToString( - data->GetTableValue(qApp->TrVars()->VarFromUser(iMap.key())))); + data->GetTableValue(qApp->TrVars()->VarFromUser(iMap.key()), + qApp->patternType()))); item->setTextAlignment(Qt::AlignHCenter); SetItemViewOnly(item); ui->tableWidgetMeasurements->setItem(currentRow, 1, item);// calculated value @@ -286,7 +287,7 @@ void DialogIncrements::FillIncrements() if (qApp->patternType() == MeasurementsType::Standard) { - item = new QTableWidgetItem(qApp->LocaleToString(data->GetTableValue(iMap.value()))); + item = new QTableWidgetItem(qApp->LocaleToString(data->GetTableValue(iMap.value(), qApp->patternType()))); item->setTextAlignment(Qt::AlignHCenter); SetItemViewOnly(item); ui->tableWidgetIncrement->setItem(currentRow, 1, item); diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index 61769e145..c009b5819 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -137,7 +137,8 @@ void DialogEditWrongFormula::ValChenged(int row) { const QString name = qApp->TrVars()->VarFromUser(item->text()); const QSharedPointer stable = data->GetVariable(name); - const QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetTableValue(name)) + const QString desc = QString("%1(%2) - %3").arg(item->text()) + .arg(data->GetTableValue(name, qApp->patternType())) .arg(stable->GetGuiText()); ui->labelDescription->setText(desc); return; @@ -145,7 +146,8 @@ void DialogEditWrongFormula::ValChenged(int row) if (ui->radioButtonIncrements->isChecked()) { const QSharedPointer incr = data->GetVariable(item->text()); - const QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetTableValue(item->text())) + const QString desc = QString("%1(%2) - %3").arg(item->text()) + .arg(data->GetTableValue(item->text(), qApp->patternType())) .arg(incr->GetDescription()); ui->labelDescription->setText(desc); return; diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index b289d9f83..28e837907 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -57,7 +57,7 @@ //--------------------------------------------------------------------------------------------------------------------- MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer()), doc(nullptr), papers(QList()), shadows(QList()), + pattern(new VContainer(qApp->TrVars())), doc(nullptr), papers(QList()), shadows(QList()), scenes(QList()), details(QList >()), undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), isLayoutStale(true), isTiled(false) {