Refactoring. Better support units - conversion (cm and mm). Standard table

doesn't support inches anymore.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-09 15:23:04 +03:00
parent c1319d8da7
commit f8d304e7fc
17 changed files with 432 additions and 275 deletions

View File

@ -2,10 +2,12 @@ SOURCES += \
container/vcontainer.cpp \ container/vcontainer.cpp \
container/calculator.cpp \ container/calculator.cpp \
container/vmeasurement.cpp \ container/vmeasurement.cpp \
container/vincrement.cpp container/vincrement.cpp \
container/vvariable.cpp
HEADERS += \ HEADERS += \
container/vcontainer.h \ container/vcontainer.h \
container/calculator.h \ container/calculator.h \
container/vmeasurement.h \ container/vmeasurement.h \
container/vincrement.h container/vincrement.h \
container/vvariable.h

View File

@ -33,49 +33,35 @@
* @brief VIncrement create enpty increment * @brief VIncrement create enpty increment
*/ */
VIncrement::VIncrement() VIncrement::VIncrement()
:id(0), base(0), ksize(50.0), kheight(176.0), description(QString()) :VVariable(), id(0)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VIncrementTableRow create increment * @brief VIncrementTableRow create increment
* @param id id * @param id id
* @param base value in base size and growth * @param base value in base size and height
* @param ksize increment in sizes * @param ksize increment in sizes
* @param kheight increment in heights * @param kheight increment in heights
* @param description description of increment * @param description description of increment
*/ */
VIncrement::VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description) VIncrement::VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description)
:id(id), base(base), ksize(ksize), kheight(kheight), description(description) :VVariable(base, ksize, kheight, description), id(id)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VIncrement::VIncrement(const VIncrement &incr) VIncrement::VIncrement(const VIncrement &incr)
:id(incr.getId()), base(incr.getBase()), ksize(incr.getKsize()), kheight(incr.getKheight()), :VVariable(incr), id(incr.getId())
description(incr.getDescription())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VIncrement &VIncrement::operator=(const VIncrement &incr) VIncrement &VIncrement::operator=(const VIncrement &incr)
{ {
VVariable::operator=(incr);
this->id = incr.getId(); this->id = incr.getId();
this->base = incr.getBase();
this->ksize = incr.getKsize();
this->kheight = incr.getKheight();
this->description = incr.getDescription();
return *this; return *this;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VIncrement::GetValue() const VIncrement::~VIncrement()
{ {}
return base;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VIncrement::GetValue(const qreal &size, const qreal &height) const
{
const qreal k_size = ( size - 50.0 ) / 2.0;
const qreal k_height = ( height - 176.0 ) / 6.0;
return base + k_size * ksize + k_height * kheight;
}

View File

@ -29,45 +29,29 @@
#ifndef VINCREMENTTABLEROW_H #ifndef VINCREMENTTABLEROW_H
#define VINCREMENTTABLEROW_H #define VINCREMENTTABLEROW_H
#include "vvariable.h"
#include <QString> #include <QString>
/** /**
* @brief The VIncrement class keep data row of increment table * @brief The VIncrement class keep data row of increment table
*/ */
class VIncrement class VIncrement :public VVariable
{ {
public: public:
VIncrement(); VIncrement();
VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description = QString()); VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description = QString());
VIncrement(const VIncrement &incr); VIncrement(const VIncrement &incr);
VIncrement &operator=(const VIncrement &incr); VIncrement &operator=(const VIncrement &incr);
virtual ~VIncrement();
quint32 getId() const; quint32 getId() const;
void setId(const quint32 &value); void setId(const quint32 &value);
qreal getBase() const;
void setBase(const qreal &value);
qreal getKsize() const;
void setKsize(const qreal &value); void setKsize(const qreal &value);
qreal getKheight() const;
void setKheight(const qreal &value); void setKheight(const qreal &value);
QString getDescription() const;
void setDescription(const QString &value); void setDescription(const QString &value);
qreal GetValue() const;
qreal GetValue(const qreal &size, const qreal &height) const;
private: private:
/** @brief id identificator */ /** @brief id identificator */
quint32 id; quint32 id;
/** @brief base value in base size and height */
qreal base;
/** @brief ksize increment in sizes */
qreal ksize;
/** @brief kgrowth increment in growths */
qreal kheight;
/** @brief description description of increment */
QString description;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -90,36 +74,6 @@ inline void VIncrement::setId(const quint32 &value)
id = value; id = value;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getBase return value in base size and growth
* @return value
*/
inline qreal VIncrement::getBase() const
{
return base;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief setBase set value in base size and growth
* @param value base value
*/
inline void VIncrement::setBase(const qreal &value)
{
base = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getKsize return increment in sizes
* @return increment
*/
inline qreal VIncrement::getKsize() const
{
return ksize;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setKsize set increment in sizes * @brief setKsize set increment in sizes
@ -130,16 +84,6 @@ inline void VIncrement::setKsize(const qreal &value)
ksize = value; ksize = value;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getKheight return increment in growths
* @return increment
*/
inline qreal VIncrement::getKheight() const
{
return kheight;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setKheight set increment in growths * @brief setKheight set increment in growths
@ -150,16 +94,6 @@ inline void VIncrement::setKheight(const qreal &value)
kheight = value; kheight = value;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getDescription return description
* @return description
*/
inline QString VIncrement::getDescription() const
{
return description;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief setDescription set description for row * @brief setDescription set description for row

View File

@ -27,19 +27,21 @@
*************************************************************************/ *************************************************************************/
#include "vmeasurement.h" #include "vmeasurement.h"
#include "../widgets/vapplication.h"
#include "../xml/vabstractmeasurements.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VMeasurement create empty measurement * @brief VMeasurement create empty measurement
*/ */
VMeasurement::VMeasurement() VMeasurement::VMeasurement()
:base(0), ksize(50.0), kheight(176.0), gui_text(QString()), description(QString()), _tagName(QString()) :VVariable(), gui_text(QString()), _tagName(QString())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VMeasurement create measurement for standard table * @brief VMeasurement create measurement for standard table
* @param base value in base size and growth * @param base value in base size and height
* @param ksize increment in sizes * @param ksize increment in sizes
* @param kheight increment in heights * @param kheight increment in heights
* @param gui_text shor tooltip for user * @param gui_text shor tooltip for user
@ -48,44 +50,78 @@ VMeasurement::VMeasurement()
*/ */
VMeasurement::VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight, VMeasurement::VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight,
const QString &gui_text, const QString &description, const QString &tagName) const QString &gui_text, const QString &description, const QString &tagName)
:base(base), ksize(ksize), kheight(kheight), gui_text(gui_text), description(description), _tagName(tagName) :VVariable(base, ksize, kheight, description), gui_text(gui_text), _tagName(tagName)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief VMeasurement create measurement for individual table * @brief VMeasurement create measurement for individual table
* @param base value in base size and growth * @param base value in base size and height
* @param gui_text shor tooltip for user * @param gui_text shor tooltip for user
* @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(const qreal &base, const QString &gui_text, const QString &description, VMeasurement::VMeasurement(const qreal &base, const QString &gui_text, const QString &description,
const QString &tagName) const QString &tagName)
:base(base), ksize(50.0), kheight(176.0), gui_text(gui_text), description(description), _tagName(tagName) :VVariable(base, description), gui_text(gui_text), _tagName(tagName)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VMeasurement::VMeasurement(const VMeasurement &m) VMeasurement::VMeasurement(const VMeasurement &m)
:base(m.GetBase()), ksize(m.GetKsize()), kheight(m.GetKheight()), gui_text(m.GetGuiText()), :VVariable(m), gui_text(m.GetGuiText()), _tagName(m.TagName())
description(m.GetDescription()), _tagName(m.TagName())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VMeasurement &VMeasurement::operator=(const VMeasurement &m) VMeasurement &VMeasurement::operator=(const VMeasurement &m)
{ {
this->base = m.GetBase(); VVariable::operator=(m);
this->ksize = m.GetKsize();
this->kheight = m.GetKheight();
this->gui_text = m.GetGuiText(); this->gui_text = m.GetGuiText();
this->description = m.GetDescription();
this->_tagName = m.TagName(); this->_tagName = m.TagName();
return *this; return *this;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VMeasurement::GetValue(const qreal &size, const qreal &height) const VMeasurement::~VMeasurement()
{}
//---------------------------------------------------------------------------------------------------------------------
QStringList VMeasurement::ListHeights()
{ {
const qreal k_size = ( size - 50.0 ) / 2.0; if (qApp->patternUnit() == Unit::Inch)
const qreal k_height = ( height - 176.0 ) / 6.0; {
return base + k_size * ksize + k_height * kheight; qWarning()<<"Standard table doesn't support inches.";
}
QStringList list;
// from 92 cm to 188 cm
for (int i = 92; i<= 188; i = i+6)
{
ListValue(list, i);
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VMeasurement::ListSizes()
{
if (qApp->patternUnit() == Unit::Inch)
{
qWarning()<<"Standard table doesn't support inches.";
}
QStringList list;
// from 22 cm to 56 cm
for (int i = 22; i<= 56; i = i+2)
{
ListValue(list, i);
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurement::ListValue(QStringList &list, qreal value)
{
qreal val = VAbstractMeasurements::UnitConvertor(value, Unit::Cm, qApp->patternUnit());
QString strVal = QString("%1").arg(val);
list.append(strVal);
} }

View File

@ -29,12 +29,13 @@
#ifndef VSTANDARDTABLEROW_H #ifndef VSTANDARDTABLEROW_H
#define VSTANDARDTABLEROW_H #define VSTANDARDTABLEROW_H
#include "vvariable.h"
#include <QString> #include <QString>
/** /**
* @brief The VMeasurement class keep data row of standard table * @brief The VMeasurement class keep data row of standard table
*/ */
class VMeasurement class VMeasurement :public VVariable
{ {
public: public:
VMeasurement(); VMeasurement();
@ -45,70 +46,21 @@ public:
const QString &description = QString(), const QString &TagName = QString()); const QString &description = QString(), const QString &TagName = QString());
VMeasurement(const VMeasurement &m); VMeasurement(const VMeasurement &m);
VMeasurement &operator=(const VMeasurement &m); VMeasurement &operator=(const VMeasurement &m);
~VMeasurement(){} virtual ~VMeasurement();
qreal GetBase() const;
void setBase(const qreal &value); QString GetGuiText() const;
qreal GetKsize() const; QString TagName() const;
qreal GetKheight() const; void setTagName(const QString &TagName);
QString GetGuiText() const; static QStringList ListHeights();
QString GetDescription() const; static QStringList ListSizes();
qreal GetValue() const;
qreal GetValue(const qreal &size, const qreal &height) const;
QString TagName() const;
void setTagName(const QString &TagName);
private: private:
/** @brief base value in base size and growth */
qreal base;
/** @brief ksize increment in sizes */
qreal ksize;
/** @brief kgrowth increment in growths */
qreal kheight;
/** @brief description description measurement */ /** @brief description description measurement */
QString gui_text; QString gui_text;
QString description;
QString _tagName; QString _tagName;
static void ListValue(QStringList &list, qreal value);
}; };
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetBase return value in base size and growth
* @return value
*/
inline qreal VMeasurement::GetBase() const
{
return base;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VMeasurement::setBase(const qreal &value)
{
base = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKsize return increment in sizes
* @return increment
*/
inline qreal VMeasurement::GetKsize() const
{
return ksize;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKheight return increment in heights
* @return increment
*/
inline qreal VMeasurement::GetKheight() const
{
return kheight;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetGuiText measurement name for tooltip * @brief GetGuiText measurement name for tooltip
@ -119,18 +71,6 @@ inline QString VMeasurement::GetGuiText() const
return gui_text; return gui_text;
} }
//---------------------------------------------------------------------------------------------------------------------
inline QString VMeasurement::GetDescription() const
{
return description;
}
//---------------------------------------------------------------------------------------------------------------------
inline qreal VMeasurement::GetValue() const
{
return base;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
inline QString VMeasurement::TagName() const inline QString VMeasurement::TagName() const
{ {

View File

@ -0,0 +1,100 @@
/************************************************************************
**
** @file vvariable.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 9 7, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vvariable.h"
#include "../widgets/vapplication.h"
#include "../xml/vabstractmeasurements.h"
//---------------------------------------------------------------------------------------------------------------------
VVariable::VVariable()
:base(0), ksize(0), kheight(0), description(QString())
{
Init();
}
//---------------------------------------------------------------------------------------------------------------------
VVariable::VVariable(const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description)
:base(base), ksize(ksize), kheight(kheight), description(description)
{}
//---------------------------------------------------------------------------------------------------------------------
VVariable::VVariable(const qreal &base, const QString &description)
:base(base), ksize(0), kheight(0), description(description)
{
Init();
}
//---------------------------------------------------------------------------------------------------------------------
VVariable::VVariable(const VVariable &var)
:base(var.GetBase()), ksize(var.GetKsize()), kheight(var.GetKheight()), description(var.GetDescription())
{}
//---------------------------------------------------------------------------------------------------------------------
VVariable &VVariable::operator=(const VVariable &var)
{
this->base = var.GetBase();
this->ksize = var.GetKsize();
this->kheight = var.GetKheight();
this->description = var.GetDescription();
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
VVariable::~VVariable()
{}
//---------------------------------------------------------------------------------------------------------------------
qreal VVariable::GetValue(const qreal &size, const qreal &height) const
{
if (qApp->patternUnit() != Unit::Inch)
{
const qreal baseSize = VAbstractMeasurements::UnitConvertor(50.0, Unit::Cm, qApp->patternUnit());
const qreal baseHeight = VAbstractMeasurements::UnitConvertor(176.0, Unit::Cm, qApp->patternUnit());
const qreal sizeIncrement = VAbstractMeasurements::UnitConvertor(2.0, Unit::Cm, qApp->patternUnit());
const qreal heightIncrement = VAbstractMeasurements::UnitConvertor(6.0, Unit::Cm, qApp->patternUnit());
// Formula for calculation gradation
const qreal k_size = ( size - baseSize ) / sizeIncrement;
const qreal k_height = ( height - baseHeight ) / heightIncrement;
return base + k_size * ksize + k_height * kheight;
}
else// Must not be reached!!!!
{
return base;
}
}
//---------------------------------------------------------------------------------------------------------------------
void VVariable::Init()
{
if (qApp->patternUnit() != Unit::Inch)
{
ksize = VAbstractMeasurements::UnitConvertor(50.0, Unit::Cm, qApp->patternUnit());
kheight = VAbstractMeasurements::UnitConvertor(176.0, Unit::Cm, qApp->patternUnit());
}
}

View File

@ -0,0 +1,115 @@
/************************************************************************
**
** @file vvariable.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 9 7, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VVARIABLE_H
#define VVARIABLE_H
#include <QString>
class VVariable
{
public:
VVariable();
VVariable(const qreal &base, const qreal &ksize, const qreal &kheight, const QString &description = QString());
VVariable(const qreal &base, const QString &description = QString());
VVariable(const VVariable &var);
VVariable &operator=(const VVariable &var);
virtual ~VVariable();
qreal GetBase() const;
void SetBase(const qreal &value);
qreal GetKsize() const;
qreal GetKheight() const;
QString GetDescription() const;
qreal GetValue() const;
qreal GetValue(const qreal &size, const qreal &height) const;
protected:
/** @brief base value in base size and height */
qreal base;
/** @brief ksize increment in sizes */
qreal ksize;
/** @brief kgrowth increment in heights */
qreal kheight;
/** @brief description description of increment */
QString description;
private:
void Init();
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetBase return value in base size and height
* @return value
*/
inline qreal VVariable::GetBase() const
{
return base;
}
//---------------------------------------------------------------------------------------------------------------------
inline void VVariable::SetBase(const qreal &value)
{
base = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKsize return increment in sizes
* @return increment
*/
inline qreal VVariable::GetKsize() const
{
return ksize;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKheight return increment in heights
* @return increment
*/
inline qreal VVariable::GetKheight() const
{
return kheight;
}
//---------------------------------------------------------------------------------------------------------------------
inline QString VVariable::GetDescription() const
{
return description;
}
//---------------------------------------------------------------------------------------------------------------------
inline qreal VVariable::GetValue() const
{
return base;
}
#endif // VVARIABLE_H

View File

@ -268,22 +268,22 @@ void DialogIncrements::FillIncrements()
ui->tableWidgetIncrement->setItem(currentRow, 1, item); ui->tableWidgetIncrement->setItem(currentRow, 1, item);
} }
item = new QTableWidgetItem(QString().setNum(incr.getBase())); item = new QTableWidgetItem(QString().setNum(incr.GetBase()));
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 2, item); ui->tableWidgetIncrement->setItem(currentRow, 2, item);
if (qApp->patternType() == MeasurementsType::Standard) if (qApp->patternType() == MeasurementsType::Standard)
{ {
item = new QTableWidgetItem(QString().setNum(incr.getKsize())); item = new QTableWidgetItem(QString().setNum(incr.GetKsize()));
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 3, item); ui->tableWidgetIncrement->setItem(currentRow, 3, item);
item = new QTableWidgetItem(QString().setNum(incr.getKheight())); item = new QTableWidgetItem(QString().setNum(incr.GetKheight()));
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
ui->tableWidgetIncrement->setItem(currentRow, 4, item); ui->tableWidgetIncrement->setItem(currentRow, 4, item);
} }
item = new QTableWidgetItem(incr.getDescription()); item = new QTableWidgetItem(incr.GetDescription());
item->setTextAlignment(Qt::AlignLeft); item->setTextAlignment(Qt::AlignLeft);
ui->tableWidgetIncrement->setItem(currentRow, 5, item); ui->tableWidgetIncrement->setItem(currentRow, 5, item);
} }
@ -734,13 +734,13 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column)
const qreal base = item->text().replace(",", ".").toDouble(&ok); const qreal base = item->text().replace(",", ".").toDouble(&ok);
if (ok == false) if (ok == false)
{ {
measur.setBase(0); measur.SetBase(0);
item->setText("0"); item->setText("0");
qDebug()<<"Can't convert toDouble measurement value"<<Q_FUNC_INFO; qDebug()<<"Can't convert toDouble measurement value"<<Q_FUNC_INFO;
} }
else else
{ {
measur.setBase(base); measur.SetBase(base);
} }
data->ClearMeasurements(); data->ClearMeasurements();
m->Measurements(); m->Measurements();

View File

@ -163,7 +163,14 @@ void DialogStandardMeasurements::LoadStandardTables()
VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath()); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath());
VStandardMeasurements m(data); VStandardMeasurements m(data);
m.setContent(fi.absoluteFilePath()); m.setContent(fi.absoluteFilePath());
ui->comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath())); if (m.MUnit() == Unit::Inch)
{
qWarning()<<"We do not support inches for standard table. Ignore table"<<fi.absoluteFilePath()<<".";
}
else
{
ui->comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath()));
}
} }
catch (VException &e) catch (VException &e)
{ {

View File

@ -961,7 +961,7 @@ void DialogTool::ValChenged(int row)
{ {
VIncrement incr = data->GetIncrement(item->text()); VIncrement incr = data->GetIncrement(item->text());
QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text())) QString desc = QString("%1(%2) - %3").arg(item->text()).arg(data->GetValueIncrementTableRow(item->text()))
.arg(incr.getDescription()); .arg(incr.GetDescription());
labelDescription->setText(desc); labelDescription->setText(desc);
return; return;
} }

View File

@ -169,6 +169,7 @@ void MainWindow::ActionNewPP()
//Set scene size to size scene view //Set scene size to size scene view
VAbstractTool::NewSceneRect(sceneDraw, view); VAbstractTool::NewSceneRect(sceneDraw, view);
VAbstractTool::NewSceneRect(sceneDetails, view); VAbstractTool::NewSceneRect(sceneDetails, view);
ToolBarOption();
} }
else else
{ {
@ -993,36 +994,33 @@ void MainWindow::ToolBarOption()
{ {
if (qApp->patternType() == MeasurementsType::Standard) if (qApp->patternType() == MeasurementsType::Standard)
{ {
ui->toolBarOption->addWidget(new QLabel(tr("Height: "))); const QStringList listHeights = VMeasurement::ListHeights();
const QStringList listSizes = VMeasurement::ListSizes();
QStringList list{"92", "98", "104", "110", "116", "122", "128", "134", "140", "146", "152", "158", "164", "170", SetGradationList(tr("Height: "), listHeights, &MainWindow::ChangedHeight);
"176", "182", "188"}; SetGradationList(tr("Size: "), listSizes, &MainWindow::ChangedSize);
QComboBox *comboBoxHeight = new QComboBox;
comboBoxHeight->addItems(list);
comboBoxHeight->setCurrentIndex(14);//176
ui->toolBarOption->addWidget(comboBoxHeight);
connect(comboBoxHeight, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedHeight);
ui->toolBarOption->addWidget(new QLabel(tr(" Size: ")));
list.clear();
list <<"22"<<"24"<<"26"<<"28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50"<<"52"<<"54"
<<"56";
QComboBox *comboBoxSize = new QComboBox;
comboBoxSize->addItems(list);
comboBoxSize->setCurrentIndex(14);//50
ui->toolBarOption->addWidget(comboBoxSize);
connect(comboBoxSize, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &MainWindow::ChangedSize);
ui->toolBarOption->addSeparator(); ui->toolBarOption->addSeparator();
} }
mouseCoordinate = new QLabel("0, 0"); mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(doc->UnitsToStr(qApp->patternUnit())));
ui->toolBarOption->addWidget(mouseCoordinate); ui->toolBarOption->addWidget(mouseCoordinate);
} }
//---------------------------------------------------------------------------------------------------------------------
template <typename Func>
void MainWindow::SetGradationList(const QString &label, const QStringList &list, Func changeSlot)
{
ui->toolBarOption->addWidget(new QLabel(label));
QComboBox *comboBox = new QComboBox;
comboBox->addItems(list);
comboBox->setCurrentIndex(14);//176 cm
ui->toolBarOption->addWidget(comboBox);
connect(comboBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, changeSlot);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief ToolBarDraws enable draw toolbar. * @brief ToolBarDraws enable draw toolbar.
@ -1126,8 +1124,9 @@ void MainWindow::currentDrawChanged( int index )
*/ */
void MainWindow::mouseMove(const QPointF &scenePos) void MainWindow::mouseMove(const QPointF &scenePos)
{ {
QString string = QString("%1, %2").arg(static_cast<qint32>(qApp->fromPixel(scenePos.x()))) QString string = QString("%1, %2 (%3)").arg(static_cast<qint32>(qApp->fromPixel(scenePos.x())))
.arg(static_cast<qint32>(qApp->fromPixel(scenePos.y()))); .arg(static_cast<qint32>(qApp->fromPixel(scenePos.y())))
.arg(doc->UnitsToStr(qApp->patternUnit()));
if (mouseCoordinate != nullptr) if (mouseCoordinate != nullptr)
{ {
mouseCoordinate->setText(string); mouseCoordinate->setText(string);
@ -2226,7 +2225,6 @@ void MainWindow::LoadPattern(const QString &fileName)
} }
m.SetSize(); m.SetSize();
m.SetHeight(); m.SetHeight();
ToolBarOption();
} }
else else
{ {
@ -2240,6 +2238,7 @@ void MainWindow::LoadPattern(const QString &fileName)
return; return;
} }
} }
ToolBarOption();
} }
catch (VException &e) catch (VException &e)
{ {

View File

@ -255,6 +255,8 @@ private:
QString PatternPieceName(const QString &text); QString PatternPieceName(const QString &text);
QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType); QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType);
void OpenPattern(const QString &filePath); void OpenPattern(const QString &filePath);
template <typename Func>
void SetGradationList(const QString &label, const QStringList &list, Func changeSlot);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -195,6 +195,56 @@ Unit VAbstractMeasurements::MUnit() const
return VDomDocument::StrToUnits(unit); return VDomDocument::StrToUnits(unit);
} }
//---------------------------------------------------------------------------------------------------------------------
qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const Unit &to)
{
switch (from)
{
case Unit::Mm:
switch(to)
{
case Unit::Mm:
return value;
case Unit::Cm:
return value / 10.0;
case Unit::Inch:
return value / 25.4;
default:
break;
}
break;
case Unit::Cm:
switch(to)
{
case Unit::Mm:
return value * 10.0;
case Unit::Cm:
return value;
case Unit::Inch:
return value / 2.54;
default:
break;
}
break;
case Unit::Inch:
switch(to)
{
case Unit::Mm:
return value * 25.4;
case Unit::Cm:
return value * 2.54;
case Unit::Inch:
return value;
default:
break;
}
break;
default:
break;
}
return 0;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VAbstractMeasurements::Measurement(const QString &tag) void VAbstractMeasurements::Measurement(const QString &tag)
{ {

View File

@ -40,6 +40,7 @@ public:
Unit MUnit() const; Unit MUnit() const;
static const QString TagUnit; static const QString TagUnit;
static const QString AttrValue; static const QString AttrValue;
static qreal UnitConvertor(qreal value, const Unit &from, const Unit &to);
protected: protected:
void Measurement(const QString &tag); void Measurement(const QString &tag);
virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag) = 0; virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag) = 0;

View File

@ -69,11 +69,7 @@ void VIndividualMeasurements::Measurements()
void VIndividualMeasurements::ReadMeasurement(const QDomElement &domElement, const QString &tag) void VIndividualMeasurements::ReadMeasurement(const QDomElement &domElement, const QString &tag)
{ {
qreal value = GetParametrDouble(domElement, AttrValue, "0.0"); qreal value = GetParametrDouble(domElement, AttrValue, "0.0");
value = UnitConvertor(value, MUnit(), qApp->patternUnit());
if (MUnit() == Unit::Mm)//Convert to Cm.
{
value = value / 10.0;
}
data->AddMeasurement(tag, VMeasurement(value, qApp->GuiText(tag), qApp->Description(tag), tag)); data->AddMeasurement(tag, VMeasurement(value, qApp->GuiText(tag), qApp->Description(tag), tag));
} }

View File

@ -53,7 +53,7 @@ QString VStandardMeasurements::Description()
const QString desc = UniqueTagText(TagDescription, ""); const QString desc = UniqueTagText(TagDescription, "");
if (desc.isEmpty()) if (desc.isEmpty())
{ {
qDebug()<<"Empty description in standard table."<<Q_FUNC_INFO; qWarning()<<"Empty description in standard table."<<Q_FUNC_INFO;
} }
return desc; return desc;
} }
@ -61,76 +61,64 @@ QString VStandardMeasurements::Description()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VStandardMeasurements::ReadMeasurement(const QDomElement &domElement, const QString &tag) void VStandardMeasurements::ReadMeasurement(const QDomElement &domElement, const QString &tag)
{ {
const qreal value = GetParametrDouble(domElement, AttrValue, "0.0"); qreal value = GetParametrDouble(domElement, AttrValue, "0.0");
const qreal size_increase = GetParametrDouble(domElement, AttrSize_increase, "0.0"); value = UnitConvertor(value, MUnit(), qApp->patternUnit());
const qreal height_increase = GetParametrDouble(domElement, AttrHeight_increase, "0.0");
if (MUnit() == Unit::Mm)// Convert to Cm. qreal size_increase = GetParametrDouble(domElement, AttrSize_increase, "0.0");
size_increase = UnitConvertor(size_increase, MUnit(), qApp->patternUnit());
qreal height_increase = GetParametrDouble(domElement, AttrHeight_increase, "0.0");
height_increase = UnitConvertor(height_increase, MUnit(), qApp->patternUnit());
if (MUnit() == Unit::Inch)
{ {
data->AddMeasurement(tag, VMeasurement(value/10.0, size_increase/10.0, height_increase/10.0, qWarning()<<"Standard table can't use inch unit.";
qApp->GuiText(tag), qApp->Description(tag), tag));
} }
else// Cm or inch.
data->AddMeasurement(tag, VMeasurement(value, size_increase, height_increase, qApp->GuiText(tag),
qApp->Description(tag), tag));
}
//---------------------------------------------------------------------------------------------------------------------
qreal VStandardMeasurements::TakeParametr(const QString &tag, qreal defValue) const
{
const qreal defVal = UnitConvertor(defValue, Unit::Cm, qApp->patternUnit());
const QDomNodeList nodeList = this->elementsByTagName(tag);
if (nodeList.isEmpty())
{ {
data->AddMeasurement(tag, VMeasurement(value, size_increase, height_increase, qApp->GuiText(tag), return defVal;
qApp->Description(tag), tag));
} }
else
{
const QDomNode domNode = nodeList.at(0);
if (domNode.isNull() == false && domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
qreal value = GetParametrDouble(domElement, AttrValue, QString("%1").arg(defVal));
value = UnitConvertor(value, MUnit(), qApp->patternUnit());
return value;
}
}
}
return defVal;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VStandardMeasurements::SetSize() void VStandardMeasurements::SetSize()
{ {
const QDomNodeList nodeList = this->elementsByTagName(TagSize); const qreal value = TakeParametr(TagSize, 50);
if (nodeList.isEmpty()) data->SetSize(value);
{ data->SetSizeName(size_M);
data->SetSize(50);
data->SetSizeName(size_M);
}
else
{
const QDomNode domNode = nodeList.at(0);
if (domNode.isNull() == false && domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
qreal value = GetParametrDouble(domElement, AttrValue, "50.0");
if (MUnit() == Unit::Mm)// Convert to Cm.
{
value = value/10.0;
}
data->SetSize(value);
data->SetSizeName(size_M);
}
}
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VStandardMeasurements::SetHeight() void VStandardMeasurements::SetHeight()
{ {
const QDomNodeList nodeList = this->elementsByTagName(TagHeight); const qreal value = TakeParametr(TagHeight, 176);
if (nodeList.isEmpty()) data->SetHeight(value);
{ data->SetHeightName(height_M);
data->SetHeight(176);
data->SetHeightName(height_M);
}
else
{
const QDomNode domNode = nodeList.at(0);
if (domNode.isNull() == false && domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
qreal value = GetParametrDouble(domElement, AttrValue, "176.0");
if (MUnit() == Unit::Mm)// Convert to Cm.
{
value = value / 10.0;
}
data->SetHeight(value);
data->SetHeightName(height_M);
}
}
}
} }

View File

@ -57,6 +57,7 @@ protected:
virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag); virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag);
private: private:
Q_DISABLE_COPY(VStandardMeasurements) Q_DISABLE_COPY(VStandardMeasurements)
qreal TakeParametr(const QString &tag, qreal defValue) const;
}; };
#endif // VSTANDARDMEASUREMENTS_H #endif // VSTANDARDMEASUREMENTS_H