Show unit near formula result in dialogs.

--HG--
branch : feature
This commit is contained in:
dismine 2014-06-12 10:49:45 +03:00
parent 37d2dd667f
commit bc545db1dc
4 changed files with 50 additions and 12 deletions

View file

@ -34,6 +34,8 @@
#include "../../geometry/vsplinepath.h" #include "../../geometry/vsplinepath.h"
#include "../../tools/vabstracttool.h" #include "../../tools/vabstracttool.h"
#include "../../../libs/qmuparser/qmuparsererror.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) if (osSeparatorValue)
{ {
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
label->setText(loc.toString(result)); label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true));
} }
else else
{ {
QLocale loc = QLocale(QLocale::C); QLocale loc = QLocale(QLocale::C);
label->setText(loc.toString(result)); label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true));
} }
flag = true; flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); 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) if (osSeparatorValue)
{ {
QLocale loc = QLocale::system(); QLocale loc = QLocale::system();
label->setText(loc.toString(result)); label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true));
} }
else else
{ {
QLocale loc = QLocale(QLocale::C); QLocale loc = QLocale(QLocale::C);
label->setText(loc.toString(result)); label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true));
} }
flag = true; flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76)); palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));

View file

@ -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; QString result;
switch (unit) switch (unit)
{ {
case Unit::Mm: case Unit::Mm:
if (translate)
{
result = QObject::tr("mm");
}
else
{
result = "mm"; result = "mm";
}
break; break;
case Unit::Cm: case Unit::Cm:
if (translate)
{
result = QObject::tr("cm");
}
else
{
result = "cm"; result = "cm";
}
break; break;
case Unit::Inch: 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; break;
default: default:
if (translate)
{
result = QObject::tr("cm");
}
else
{
result = "cm"; result = "cm";
}
break; break;
} }
return result; return result;

View file

@ -141,7 +141,7 @@ public:
static void ValidateXML(const QString &schema, const QString &fileName); static void ValidateXML(const QString &schema, const QString &fileName);
void setContent(const QString &fileName); void setContent(const QString &fileName);
static Unit StrToUnits(const QString &unit); 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); virtual bool SaveDocument(const QString &fileName);
QString Major() const; QString Major() const;
QString Minor() const; QString Minor() const;