add class QuantityFormat to control user string of Quantity
do some code refactoration to reduce duplicate code
This commit is contained in:
@@ -21,12 +21,30 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifdef __GNUC__
|
||||
# include <unistd.h>
|
||||
#include "PreCompiled.h"
|
||||
#ifdef __GNUC__
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
#include <QLocale>
|
||||
|
||||
#include "Exception.h"
|
||||
#include "UnitsApi.h"
|
||||
#include "UnitsSchema.h"
|
||||
|
||||
|
||||
using namespace Base;
|
||||
|
||||
QString UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const
|
||||
{
|
||||
//return QString::fromUtf8("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
QLocale Lc = QLocale::system();
|
||||
const QuantityFormat& format = quant.getFormat();
|
||||
if (format.option != QuantityFormat::None) {
|
||||
uint opt = static_cast<uint>(format.option);
|
||||
Lc.setNumberOptions(static_cast<QLocale::NumberOptions>(opt));
|
||||
}
|
||||
|
||||
QString Ln = Lc.toString((quant.getValue() / factor), format.toFormat(), format.precision);
|
||||
return QString::fromUtf8("%1 %2").arg(Ln).arg(unitString);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user