diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp
index ceb773473..91b71eba8 100644
--- a/src/Base/UnitsApi.cpp
+++ b/src/Base/UnitsApi.cpp
@@ -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" );
diff --git a/src/Base/UnitsApi.h b/src/Base/UnitsApi.h
index e3beae5d5..1b2fdcd64 100644
--- a/src/Base/UnitsApi.h
+++ b/src/Base/UnitsApi.h
@@ -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);
diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp
index a4c3542b3..ad5663902 100644
--- a/src/Gui/Application.cpp
+++ b/src/Gui/Application.cpp
@@ -52,6 +52,7 @@
#include
#include
#include
+#include
#include
#include
@@ -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,
diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp
index 3f0e5b08f..eab7c4c20 100644
--- a/src/Gui/propertyeditor/PropertyItem.cpp
+++ b/src/Gui/propertyeditor/PropertyItem.cpp
@@ -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();
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();
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);
}
diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h
index d334d8ced..bc247966f 100644
--- a/src/Gui/propertyeditor/PropertyItem.h
+++ b/src/Gui/propertyeditor/PropertyItem.h
@@ -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 childItems;
bool readonly;
+ int precision;
};
/**