new Events_Message(aChangedEvent, this)));
}
}
+
+void Config_Prop::setDefaultValue(const std::string& theValue)
+{
+ if (theValue != myDefaultValue) {
+ myDefaultValue = theValue;
+ }
+}
* \param theSection - name of section (domain of using) of the property.
* \param theName - name (title) of the value.
* \param theType - type of the value.
- * \param theValue - initial value of the property.
+ * \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& theValue)
+ const std::string& theTitle, PropType theType, const std::string& theDefaultValue)
{
mySection = theSection;
myName = theName;
myTitle = theTitle;
myType = theType;
- myValue = theValue;
+ myValue = theDefaultValue;
+ myDefaultValue = theDefaultValue;
}
std::string section() const
}
CONFIG_EXPORT void setValue(const std::string& theValue);
+
+ std::string defaultValue() const
+ {
+ return myDefaultValue;
+ }
+
+ CONFIG_EXPORT void setDefaultValue(const std::string& theValue);
bool operator==(const Config_Prop* theProp) const
{
std::string myTitle;
PropType myType;
std::string myValue;
+ std::string myDefaultValue;
};
typedef std::list<Config_Prop*> Config_Properties;
Config_Properties Config_PropManager::myProps;
-bool Config_PropManager::registerProp(const std::string& theSection, const std::string& theName,
- const std::string& theTitle, Config_Prop::PropType theType,
- const std::string& theValue)
+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)
{
Config_Prop* aProp = findProp(theSection, theName);
+
if (aProp) {
+ if (aProp->value() == "") {
+ aProp->setValue(theDefaultValue);
+ }
+ if (aProp->defaultValue() == "") {
+ aProp->setDefaultValue(theDefaultValue);
+ }
if (aProp->type() == Config_Prop::Disabled) {
aProp->setType(theType);
aProp->setTitle(theTitle);
- return true;
}
- return false;
}
- aProp = new Config_Prop(theSection, theName, theTitle, theType, theValue);
- myProps.push_back(aProp);
- return true;
+ else {
+ aProp = new Config_Prop(theSection, theName, theTitle, theType, theDefaultValue);
+ myProps.push_back(aProp);
+ }
+ return aProp;
}
Config_Prop* Config_PropManager::findProp(const std::string& theSection, const std::string& theName)
LightApp_Module::initialize(theApp);
myWorkshop->startApplication();
+ LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
+ if (anApp)
+ connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
}
//******************************************************
}
}
+//******************************************************
+void NewGeom_Module::onDefaultPreferences()
+{
+ XGUI_Preferences::resetConfig();
+ XGUI_Preferences::updateResourcesByConfig();
+
+ LightApp_Preferences* pref = preferences();
+ if (pref)
+ pref->retrieve();
+}
+
//******************************************************
NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr)
{
LightApp_Preferences* pref = preferences();
if (!pref)
return;
- XGUI_Preferences::updateCustomProps();
+ XGUI_Preferences::updateConfigByResources();
QString aModName = moduleName();
QtxPreferenceItem* item = pref->findItem(aModName, true );
{
SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
QString aVal = aResMgr->stringValue(theSection, theParam);
- if (!aVal.isNull()) {
- Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
- aProp->setValue(aVal.toStdString());
+ Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(), theParam.toStdString());
+ std::string aValue = aVal.toStdString();
+ if (aValue.empty()) {
+ aValue = aProp->defaultValue();
+ aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
+
+ LightApp_Preferences* pref = preferences();
+ if (pref)
+ pref->retrieve();
}
+ aProp->setValue(aValue);
+
}
protected slots:
virtual void onViewManagerAdded(SUIT_ViewManager* theMgr);
+ void onDefaultPreferences();
protected:
CAM_DataModel* createDataModel();
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("SketchPlugin_DistanceAttr",
- new SketchPlugin_DistanceAttrValidator);
+ new SketchPlugin_DistanceAttrValidator);
aFactory->registerValidator("SketchPlugin_DifferentObjects",
new SketchPlugin_DifferentObjectsValidator);
aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
SKETCH_PLANE_COLOR);
Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
PLANE_SIZE);
- Config_PropManager::registerProp("Sketch planes", "planes_thikness", "Thickness",
+ Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
Config_Prop::Integer, SKETCH_WIDTH);
Config_PropManager::registerProp("Visualization", "parallel_color", "Parallel constraint color",
SKETCH_PLANE_COLOR);
aAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
- aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thikness",
+ aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness",
SKETCH_WIDTH));
}
return aAIS;
#include <QLayout>
#include <QApplication>
#include <QDialogButtonBox>
+#include <QPushButton>
const QString XGUI_Preferences::VIEWER_SECTION = "Viewer";
const QString XGUI_Preferences::MENU_SECTION = "Menu";
return false;
}
-void XGUI_Preferences::updateCustomProps()
+void XGUI_Preferences::updateConfigByResources()
{
Config_Properties aProps = Config_PropManager::getProperties();
Config_Properties::iterator aIt;
Config_Prop* aProp = (*aIt);
QString aVal = myResourceMgr->stringValue(QString(aProp->section().c_str()),
QString(aProp->name().c_str()));
- if (!aVal.isNull())
+ if (!aVal.isEmpty()) {
aProp->setValue(aVal.toStdString());
+ }
+ }
+}
+
+void XGUI_Preferences::updateResourcesByConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ myResourceMgr->setValue(QString(aProp->section().c_str()), QString(aProp->name().c_str()),
+ QString(aProp->value().c_str()));
+ }
+}
+
+void XGUI_Preferences::resetConfig()
+{
+ Config_Properties aProps = Config_PropManager::getProperties();
+ Config_Properties::iterator aIt;
+ for (aIt = aProps.begin(); aIt != aProps.end(); ++aIt) {
+ Config_Prop* aProp = (*aIt);
+ aProp->setValue(aProp->defaultValue());
}
}
QStringList aParams = myResourceMgr->parameters(aSection);
foreach (QString aParam, aParams)
{
- Config_PropManager::registerProp(aSection.toStdString(), aParam.toStdString(), "",
- Config_Prop::Disabled,
- myResourceMgr->stringValue(aSection, aParam).toStdString());
+ Config_Prop* aProp = Config_PropManager::registerProp(aSection.toStdString(),
+ aParam.toStdString(), "", Config_Prop::Disabled);
+ aProp->setValue(myResourceMgr->stringValue(aSection, aParam).toStdString());
}
}
}
setFocusProxy(myPreferences);
myPreferences->setFrameStyle(QFrame::Box | QFrame::Sunken);
- QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ QDialogButtonBox* aBtnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel |
+ QDialogButtonBox::Reset,
Qt::Horizontal, this);
+ QPushButton* aDefaultButton = aBtnBox->button(QDialogButtonBox::Reset);
+ aDefaultButton->setText(tr("Default"));
+ connect(aDefaultButton, SIGNAL(clicked()), this, SLOT(onDefault()));
+
main->addWidget(aBtnBox);
connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
myIsChanged = true;
// Save custom properties
- XGUI_Preferences::updateCustomProps();
+ XGUI_Preferences::updateConfigByResources();
QDialog::accept();
}
theModified = myPreferences->modified();
}
+void XGUI_PreferencesDlg::onDefault()
+{
+ // reset main resources
+ QtxResourceMgr::WorkingMode aPrev = myPreferences->resourceMgr()->setWorkingMode
+ (QtxResourceMgr::IgnoreUserValues);
+ myPreferences->retrieve();
+ myPreferences->resourceMgr()->setWorkingMode(aPrev);
+
+ // reset plugin's resources
+ XGUI_Preferences::resetConfig();
+ XGUI_Preferences::updateResourcesByConfig(false);
+
+ myPreferences->retrieve();
+}
+
//**********************************************************
//**********************************************************
//**********************************************************
/// It is used in case of necessity to define external resource manager (not NewGeom)
static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
- /// Updates properties defined by module from SUIT_ResourceMgr to Config_PropManager
- static void updateCustomProps();
+ /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
+ static void updateConfigByResources();
+
+ /// Updates SUIT_ResourceMgr values by Config_PropManager properties
+ /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
+ static void updateResourcesByConfig();
+
+ /// Set default values to the Config_PropManager properties
+ static void resetConfig();
/// Loads properties defined by module to Config_PropManager
static void loadCustomProps();
public slots:
virtual void accept();
+protected slots:
+ void onDefault();
+
private:
/// Create editors for aplication properties
void createEditors();