Commit 10ca8716 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Tim Jenssen

QmlDesigner: Read hints for item handling

This patch allows an arbitrary hints
section section for each item in the .metainfo file.

Change-Id: I85d7171d1aaacd96a327df3e350978b859913d00
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 683b9652
......@@ -74,6 +74,7 @@ public:
typedef QmlDesigner::PropertyContainer Property;
QList<Property> properties() const;
QHash<QString, QString> hints() const;
void setType(const TypeName &typeName, int majorVersion = -1, int minorVersion = -1);
void setName(const QString &name);
......@@ -84,6 +85,7 @@ public:
void setCategory(const QString &category);
void setQmlPath(const QString &qml);
void setRequiredImport(const QString &requiredImport);
void addHints(const QHash<QString, QString> &hints);
private:
QExplicitlySharedDataPointer<Internal::ItemLibraryEntryData> m_data;
......
......@@ -67,6 +67,7 @@ private:
ParsingMetaInfo,
ParsingType,
ParsingItemLibrary,
ParsingHints,
ParsingProperty,
ParsingQmlSource
};
......@@ -83,6 +84,7 @@ private:
void readItemLibraryEntryProperty(const QString &name, const QVariant &value);
void readPropertyProperty(const QString &name, const QVariant &value);
void readQmlSourceProperty(const QString &name, const QVariant &value);
void readHint(const QString &name, const QVariant &value);
void setVersion(const QString &versionNumber);
......@@ -103,6 +105,7 @@ private:
TypeName m_currentClassName;
QString m_currentIcon;
QHash<QString, QString> m_currentHints;
QString m_currentSource;
ItemLibraryEntry m_currentEntry;
QList<ItemLibraryEntry> m_bufferedEntries;
......
......@@ -50,6 +50,7 @@ public:
QString qml;
QString qmlSource;
QString requiredImport;
QHash<QString, QString> hints;
};
} // namespace Internal
......@@ -86,6 +87,11 @@ QList<ItemLibraryEntry::Property> ItemLibraryEntry::properties() const
return m_data->properties;
}
QHash<QString, QString> ItemLibraryEntry::hints() const
{
return m_data->hints;
}
ItemLibraryEntry::ItemLibraryEntry() : m_data(new Internal::ItemLibraryEntryData)
{
m_data->name.clear();
......@@ -189,6 +195,11 @@ void ItemLibraryEntry::setRequiredImport(const QString &requiredImport)
m_data->requiredImport = requiredImport;
}
void ItemLibraryEntry::addHints(const QHash<QString, QString> &hints)
{
m_data->hints.unite(hints);
}
void ItemLibraryEntry::addProperty(PropertyName &name, QString &type, QVariant &value)
{
Property property;
......@@ -206,6 +217,7 @@ QDataStream& operator<<(QDataStream& stream, const ItemLibraryEntry &itemLibrary
stream << itemLibraryEntry.libraryEntryIconPath();
stream << itemLibraryEntry.category();
stream << itemLibraryEntry.requiredImport();
stream << itemLibraryEntry.hints();
stream << itemLibraryEntry.m_data->properties;
stream << itemLibraryEntry.m_data->qml;
......@@ -224,6 +236,7 @@ QDataStream& operator>>(QDataStream& stream, ItemLibraryEntry &itemLibraryEntry)
stream >> itemLibraryEntry.m_data->libraryEntryIconPath;
stream >> itemLibraryEntry.m_data->category;
stream >> itemLibraryEntry.m_data->requiredImport;
stream >> itemLibraryEntry.m_data->hints;
stream >> itemLibraryEntry.m_data->properties;
stream >> itemLibraryEntry.m_data->qml;
......@@ -242,6 +255,7 @@ QDebug operator<<(QDebug debug, const ItemLibraryEntry &itemLibraryEntry)
debug << itemLibraryEntry.m_data->libraryEntryIconPath;
debug << itemLibraryEntry.m_data->category;
debug << itemLibraryEntry.m_data->requiredImport;
debug << itemLibraryEntry.m_data->hints;
debug << itemLibraryEntry.m_data->properties;
debug << itemLibraryEntry.m_data->qml;
......
......@@ -41,6 +41,7 @@ enum {
const QString rootElementName = QStringLiteral("MetaInfo");
const QString typeElementName = QStringLiteral("Type");
const QString ItemLibraryEntryElementName = QStringLiteral("ItemLibraryEntry");
const QString HintsElementName = QStringLiteral("Hints");
const QString QmlSourceElementName = QStringLiteral("QmlSource");
const QString PropertyElementName = QStringLiteral("Property");
......@@ -91,6 +92,7 @@ void MetaInfoReader::elementStart(const QString &name)
case ParsingItemLibrary: setParserState(readItemLibraryEntryElement(name)); break;
case ParsingProperty: setParserState(readPropertyElement(name)); break;
case ParsingQmlSource: setParserState(readQmlSourceElement(name)); break;
case ParsingHints:
case Finished:
case Undefined: setParserState(Error);
addError(tr("Illegal state while parsing"), currentSourceLocation());
......@@ -105,6 +107,7 @@ void MetaInfoReader::elementEnd()
case ParsingMetaInfo: setParserState(Finished); break;
case ParsingType: setParserState(ParsingMetaInfo); break;
case ParsingItemLibrary: keepCurrentItemLibraryEntry(); setParserState((ParsingType)); break;
case ParsingHints: setParserState(ParsingType); break;
case ParsingProperty: insertProperty(); setParserState(ParsingItemLibrary); break;
case ParsingQmlSource: setParserState(ParsingItemLibrary); break;
case ParsingDocument:
......@@ -125,6 +128,7 @@ void MetaInfoReader::propertyDefinition(const QString &name, const QVariant &val
case ParsingQmlSource: readQmlSourceProperty(name, value); break;
case ParsingMetaInfo: addError(tr("No property definition allowed"), currentSourceLocation()); break;
case ParsingDocument:
case ParsingHints: readHint(name, value); break;
case Finished:
case Undefined: setParserState(Error);
addError(tr("Illegal state while parsing"), currentSourceLocation());
......@@ -163,7 +167,12 @@ MetaInfoReader::ParserSate MetaInfoReader::readTypeElement(const QString &name)
m_currentEntry = ItemLibraryEntry();
m_currentEntry.setType(m_currentClassName);
m_currentEntry.setTypeIcon(QIcon(m_currentIcon));
m_currentEntry.addHints(m_currentHints);
return ParsingItemLibrary;
} else if (name == HintsElementName) {
return ParsingHints;
} else {
addErrorInvalidType(name);
return Error;
......@@ -253,6 +262,11 @@ void MetaInfoReader::readQmlSourceProperty(const QString &name, const QVariant &
}
}
void MetaInfoReader::readHint(const QString &name, const QVariant &value)
{
m_currentHints.insert(name, value.toString());
}
void MetaInfoReader::setVersion(const QString &versionNumber)
{
const TypeName typeName = m_currentEntry.typeName();
......
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