Refactoring. VContainer is more independent now.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-06-11 15:40:43 +03:00
parent 4c7033492a
commit 8e8422c5fd
5 changed files with 24 additions and 16 deletions

View File

@ -27,10 +27,10 @@
*************************************************************************/ *************************************************************************/
#include "vcontainer.h" #include "vcontainer.h"
#include "../core/vapplication.h"
#include "../libs/vgeometry/varc.h" #include "../libs/vgeometry/varc.h"
#include "../libs/vgeometry/vsplinepath.h" #include "../libs/vgeometry/vsplinepath.h"
#include "../../utils/logging.h" #include "../../utils/logging.h"
#include "vtranslatevars.h"
#include <QLineF> #include <QLineF>
#include <QtAlgorithms> #include <QtAlgorithms>
@ -47,8 +47,8 @@ QSet<const QString> VContainer::uniqueNames = QSet<const QString>();
/** /**
* @brief VContainer create empty container * @brief VContainer create empty container
*/ */
VContainer::VContainer() VContainer::VContainer(const VTranslateVars *trVars)
:d(new VContainerData) :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<VVariable> m = GetVariable<VVariable>(name); QSharedPointer<VVariable> m = GetVariable<VVariable>(name);
if (qApp->patternType() == MeasurementsType::Standard) if (patternType == MeasurementsType::Standard)
{ {
m->SetValue(size(), height()); m->SetValue(size(), height());
} }
@ -489,7 +489,7 @@ const QMap<QString, QSharedPointer<T> > VContainer::DataVar(const VarType &type)
if (i.value()->GetType() == type) if (i.value()->GetType() == type)
{ {
QSharedPointer<T> var = GetVariable<T>(i.key()); QSharedPointer<T> var = GetVariable<T>(i.key());
map.insert(qApp->TrVars()->VarToUser(i.key()), var); map.insert(d->trVars->VarToUser(i.key()), var);
} }
} }
return map; return map;

View File

@ -40,6 +40,8 @@
#include <QSet> #include <QSet>
#include <QSharedPointer> #include <QSharedPointer>
class VTranslateVars;
#ifdef Q_CC_GNU #ifdef Q_CC_GNU
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Weffc++"
@ -49,14 +51,15 @@ class VContainerData : public QSharedData
{ {
public: public:
VContainerData() VContainerData(const VTranslateVars *trVars)
:sizeName(size_M), heightName(height_M), gObjects(QHash<quint32, QSharedPointer<VGObject> >()), :sizeName(size_M), heightName(height_M), gObjects(QHash<quint32, QSharedPointer<VGObject> >()),
variables(QHash<QString, QSharedPointer<VInternalVariable> > ()), details(QHash<quint32, VDetail>()) variables(QHash<QString, QSharedPointer<VInternalVariable> > ()), details(QHash<quint32, VDetail>()),
trVars(trVars)
{} {}
VContainerData(const VContainerData &data) VContainerData(const VContainerData &data)
:QSharedData(data), sizeName(data.sizeName), heightName(data.heightName), gObjects(data.gObjects), :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(); virtual ~VContainerData();
@ -76,6 +79,8 @@ public:
* @brief details container of details * @brief details container of details
*/ */
QHash<quint32, VDetail> details; QHash<quint32, VDetail> details;
const VTranslateVars *trVars;
}; };
#ifdef Q_CC_GNU #ifdef Q_CC_GNU
@ -89,7 +94,7 @@ class VContainer
{ {
Q_DECLARE_TR_FUNCTIONS(VContainer) Q_DECLARE_TR_FUNCTIONS(VContainer)
public: public:
VContainer(); VContainer(const VTranslateVars *trVars);
VContainer &operator=(const VContainer &data); VContainer &operator=(const VContainer &data);
VContainer(const VContainer &data); VContainer(const VContainer &data);
~VContainer(); ~VContainer();
@ -98,7 +103,7 @@ public:
const QSharedPointer<T> GeometricObject(const quint32 &id) const; const QSharedPointer<T> GeometricObject(const quint32 &id) const;
const QSharedPointer<VGObject> GetGObject(quint32 id) const; const QSharedPointer<VGObject> GetGObject(quint32 id) const;
const VDetail GetDetail(quint32 id) const; const VDetail GetDetail(quint32 id) const;
qreal GetTableValue(const QString& name) const; qreal GetTableValue(const QString& name, MeasurementsType patternType) const;
template <typename T> template <typename T>
QSharedPointer<T> GetVariable(QString name) const; QSharedPointer<T> GetVariable(QString name) const;
static quint32 getId(); static quint32 getId();

View File

@ -214,7 +214,8 @@ void DialogIncrements::FillMeasurements()
if (qApp->patternType() == MeasurementsType::Standard) if (qApp->patternType() == MeasurementsType::Standard)
{ {
QTableWidgetItem *item = new QTableWidgetItem(qApp->LocaleToString( 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); item->setTextAlignment(Qt::AlignHCenter);
SetItemViewOnly(item); SetItemViewOnly(item);
ui->tableWidgetMeasurements->setItem(currentRow, 1, item);// calculated value ui->tableWidgetMeasurements->setItem(currentRow, 1, item);// calculated value
@ -286,7 +287,7 @@ void DialogIncrements::FillIncrements()
if (qApp->patternType() == MeasurementsType::Standard) 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); item->setTextAlignment(Qt::AlignHCenter);
SetItemViewOnly(item); SetItemViewOnly(item);
ui->tableWidgetIncrement->setItem(currentRow, 1, item); ui->tableWidgetIncrement->setItem(currentRow, 1, item);

View File

@ -137,7 +137,8 @@ void DialogEditWrongFormula::ValChenged(int row)
{ {
const QString name = qApp->TrVars()->VarFromUser(item->text()); const QString name = qApp->TrVars()->VarFromUser(item->text());
const QSharedPointer<VMeasurement> stable = data->GetVariable<VMeasurement>(name); const QSharedPointer<VMeasurement> stable = data->GetVariable<VMeasurement>(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()); .arg(stable->GetGuiText());
ui->labelDescription->setText(desc); ui->labelDescription->setText(desc);
return; return;
@ -145,7 +146,8 @@ void DialogEditWrongFormula::ValChenged(int row)
if (ui->radioButtonIncrements->isChecked()) if (ui->radioButtonIncrements->isChecked())
{ {
const QSharedPointer<VIncrement> incr = data->GetVariable<VIncrement>(item->text()); const QSharedPointer<VIncrement> incr = data->GetVariable<VIncrement>(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()); .arg(incr->GetDescription());
ui->labelDescription->setText(desc); ui->labelDescription->setText(desc);
return; return;

View File

@ -57,7 +57,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
: QMainWindow(parent), listDetails(QVector<VLayoutDetail>()), currentScene(nullptr), tempSceneLayout(nullptr), : QMainWindow(parent), listDetails(QVector<VLayoutDetail>()), currentScene(nullptr), tempSceneLayout(nullptr),
pattern(new VContainer()), doc(nullptr), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()), pattern(new VContainer(qApp->TrVars())), doc(nullptr), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()), undoAction(nullptr), scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()), undoAction(nullptr),
redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), isLayoutStale(true), isTiled(false) redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), isLayoutStale(true), isTiled(false)
{ {