forked from qt-creator/qt-creator
QmlDesigner: Extend support for custom property editor
* Allow custom '.' properties to show up in custom editor * Allow custom property editors to span multiple sections This allows us to support alias proprties to e.g. Text and Rectangle items. Change-Id: I7939a5cf5769387dbb3a27df0fd9e74c493a577c Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
4fc3ee8e5b
commit
feaf2a3b95
@@ -1,5 +1,11 @@
|
|||||||
|
|
||||||
|
Section {
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
caption: "%1"
|
||||||
|
|
||||||
ColorEditor {
|
ColorEditor {
|
||||||
backendValue: backendValues.%2
|
backendValue: backendValues.%2
|
||||||
supportGradient: false
|
supportGradient: false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -401,6 +401,39 @@ QString PropertyEditorQmlBackend::propertyEditorResourcesPath() {
|
|||||||
return Core::ICore::resourcePath() + QStringLiteral("/qmldesigner/propertyEditorQmlSources");
|
return Core::ICore::resourcePath() + QStringLiteral("/qmldesigner/propertyEditorQmlSources");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool dotPropertyHeuristic(const QmlObjectNode &node, const NodeMetaInfo &type, const PropertyName &name)
|
||||||
|
{
|
||||||
|
if (!name.contains("."))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (name.count('.') > 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QList<QByteArray> list =name.split('.');
|
||||||
|
const PropertyName parentProperty = list.first();
|
||||||
|
const PropertyName itemProperty = list.last();
|
||||||
|
|
||||||
|
TypeName typeName = type.propertyTypeName(parentProperty);
|
||||||
|
|
||||||
|
NodeMetaInfo itemInfo = node.view()->model()->metaInfo("QtQuick.Item");
|
||||||
|
NodeMetaInfo textInfo = node.view()->model()->metaInfo("QtQuick.Text");
|
||||||
|
NodeMetaInfo rectangleInfo = node.view()->model()->metaInfo("QtQuick.Rectangle");
|
||||||
|
|
||||||
|
if (itemInfo.hasProperty(itemProperty))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (typeName == "font")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (textInfo.isSubclassOf(typeName))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (rectangleInfo.isSubclassOf(typeName))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type,
|
QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type,
|
||||||
const NodeMetaInfo &superType,
|
const NodeMetaInfo &superType,
|
||||||
const QmlObjectNode &node)
|
const QmlObjectNode &node)
|
||||||
@@ -461,9 +494,9 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type,
|
|||||||
|
|
||||||
auto nodes = templateConfiguration()->children();
|
auto nodes = templateConfiguration()->children();
|
||||||
|
|
||||||
if (!superType.hasProperty(name) && type.propertyIsWritable(name) && !name.contains(".")) {
|
if (!superType.hasProperty(name) && type.propertyIsWritable(name) && dotPropertyHeuristic(node, type, name)) {
|
||||||
|
|
||||||
foreach (const QmlJS::SimpleReaderNode::Ptr &node, nodes)
|
for (const QmlJS::SimpleReaderNode::Ptr &node : nodes) {
|
||||||
if (variantToStringList(node->property(QStringLiteral("typeNames"))).contains(QString::fromLatin1(typeName))) {
|
if (variantToStringList(node->property(QStringLiteral("typeNames"))).contains(QString::fromLatin1(typeName))) {
|
||||||
const QString fileName = propertyTemplatesPath() + node->property(QStringLiteral("sourceFile")).toString();
|
const QString fileName = propertyTemplatesPath() + node->property(QStringLiteral("sourceFile")).toString();
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
@@ -472,10 +505,6 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type,
|
|||||||
file.close();
|
file.close();
|
||||||
const bool section = node->propertyNames().contains("separateSection");
|
const bool section = node->propertyNames().contains("separateSection");
|
||||||
if (section) {
|
if (section) {
|
||||||
qmlTemplate += "Section {\n";
|
|
||||||
qmlTemplate += "anchors.left: parent.left\n";
|
|
||||||
qmlTemplate += "anchors.right: parent.right\n";
|
|
||||||
qmlTemplate += QString("caption: \"%1\"\n").arg(QString::fromUtf8(properName));
|
|
||||||
} else if (!sectionStarted) {
|
} else if (!sectionStarted) {
|
||||||
qmlTemplate += QStringLiteral("Section {\n");
|
qmlTemplate += QStringLiteral("Section {\n");
|
||||||
qmlTemplate += QStringLiteral("caption: \"%1\"\n").arg(QString::fromUtf8(type.simplifiedTypeName()));
|
qmlTemplate += QStringLiteral("caption: \"%1\"\n").arg(QString::fromUtf8(type.simplifiedTypeName()));
|
||||||
@@ -486,8 +515,6 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
qmlTemplate += source.arg(QString::fromUtf8(name)).arg(QString::fromUtf8(properName));
|
qmlTemplate += source.arg(QString::fromUtf8(name)).arg(QString::fromUtf8(properName));
|
||||||
if (section)
|
|
||||||
qmlTemplate += "}\n";
|
|
||||||
emptyTemplate = false;
|
emptyTemplate = false;
|
||||||
} else {
|
} else {
|
||||||
qWarning().nospace() << "template definition source file not found:" << fileName;
|
qWarning().nospace() << "template definition source file not found:" << fileName;
|
||||||
@@ -495,6 +522,7 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (sectionStarted) {
|
if (sectionStarted) {
|
||||||
qmlTemplate += QStringLiteral("}\n"); //Section
|
qmlTemplate += QStringLiteral("}\n"); //Section
|
||||||
qmlTemplate += QStringLiteral("}\n"); //SectionLayout
|
qmlTemplate += QStringLiteral("}\n"); //SectionLayout
|
||||||
@@ -666,3 +694,4 @@ QString PropertyEditorQmlBackend::locateQmlFile(const NodeMetaInfo &info, const
|
|||||||
|
|
||||||
|
|
||||||
} //QmlDesigner
|
} //QmlDesigner
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user