Commit d5822aed authored by Ahmad Samir's avatar Ahmad Samir Committed by Tomaz Canabrava
Browse files

Adjust usage of Profile::DefaultPropertyNames

Now we can use range-for.
parent dfc8e6ed
......@@ -158,11 +158,7 @@ void Profile::fillTableWithDefaultNames()
return;
}
const PropertyInfo *iter = DefaultPropertyNames;
while (iter->name != nullptr) {
registerProperty(*iter);
iter++;
}
std::for_each(DefaultPropertyNames.cbegin(), DefaultPropertyNames.cend(), Profile::registerProperty);
filledDefaults = true;
}
......@@ -267,20 +263,15 @@ Profile::Profile(const Profile::Ptr &parent)
void Profile::clone(Profile::Ptr profile, bool differentOnly)
{
const PropertyInfo *properties = DefaultPropertyNames;
while (properties->name != nullptr) {
Property current = properties->property;
for (const PropertyInfo &info : DefaultPropertyNames) {
Property current = info.property;
QVariant otherValue = profile->property<QVariant>(current);
switch (current) {
case Name:
case Path:
break;
default:
if (!differentOnly || property<QVariant>(current) != otherValue) {
setProperty(current, otherValue);
}
if (current == Name || current == Path) { // These are unique per Profile
continue;
}
if (!differentOnly || property<QVariant>(current) != otherValue) {
setProperty(current, otherValue);
}
properties++;
}
}
......@@ -343,16 +334,14 @@ void Profile::registerProperty(const PropertyInfo &info)
PropertyInfoByName.insert(name.toLower(), info);
}
const QStringList Profile::propertiesInfoList() const
QStringList Profile::propertiesInfoList() const
{
QStringList info;
const PropertyInfo *iter = DefaultPropertyNames;
while (iter->name != nullptr) {
info << QLatin1String(iter->name) + QStringLiteral(" : ") + QLatin1String(QVariant(iter->type).typeName());
iter++;
QStringList list;
list.reserve(DefaultPropertyNames.size());
for (const PropertyInfo &info : DefaultPropertyNames) {
list.push_back(QLatin1String(info.name) + QLatin1String(" : ") + QLatin1String(QVariant(info.type).typeName()));
}
return info;
return list;
}
const Profile::GroupPtr Profile::asGroup() const
......
......@@ -743,7 +743,7 @@ public:
/** Return a list of all properties names and their type
* (for use with -p option).
*/
const QStringList propertiesInfoList() const;
QStringList propertiesInfoList() const;
/**
* Returns the element from the Property enum associated with the
......
......@@ -30,21 +30,19 @@ QList<Profile::Ptr> ProfileGroup::profiles() const
void ProfileGroup::updateValues()
{
const PropertyInfo *properties = Profile::DefaultPropertyNames;
while (properties->name != nullptr) {
for (const PropertyInfo &info : Profile::DefaultPropertyNames) {
// the profile group does not store a value for some properties
// (eg. name, path) if even they are equal between profiles -
//
// the exception is when the group has only one profile in which
// case it behaves like a standard Profile
if (_profiles.count() > 1 && !canInheritProperty(properties->property)) {
properties++;
if (_profiles.count() > 1 && !canInheritProperty(info.property)) {
continue;
}
QVariant value;
for (int i = 0; i < _profiles.count(); i++) {
QVariant profileValue = _profiles[i]->property<QVariant>(properties->property);
QVariant profileValue = _profiles[i]->property<QVariant>(info.property);
if (value.isNull()) {
value = profileValue;
} else if (value != profileValue) {
......@@ -52,8 +50,7 @@ void ProfileGroup::updateValues()
break;
}
}
Profile::setProperty(properties->property, value);
properties++;
Profile::setProperty(info.property, value);
}
}
......
......@@ -46,26 +46,24 @@ QStringList ProfileReader::findProfiles()
return profiles;
}
void ProfileReader::readProperties(const KConfig &config, Profile::Ptr profile, const Profile::PropertyInfo *properties)
void ProfileReader::readProperties(const KConfig &config, Profile::Ptr profile)
{
const char *groupName = nullptr;
KConfigGroup group;
for (const Profile::PropertyInfo &info : Profile::DefaultPropertyNames) {
if (info.group == nullptr) {
continue;
}
if (groupName == nullptr || qstrcmp(groupName, info.group) != 0) {
group = config.group(info.group);
groupName = info.group;
}
while (properties->name != nullptr) {
if (properties->group != nullptr) {
if (groupName == nullptr || qstrcmp(groupName, properties->group) != 0) {
group = config.group(properties->group);
groupName = properties->group;
}
QString name(QLatin1String(properties->name));
const QString name(QLatin1String(info.name));
if (group.hasKey(name)) {
profile->setProperty(properties->property, group.readEntry(name, QVariant(properties->type)));
}
if (group.hasKey(name)) {
profile->setProperty(info.property, group.readEntry(name, QVariant(info.type)));
}
properties++;
}
}
......@@ -105,7 +103,7 @@ bool ProfileReader::readProfile(const QString &path, Profile::Ptr profile, QStri
profile->setProperty(Profile::UntranslatedName, general.readEntryUntranslated("Name"));
// Read remaining properties
readProperties(config, profile, Profile::DefaultPropertyNames);
readProperties(config, profile);
return true;
}
......@@ -38,7 +38,7 @@ public:
bool readProfile(const QString &path, Profile::Ptr profile, QString &parentProfile);
private:
void readProperties(const KConfig &config, Profile::Ptr profile, const Profile::PropertyInfo *properties);
void readProperties(const KConfig &config, Profile::Ptr profile);
};
}
......
......@@ -36,24 +36,22 @@ QString ProfileWriter::getPath(const Profile::Ptr &profile)
return localDataLocation % QLatin1String("/") % profile->untranslatedName() % QLatin1String(".profile");
}
void ProfileWriter::writeProperties(KConfig &config, const Profile::Ptr &profile, const Profile::PropertyInfo *properties)
void ProfileWriter::writeProperties(KConfig &config, const Profile::Ptr &profile)
{
const char *groupName = nullptr;
KConfigGroup group;
while (properties->name != nullptr) {
if (properties->group != nullptr) {
if (groupName == nullptr || qstrcmp(groupName, properties->group) != 0) {
group = config.group(properties->group);
groupName = properties->group;
for (const Profile::PropertyInfo &info : Profile::DefaultPropertyNames) {
if (info.group != nullptr) {
if (groupName == nullptr || qstrcmp(groupName, info.group) != 0) {
group = config.group(info.group);
groupName = info.group;
}
if (profile->isPropertySet(properties->property)) {
group.writeEntry(QLatin1String(properties->name), profile->property<QVariant>(properties->property));
if (profile->isPropertySet(info.property)) {
group.writeEntry(QLatin1String(info.name), profile->property<QVariant>(info.property));
}
}
properties++;
}
}
......@@ -78,7 +76,7 @@ bool ProfileWriter::writeProfile(const QString &path, const Profile::Ptr &profil
}
// Write remaining properties
writeProperties(config, profile, Profile::DefaultPropertyNames);
writeProperties(config, profile);
return true;
}
......@@ -36,7 +36,7 @@ public:
bool writeProfile(const QString &path, const Profile::Ptr &profile);
private:
void writeProperties(KConfig &config, const Profile::Ptr &profile, const Profile::PropertyInfo *properties);
void writeProperties(KConfig &config, const Profile::Ptr &profile);
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment