QmlDesigner: Improve Has*TypeName interface

Instead of putting some strings into a list let the compiler to his
job and put it in a compile time tuple. This has the advantage too
that it can be of different types.

Change-Id: Ic4e7a9da8994d2a43ca115c1d69eab622c610437
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marco Bubke
2022-06-30 18:57:07 +02:00
parent fe50af151d
commit bcd9c2e8f2
3 changed files with 31 additions and 13 deletions

View File

@@ -42,6 +42,8 @@
#include <qmljs/qmljsscopechain.h>
#include <qmljs/qmljsvalueowner.h>
#include <tuple>
static Q_LOGGING_CATEGORY(ceLog, "qtc.qmldesigner.connectioneditor", QtWarningMsg)
namespace QmlDesigner {
@@ -190,11 +192,8 @@ void ActionEditor::prepareConnections()
const QmlJS::ContextPtr &context = semanticInfo.context;
const QmlJS::ScopeChain &scopeChain = semanticInfo.scopeChain(path);
static QList<TypeName> typeWhiteList({"string",
"real", "int", "double",
"bool",
"QColor", "color",
"QtQuick.Item", "QQuickItem"});
constexpr auto typeWhiteList = std::make_tuple(
"string", "real", "int", "double", "bool", "QColor", "color", "QtQuick.Item", "QQuickItem");
static QList<PropertyName> methodBlackList({"toString", "destroy"});
@@ -211,19 +210,18 @@ void ActionEditor::prepareConnections()
ActionEditorDialog::ConnectionOption connection(modelNode.id());
for (const auto &property : modelNode.metaInfo().properties()) {
const auto &propertyTypeName = property.propertyTypeName();
if (!typeWhiteList.contains(propertyTypeName))
if (!property.hasPropertyTypeName(typeWhiteList))
continue;
connection.properties.append(
ActionEditorDialog::PropertyOption(QString::fromUtf8(property.name()),
skipCpp(std::move(propertyTypeName)),
skipCpp(std::move(property.propertyTypeName())),
property.isWritable()));
}
for (const VariantProperty &variantProperty : modelNode.variantProperties()) {
if (variantProperty.isValid() && variantProperty.isDynamic()) {
if (!typeWhiteList.contains(variantProperty.dynamicTypeName()))
if (!variantProperty.hasDynamicTypeName(typeWhiteList))
continue;
const QString name = QString::fromUtf8(variantProperty.name());
@@ -271,14 +269,12 @@ void ActionEditor::prepareConnections()
if (metaInfo.isValid()) {
ActionEditorDialog::SingletonOption singelton;
for (const auto &property : metaInfo.properties()) {
const TypeName &typeName = property.propertyTypeName();
if (!typeWhiteList.contains(typeName))
if (!property.hasPropertyTypeName(typeWhiteList))
continue;
singelton.properties.append(
ActionEditorDialog::PropertyOption(QString::fromUtf8(property.name()),
skipCpp(typeName),
skipCpp(property.propertyTypeName()),
property.isWritable()));
}