forked from qt-creator/qt-creator
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:
@@ -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()));
|
||||
}
|
||||
|
||||
|
@@ -99,6 +99,21 @@ public:
|
||||
bool isDynamic() const;
|
||||
TypeName dynamicTypeName() const;
|
||||
|
||||
template<typename... TypeName>
|
||||
bool hasDynamicTypeName(const TypeName &...typeName) const
|
||||
{
|
||||
auto dynamicTypeName_ = dynamicTypeName();
|
||||
return ((dynamicTypeName_ == typeName) || ...);
|
||||
}
|
||||
|
||||
template<typename... TypeName>
|
||||
bool hasDynamicTypeName(const std::tuple<TypeName...> &typeNames) const
|
||||
{
|
||||
auto dynamicTypeName_ = dynamicTypeName();
|
||||
return std::apply([&](auto... typeName) { return hasDynamicTypeName(typeName...); },
|
||||
typeNames);
|
||||
}
|
||||
|
||||
Model *model() const;
|
||||
AbstractView *view() const;
|
||||
|
||||
|
@@ -59,6 +59,13 @@ public:
|
||||
return ((propertyTypeName_ == typeName) || ...);
|
||||
}
|
||||
|
||||
template<typename... TypeName>
|
||||
bool hasPropertyTypeName(const std::tuple<TypeName...> &typeNames) const
|
||||
{
|
||||
return std::apply([&](auto... typeName) { return hasPropertyTypeName(typeName...); },
|
||||
typeNames);
|
||||
}
|
||||
|
||||
bool propertyTypeNameIsColor() const { return hasPropertyTypeName("QColor", "color"); }
|
||||
bool propertyTypeNameIsString() const { return hasPropertyTypeName("QString", "string"); }
|
||||
bool propertyTypeNameIsUrl() const { return hasPropertyTypeName("QUrl", "url"); }
|
||||
|
Reference in New Issue
Block a user