Base: simplify UnitsSchemas management
Fixes: Maintaining schemas is difficult and error-prone - Facilitate easy schemas add, remove, change, etc. - Remove 14 files containing approx 2,190 lines of if/else code and data - Place data in one file (UnitsSchemasData.h) using a normalized structure (including special functions) - Isolate and simplify data operations (code) - Remove schemas enum to keep data independent of code - Separate responsibilities: Specifications, data, schemas, schema - Add schema data 'isDefault' - Add schema data name - Prefer algorithms to raw loops - Add schemas unit tests - Tweak quantity unit tests
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsSchema.h>
|
||||
|
||||
#include "QuantitySpinBox.h"
|
||||
#include "QuantitySpinBox_p.h"
|
||||
@@ -714,7 +715,7 @@ void QuantitySpinBox::setDecimals(int v)
|
||||
updateText(d->quantity);
|
||||
}
|
||||
|
||||
void QuantitySpinBox::setSchema(const Base::UnitSystem& s)
|
||||
void QuantitySpinBox::setSchema(const int s)
|
||||
{
|
||||
Q_D(QuantitySpinBox);
|
||||
d->scheme = Base::UnitsApi::createSchema(s);
|
||||
@@ -732,7 +733,7 @@ QString QuantitySpinBox::getUserString(const Base::Quantity& val, double& factor
|
||||
{
|
||||
Q_D(const QuantitySpinBox);
|
||||
std::string unitStr;
|
||||
std::string str = d->scheme ? val.getUserString(d->scheme.get(), factor, unitStr)
|
||||
const std::string str = d->scheme ? val.getUserString(d->scheme.get(), factor, unitStr)
|
||||
: val.getUserString(factor, unitStr);
|
||||
unitString = QString::fromStdString(unitStr);
|
||||
return QString::fromStdString(str);
|
||||
|
||||
Reference in New Issue
Block a user