Commit a8a99534 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner.MetaInfo: Cleanup

parent def8944f
...@@ -573,16 +573,14 @@ QStringList NavigatorTreeModel::visibleProperties(const ModelNode &node) const ...@@ -573,16 +573,14 @@ QStringList NavigatorTreeModel::visibleProperties(const ModelNode &node) const
{ {
QStringList propertyList; QStringList propertyList;
foreach (PropertyMetaInfo propertyMetaInfo, node.metaInfo().properties().values()) { foreach (const QString &propertyName, node.metaInfo().propertyNamesOnlyContainer()) {
if (!m_hiddenProperties.contains(propertyMetaInfo.name()) && if (!m_hiddenProperties.contains(propertyName) &&
propertyMetaInfo.name() != node.metaInfo().defaultProperty() && propertyName != node.metaInfo().defaultProperty()) { // TODO: ask the node instances
propertyMetaInfo.isReadable() &&
propertyMetaInfo.isWriteable()) {
QString qmlType = qmlTypeInQtContainer(propertyMetaInfo.type()); QString qmlType = qmlTypeInQtContainer(node.metaInfo().propertyType(propertyName));
if (node.metaInfo().metaInfo().hasNodeMetaInfo(qmlType) && if (node.metaInfo().metaInfo().hasNodeMetaInfo(qmlType) &&
node.metaInfo().metaInfo().nodeMetaInfo(qmlType).isSubclassOf("QGraphicsObject", -1, -1)) { node.metaInfo().metaInfo().nodeMetaInfo(qmlType).isSubclassOf("Qt/QtObject", 4, 7)) {
propertyList << propertyMetaInfo.name(); propertyList.append(propertyName);
} }
} }
} }
......
...@@ -175,7 +175,7 @@ void PropertyEditor::NodeType::setup(const QmlObjectNode &fxObjectNode, const QS ...@@ -175,7 +175,7 @@ void PropertyEditor::NodeType::setup(const QmlObjectNode &fxObjectNode, const QS
QDeclarativeContext *ctxt = m_view->rootContext(); QDeclarativeContext *ctxt = m_view->rootContext();
if (fxObjectNode.isValid()) { if (fxObjectNode.isValid()) {
foreach (const QString &propertyName, fxObjectNode.modelNode().metaInfo().properties(true).keys()) foreach (const QString &propertyName, fxObjectNode.modelNode().metaInfo().propertyNames())
createPropertyEditorValue(fxObjectNode, propertyName, fxObjectNode.instanceValue(propertyName), &m_backendValuesPropertyMap, propertyEditor); createPropertyEditorValue(fxObjectNode, propertyName, fxObjectNode.instanceValue(propertyName), &m_backendValuesPropertyMap, propertyEditor);
// className // className
...@@ -227,8 +227,8 @@ void PropertyEditor::NodeType::initialSetup(const QString &typeName, const QUrl ...@@ -227,8 +227,8 @@ void PropertyEditor::NodeType::initialSetup(const QString &typeName, const QUrl
NodeMetaInfo metaInfo = propertyEditor->model()->metaInfo().nodeMetaInfo(typeName, 4, 7); NodeMetaInfo metaInfo = propertyEditor->model()->metaInfo().nodeMetaInfo(typeName, 4, 7);
foreach (const QString &propertyName, metaInfo.properties(true).keys()) foreach (const QString &propertyName, metaInfo.propertyNames())
setupPropertyEditorValue(propertyName, &m_backendValuesPropertyMap, propertyEditor, metaInfo.property(propertyName, true).type()); setupPropertyEditorValue(propertyName, &m_backendValuesPropertyMap, propertyEditor, metaInfo.propertyType(propertyName));
PropertyEditorValue *valueObject = qobject_cast<PropertyEditorValue*>(QDeclarativeMetaType::toQObject(m_backendValuesPropertyMap.value("className"))); PropertyEditorValue *valueObject = qobject_cast<PropertyEditorValue*>(QDeclarativeMetaType::toQObject(m_backendValuesPropertyMap.value("className")));
if (!valueObject) if (!valueObject)
...@@ -386,8 +386,8 @@ void PropertyEditor::changeValue(const QString &propertyName) ...@@ -386,8 +386,8 @@ void PropertyEditor::changeValue(const QString &propertyName)
QVariant castedValue; QVariant castedValue;
if (fxObjectNode.modelNode().metaInfo().isValid() && fxObjectNode.modelNode().metaInfo().property(propertyName, true).isValid()) { if (fxObjectNode.modelNode().metaInfo().isValid() && fxObjectNode.modelNode().metaInfo().hasProperty(propertyName)) {
castedValue = fxObjectNode.modelNode().metaInfo().property(propertyName, true).castedValue(value->value()); castedValue = fxObjectNode.modelNode().metaInfo().nativePropertyValue(propertyName, value->value());
} else { } else {
qWarning() << "PropertyEditor:" <<propertyName << "cannot be casted (metainfo)"; qWarning() << "PropertyEditor:" <<propertyName << "cannot be casted (metainfo)";
return ; return ;
...@@ -398,8 +398,8 @@ void PropertyEditor::changeValue(const QString &propertyName) ...@@ -398,8 +398,8 @@ void PropertyEditor::changeValue(const QString &propertyName)
return ; return ;
} }
if (fxObjectNode.modelNode().metaInfo().isValid() && fxObjectNode.modelNode().metaInfo().property(propertyName).isValid()) if (fxObjectNode.modelNode().metaInfo().isValid() && fxObjectNode.modelNode().metaInfo().hasProperty(propertyName))
if (fxObjectNode.modelNode().metaInfo().property(propertyName).type() == QLatin1String("QUrl")) { //turn absolute local file paths into relative paths if (fxObjectNode.modelNode().metaInfo().propertyType(propertyName) == QLatin1String("QUrl")) { //turn absolute local file paths into relative paths
QString filePath = castedValue.toUrl().toString(); QString filePath = castedValue.toUrl().toString();
if (QFileInfo(filePath).exists() && QFileInfo(filePath).isAbsolute()) { if (QFileInfo(filePath).exists() && QFileInfo(filePath).isAbsolute()) {
QDir fileDir(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath()); QDir fileDir(QFileInfo(model()->fileUrl().toLocalFile()).absolutePath());
...@@ -446,13 +446,13 @@ void PropertyEditor::changeExpression(const QString &name) ...@@ -446,13 +446,13 @@ void PropertyEditor::changeExpression(const QString &name)
QmlObjectNode fxObjectNode(m_selectedNode); QmlObjectNode fxObjectNode(m_selectedNode);
PropertyEditorValue *value = qobject_cast<PropertyEditorValue*>(QDeclarativeMetaType::toQObject(m_currentType->m_backendValuesPropertyMap.value(underscoreName))); PropertyEditorValue *value = qobject_cast<PropertyEditorValue*>(QDeclarativeMetaType::toQObject(m_currentType->m_backendValuesPropertyMap.value(underscoreName)));
if (fxObjectNode.modelNode().metaInfo().isValid() && fxObjectNode.modelNode().metaInfo().property(name).isValid()) { if (fxObjectNode.modelNode().metaInfo().isValid() && fxObjectNode.modelNode().metaInfo().hasProperty(name)) {
if (fxObjectNode.modelNode().metaInfo().property(name).type() == QLatin1String("QColor")) { if (fxObjectNode.modelNode().metaInfo().propertyType(name) == QLatin1String("QColor")) {
if (QColor(value->expression().remove('"')).isValid()) { if (QColor(value->expression().remove('"')).isValid()) {
fxObjectNode.setVariantProperty(name, QColor(value->expression().remove('"'))); fxObjectNode.setVariantProperty(name, QColor(value->expression().remove('"')));
return; return;
} }
} else if (fxObjectNode.modelNode().metaInfo().property(name).type() == QLatin1String("bool")) { } else if (fxObjectNode.modelNode().metaInfo().propertyType(name) == QLatin1String("bool")) {
if (value->expression().compare("false", Qt::CaseInsensitive) == 0 || value->expression().compare("true", Qt::CaseInsensitive) == 0) { if (value->expression().compare("false", Qt::CaseInsensitive) == 0 || value->expression().compare("true", Qt::CaseInsensitive) == 0) {
if (value->expression().compare("true", Qt::CaseInsensitive) == 0) if (value->expression().compare("true", Qt::CaseInsensitive) == 0)
fxObjectNode.setVariantProperty(name, true); fxObjectNode.setVariantProperty(name, true);
...@@ -460,14 +460,14 @@ void PropertyEditor::changeExpression(const QString &name) ...@@ -460,14 +460,14 @@ void PropertyEditor::changeExpression(const QString &name)
fxObjectNode.setVariantProperty(name, false); fxObjectNode.setVariantProperty(name, false);
return; return;
} }
} else if (fxObjectNode.modelNode().metaInfo().property(name).type() == QLatin1String("int")) { } else if (fxObjectNode.modelNode().metaInfo().propertyType(name) == QLatin1String("int")) {
bool ok; bool ok;
int intValue = value->expression().toInt(&ok); int intValue = value->expression().toInt(&ok);
if (ok) { if (ok) {
fxObjectNode.setVariantProperty(name, intValue); fxObjectNode.setVariantProperty(name, intValue);
return; return;
} }
} else if (fxObjectNode.modelNode().metaInfo().property(name).type() == QLatin1String("qreal")) { } else if (fxObjectNode.modelNode().metaInfo().propertyType(name) == QLatin1String("qreal")) {
bool ok; bool ok;
qreal realValue = value->expression().toFloat(&ok); qreal realValue = value->expression().toFloat(&ok);
if (ok) { if (ok) {
...@@ -561,20 +561,19 @@ QString templateGeneration(NodeMetaInfo type, NodeMetaInfo superType, const QmlO ...@@ -561,20 +561,19 @@ QString templateGeneration(NodeMetaInfo type, NodeMetaInfo superType, const QmlO
qmlTemplate += QLatin1String("layout: VerticalLayout {\n"); qmlTemplate += QLatin1String("layout: VerticalLayout {\n");
QList<QString> orderedList; QList<QString> orderedList;
orderedList = type.properties(true).keys(); orderedList = type.propertyNames();
qSort(orderedList); qSort(orderedList);
foreach (const QString &name, orderedList) { foreach (const QString &name, orderedList) {
const PropertyMetaInfo propertyMetaInfo(type.property(name, true));
QString properName = name; QString properName = name;
properName.replace(".", "_"); properName.replace(".", "_");
QString typeName = propertyMetaInfo.type(); QString typeName = type.propertyType(name);
//alias resolution only possible with instance //alias resolution only possible with instance
if (typeName == QLatin1String("alias") && objectNode.isValid()) if (typeName == QLatin1String("alias") && objectNode.isValid())
typeName = objectNode.instanceType(name); typeName = objectNode.instanceType(name);
if (!superType.hasProperty(name, true)) { if (!superType.hasProperty(name)) {
if (typeName == "int") { if (typeName == "int") {
qmlTemplate += QString(QLatin1String( qmlTemplate += QString(QLatin1String(
"IntEditor { backendValue: backendValues.%2\n caption: \"%1\"\nbaseStateFlag: isBaseState\nslider: false\n}" "IntEditor { backendValue: backendValues.%2\n caption: \"%1\"\nbaseStateFlag: isBaseState\nslider: false\n}"
......
...@@ -53,8 +53,8 @@ PropertyEditorValue::PropertyEditorValue(QObject *parent) ...@@ -53,8 +53,8 @@ PropertyEditorValue::PropertyEditorValue(QObject *parent)
QVariant PropertyEditorValue::value() const QVariant PropertyEditorValue::value() const
{ {
QVariant returnValue = m_value; QVariant returnValue = m_value;
if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().property(name()).isValid()) if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name()))
if (modelNode().metaInfo().property(name()).type() == QLatin1String("QUrl")) { if (modelNode().metaInfo().propertyType(name()) == QLatin1String("QUrl")) {
returnValue = returnValue.toUrl().toString(); returnValue = returnValue.toUrl().toString();
} }
return returnValue; return returnValue;
...@@ -97,8 +97,8 @@ void PropertyEditorValue::setValueWithEmit(const QVariant &value) ...@@ -97,8 +97,8 @@ void PropertyEditorValue::setValueWithEmit(const QVariant &value)
{ {
if (m_value != value) { if (m_value != value) {
QVariant newValue = value; QVariant newValue = value;
if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().property(name()).isValid()) if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name()))
if (modelNode().metaInfo().property(name()).type() == QLatin1String("QUrl")) { if (modelNode().metaInfo().propertyType(name()) == QLatin1String("QUrl")) {
newValue = QUrl(newValue.toString()); newValue = QUrl(newValue.toString());
} }
...@@ -272,7 +272,7 @@ void PropertyEditorNodeWrapper::add(const QString &type) ...@@ -272,7 +272,7 @@ void PropertyEditorNodeWrapper::add(const QString &type)
if ((m_editorValue && m_editorValue->modelNode().isValid())) { if ((m_editorValue && m_editorValue->modelNode().isValid())) {
if (propertyType.isEmpty()) if (propertyType.isEmpty())
propertyType = m_editorValue->modelNode().metaInfo().property(m_editorValue->name()).type(); propertyType = m_editorValue->modelNode().metaInfo().propertyType(m_editorValue->name());
while (propertyType.contains('*')) //strip star while (propertyType.contains('*')) //strip star
propertyType.chop(1); propertyType.chop(1);
m_modelNode = m_editorValue->modelNode().view()->createModelNode(propertyType, 4, 7); m_modelNode = m_editorValue->modelNode().view()->createModelNode(propertyType, 4, 7);
...@@ -332,7 +332,7 @@ void PropertyEditorNodeWrapper::setup() ...@@ -332,7 +332,7 @@ void PropertyEditorNodeWrapper::setup()
foreach (QObject *object, m_valuesPropertyMap.children()) foreach (QObject *object, m_valuesPropertyMap.children())
delete object; delete object;
foreach (const QString &propertyName, m_modelNode.metaInfo().properties().keys()) { foreach (const QString &propertyName, m_modelNode.metaInfo().propertyNames()) {
if (fxObjectNode.isValid()) { if (fxObjectNode.isValid()) {
PropertyEditorValue *valueObject = new PropertyEditorValue(&m_valuesPropertyMap); PropertyEditorValue *valueObject = new PropertyEditorValue(&m_valuesPropertyMap);
valueObject->setName(propertyName); valueObject->setName(propertyName);
......
...@@ -77,11 +77,14 @@ public: ...@@ -77,11 +77,14 @@ public:
bool isValid() const; bool isValid() const;
MetaInfo metaInfo() const; MetaInfo metaInfo() const;
PropertyMetaInfo property(const QString &propertyName, bool resolveDotSyntax = false) const;
QList<NodeMetaInfo> superClasses() const; QList<NodeMetaInfo> superClasses() const;
NodeMetaInfo directSuperClass() const; NodeMetaInfo directSuperClass() const;
QHash<QString,PropertyMetaInfo> properties(bool resolveDotSyntax = false) const;
QStringList propertyNames() const;
QStringList propertyNamesOnlyContainer() const;
QString propertyType(const QString &propertyName) const;
QVariant nativePropertyValue(const QString &propertyName, const QVariant &value) const;
QString typeName() const; QString typeName() const;
int majorVersion() const; int majorVersion() const;
...@@ -92,7 +95,7 @@ public: ...@@ -92,7 +95,7 @@ public:
bool hasDefaultProperty() const; bool hasDefaultProperty() const;
QString defaultProperty() const; QString defaultProperty() const;
bool hasProperty(const QString &propertyName, bool resolveDotSyntax = false) const; bool hasProperty(const QString &propertyName) const;
bool isContainer() const; bool isContainer() const;
bool isComponent() const; bool isComponent() const;
bool isSubclassOf(const QString& type, int majorVersion, int minorVersio) const; bool isSubclassOf(const QString& type, int majorVersion, int minorVersio) const;
...@@ -113,8 +116,11 @@ private: ...@@ -113,8 +116,11 @@ private:
void setDefaultProperty(const QString &defaultProperty); void setDefaultProperty(const QString &defaultProperty);
void setSuperClass(const QString &typeName, int majorVersion = -1, int minorVersion = -1); void setSuperClass(const QString &typeName, int majorVersion = -1, int minorVersion = -1);
bool hasLocalProperty(const QString &propertyName, bool resolveDotSyntax = false) const; bool hasLocalProperty(const QString &propertyName, bool resolveDotSyntax = true) const;
QHash<QString,PropertyMetaInfo> dotProperties() const; QHash<QString,PropertyMetaInfo> dotProperties() const;
QHash<QString,PropertyMetaInfo> properties(bool resolveDotSyntax = true) const;
PropertyMetaInfo property(const QString &propertyName, bool resolveDotSyntax = true) const;
private: private:
QExplicitlySharedDataPointer<Internal::NodeMetaInfoData> m_data; QExplicitlySharedDataPointer<Internal::NodeMetaInfoData> m_data;
......
...@@ -255,9 +255,9 @@ QHash<QString,PropertyMetaInfo> NodeMetaInfo::dotProperties() const ...@@ -255,9 +255,9 @@ QHash<QString,PropertyMetaInfo> NodeMetaInfo::dotProperties() const
QHash<QString,PropertyMetaInfo> propertiesInfo; QHash<QString,PropertyMetaInfo> propertiesInfo;
foreach (const QString &propertyName, properties().keys()) { foreach (const QString &propertyName, properties(false).keys()) {
if (property(propertyName).hasDotSubProperties()) { if (property(propertyName).hasDotSubProperties()) {
QString propertyType = property(propertyName).type(); QString propertyType = property(propertyName, false).type();
if (propertyType.right(1) == "*") if (propertyType.right(1) == "*")
propertyType = propertyType.left(propertyType.size() - 1).trimmed(); propertyType = propertyType.left(propertyType.size() - 1).trimmed();
...@@ -377,17 +377,17 @@ bool NodeMetaInfo::hasLocalProperty(const QString &propertyName, bool resolveDot ...@@ -377,17 +377,17 @@ bool NodeMetaInfo::hasLocalProperty(const QString &propertyName, bool resolveDot
\throws InvalidMetaInfoException if the object is not valid \throws InvalidMetaInfoException if the object is not valid
*/ */
bool NodeMetaInfo::hasProperty(const QString &propertyName, bool resolveDotSyntax) const bool NodeMetaInfo::hasProperty(const QString &propertyName) const
{ {
if (!isValid()) { if (!isValid()) {
qWarning() << "NodeMetaInfo is invalid"; qWarning() << "NodeMetaInfo is invalid";
return false; return false;
} }
if (hasLocalProperty(propertyName, resolveDotSyntax)) if (hasLocalProperty(propertyName, true))
return true; return true;
if (directSuperClass().isValid() && directSuperClass().hasProperty(propertyName, resolveDotSyntax)) if (directSuperClass().isValid() && directSuperClass().hasProperty(propertyName))
return true; return true;
return false; return false;
...@@ -610,6 +610,38 @@ bool NodeMetaInfo::isSubclassOf(const QString &type, int majorVersion, int minor ...@@ -610,6 +610,38 @@ bool NodeMetaInfo::isSubclassOf(const QString &type, int majorVersion, int minor
return false; return false;
} }
QStringList NodeMetaInfo::propertyNames() const
{
return properties(true).keys();
}
QStringList NodeMetaInfo::propertyNamesOnlyContainer() const
{
QStringList nameList;
foreach(const PropertyMetaInfo &propertyMetaInfo, properties(true).values()) {
if (propertyMetaInfo.isReadable() && propertyMetaInfo.isWriteable())
nameList.append(propertyMetaInfo.name());
}
return nameList;
}
QString NodeMetaInfo::propertyType(const QString &propertyName) const
{
if (!hasProperty(propertyName))
return QString();
return property(propertyName).type();
}
QVariant NodeMetaInfo::nativePropertyValue(const QString &propertyName, const QVariant &value) const
{
if (!hasProperty(propertyName))
return value;
return property(propertyName).castedValue(value);
}
void NodeMetaInfo::setQmlFile(const QString &filePath) void NodeMetaInfo::setQmlFile(const QString &filePath)
{ {
if (!isValid()) { if (!isValid()) {
......
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