From: vsv Date: Tue, 9 Oct 2018 16:15:38 +0000 (+0300) Subject: Provide Min/Max for properties with Double Spin control X-Git-Tag: V9_2_0a2~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e9095021919b0e85e4708dbcdb6fd2b55530d1dd;p=modules%2Fshaper.git Provide Min/Max for properties with Double Spin control --- diff --git a/src/Config/Config_Prop.h b/src/Config/Config_Prop.h index 5411766e4..564c0a2d0 100644 --- a/src/Config/Config_Prop.h +++ b/src/Config/Config_Prop.h @@ -73,7 +73,9 @@ class Config_Prop * \param theDefaultValue - default value of the property. This is an initial property value */ Config_Prop(const std::string& theSection, const std::string& theName, - const std::string& theTitle, PropType theType, const std::string& theDefaultValue) + const std::string& theTitle, PropType theType, + const std::string& theDefaultValue, + const std::string& theMin, const std::string& theMax) { mySection = theSection; myName = theName; @@ -81,6 +83,8 @@ class Config_Prop myType = theType; myValue = theDefaultValue; myDefaultValue = theDefaultValue; + myMin = theMin; + myMax = theMax; } /// Get name of section @@ -133,6 +137,20 @@ class Config_Prop return (mySection == theProp->section()) && (myName == theProp->name()); } + /// Returns minimal value + std::string min() const { return myMin; } + + void setMin(const std::string& theMin) { + myMin = theMin; + } + + /// Returns maximal value + std::string max() const { return myMax; } + + void setMax(const std::string& theMax) { + myMax = theMax; + } + private: std::string mySection; ///< Name of section std::string myName; ///< Name of property @@ -140,6 +158,8 @@ class Config_Prop PropType myType; ///< Type of property std::string myValue; // Value in string format std::string myDefaultValue; // Default value + std::string myMin; // Minimal value + std::string myMax; // Maximal value }; typedef std::list Config_Properties; diff --git a/src/Config/Config_PropManager.cpp b/src/Config/Config_PropManager.cpp index 25745a01d..4f6530dd3 100644 --- a/src/Config/Config_PropManager.cpp +++ b/src/Config/Config_PropManager.cpp @@ -31,7 +31,9 @@ Config_Prop* Config_PropManager::registerProp(const std::string& theSection, const std::string& theName, const std::string& theTitle, Config_Prop::PropType theType, - const std::string& theDefaultValue) + const std::string& theDefaultValue, + const std::string& theMin, + const std::string& theMax) { Config_Prop* aProp = findProp(theSection, theName); @@ -46,9 +48,12 @@ Config_Prop* Config_PropManager::registerProp(const std::string& theSection, aProp->setType(theType); aProp->setTitle(theTitle); } + aProp->setMin(theMin); + aProp->setMax(theMax); } else { - aProp = new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue); + aProp = + new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue, theMin, theMax); myProps.push_back(aProp); } return aProp; diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h index 60e32f589..00dd75b73 100644 --- a/src/Config/Config_PropManager.h +++ b/src/Config/Config_PropManager.h @@ -44,19 +44,27 @@ class Config_PropManager * \param theTitle - title of the value. * \param theType - type of the value. * \param theDefValue - default and initial value of the property + * \param theMin - minimal value + * \param theMax - minimal value * Returns True if the property succesfully registered */ CONFIG_EXPORT static Config_Prop* registerProp(const std::string& theSection, const std::string& theName, const std::string& theTitle, Config_Prop::PropType theType, - const std::string& theDefValue = ""); + const std::string& theDefValue = "", + const std::string& theMin = "", + const std::string& theMax = ""); + //! Finds property in the given section by the given name, if property not found returns NULL CONFIG_EXPORT static Config_Prop* findProp( const std::string& theSection, const std::string& theName); + //! Returns std::list of all existing properies CONFIG_EXPORT static Config_Properties getProperties(); + //! Returns list of registered section names. CONFIG_EXPORT static std::list getSections(); + //! Returns list of properties by its owner and section. CONFIG_EXPORT static Config_Properties getProperties(const std::string& theSection); @@ -74,7 +82,8 @@ class Config_PropManager const std::string& theName); //! Returns boolean by given section and name CONFIG_EXPORT static bool boolean(const std::string& theSection, - const std::string& theName); + const std::string& theName); + //! Returns convertion of the string to double value. Temporary changes locale to process //! values contained "," or "." separator. //! \param theDouble a value to be converted diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 3eaecc591..c417c11d8 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -56,7 +56,7 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() new ConstructionPlugin_ValidatorPointThreeNonParallelPlanes()); Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::DblSpin, - PLANE_SIZE); + PLANE_SIZE, "0", "1000"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness", Config_Prop::IntSpin, SKETCH_WIDTH); Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane", diff --git a/src/ModuleBase/ModuleBase_Preferences.cpp b/src/ModuleBase/ModuleBase_Preferences.cpp index c7da97099..e53ec5088 100644 --- a/src/ModuleBase/ModuleBase_Preferences.cpp +++ b/src/ModuleBase/ModuleBase_Preferences.cpp @@ -188,6 +188,16 @@ void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int if(aProp->type() == Config_Prop::Directory) { thePref->setItemProperty("path_type", Qtx::PT_Directory, anId); } + if (aPrefType == SUIT_PreferenceMgr::DblSpin) { + if (aProp->min() != "") { + double aMin = QString(aProp->min().c_str()).toDouble(); + thePref->setItemProperty("min", aMin, anId); + } + if (aProp->max() != "") { + double aMax = QString(aProp->max().c_str()).toDouble(); + thePref->setItemProperty("max", aMax, anId); + } + } } } }