[TD][SS]Fix 4131 SS formatting in TD View
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include "Cell.h"
|
||||
@@ -32,6 +34,8 @@
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <Base/Console.h>
|
||||
#include <App/Expression.h>
|
||||
@@ -960,4 +964,53 @@ App::Color Cell::decodeColor(const std::string & color, const App::Color & defau
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
//roughly based on Spreadsheet/Gui/SheetModel.cpp
|
||||
std::string Cell::getFormattedQuantity(void)
|
||||
{
|
||||
std::string result;
|
||||
QString qFormatted;
|
||||
App::CellAddress thisCell = getAddress();
|
||||
Property* prop = owner->sheet()->getPropertyByName(thisCell.toString().c_str());
|
||||
|
||||
if (prop->isDerivedFrom(App::PropertyString::getClassTypeId())) {
|
||||
const App::PropertyString * stringProp = static_cast<const App::PropertyString*>(prop);
|
||||
qFormatted = QString::fromUtf8(stringProp->getValue());
|
||||
|
||||
} else if (prop->isDerivedFrom(App::PropertyQuantity::getClassTypeId())) {
|
||||
double rawVal = static_cast<App::PropertyQuantity*>(prop)->getValue();
|
||||
const App::PropertyQuantity * floatProp = static_cast<const App::PropertyQuantity*>(prop);
|
||||
DisplayUnit du;
|
||||
bool hasDisplayUnit = getDisplayUnit(du);
|
||||
double duScale = du.scaler;
|
||||
const Base::Unit& computedUnit = floatProp->getUnit();
|
||||
qFormatted = QLocale::system().toString(rawVal,'f',Base::UnitsApi::getDecimals());
|
||||
if (hasDisplayUnit) {
|
||||
if (computedUnit.isEmpty() || computedUnit == du.unit) {
|
||||
QString number =
|
||||
QLocale::system().toString(rawVal / duScale,'f',Base::UnitsApi::getDecimals());
|
||||
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()) ||
|
||||
prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
|
||||
double rawVal;
|
||||
if(prop->isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
|
||||
rawVal = static_cast<const App::PropertyFloat*>(prop)->getValue();
|
||||
} else {
|
||||
rawVal = static_cast<const App::PropertyInteger*>(prop)->getValue();
|
||||
}
|
||||
DisplayUnit du;
|
||||
bool hasDisplayUnit = getDisplayUnit(du);
|
||||
double duScale = du.scaler;
|
||||
qFormatted = QLocale::system().toString(rawVal,'f',Base::UnitsApi::getDecimals());
|
||||
if (hasDisplayUnit) {
|
||||
QString number = QLocale::system().toString(rawVal / duScale, 'f',Base::UnitsApi::getDecimals());
|
||||
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
|
||||
}
|
||||
}
|
||||
result = Base::Tools::toStdString(qFormatted);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -122,6 +122,8 @@ public:
|
||||
|
||||
App::CellAddress getAddress() const { return address; }
|
||||
|
||||
std::string getFormattedQuantity(void);
|
||||
|
||||
/* Alignment */
|
||||
static const int ALIGNMENT_LEFT;
|
||||
static const int ALIGNMENT_HCENTER;
|
||||
|
||||
@@ -257,14 +257,15 @@ std::string DrawViewSpreadsheet::getSheetImage(void)
|
||||
cellwidth = sheet->getColumnWidth(address.col());
|
||||
cellheight = sheet->getRowHeight(address.row());
|
||||
celltext = "";
|
||||
Spreadsheet::Cell* cell = sheet->getCell(address);
|
||||
// get the text
|
||||
App::Property* prop = sheet->getPropertyByName(address.toString().c_str());
|
||||
std::stringstream field;
|
||||
if (prop != 0) {
|
||||
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId())))
|
||||
field << static_cast<App::PropertyQuantity*>(prop)->getValue();
|
||||
else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId())))
|
||||
field << static_cast<App::PropertyFloat*>(prop)->getValue();
|
||||
if (prop->isDerivedFrom((App::PropertyQuantity::getClassTypeId()))) {
|
||||
field << cell->getFormattedQuantity();
|
||||
} else if (prop->isDerivedFrom((App::PropertyFloat::getClassTypeId())))
|
||||
field << cell->getFormattedQuantity();
|
||||
else if (prop->isDerivedFrom((App::PropertyString::getClassTypeId())))
|
||||
field << static_cast<App::PropertyString*>(prop)->getValue();
|
||||
else
|
||||
@@ -276,7 +277,6 @@ std::string DrawViewSpreadsheet::getSheetImage(void)
|
||||
std::string bcolor = "none";
|
||||
std::string fcolor = c.asCSSString();
|
||||
std::string textstyle = "";
|
||||
Spreadsheet::Cell* cell = sheet->getCell(address);
|
||||
if (cell) {
|
||||
App::Color f,b;
|
||||
std::set<std::string> st;
|
||||
|
||||
Reference in New Issue
Block a user