void Settings::saveSettings(const QString & fileName, const QByteArray & windowGeometry, const QByteArray & windowState) { QString path = fileName; if(fileName.isEmpty()) { path = iniDefaultPath(); } QSettings ini(path, QSettings::IniFormat); for(ParametersMap::const_iterator iter = parameters_.begin(); iter!=parameters_.end(); ++iter) { QString type = Settings::getParametersType().value(iter.key()); if(type.compare("float") == 0) { ini.setValue(iter.key(), QString::number(iter.value().toFloat(),'g',6)); } else { ini.setValue(iter.key(), iter.value()); } } if(!windowGeometry.isEmpty()) { ini.setValue("windowGeometry", windowGeometry); } if(!windowState.isEmpty()) { ini.setValue("windowState", windowState); } printf("Settings saved to %s\n", path.toStdString().c_str()); }
QString Settings::iniPath() { if(!iniPath_.isNull()) { return iniPath_; } return iniDefaultPath(); }
void Settings::loadSettings(const QString & fileName, QByteArray * windowGeometry, QByteArray * windowState) { QString path = fileName; if(fileName.isEmpty()) { path = iniDefaultPath(); } QSettings ini(path, QSettings::IniFormat); for(ParametersMap::const_iterator iter = defaultParameters_.begin(); iter!=defaultParameters_.end(); ++iter) { const QString & key = iter.key(); QVariant value = ini.value(key, QVariant()); if(value.isValid()) { QString str = value.toString(); if(str.contains(";") && str.size() != getParameter(key).toString().size()) { // If a string list is modified, update the value // (assuming that index < 10... one character for index) QChar index = str.at(0); str = getParameter(key).toString(); str[0] = index.toAscii(); value = QVariant(str); printf("Updated list of parameter \"%s\"\n", key.toStdString().c_str()); } setParameter(key, value); } } if(windowGeometry) { QVariant value = ini.value("windowGeometry", QVariant()); if(value.isValid()) { *windowGeometry = value.toByteArray(); } } if(windowState) { QVariant value = ini.value("windowState", QVariant()); if(value.isValid()) { *windowState = value.toByteArray(); } } printf("Settings loaded from %s\n", path.toStdString().c_str()); }