void DlgPreferencesImp::restoreDefaults() { QMessageBox box(this); box.setIcon(QMessageBox::Question); box.setWindowTitle(tr("Clear user settings")); box.setText(tr("Do you want to clear all your user settings?")); box.setInformativeText(tr("If you agree all your settings will be cleared.")); box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); box.setDefaultButton(QMessageBox::No); if (box.exec() == QMessageBox::Yes) { // keep this parameter bool saveParameter = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> GetBool("SaveUserParameter", true); ParameterManager* mgr = App::GetApplication().GetParameterSet("User parameter"); mgr->Clear(); App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> SetBool("SaveUserParameter", saveParameter); #if 0 QList<PreferencePage*> pages = this->findChildren<PreferencePage*>(); for (QList<PreferencePage*>::iterator it = pages.begin(); it != pages.end(); ++it) { (*it)->loadSettings(); } #else reject(); #endif } }
void ParameterGrp::insert(const char* FileName) { ParameterManager Mngr; if (Mngr.LoadDocument(FileName) != 1) throw FileException("ParameterGrp::import() cannot load document", FileName); Mngr.GetGroup("root")->insertTo(Base::Reference<ParameterGrp>(this)); }
void ParameterGrp::importFrom(const char* FileName) { ParameterManager Mngr; if (Mngr.LoadDocument(FileName) != 1) throw Exception("ParameterGrp::import() cannot load document"); Mngr.GetGroup("BaseApp")->copyTo(Base::Reference<ParameterGrp>(this)); }
void ParameterGrp::exportTo(const char* FileName) { ParameterManager Mngr; Mngr.CreateDocument(); // copy all into the new document insertTo(Mngr.GetGroup("BaseApp")); Mngr.SaveDocument(FileName); }
void DlgPreferencesImp::applyChanges() { try { for (int i=0; i<ui->tabWidgetStack->count(); i++) { QTabWidget* tabWidget = (QTabWidget*)ui->tabWidgetStack->widget(i); for (int j=0; j<tabWidget->count(); j++) { QWidget* page = tabWidget->widget(j); int index = page->metaObject()->indexOfMethod("checkSettings()"); try { if (index >= 0) { page->qt_metacall(QMetaObject::InvokeMetaMethod, index, 0); } } catch (const Base::Exception& e) { ui->listBox->setCurrentRow(i); tabWidget->setCurrentIndex(j); QMessageBox::warning(this, tr("Wrong parameter"), QString::fromAscii(e.what())); throw; } } } } catch (const Base::Exception&) { this->invalidParameter = true; return; } for (int i=0; i<ui->tabWidgetStack->count(); i++) { QTabWidget* tabWidget = (QTabWidget*)ui->tabWidgetStack->widget(i); for (int j=0; j<tabWidget->count(); j++) { PreferencePage* page = qobject_cast<PreferencePage*>(tabWidget->widget(j)); if (page) page->saveSettings(); } } bool saveParameter = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> GetBool("SaveUserParameter", true); if (saveParameter) { ParameterManager* parmgr = App::GetApplication().GetParameterSet("User parameter"); parmgr->SaveDocument(App::Application::Config()["UserParameter"].c_str()); } }
bool ParameterSerializer::LoadOrCreateDocument(ParameterManager& mgr) { return mgr.LoadOrCreateDocument(filename.c_str()); }
int ParameterSerializer::LoadDocument(ParameterManager& mgr) { return mgr.LoadDocument(filename.c_str()); }
void ParameterSerializer::SaveDocument(const ParameterManager& mgr) { mgr.SaveDocument(filename.c_str()); }