Commit 303a2106 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.rewriter: handle enums as enums instead of pure strings

The scopes of enumerators have to be fixed for this.


Reviewed-by: Marco Bubke
parent 1473d205
......@@ -144,6 +144,14 @@ void MetaInfoPrivate::loadPlugins(QDeclarativeEngine *engine)
pluginComponent.setData(componentString.toLatin1(), QUrl());
}
QString static inline stripPrefix(const QString &typeName)
{
QStringList list = typeName.split('/');
if (list.count() == 2)
return list.last();
return typeName;
}
void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObject *qMetaObject) const
{
Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject");
......@@ -181,7 +189,11 @@ void MetaInfoPrivate::parseProperties(NodeMetaInfo &nodeMetaInfo, const QMetaObj
enumerator.setValid(qEnumerator.isValid());
enumerator.setIsFlagType(qEnumerator.isFlag());
enumerator.setScope(qEnumerator.scope());
QString scope = qEnumerator.scope();
if (m_QtTypesToQmlTypes.contains(scope))
scope = stripPrefix(m_QtTypesToQmlTypes.value(scope));
enumerator.setScope(scope);
enumerator.setName(qEnumerator.name());
for (int i = 0 ;i < qEnumerator.keyCount(); i++)
{
......
......@@ -94,25 +94,30 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
if (property.name() == QLatin1String("id"))
return stringValue;
switch (value.type()) {
case QVariant::Bool:
if (value.value<bool>())
return QLatin1String("true");
else
return QLatin1String("false");
if (variantProperty.metaInfo().isValid() && variantProperty.metaInfo().isEnumType()) {
return variantProperty.metaInfo().enumerator().scope() + '.' + stringValue;
} else {
switch (value.type()) {
case QVariant::Bool:
if (value.value<bool>())
return QLatin1String("true");
else
return QLatin1String("false");
case QVariant::Color:
return QString(QLatin1String("\"%1\"")).arg(properColorName(value.value<QColor>()));
case QVariant::Color:
return QString(QLatin1String("\"%1\"")).arg(properColorName(value.value<QColor>()));
case QVariant::Double:
case QVariant::Int:
case QVariant::LongLong:
case QVariant::UInt:
case QVariant::ULongLong:
return stringValue;
case QVariant::Double:
case QVariant::Int:
case QVariant::LongLong:
case QVariant::UInt:
case QVariant::ULongLong:
return stringValue;
default:
return QString(QLatin1String("\"%1\"")).arg(escape(stringValue));
default:
return QString(QLatin1String("\"%1\"")).arg(escape(stringValue));
}
}
} else {
Q_ASSERT("Unknown property type");
......
Markdown is supported
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