From 378f99f1b318202db3bc89b45d691a0376d07512 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 10 Mar 2017 04:40:44 +0800 Subject: [PATCH] Added App::PropertyPrecision The purpose of this property and the associated property item is to properly display floating value of many decimal points, such as Precision::Confusion() --- src/App/Application.cpp | 1 + src/App/PropertyStandard.cpp | 21 +++++++++++++++++++++ src/App/PropertyStandard.h | 17 +++++++++++++++++ src/Gui/SoFCDB.cpp | 1 + src/Gui/propertyeditor/PropertyItem.cpp | 9 +++++++++ src/Gui/propertyeditor/PropertyItem.h | 10 ++++++++++ 6 files changed, 59 insertions(+) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 9d8fc1150f..52f41f8313 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1177,6 +1177,7 @@ void Application::initTypes(void) App ::PropertyFloat ::init(); App ::PropertyFloatList ::init(); App ::PropertyFloatConstraint ::init(); + App ::PropertyPrecision ::init(); App ::PropertyQuantity ::init(); App ::PropertyQuantityConstraint::init(); App ::PropertyAngle ::init(); diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index ddac0a85db..31920dbafa 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1097,6 +1097,27 @@ void PropertyFloatConstraint::setPyObject(PyObject *value) } } +//************************************************************************** +// PropertyPrecision +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyPrecision, App::PropertyFloatConstraint); + +//************************************************************************** +// Construction/Destruction +// +const PropertyFloatConstraint::Constraints PrecisionStandard = {0.0,DBL_MAX,0.001}; + +PropertyPrecision::PropertyPrecision() +{ + setConstraints(&PrecisionStandard); +} + +PropertyPrecision::~PropertyPrecision() +{ + +} + //************************************************************************** // PropertyFloatList diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index 2e1a034c5f..cbf5b5c815 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -518,6 +518,23 @@ protected: const Constraints* _ConstStruct; }; + +/** Precision properties + * This property fulfills the need of a floating value with many decimal points, + * e.g. for holding values like Precision::Confusion(). The value has a default + * constraint for non-negative, but can be overidden + */ +class AppExport PropertyPrecision: public PropertyFloatConstraint +{ + TYPESYSTEM_HEADER(); +public: + PropertyPrecision(void); + virtual ~PropertyPrecision(); + virtual const char* getEditorName(void) const + { return "Gui::PropertyEditor::PropertyPrecisionItem"; } +}; + + class AppExport PropertyFloatList: public PropertyLists { TYPESYSTEM_HEADER(); diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 9e424b9dda..92cfcdb3c6 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -128,6 +128,7 @@ void Gui::SoFCDB::init() PropertyFloatItem ::init(); PropertyUnitItem ::init(); PropertyFloatConstraintItem ::init(); + PropertyPrecisionItem ::init(); PropertyUnitConstraintItem ::init(); PropertyAngleItem ::init(); PropertyBoolItem ::init(); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 516fdf9739..66a3a67cf8 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1019,6 +1019,15 @@ QVariant PropertyFloatConstraintItem::editorData(QWidget *editor) const // -------------------------------------------------------------------- +PROPERTYITEM_SOURCE(Gui::PropertyEditor::PropertyPrecisionItem) + +PropertyPrecisionItem::PropertyPrecisionItem() +{ + setDecimals(16); +} + +// -------------------------------------------------------------------- + PROPERTYITEM_SOURCE(Gui::PropertyEditor::PropertyAngleItem) PropertyAngleItem::PropertyAngleItem() diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index 7967591fbc..93ef4424e2 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -349,6 +349,16 @@ protected: PropertyFloatConstraintItem(); }; +/** + * Change a floating point number with many decimal points (hard coded as 16) + */ +class GuiExport PropertyPrecisionItem: public PropertyFloatConstraintItem +{ + PROPERTYITEM_HEADER +protected: + PropertyPrecisionItem(); +}; + /** * Change a floating point number. * \author Werner Mayer