diff --git a/src/app/container/container.pri b/src/app/container/container.pri index ffbefb2cf..9a4d2b572 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -2,10 +2,12 @@ SOURCES += \ container/vcontainer.cpp \ container/calculator.cpp \ container/vmeasurement.cpp \ - container/vincrement.cpp + container/vincrement.cpp \ + container/vvariable.cpp HEADERS += \ container/vcontainer.h \ container/calculator.h \ container/vmeasurement.h \ - container/vincrement.h + container/vincrement.h \ + container/vvariable.h diff --git a/src/app/container/vincrement.cpp b/src/app/container/vincrement.cpp index 97d4aa2b9..b288b0794 100644 --- a/src/app/container/vincrement.cpp +++ b/src/app/container/vincrement.cpp @@ -33,49 +33,35 @@ * @brief VIncrement create enpty increment */ VIncrement::VIncrement() - :id(0), base(0), ksize(50.0), kheight(176.0), description(QString()) + :VVariable(), id(0) {} //--------------------------------------------------------------------------------------------------------------------- /** * @brief VIncrementTableRow create increment * @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 kheight increment in heights * @param description description of increment */ 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) - :id(incr.getId()), base(incr.getBase()), ksize(incr.getKsize()), kheight(incr.getKheight()), - description(incr.getDescription()) + :VVariable(incr), id(incr.getId()) {} //--------------------------------------------------------------------------------------------------------------------- VIncrement &VIncrement::operator=(const VIncrement &incr) { + VVariable::operator=(incr); this->id = incr.getId(); - this->base = incr.getBase(); - this->ksize = incr.getKsize(); - this->kheight = incr.getKheight(); - this->description = incr.getDescription(); return *this; } //--------------------------------------------------------------------------------------------------------------------- -qreal VIncrement::GetValue() const -{ - 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; -} +VIncrement::~VIncrement() +{} diff --git a/src/app/container/vincrement.h b/src/app/container/vincrement.h index 4a31efe06..b7887043d 100644 --- a/src/app/container/vincrement.h +++ b/src/app/container/vincrement.h @@ -29,45 +29,29 @@ #ifndef VINCREMENTTABLEROW_H #define VINCREMENTTABLEROW_H +#include "vvariable.h" #include /** * @brief The VIncrement class keep data row of increment table */ -class VIncrement +class VIncrement :public VVariable { public: VIncrement(); VIncrement(quint32 id, qreal base, qreal ksize, qreal kheight, QString description = QString()); VIncrement(const VIncrement &incr); VIncrement &operator=(const VIncrement &incr); + virtual ~VIncrement(); + quint32 getId() const; void setId(const quint32 &value); - qreal getBase() const; - void setBase(const qreal &value); - qreal getKsize() const; void setKsize(const qreal &value); - qreal getKheight() const; void setKheight(const qreal &value); - QString getDescription() const; void setDescription(const QString &value); - qreal GetValue() const; - qreal GetValue(const qreal &size, const qreal &height) const; private: /** @brief id identificator */ - 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; + quint32 id; }; //--------------------------------------------------------------------------------------------------------------------- @@ -90,36 +74,6 @@ inline void VIncrement::setId(const quint32 &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 @@ -130,16 +84,6 @@ inline void VIncrement::setKsize(const qreal &value) ksize = value; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief getKheight return increment in growths - * @return increment - */ -inline qreal VIncrement::getKheight() const -{ - return kheight; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief setKheight set increment in growths @@ -150,16 +94,6 @@ inline void VIncrement::setKheight(const qreal &value) kheight = value; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief getDescription return description - * @return description - */ -inline QString VIncrement::getDescription() const -{ - return description; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDescription set description for row diff --git a/src/app/container/vmeasurement.cpp b/src/app/container/vmeasurement.cpp index 8a3bbf32f..35ef9bce3 100644 --- a/src/app/container/vmeasurement.cpp +++ b/src/app/container/vmeasurement.cpp @@ -27,19 +27,21 @@ *************************************************************************/ #include "vmeasurement.h" +#include "../widgets/vapplication.h" +#include "../xml/vabstractmeasurements.h" //--------------------------------------------------------------------------------------------------------------------- /** * @brief VMeasurement create empty measurement */ 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 - * @param base value in base size and growth + * @param base value in base size and height * @param ksize increment in sizes * @param kheight increment in heights * @param gui_text shor tooltip for user @@ -48,44 +50,78 @@ VMeasurement::VMeasurement() */ VMeasurement::VMeasurement(const qreal &base, const qreal &ksize, const qreal &kheight, 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 - * @param base value in base size and growth + * @param base value in base size and height * @param gui_text shor tooltip for user * @param description measurement full description * @param tagName measurement's tag name in file */ VMeasurement::VMeasurement(const qreal &base, const QString &gui_text, const QString &description, 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) - :base(m.GetBase()), ksize(m.GetKsize()), kheight(m.GetKheight()), gui_text(m.GetGuiText()), - description(m.GetDescription()), _tagName(m.TagName()) + :VVariable(m), gui_text(m.GetGuiText()), _tagName(m.TagName()) {} //--------------------------------------------------------------------------------------------------------------------- VMeasurement &VMeasurement::operator=(const VMeasurement &m) { - this->base = m.GetBase(); - this->ksize = m.GetKsize(); - this->kheight = m.GetKheight(); + VVariable::operator=(m); this->gui_text = m.GetGuiText(); - this->description = m.GetDescription(); this->_tagName = m.TagName(); 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; - const qreal k_height = ( height - 176.0 ) / 6.0; - return base + k_size * ksize + k_height * kheight; + if (qApp->patternUnit() == Unit::Inch) + { + 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); } diff --git a/src/app/container/vmeasurement.h b/src/app/container/vmeasurement.h index f6b5beb8d..87a5122f1 100644 --- a/src/app/container/vmeasurement.h +++ b/src/app/container/vmeasurement.h @@ -29,12 +29,13 @@ #ifndef VSTANDARDTABLEROW_H #define VSTANDARDTABLEROW_H +#include "vvariable.h" #include /** * @brief The VMeasurement class keep data row of standard table */ -class VMeasurement +class VMeasurement :public VVariable { public: VMeasurement(); @@ -45,70 +46,21 @@ public: const QString &description = QString(), const QString &TagName = QString()); VMeasurement(const VMeasurement &m); VMeasurement &operator=(const VMeasurement &m); - ~VMeasurement(){} - qreal GetBase() const; - void setBase(const qreal &value); - qreal GetKsize() const; - qreal GetKheight() const; - QString GetGuiText() const; - QString GetDescription() const; - qreal GetValue() const; - qreal GetValue(const qreal &size, const qreal &height) const; - QString TagName() const; - void setTagName(const QString &TagName); + virtual ~VMeasurement(); + + QString GetGuiText() const; + QString TagName() const; + void setTagName(const QString &TagName); + static QStringList ListHeights(); + static QStringList ListSizes(); 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 */ QString gui_text; - QString description; 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 @@ -119,18 +71,6 @@ inline QString VMeasurement::GetGuiText() const return gui_text; } -//--------------------------------------------------------------------------------------------------------------------- -inline QString VMeasurement::GetDescription() const -{ - return description; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline qreal VMeasurement::GetValue() const -{ - return base; -} - //--------------------------------------------------------------------------------------------------------------------- inline QString VMeasurement::TagName() const { diff --git a/src/app/container/vvariable.cpp b/src/app/container/vvariable.cpp new file mode 100644 index 000000000..3ca2cb0ef --- /dev/null +++ b/src/app/container/vvariable.cpp @@ -0,0 +1,100 @@ +/************************************************************************ + ** + ** @file vvariable.cpp + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#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()); + } +} diff --git a/src/app/container/vvariable.h b/src/app/container/vvariable.h new file mode 100644 index 000000000..18a850f7a --- /dev/null +++ b/src/app/container/vvariable.h @@ -0,0 +1,115 @@ +/************************************************************************ + ** + ** @file vvariable.h + ** @author Roman Telezhynskyi + ** @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 + ** 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 . + ** + *************************************************************************/ + +#ifndef VVARIABLE_H +#define VVARIABLE_H + +#include + +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 diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index 1d9d1ef87..8909e685b 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -268,22 +268,22 @@ void DialogIncrements::FillIncrements() ui->tableWidgetIncrement->setItem(currentRow, 1, item); } - item = new QTableWidgetItem(QString().setNum(incr.getBase())); + item = new QTableWidgetItem(QString().setNum(incr.GetBase())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 2, item); if (qApp->patternType() == MeasurementsType::Standard) { - item = new QTableWidgetItem(QString().setNum(incr.getKsize())); + item = new QTableWidgetItem(QString().setNum(incr.GetKsize())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 3, item); - item = new QTableWidgetItem(QString().setNum(incr.getKheight())); + item = new QTableWidgetItem(QString().setNum(incr.GetKheight())); item->setTextAlignment(Qt::AlignHCenter); ui->tableWidgetIncrement->setItem(currentRow, 4, item); } - item = new QTableWidgetItem(incr.getDescription()); + item = new QTableWidgetItem(incr.GetDescription()); item->setTextAlignment(Qt::AlignLeft); 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); if (ok == false) { - measur.setBase(0); + measur.SetBase(0); item->setText("0"); qDebug()<<"Can't convert toDouble measurement value"<ClearMeasurements(); m->Measurements(); diff --git a/src/app/dialogs/app/dialogstandardmeasurements.cpp b/src/app/dialogs/app/dialogstandardmeasurements.cpp index 8aff937f0..cfffa372d 100644 --- a/src/app/dialogs/app/dialogstandardmeasurements.cpp +++ b/src/app/dialogs/app/dialogstandardmeasurements.cpp @@ -163,7 +163,14 @@ void DialogStandardMeasurements::LoadStandardTables() VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath()); VStandardMeasurements m(data); 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"<comboBoxTables->addItem(m.Description(), QVariant(fi.absoluteFilePath())); + } } catch (VException &e) { diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index d070176fe..57739458c 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -961,7 +961,7 @@ void DialogTool::ValChenged(int row) { VIncrement incr = data->GetIncrement(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); return; } diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 25a9b5b18..f2ef69dfd 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -169,6 +169,7 @@ void MainWindow::ActionNewPP() //Set scene size to size scene view VAbstractTool::NewSceneRect(sceneDraw, view); VAbstractTool::NewSceneRect(sceneDetails, view); + ToolBarOption(); } else { @@ -993,36 +994,33 @@ void MainWindow::ToolBarOption() { 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", - "176", "182", "188"}; - QComboBox *comboBoxHeight = new QComboBox; - comboBoxHeight->addItems(list); - comboBoxHeight->setCurrentIndex(14);//176 - ui->toolBarOption->addWidget(comboBoxHeight); - connect(comboBoxHeight, static_cast(&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(&QComboBox::currentIndexChanged), - this, &MainWindow::ChangedSize); + SetGradationList(tr("Height: "), listHeights, &MainWindow::ChangedHeight); + SetGradationList(tr("Size: "), listSizes, &MainWindow::ChangedSize); ui->toolBarOption->addSeparator(); } - mouseCoordinate = new QLabel("0, 0"); + mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(doc->UnitsToStr(qApp->patternUnit()))); ui->toolBarOption->addWidget(mouseCoordinate); } +//--------------------------------------------------------------------------------------------------------------------- +template +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(&QComboBox::currentIndexChanged), + this, changeSlot); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ToolBarDraws enable draw toolbar. @@ -1126,8 +1124,9 @@ void MainWindow::currentDrawChanged( int index ) */ void MainWindow::mouseMove(const QPointF &scenePos) { - QString string = QString("%1, %2").arg(static_cast(qApp->fromPixel(scenePos.x()))) - .arg(static_cast(qApp->fromPixel(scenePos.y()))); + QString string = QString("%1, %2 (%3)").arg(static_cast(qApp->fromPixel(scenePos.x()))) + .arg(static_cast(qApp->fromPixel(scenePos.y()))) + .arg(doc->UnitsToStr(qApp->patternUnit())); if (mouseCoordinate != nullptr) { mouseCoordinate->setText(string); @@ -2226,7 +2225,6 @@ void MainWindow::LoadPattern(const QString &fileName) } m.SetSize(); m.SetHeight(); - ToolBarOption(); } else { @@ -2240,6 +2238,7 @@ void MainWindow::LoadPattern(const QString &fileName) return; } } + ToolBarOption(); } catch (VException &e) { diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 3889454fd..f96f8c446 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -255,6 +255,8 @@ private: QString PatternPieceName(const QString &text); QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType); void OpenPattern(const QString &filePath); + template + void SetGradationList(const QString &label, const QStringList &list, Func changeSlot); }; #endif // MAINWINDOW_H diff --git a/src/app/xml/vabstractmeasurements.cpp b/src/app/xml/vabstractmeasurements.cpp index 810a78bdc..320486fc2 100644 --- a/src/app/xml/vabstractmeasurements.cpp +++ b/src/app/xml/vabstractmeasurements.cpp @@ -195,6 +195,56 @@ Unit VAbstractMeasurements::MUnit() const 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) { diff --git a/src/app/xml/vabstractmeasurements.h b/src/app/xml/vabstractmeasurements.h index ab63da146..5de17cc73 100644 --- a/src/app/xml/vabstractmeasurements.h +++ b/src/app/xml/vabstractmeasurements.h @@ -40,6 +40,7 @@ public: Unit MUnit() const; static const QString TagUnit; static const QString AttrValue; + static qreal UnitConvertor(qreal value, const Unit &from, const Unit &to); protected: void Measurement(const QString &tag); virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag) = 0; diff --git a/src/app/xml/vindividualmeasurements.cpp b/src/app/xml/vindividualmeasurements.cpp index bafbc4f88..c0cd57b0c 100644 --- a/src/app/xml/vindividualmeasurements.cpp +++ b/src/app/xml/vindividualmeasurements.cpp @@ -69,11 +69,7 @@ void VIndividualMeasurements::Measurements() void VIndividualMeasurements::ReadMeasurement(const QDomElement &domElement, const QString &tag) { qreal value = GetParametrDouble(domElement, AttrValue, "0.0"); - - if (MUnit() == Unit::Mm)//Convert to Cm. - { - value = value / 10.0; - } + value = UnitConvertor(value, MUnit(), qApp->patternUnit()); data->AddMeasurement(tag, VMeasurement(value, qApp->GuiText(tag), qApp->Description(tag), tag)); } diff --git a/src/app/xml/vstandardmeasurements.cpp b/src/app/xml/vstandardmeasurements.cpp index 1c99fc8a1..1528537e0 100644 --- a/src/app/xml/vstandardmeasurements.cpp +++ b/src/app/xml/vstandardmeasurements.cpp @@ -53,7 +53,7 @@ QString VStandardMeasurements::Description() const QString desc = UniqueTagText(TagDescription, ""); if (desc.isEmpty()) { - qDebug()<<"Empty description in standard table."<patternUnit()); - 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, - qApp->GuiText(tag), qApp->Description(tag), tag)); + qWarning()<<"Standard table can't use inch unit."; } - 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), - qApp->Description(tag), tag)); + return defVal; } + 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() { - const QDomNodeList nodeList = this->elementsByTagName(TagSize); - if (nodeList.isEmpty()) - { - 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); - } - } - } + const qreal value = TakeParametr(TagSize, 50); + data->SetSize(value); + data->SetSizeName(size_M); } //--------------------------------------------------------------------------------------------------------------------- void VStandardMeasurements::SetHeight() { - const QDomNodeList nodeList = this->elementsByTagName(TagHeight); - if (nodeList.isEmpty()) - { - 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); - } - } - } + const qreal value = TakeParametr(TagHeight, 176); + data->SetHeight(value); + data->SetHeightName(height_M); } diff --git a/src/app/xml/vstandardmeasurements.h b/src/app/xml/vstandardmeasurements.h index c9d0ee1de..06d9ab967 100644 --- a/src/app/xml/vstandardmeasurements.h +++ b/src/app/xml/vstandardmeasurements.h @@ -57,6 +57,7 @@ protected: virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag); private: Q_DISABLE_COPY(VStandardMeasurements) + qreal TakeParametr(const QString &tag, qreal defValue) const; }; #endif // VSTANDARDMEASUREMENTS_H