From bc545db1dc8fd2b70a90767492c68e9dc5b70f48 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 12 Jun 2014 10:49:45 +0300 Subject: [PATCH] Show unit near formula result in dialogs. --HG-- branch : feature --- src/app/dialogs/tools/dialogtool.cpp | 10 +++--- src/app/widgets/vapplication.h | 4 +-- src/app/xml/vdomdocument.cpp | 46 +++++++++++++++++++++++++--- src/app/xml/vdomdocument.h | 2 +- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 8ae922095..1707ece65 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -34,6 +34,8 @@ #include "../../geometry/vsplinepath.h" #include "../../tools/vabstracttool.h" #include "../../../libs/qmuparser/qmuparsererror.h" +#include "../../widgets/vapplication.h" +#include "../../xml/vdomdocument.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -454,12 +456,12 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label) if (osSeparatorValue) { QLocale loc = QLocale::system(); - label->setText(loc.toString(result)); + label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); } else { QLocale loc = QLocale(QLocale::C); - label->setText(loc.toString(result)); + label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); } flag = true; palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); @@ -515,12 +517,12 @@ void DialogTool::Eval(QPlainTextEdit *edit, bool &flag, QTimer *timer, QLabel *l if (osSeparatorValue) { QLocale loc = QLocale::system(); - label->setText(loc.toString(result)); + label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); } else { QLocale loc = QLocale(QLocale::C); - label->setText(loc.toString(result)); + label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); } flag = true; palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); diff --git a/src/app/widgets/vapplication.h b/src/app/widgets/vapplication.h index eea6c9b00..0b5448581 100644 --- a/src/app/widgets/vapplication.h +++ b/src/app/widgets/vapplication.h @@ -63,9 +63,9 @@ public: * @return value that is returned from the receiver's event handler. */ virtual bool notify(QObject * receiver, QEvent * event); - Unit patternUnit() const; + Unit patternUnit() const; void setPatternUnit(const Unit &patternUnit); - MeasurementsType patternType() const; + MeasurementsType patternType() const; void setPatternType(const MeasurementsType &patternType); double toPixel(double unit) const; double fromPixel(double pix) const; diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index 20610ceea..b1de1d07f 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -367,22 +367,58 @@ Unit VDomDocument::StrToUnits(const QString &unit) } //--------------------------------------------------------------------------------------------------------------------- -QString VDomDocument::UnitsToStr(const Unit &unit) +/** + * @brief UnitsToStr translate unit to string. + * + * This method used when need write unit in xml file and for showing unit in dialogs. + * @param unit curent unit + * @param translate true if need show translated name. Default value false. + * @return string reprezantation for unit. + */ +QString VDomDocument::UnitsToStr(const Unit &unit, const bool translate) { QString result; switch (unit) { case Unit::Mm: - result = "mm"; + if (translate) + { + result = QObject::tr("mm"); + } + else + { + result = "mm"; + } break; case Unit::Cm: - result = "cm"; + if (translate) + { + result = QObject::tr("cm"); + } + else + { + result = "cm"; + } break; case Unit::Inch: - result = "inch"; + if (translate) + { + result = QObject::tr("in", "inch abbreviation"); + } + else + { + result = "inch";//I decided use full name in xml file. + } break; default: - result = "cm"; + if (translate) + { + result = QObject::tr("cm"); + } + else + { + result = "cm"; + } break; } return result; diff --git a/src/app/xml/vdomdocument.h b/src/app/xml/vdomdocument.h index e2c427739..5a51dfdec 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/app/xml/vdomdocument.h @@ -141,7 +141,7 @@ public: static void ValidateXML(const QString &schema, const QString &fileName); void setContent(const QString &fileName); static Unit StrToUnits(const QString &unit); - static QString UnitsToStr(const Unit &unit); + static QString UnitsToStr(const Unit &unit, const bool translate = false); virtual bool SaveDocument(const QString &fileName); QString Major() const; QString Minor() const;