Refactor Configuration.cpp to improve performance and code quality
This commit is contained in:
parent
9441b50e92
commit
21cadcc5af
|
|
@ -670,21 +670,15 @@ void Configuration::readColors()
|
|||
{
|
||||
Colors = defaultColors;
|
||||
//read config
|
||||
for(int i = 0; i < Colors.size(); i++)
|
||||
{
|
||||
QString id = Colors.keys().at(i);
|
||||
Colors[id] = colorFromConfig(id);
|
||||
}
|
||||
for(auto it = Colors.begin(); it != Colors.end(); ++it)
|
||||
it.value() = colorFromConfig(it.key());
|
||||
}
|
||||
|
||||
void Configuration::writeColors()
|
||||
{
|
||||
//write config
|
||||
for(int i = 0; i < Colors.size(); i++)
|
||||
{
|
||||
QString id = Colors.keys().at(i);
|
||||
colorToConfig(id, Colors[id]);
|
||||
}
|
||||
for(auto it = Colors.begin(); it != Colors.end(); ++it)
|
||||
colorToConfig(it.key(), it.value());
|
||||
emit colorsUpdated();
|
||||
}
|
||||
|
||||
|
|
@ -692,14 +686,12 @@ void Configuration::readBools()
|
|||
{
|
||||
Bools = defaultBools;
|
||||
//read config
|
||||
for(int i = 0; i < Bools.size(); i++)
|
||||
for(auto itMap = Bools.begin(); itMap != Bools.end(); ++itMap)
|
||||
{
|
||||
QString category = Bools.keys().at(i);
|
||||
QMap<QString, bool> & currentBool = Bools[category];
|
||||
for(int j = 0; j < currentBool.size(); j++)
|
||||
const QString & category = itMap.key();
|
||||
for(auto it = itMap.value().begin(); it != itMap.value().end(); it++)
|
||||
{
|
||||
QString id = currentBool.keys().at(j);
|
||||
currentBool[id] = boolFromConfig(category, id);
|
||||
it.value() = boolFromConfig(category, it.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -707,14 +699,12 @@ void Configuration::readBools()
|
|||
void Configuration::writeBools()
|
||||
{
|
||||
//write config
|
||||
for(int i = 0; i < Bools.size(); i++)
|
||||
for(auto itMap = Bools.cbegin(); itMap != Bools.cend(); ++itMap)
|
||||
{
|
||||
QString category = Bools.keys().at(i);
|
||||
QMap<QString, bool>* currentBool = &Bools[category];
|
||||
for(int j = 0; j < currentBool->size(); j++)
|
||||
const QString & category = itMap.key();
|
||||
for(auto it = itMap.value().cbegin(); it != itMap.value().cend(); it++)
|
||||
{
|
||||
QString id = (*currentBool).keys().at(j);
|
||||
boolToConfig(category, id, (*currentBool)[id]);
|
||||
boolToConfig(category, it.key(), it.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -723,14 +713,12 @@ void Configuration::readUints()
|
|||
{
|
||||
Uints = defaultUints;
|
||||
//read config
|
||||
for(int i = 0; i < Uints.size(); i++)
|
||||
for(auto itMap = Uints.begin(); itMap != Uints.end(); ++itMap)
|
||||
{
|
||||
QString category = Uints.keys().at(i);
|
||||
QMap<QString, duint> & currentUint = Uints[category];
|
||||
for(int j = 0; j < currentUint.size(); j++)
|
||||
const QString & category = itMap.key();
|
||||
for(auto it = itMap.value().begin(); it != itMap.value().end(); it++)
|
||||
{
|
||||
QString id = currentUint.keys().at(j);
|
||||
currentUint[id] = uintFromConfig(category, id);
|
||||
it.value() = uintFromConfig(category, it.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -741,19 +729,17 @@ void Configuration::writeUints()
|
|||
bool bSaveLoadTabOrder = ConfigBool("Gui", "LoadSaveTabOrder");
|
||||
|
||||
//write config
|
||||
for(int i = 0; i < Uints.size(); i++)
|
||||
for(auto itMap = Bools.cbegin(); itMap != Bools.cend(); ++itMap)
|
||||
{
|
||||
QString category = Uints.keys().at(i);
|
||||
QMap<QString, duint>* currentUint = &Uints[category];
|
||||
for(int j = 0; j < currentUint->size(); j++)
|
||||
const QString & category = itMap.key();
|
||||
for(auto it = itMap.value().cbegin(); it != itMap.value().cend(); it++)
|
||||
{
|
||||
QString id = (*currentUint).keys().at(j);
|
||||
|
||||
// Do not save settings to file if saveLoadTabOrder checkbox is Unchecked
|
||||
const QString & id = it.key();
|
||||
if(!bSaveLoadTabOrder && category == "TabOrder" && BridgeSettingGetUint(category.toUtf8().constData(), id.toUtf8().constData(), &setting))
|
||||
continue;
|
||||
|
||||
uintToConfig(category, id, (*currentUint)[id]);
|
||||
uintToConfig(category, id, it.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -762,24 +748,21 @@ void Configuration::readFonts()
|
|||
{
|
||||
Fonts = defaultFonts;
|
||||
//read config
|
||||
for(int i = 0; i < Fonts.size(); i++)
|
||||
for(auto it = Fonts.begin(); it != Fonts.end(); ++it)
|
||||
{
|
||||
QString id = Fonts.keys().at(i);
|
||||
const QString & id = it.key();
|
||||
QFont font = fontFromConfig(id);
|
||||
QFontInfo fontInfo(font);
|
||||
if(id == "Application" || fontInfo.fixedPitch())
|
||||
Fonts[id] = font;
|
||||
it.value() = font;
|
||||
}
|
||||
}
|
||||
|
||||
void Configuration::writeFonts()
|
||||
{
|
||||
//write config
|
||||
for(int i = 0; i < Fonts.size(); i++)
|
||||
{
|
||||
QString id = Fonts.keys().at(i);
|
||||
fontToConfig(id, Fonts[id]);
|
||||
}
|
||||
for(auto it = Fonts.cbegin(); it != Fonts.cend(); ++it)
|
||||
fontToConfig(it.key(), it.value());
|
||||
emit fontsUpdated();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue