code format
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <QColor>
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
|
||||
PropertyStorage::PropertyStorage(const QVariantMap & pl) {
|
||||
QMapIterator<QString, QVariant> it(pl);
|
||||
@@ -13,7 +14,7 @@ PropertyStorage::PropertyStorage(const QVariantMap & pl) {
|
||||
|
||||
QVariantMap PropertyStorage::toVariantMap() const {
|
||||
QVariantMap ret;
|
||||
foreach (const Property & p, props)
|
||||
foreach(const Property & p, props)
|
||||
ret[p.name] = p.value;
|
||||
return ret;
|
||||
}
|
||||
@@ -21,8 +22,7 @@ QVariantMap PropertyStorage::toVariantMap() const {
|
||||
|
||||
bool PropertyStorage::isPropertyExists(const QString & _name) const {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == _name)
|
||||
return true;
|
||||
if (props[i].name == _name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,33 +57,29 @@ void PropertyStorage::removePropertiesByFlag(int flag) {
|
||||
|
||||
void PropertyStorage::updateProperties(const QList<PropertyStorage::Property> & properties_, int flag_ignore) {
|
||||
QVariantMap values;
|
||||
foreach (const PropertyStorage::Property & p, props)
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0))
|
||||
values[p.name] = p.value;
|
||||
foreach(const PropertyStorage::Property & p, props)
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0)) values[p.name] = p.value;
|
||||
props = properties_;
|
||||
for (int i = 0; i < props.size(); ++i) {
|
||||
PropertyStorage::Property & p(props[i]);
|
||||
if (values.contains(p.name)) {
|
||||
QVariant pv = values[p.name];
|
||||
if (pv.userType() == p.value.userType())
|
||||
p.value = pv;
|
||||
if (pv.userType() == p.value.userType()) p.value = pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PropertyStorage::Property PropertyStorage::propertyByName(const QString & name) const {
|
||||
foreach (const Property & p, props)
|
||||
if (p.name == name)
|
||||
return p;
|
||||
foreach(const Property & p, props)
|
||||
if (p.name == name) return p;
|
||||
return Property();
|
||||
}
|
||||
|
||||
|
||||
QVariant PropertyStorage::propertyValueByName(const QString & name) const {
|
||||
foreach (const Property & p, props)
|
||||
if (p.name == name)
|
||||
return p.value;
|
||||
foreach(const Property & p, props)
|
||||
if (p.name == name) return p.value;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@@ -120,8 +116,8 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
QString pn, pc, pt("s"), pv;
|
||||
if (l.contains('#')) {
|
||||
int i = l.indexOf('#');
|
||||
pn = l.left(i).trimmed();
|
||||
pc = l.right(l.length() - i - 1).trimmed();
|
||||
pn = l.left(i).trimmed();
|
||||
pc = l.right(l.length() - i - 1).trimmed();
|
||||
} else {
|
||||
if (l.contains('(')) {
|
||||
int bs = l.indexOf('('), be = l.indexOf(')');
|
||||
@@ -130,7 +126,7 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
l.remove(bs, be - bs + 1);
|
||||
} else {
|
||||
pc = l.right(l.length() - bs - 1).trimmed();
|
||||
l = l.left(bs);
|
||||
l = l.left(bs);
|
||||
}
|
||||
}
|
||||
pn = l.trimmed();
|
||||
@@ -141,36 +137,42 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
}
|
||||
if (pn.contains('=')) {
|
||||
int i = pn.indexOf('=');
|
||||
pv = pn.right(pn.length() - i - 1).trimmed();
|
||||
pv = pn.right(pn.length() - i - 1).trimmed();
|
||||
pn.truncate(i);
|
||||
pn = pn.trimmed();
|
||||
}
|
||||
ret.name = pn;
|
||||
ret.name = pn;
|
||||
ret.comment = pc;
|
||||
ret.value = QVariant(typeFromLetter(pt));
|
||||
ret.value = QVariant(typeFromLetter(pt));
|
||||
if (!pv.isEmpty()) {
|
||||
//qDebug() << "set value !" << pv;
|
||||
// qDebug() << "set value !" << pv;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
switch (ret.value.type()) {
|
||||
case QVariant::Bool: pv = pv.toLower(); ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false); break;
|
||||
case QVariant::Int: ret.value = pv.toInt(); break;
|
||||
case QVariant::UInt: ret.value = pv.toUInt(); break;
|
||||
case QVariant::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QVariant::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QVariant::Double: ret.value = pv.toDouble(); break;
|
||||
case QVariant::Color: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
case QVariant::Bool:
|
||||
pv = pv.toLower();
|
||||
ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false);
|
||||
break;
|
||||
case QVariant::Int: ret.value = pv.toInt(); break;
|
||||
case QVariant::UInt: ret.value = pv.toUInt(); break;
|
||||
case QVariant::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QVariant::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QVariant::Double: ret.value = pv.toDouble(); break;
|
||||
case QVariant::Color: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
};
|
||||
#else
|
||||
switch (ret.value.metaType().id()) {
|
||||
case QMetaType::Bool: pv = pv.toLower(); ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false); break;
|
||||
case QMetaType::Int: ret.value = pv.toInt(); break;
|
||||
case QMetaType::UInt: ret.value = pv.toUInt(); break;
|
||||
case QMetaType::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QMetaType::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QMetaType::Double: ret.value = pv.toDouble(); break;
|
||||
case QMetaType::QColor: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
case QMetaType::Bool:
|
||||
pv = pv.toLower();
|
||||
ret.value = (pv == "on" || pv == "true" || pv == "enable" || pv == "enabled" || pv.toInt() > 0 ? true : false);
|
||||
break;
|
||||
case QMetaType::Int: ret.value = pv.toInt(); break;
|
||||
case QMetaType::UInt: ret.value = pv.toUInt(); break;
|
||||
case QMetaType::LongLong: ret.value = pv.toLongLong(); break;
|
||||
case QMetaType::ULongLong: ret.value = pv.toULongLong(); break;
|
||||
case QMetaType::Double: ret.value = pv.toDouble(); break;
|
||||
case QMetaType::QColor: ret.value = QColor(pv); break;
|
||||
default: ret.value = pv; break;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
@@ -180,8 +182,7 @@ PropertyStorage::Property PropertyStorage::parsePropertyLine(QString l) {
|
||||
|
||||
PropertyStorage::Property & PropertyStorage::operator[](const QString & name) {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name)
|
||||
return props[i];
|
||||
if (props[i].name == name) return props[i];
|
||||
addProperty(name, "");
|
||||
return props.back();
|
||||
}
|
||||
@@ -189,7 +190,6 @@ PropertyStorage::Property & PropertyStorage::operator[](const QString & name) {
|
||||
|
||||
const PropertyStorage::Property PropertyStorage::operator[](const QString & name) const {
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == name)
|
||||
return props[i];
|
||||
if (props[i].name == name) return props[i];
|
||||
return Property();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user