diff options
author | Henning Gruendl <henning.gruendl@qt.io> | 2020-07-17 15:09:01 +0200 |
---|---|---|
committer | Henning Gründl <henning.gruendl@qt.io> | 2020-08-03 12:56:27 +0000 |
commit | d1aabbe262589fab96a9cf1fa98aa1c7e63e4b5b (patch) | |
tree | 95f3ccf311c404cfcd9a75ac523e22a71f2ccdc2 | |
parent | c113a7e8515bddb03d467167927b2f434222d245 (diff) |
QmlDesigner: Fix change type to include signals
* Fix the change type dialog to also include checking for signals
* Add check for same type
* Add dynamic properties and signals
Task-number: QDS-2562
Change-Id: I34652e702d9051fb5a237afae584e345c731622f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r-- | src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp index 8032f41ad8..5f17ca77ff 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp @@ -194,24 +194,60 @@ void PropertyEditorContextObject::changeTypeName(const QString &typeName) ModelNode selectedNode = rewriterView->selectedModelNodes().constFirst(); + // Check if the requested type is the same as already set + if (selectedNode.simplifiedTypeName() == typeName) + return; + NodeMetaInfo metaInfo = m_model->metaInfo(typeName.toLatin1()); if (!metaInfo.isValid()) { Core::AsynchronousMessageBox::warning(tr("Invalid Type"), tr("%1 is an invalid type.").arg(typeName)); return; } + // Create a list of properties available for the new type + QList<PropertyName> propertiesAndSignals(metaInfo.propertyNames()); + // Add signals to the list + for (const auto &signal : metaInfo.signalNames()) { + if (signal.isEmpty()) + continue; + + PropertyName name = signal; + QChar firstChar = QChar(signal.at(0)).toUpper().toLatin1(); + name[0] = firstChar.toLatin1(); + name.prepend("on"); + propertiesAndSignals.append(name); + } + + // Add dynamic properties and respective change signals + for (const auto &property : selectedNode.properties()) { + if (!property.isDynamic()) + continue; + + // Add dynamic property + propertiesAndSignals.append(property.name()); + // Add its change signal + PropertyName name = property.name(); + QChar firstChar = QChar(property.name().at(0)).toUpper().toLatin1(); + name[0] = firstChar.toLatin1(); + name.prepend("on"); + name.append("Changed"); + propertiesAndSignals.append(name); + } + + // Compare current properties and signals with the once available for change type QList<PropertyName> incompatibleProperties; - for (auto property : selectedNode.properties()) { - if (!metaInfo.propertyNames().contains(property.name())) + for (const auto &property : selectedNode.properties()) { + if (!propertiesAndSignals.contains(property.name())) incompatibleProperties.append(property.name()); } Utils::sort(incompatibleProperties); + // Create a dialog showing incompatible properties and signals if (!incompatibleProperties.empty()) { QString detailedText = QString("<b>Incompatible properties:</b><br>"); - for (auto p : incompatibleProperties) + for (const auto &p : incompatibleProperties) detailedText.append("- " + QString::fromUtf8(p) + "<br>"); detailedText.chop(QString("<br>").size()); |