Add support of number of decimals to unit system
This commit is contained in:
parent
e7644fd3b3
commit
cf31d43e54
|
@ -85,6 +85,7 @@ UnitsSchema *UnitsApi::UserPrefSystem = new UnitsSchemaInternal();
|
|||
|
||||
double UnitsApi::UserPrefFactor [50];
|
||||
QString UnitsApi::UserPrefUnit [50];
|
||||
int UnitsApi::UserPrefDecimals = 2;
|
||||
|
||||
UnitsApi::UnitsApi(const char* filter)
|
||||
{
|
||||
|
@ -196,6 +197,16 @@ const double UnitsApi::getPrefFactorOf(QuantityType t)
|
|||
return UserPrefFactor[t];
|
||||
}
|
||||
|
||||
void UnitsApi::setDecimals(int prec)
|
||||
{
|
||||
UserPrefDecimals = prec;
|
||||
}
|
||||
|
||||
int UnitsApi::getDecimals()
|
||||
{
|
||||
return UserPrefDecimals;
|
||||
}
|
||||
|
||||
void UnitsApi::setDefaults(void)
|
||||
{
|
||||
setPrefOf( Length ,"mm" );
|
||||
|
|
|
@ -101,6 +101,10 @@ public:
|
|||
static const QString getQuantityName(QuantityType t);
|
||||
/// get the translation factor for the default unit of a quantity
|
||||
static const double getPrefFactorOf(QuantityType t);
|
||||
// set the number of decimals
|
||||
static void setDecimals(int);
|
||||
// fet the number of decimals
|
||||
static int getDecimals();
|
||||
/// set the application defaults
|
||||
static void setDefaults(void);
|
||||
//@}
|
||||
|
@ -119,6 +123,8 @@ protected:
|
|||
static double UserPrefFactor [50] ;
|
||||
/// name of the unit the user wants to use as quantities
|
||||
static QString UserPrefUnit [50] ;
|
||||
/// number of decimals for floats
|
||||
static int UserPrefDecimals;
|
||||
|
||||
// do the real work
|
||||
static double parse(const char*,bool &UsedUnit);
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include <Base/Factory.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
|
||||
|
@ -328,6 +329,10 @@ Application::Application(bool GUIenabled)
|
|||
Translator::instance()->activateLanguage(hPGrp->GetASCII("Language", (const char*)lang.toAscii()).c_str());
|
||||
GetWidgetFactorySupplier();
|
||||
|
||||
ParameterGrp::handle hUnits = App::GetApplication().GetParameterGroupByPath
|
||||
("User parameter:BaseApp/Preferences/Units");
|
||||
Base::UnitsApi::setDecimals(hUnits->GetInt("Decimals", Base::UnitsApi::getDecimals()));
|
||||
|
||||
// setting up Python binding
|
||||
Base::PyGILStateLocker lock;
|
||||
PyObject* module = Py_InitModule3("FreeCADGui", Application::Methods,
|
||||
|
|
|
@ -57,6 +57,7 @@ TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyItem, Base::BaseClass);
|
|||
|
||||
PropertyItem::PropertyItem() : parentItem(0), readonly(false)
|
||||
{
|
||||
precision = Base::UnitsApi::getDecimals();
|
||||
}
|
||||
|
||||
PropertyItem::~PropertyItem()
|
||||
|
@ -130,6 +131,16 @@ bool PropertyItem::isReadOnly() const
|
|||
return readonly;
|
||||
}
|
||||
|
||||
void PropertyItem::setDecimals(int prec)
|
||||
{
|
||||
precision = prec;
|
||||
}
|
||||
|
||||
int PropertyItem::decimals() const
|
||||
{
|
||||
return precision;
|
||||
}
|
||||
|
||||
QVariant PropertyItem::toolTip(const App::Property* prop) const
|
||||
{
|
||||
return QVariant(QString::fromUtf8(prop->getDocumentation()));
|
||||
|
@ -574,7 +585,7 @@ void PropertyFloatItem::setValue(const QVariant& value)
|
|||
if (!value.canConvert(QVariant::Double))
|
||||
return;
|
||||
double val = value.toDouble();
|
||||
QString data = QString::fromAscii("%1").arg(val,0,'f',2);
|
||||
QString data = QString::fromAscii("%1").arg(val,0,'f',decimals());
|
||||
setPropertyValue(data);
|
||||
}
|
||||
|
||||
|
@ -582,6 +593,7 @@ QWidget* PropertyFloatItem::createEditor(QWidget* parent, const QObject* receive
|
|||
{
|
||||
QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
|
||||
sb->setFrame(false);
|
||||
sb->setDecimals(decimals());
|
||||
QObject::connect(sb, SIGNAL(valueChanged(double)), receiver, method);
|
||||
return sb;
|
||||
}
|
||||
|
@ -703,13 +715,14 @@ void PropertyFloatConstraintItem::setValue(const QVariant& value)
|
|||
if (!value.canConvert(QVariant::Double))
|
||||
return;
|
||||
double val = value.toDouble();
|
||||
QString data = QString::fromAscii("%1").arg(val,0,'f',2);
|
||||
QString data = QString::fromAscii("%1").arg(val,0,'f',decimals());
|
||||
setPropertyValue(data);
|
||||
}
|
||||
|
||||
QWidget* PropertyFloatConstraintItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||
{
|
||||
QDoubleSpinBox *sb = new QDoubleSpinBox(parent);
|
||||
sb->setDecimals(decimals());
|
||||
sb->setFrame(false);
|
||||
QObject::connect(sb, SIGNAL(valueChanged(double)), receiver, method);
|
||||
return sb;
|
||||
|
@ -873,9 +886,9 @@ void PropertyVectorItem::setValue(const QVariant& value)
|
|||
return;
|
||||
const Base::Vector3f& val = value.value<Base::Vector3f>();
|
||||
QString data = QString::fromAscii("(%1, %2, %3)")
|
||||
.arg(val.x,0,'f',2)
|
||||
.arg(val.y,0,'f',2)
|
||||
.arg(val.z,0,'f',2);
|
||||
.arg(val.x,0,'f',decimals())
|
||||
.arg(val.y,0,'f',decimals())
|
||||
.arg(val.z,0,'f',decimals());
|
||||
setPropertyValue(data);
|
||||
}
|
||||
|
||||
|
@ -976,9 +989,9 @@ void PropertyDoubleVectorItem::setValue(const QVariant& value)
|
|||
return;
|
||||
const Base::Vector3d& val = value.value<Base::Vector3d>();
|
||||
QString data = QString::fromAscii("(%1, %2, %3)")
|
||||
.arg(val.x,0,'f',2)
|
||||
.arg(val.y,0,'f',2)
|
||||
.arg(val.z,0,'f',2);
|
||||
.arg(val.x,0,'f',decimals())
|
||||
.arg(val.y,0,'f',decimals())
|
||||
.arg(val.z,0,'f',decimals());
|
||||
setPropertyValue(data);
|
||||
}
|
||||
|
||||
|
@ -1503,9 +1516,9 @@ void PropertyColorItem::setValue(const QVariant& value)
|
|||
val.g = (float)col.green()/255.0f;
|
||||
val.b = (float)col.blue()/255.0f;
|
||||
QString data = QString::fromAscii("(%1,%2,%3)")
|
||||
.arg(val.r,0,'f',2)
|
||||
.arg(val.g,0,'f',2)
|
||||
.arg(val.b,0,'f',2);
|
||||
.arg(val.r,0,'f',decimals())
|
||||
.arg(val.g,0,'f',decimals())
|
||||
.arg(val.b,0,'f',decimals());
|
||||
setPropertyValue(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ public:
|
|||
|
||||
void setReadOnly(bool);
|
||||
bool isReadOnly() const;
|
||||
void setDecimals(int);
|
||||
int decimals() const;
|
||||
|
||||
PropertyItem *child(int row);
|
||||
int childCount() const;
|
||||
|
@ -99,6 +101,7 @@ private:
|
|||
PropertyItem *parentItem;
|
||||
QList<PropertyItem*> childItems;
|
||||
bool readonly;
|
||||
int precision;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user