Fixed a bug in calculation graduation value. Values base size and heights from

file was ignored.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-25 08:41:04 +03:00
parent 5fb426c248
commit 34859e5913
12 changed files with 69 additions and 35 deletions

View File

@ -550,7 +550,7 @@ void TMainWindow::AddCustom()
VMeasurement *meash; VMeasurement *meash;
if (mType == MeasurementsType::Standard) if (mType == MeasurementsType::Standard)
{ {
meash = new VMeasurement(currentRow, name, 0, 0, 0); meash = new VMeasurement(currentRow, name, m->BaseSize(), m->BaseHeight(), 0, 0, 0);
} }
else else
{ {
@ -592,15 +592,43 @@ void TMainWindow::AddKnown()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ChangedSize(const QString &text) void TMainWindow::ChangedSize(const QString &text)
{ {
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
data->SetSize(text.toInt()); data->SetSize(text.toInt());
RefreshData(); RefreshData();
ui->tableWidget->blockSignals(true);
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ChangedHeight(const QString &text) void TMainWindow::ChangedHeight(const QString &text)
{ {
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
data->SetHeight(text.toInt()); data->SetHeight(text.toInt());
RefreshData(); RefreshData();
ui->tableWidget->blockSignals(true);
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -836,10 +864,12 @@ void TMainWindow::SaveMBaseValue(int value)
RefreshData(); RefreshData();
ui->tableWidget->blockSignals(true);
ui->tableWidget->selectRow(row); ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents(); ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents(); ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true); ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -859,10 +889,12 @@ void TMainWindow::SaveMSizeIncrease(int value)
RefreshData(); RefreshData();
ui->tableWidget->blockSignals(true);
ui->tableWidget->selectRow(row); ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents(); ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents(); ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true); ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->blockSignals(false);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1003,7 +1035,7 @@ void TMainWindow::InitWindow()
connect(ui->spinBoxBaseValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, connect(ui->spinBoxBaseValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&TMainWindow::SaveMBaseValue); &TMainWindow::SaveMBaseValue);
connect(ui->spinBoxInHeights, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, connect(ui->spinBoxInSizes, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&TMainWindow::SaveMSizeIncrease); &TMainWindow::SaveMSizeIncrease);
connect(ui->spinBoxInHeights, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, connect(ui->spinBoxInHeights, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&TMainWindow::SaveMHeightIncrease); &TMainWindow::SaveMHeightIncrease);

View File

@ -721,7 +721,7 @@ void DialogIncrements::clickedToolButtonAdd()
const quint32 id = data->getNextId(); const quint32 id = data->getNextId();
const QString description(tr("Description")); const QString description(tr("Description"));
VIncrement *incr = new VIncrement(name, id, 0, 0, 0, description); VIncrement *incr = new VIncrement(name, id, 0, description);
data->AddVariable(name, incr); data->AddVariable(name, incr);
AddIncrementToFile(id, name, 0, 0, 0, description); AddIncrementToFile(id, name, 0, 0, 0, description);

View File

@ -2164,7 +2164,7 @@ void VPattern::ParseIncrementsElement(const QDomNode &node)
const qreal kgrowth = GetParametrDouble(domElement, IncrementKgrowth, "0"); const qreal kgrowth = GetParametrDouble(domElement, IncrementKgrowth, "0");
const QString desc = GetParametrString(domElement, IncrementDescription, "Description"); const QString desc = GetParametrString(domElement, IncrementDescription, "Description");
data->UpdateId(id); data->UpdateId(id);
data->AddVariable(name, new VIncrement(name, id, base, ksize, kgrowth, desc)); data->AddVariable(name, new VIncrement(name, id, base, desc));
} }
} }
} }

View File

@ -116,7 +116,7 @@ void VStandardMeasurements::ReadMeasurement(const QDomElement &domElement, const
qWarning()<<"Standard table can't use inch unit."; qWarning()<<"Standard table can't use inch unit.";
} }
data->AddVariable(tag, new VMeasurement(0, tag, value, size_increase, height_increase, data->AddVariable(tag, new VMeasurement(0, tag, Size(), Height(), value, size_increase, height_increase,
qApp->TrVars()->GuiText(tag), qApp->TrVars()->Description(tag), tag)); qApp->TrVars()->GuiText(tag), qApp->TrVars()->Description(tag), tag));
} }

View File

@ -186,7 +186,7 @@ void VMeasurements::ReadMeasurements() const
const quint32 ksize = GetParametrUInt(dom, AttrSizeIncrease, "0"); const quint32 ksize = GetParametrUInt(dom, AttrSizeIncrease, "0");
const quint32 kheight = GetParametrUInt(dom, AttrHeightIncrease, "0"); const quint32 kheight = GetParametrUInt(dom, AttrHeightIncrease, "0");
meash = new VMeasurement(i, name, base, ksize, kheight, "", description); meash = new VMeasurement(i, name, BaseSize(), BaseHeight(), base, ksize, kheight, "", description);
} }
else else
{ {
@ -381,7 +381,7 @@ void VMeasurements::SetMBaseValue(const QString &name, int value)
QDomElement node = FindM(name); QDomElement node = FindM(name);
if (not node.isNull()) if (not node.isNull())
{ {
SetAttribute(node, AttrValue, value); SetAttribute(node, AttrBase, value);
} }
} }

View File

@ -44,13 +44,11 @@ VIncrement::VIncrement()
* @brief VIncrementTableRow create increment * @brief VIncrementTableRow create increment
* @param name increment's name * @param name increment's name
* @param id id * @param id id
* @param base value in base size and height * @param base value
* @param ksize increment in sizes
* @param kheight increment in heights
* @param description description of increment * @param description description of increment
*/ */
VIncrement::VIncrement(const QString &name, quint32 id, qreal base, qreal ksize, qreal kheight, QString description) VIncrement::VIncrement(const QString &name, quint32 id, qreal base, QString description)
:VVariable(name, base, ksize, kheight, description), d(new VIncrementData(id)) :VVariable(name, base, description), d(new VIncrementData(id))
{ {
SetType(VarType::Increment); SetType(VarType::Increment);
} }

View File

@ -40,8 +40,7 @@ class VIncrement :public VVariable
{ {
public: public:
VIncrement(); VIncrement();
VIncrement(const QString &name, quint32 id, qreal base, qreal ksize, qreal kheight, VIncrement(const QString &name, quint32 id, qreal base, QString description = QString());
QString description = QString());
VIncrement(const VIncrement &incr); VIncrement(const VIncrement &incr);
VIncrement &operator=(const VIncrement &incr); VIncrement &operator=(const VIncrement &incr);
virtual ~VIncrement() Q_DECL_OVERRIDE; virtual ~VIncrement() Q_DECL_OVERRIDE;

View File

@ -40,10 +40,11 @@
* @param description measurement full description * @param description measurement full description
* @param tagName measurement's tag name in file * @param tagName measurement's tag name in file
*/ */
VMeasurement::VMeasurement(quint32 index, const QString &name, const qreal &base, const qreal &ksize, VMeasurement::VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base,
const qreal &kheight, const qreal &ksize, const qreal &kheight, const QString &gui_text,
const QString &gui_text, const QString &description, const QString &tagName) const QString &description, const QString &tagName)
:VVariable(name, base, ksize, kheight, description), d(new VMeasurementData(index, gui_text, tagName)) :VVariable(name, baseSize, baseHeight, base, ksize, kheight, description),
d(new VMeasurementData(index, gui_text, tagName))
{ {
SetType(VarType::Measurement); SetType(VarType::Measurement);
} }

View File

@ -43,9 +43,9 @@ class VContainer;
class VMeasurement :public VVariable class VMeasurement :public VVariable
{ {
public: public:
VMeasurement(quint32 index, const QString &name, const qreal &base, const qreal &ksize, VMeasurement(quint32 index, const QString &name, qreal baseSize, qreal baseHeight, const qreal &base,
const qreal &kheight, const QString &gui_text = QString(), const QString &description = QString(), const qreal &ksize, const qreal &kheight, const QString &gui_text = QString(),
const QString &TagName = QString()); const QString &description = QString(), const QString &TagName = QString());
VMeasurement(VContainer *data, quint32 index, const QString &name, const qreal &base, const QString &formula, VMeasurement(VContainer *data, quint32 index, const QString &name, const qreal &base, const QString &formula,
bool ok, const QString &gui_text = QString(), const QString &description = QString(), bool ok, const QString &gui_text = QString(), const QString &description = QString(),
const QString &TagName = QString()); const QString &TagName = QString());

View File

@ -37,9 +37,9 @@ VVariable::VVariable()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VVariable::VVariable(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, VVariable::VVariable(const QString &name, qreal baseSize, qreal baseHeight, const qreal &base, const qreal &ksize,
const QString &description) const qreal &kheight, const QString &description)
:VInternalVariable(), d(new VVariableData(base, ksize, kheight, description)) :VInternalVariable(), d(new VVariableData(baseSize, baseHeight, base, ksize, kheight, description))
{ {
VInternalVariable::SetValue(d->base); VInternalVariable::SetValue(d->base);
SetName(name); SetName(name);
@ -82,14 +82,12 @@ void VVariable::SetValue(const qreal &size, const qreal &height, Unit patternUni
qWarning("Gradation doesn't support inches"); qWarning("Gradation doesn't support inches");
return; return;
} }
const qreal baseSize = UnitConvertor(50.0, Unit::Cm, patternUnit);
const qreal baseHeight = UnitConvertor(176.0, Unit::Cm, patternUnit);
const qreal sizeIncrement = UnitConvertor(2.0, Unit::Cm, patternUnit); const qreal sizeIncrement = UnitConvertor(2.0, Unit::Cm, patternUnit);
const qreal heightIncrement = UnitConvertor(6.0, Unit::Cm, patternUnit); const qreal heightIncrement = UnitConvertor(6.0, Unit::Cm, patternUnit);
// Formula for calculation gradation // Formula for calculation gradation
const qreal k_size = ( size - baseSize ) / sizeIncrement; const qreal k_size = ( size - d->baseSize ) / sizeIncrement;
const qreal k_height = ( height - baseHeight ) / heightIncrement; const qreal k_height = ( height - d->baseHeight ) / heightIncrement;
VInternalVariable::SetValue(d->base + k_size * d->ksize + k_height * d->kheight); VInternalVariable::SetValue(d->base + k_size * d->ksize + k_height * d->kheight);
} }

View File

@ -38,8 +38,8 @@ class VVariable :public VInternalVariable
{ {
public: public:
VVariable(); VVariable();
VVariable(const QString &name, const qreal &base, const qreal &ksize = 0, const qreal &kheight = 0, VVariable(const QString &name, qreal baseSize, qreal baseHeight, const qreal &base, const qreal &ksize = 0,
const QString &description = QString()); const qreal &kheight = 0, const QString &description = QString());
VVariable(const QString &name, const qreal &base, const QString &description = QString()); VVariable(const QString &name, const qreal &base, const QString &description = QString());
VVariable(const VVariable &var); VVariable(const VVariable &var);
VVariable &operator=(const VVariable &var); VVariable &operator=(const VVariable &var);

View File

@ -41,19 +41,22 @@ class VVariableData : public QSharedData
public: public:
VVariableData() VVariableData()
:base(0), ksize(0), kheight(0), description(QString()) :base(0), ksize(0), kheight(0), description(QString()), baseSize(0), baseHeight(0)
{} {}
VVariableData(const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description) VVariableData(qreal baseSize, qreal baseHeight, const qreal &base, const qreal &ksize, const qreal &kheight,
:base(base), ksize(ksize), kheight(kheight), description(description) const QString &description)
:base(base), ksize(ksize), kheight(kheight), description(description), baseSize(baseSize),
baseHeight(baseHeight)
{} {}
VVariableData(const qreal &base, const QString &description) VVariableData(const qreal &base, const QString &description)
:base(base), ksize(0), kheight(0), description(description) :base(base), ksize(0), kheight(0), description(description), baseSize(0), baseHeight(0)
{} {}
VVariableData(const VVariableData &var) VVariableData(const VVariableData &var)
:QSharedData(var), base(var.base), ksize(var.ksize), kheight(var.kheight), description(var.description) :QSharedData(var), base(var.base), ksize(var.ksize), kheight(var.kheight), description(var.description),
baseSize(var.baseSize), baseHeight(var.baseHeight)
{} {}
virtual ~VVariableData(); virtual ~VVariableData();
@ -69,6 +72,9 @@ public:
/** @brief description description of increment */ /** @brief description description of increment */
QString description; QString description;
qreal baseSize;
qreal baseHeight;
}; };
VVariableData::~VVariableData() VVariableData::~VVariableData()