QmlDesigner: Remove typeName usage in binding editor

Task-number: QDS-10266
Change-Id: I91232c1296c4ed3b3148af9053d3db0f43a08e24
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Aleksei German <aleksei.german@qt.io>
This commit is contained in:
Marco Bubke
2023-07-12 09:21:45 +02:00
parent db78fa9cf8
commit 2322313baf
11 changed files with 279 additions and 167 deletions

View File

@@ -91,10 +91,7 @@ void BindingEditor::setBackendValue(const QVariant &backendValue)
const ModelNode node = propertyEditorValue->modelNode(); const ModelNode node = propertyEditorValue->modelNode();
if (node.isValid()) { if (node.isValid()) {
m_backendValueTypeName = node.metaInfo() m_backendValueType = node.metaInfo().property(propertyEditorValue->name()).propertyType();
.property(propertyEditorValue->name())
.propertyType()
.simplifiedTypeName();
QString nodeId = node.id(); QString nodeId = node.id();
if (nodeId.isEmpty()) if (nodeId.isEmpty())
@@ -102,9 +99,11 @@ void BindingEditor::setBackendValue(const QVariant &backendValue)
m_targetName = nodeId + "." + propertyEditorValue->name(); m_targetName = nodeId + "." + propertyEditorValue->name();
if (m_backendValueTypeName == "alias" || m_backendValueTypeName == "unknown") if (!m_backendValueType || m_backendValueType.isAlias()) {
if (QmlObjectNode::isValidQmlObjectNode(node)) if (QmlObjectNode::isValidQmlObjectNode(node))
m_backendValueTypeName = QmlObjectNode(node).instanceType(propertyEditorValue->name()); m_backendValueType = node.model()->metaInfo(
QmlObjectNode(node).instanceType(propertyEditorValue->name()));
}
} }
emit backendValueChanged(); emit backendValueChanged();
@@ -135,7 +134,7 @@ void BindingEditor::setStateModelNode(const QVariant &stateModelNode)
m_modelNode = m_stateModelNode.value<QmlDesigner::ModelNode>(); m_modelNode = m_stateModelNode.value<QmlDesigner::ModelNode>();
if (m_modelNode.isValid()) if (m_modelNode.isValid())
m_backendValueTypeName = "bool"; m_backendValueType = m_modelNode.model()->boolMetaInfo();
emit stateModelNodeChanged(); emit stateModelNodeChanged();
} }
@@ -153,9 +152,9 @@ void BindingEditor::setModelNode(const ModelNode &modelNode)
m_modelNode = modelNode; m_modelNode = modelNode;
} }
void BindingEditor::setBackendValueTypeName(const TypeName &backendValueTypeName) void BindingEditor::setBackendValueType(const NodeMetaInfo &backendValueType)
{ {
m_backendValueTypeName = backendValueTypeName; m_backendValueType = backendValueType;
emit backendValueChanged(); emit backendValueChanged();
} }
@@ -165,65 +164,80 @@ void BindingEditor::setTargetName(const QString &target)
m_targetName = target; m_targetName = target;
} }
namespace {
template<typename Tuple>
bool isType(const Tuple &types, const TypeName &compareType)
{
return std::apply([&](const auto &...type) { return ((type == compareType) || ...); }, types);
}
template<typename... Tuple>
bool isType(const TypeName &first, const TypeName &second, const Tuple &...types)
{
return ((types == first) || ...) && ((types == second) || ...);
}
bool compareTypes(const NodeMetaInfo &sourceType, const NodeMetaInfo &targetType)
{
if constexpr (useProjectStorage()) {
return targetType.isVariant() || sourceType.isVariant() || targetType == sourceType
|| (targetType.isNumber() && sourceType.isNumber())
|| (targetType.isColor() && sourceType.isColor())
|| (targetType.isString() && sourceType.isString());
} else {
const TypeName source = sourceType.simplifiedTypeName();
const TypeName target = targetType.simplifiedTypeName();
static constexpr auto variantTypes = std::make_tuple("alias", "unknown", "variant", "var");
return isType(variantTypes, target) || isType(variantTypes, source)
|| targetType == sourceType || isType(target, source, "double", "real", "int")
|| isType(target, source, "QColor", "color")
|| isType(target, source, "QString", "string");
}
}
} // namespace
void BindingEditor::prepareBindings() void BindingEditor::prepareBindings()
{ {
if (!m_modelNode.isValid() || m_backendValueTypeName.isEmpty()) if (!m_modelNode.isValid() || !m_backendValueType) {
return; return;
}
const QList<QmlDesigner::ModelNode> allNodes = m_modelNode.view()->allModelNodes(); const QList<QmlDesigner::ModelNode> allNodes = m_modelNode.view()->allModelNodes();
QList<BindingEditorDialog::BindingOption> bindings; QList<BindingEditorDialog::BindingOption> bindings;
const QVarLengthArray<TypeName> variantTypes = {"alias", "unknown", "variant", "var"};
const QVarLengthArray<TypeName> numericTypes = {"double", "real", "int"};
const QVarLengthArray<TypeName> colorTypes = {"QColor", "color"};
const QVarLengthArray<TypeName> stringTypes = {"QString", "string"};
auto isVariant = [&variantTypes](const TypeName &compareType) {
return variantTypes.contains(compareType);
};
auto isNumeric = [&numericTypes](const TypeName &compareType) {
return numericTypes.contains(compareType);
};
auto isColor = [&colorTypes](const TypeName &compareType) {
return colorTypes.contains(compareType);
};
auto isString = [&stringTypes](const TypeName &compareType) {
return stringTypes.contains(compareType);
};
auto compareTypes = [&](const TypeName &targetType, const TypeName &sourceType) {
return isVariant(targetType) || isVariant(sourceType) || (targetType == sourceType)
|| (isNumeric(targetType) && isNumeric(sourceType))
|| (isColor(targetType) && isColor(sourceType))
|| (isString(targetType) && isString(sourceType));
};
for (const auto &objnode : allNodes) { for (const auto &objnode : allNodes) {
BindingEditorDialog::BindingOption binding; BindingEditorDialog::BindingOption binding;
for (const auto &property : objnode.metaInfo().properties()) { for (const auto &property : objnode.metaInfo().properties()) {
const TypeName &propertyTypeName = property.propertyType().simplifiedTypeName(); const auto &propertyType = property.propertyType();
if (compareTypes(m_backendValueTypeName, propertyTypeName)) if (compareTypes(m_backendValueType, propertyType)) {
binding.properties.append(QString::fromUtf8(property.name())); binding.properties.append(QString::fromUtf8(property.name()));
}
} }
//dynamic properties: //dynamic properties:
for (const BindingProperty &bindingProperty : objnode.bindingProperties()) { for (const BindingProperty &bindingProperty : objnode.bindingProperties()) {
if (bindingProperty.isValid()) { if (bindingProperty.isValid()) {
if (bindingProperty.isDynamic()) { if (bindingProperty.isDynamic()) {
const TypeName dynamicTypeName = bindingProperty.dynamicTypeName(); auto model = bindingProperty.model();
if (compareTypes(m_backendValueTypeName, dynamicTypeName)) const auto dynamicType = model->metaInfo(bindingProperty.dynamicTypeName());
if (compareTypes(m_backendValueType, dynamicType)) {
binding.properties.append(QString::fromUtf8(bindingProperty.name())); binding.properties.append(QString::fromUtf8(bindingProperty.name()));
}
} }
} }
} }
for (const VariantProperty &variantProperty : objnode.variantProperties()) { for (const VariantProperty &variantProperty : objnode.variantProperties()) {
if (variantProperty.isValid()) { if (variantProperty.isValid()) {
if (variantProperty.isDynamic()) { if (variantProperty.isDynamic()) {
const TypeName dynamicTypeName = variantProperty.dynamicTypeName(); auto model = variantProperty.model();
if (compareTypes(m_backendValueTypeName, dynamicTypeName)) const auto dynamicType = model->metaInfo(variantProperty.dynamicTypeName());
if (compareTypes(m_backendValueType, dynamicType)) {
binding.properties.append(QString::fromUtf8(variantProperty.name())); binding.properties.append(QString::fromUtf8(variantProperty.name()));
}
} }
} }
} }
@@ -244,10 +258,11 @@ void BindingEditor::prepareBindings()
BindingEditorDialog::BindingOption binding; BindingEditorDialog::BindingOption binding;
for (const auto &property : metaInfo.properties()) { for (const auto &property : metaInfo.properties()) {
const TypeName propertyTypeName = property.propertyType().typeName(); const auto propertyType = property.propertyType();
if (compareTypes(m_backendValueTypeName, propertyTypeName)) if (compareTypes(m_backendValueType, propertyType)) {
binding.properties.append(QString::fromUtf8(property.name())); binding.properties.append(QString::fromUtf8(property.name()));
}
} }
if (!binding.properties.isEmpty()) { if (!binding.properties.isEmpty()) {
@@ -260,15 +275,24 @@ void BindingEditor::prepareBindings()
} }
if (!bindings.isEmpty() && !m_dialog.isNull()) if (!bindings.isEmpty() && !m_dialog.isNull())
m_dialog->setAllBindings(bindings, m_backendValueTypeName); m_dialog->setAllBindings(bindings, m_backendValueType);
} }
void BindingEditor::updateWindowName() void BindingEditor::updateWindowName()
{ {
if (!m_dialog.isNull() && !m_backendValueTypeName.isEmpty()) { if (!m_dialog.isNull() && m_backendValueType) {
const QString targetString = " [" QString targetString;
+ (m_targetName.isEmpty() ? QString() : (m_targetName + ": ")) if constexpr (useProjectStorage()) {
+ QString::fromUtf8(m_backendValueTypeName) + "]"; auto exportedTypeNames = m_backendValueType.exportedTypeNamesForSourceId(
m_modelNode.model()->fileUrlSourceId());
if (exportedTypeNames.size()) {
targetString = " [" + (m_targetName.isEmpty() ? QString() : (m_targetName + ": "))
+ exportedTypeNames.front().name.toQString() + "]";
}
} else {
targetString = " [" + (m_targetName.isEmpty() ? QString() : (m_targetName + ": "))
+ QString::fromUtf8(m_backendValueType.simplifiedTypeName()) + "]";
}
m_dialog->setWindowTitle(m_dialog->defaultTitle() + targetString); m_dialog->setWindowTitle(m_dialog->defaultTitle() + targetString);
} }

View File

@@ -49,7 +49,7 @@ public:
//3. modelnode + backend value type name + optional target name //3. modelnode + backend value type name + optional target name
void setModelNode(const ModelNode &modelNode); void setModelNode(const ModelNode &modelNode);
void setBackendValueTypeName(const TypeName &backendValueTypeName); void setBackendValueType(const NodeMetaInfo &backendValueType);
void setTargetName(const QString &target); void setTargetName(const QString &target);
Q_INVOKABLE void prepareBindings(); Q_INVOKABLE void prepareBindings();
@@ -77,7 +77,7 @@ private:
QVariant m_modelNodeBackend; QVariant m_modelNodeBackend;
QVariant m_stateModelNode; QVariant m_stateModelNode;
QmlDesigner::ModelNode m_modelNode; QmlDesigner::ModelNode m_modelNode;
TypeName m_backendValueTypeName; NodeMetaInfo m_backendValueType;
QString m_targetName; QString m_targetName;
}; };

View File

@@ -79,7 +79,7 @@ void BindingEditorDialog::adjustProperties()
m_comboBoxProperty->setCurrentText(property); m_comboBoxProperty->setCurrentText(property);
} }
void BindingEditorDialog::setAllBindings(const QList<BindingOption> &bindings, const TypeName &type) void BindingEditorDialog::setAllBindings(const QList<BindingOption> &bindings, const NodeMetaInfo &type)
{ {
m_lock = true; m_lock = true;
@@ -118,7 +118,7 @@ void BindingEditorDialog::setupComboBoxes()
void BindingEditorDialog::setupCheckBox() void BindingEditorDialog::setupCheckBox()
{ {
const bool visible = (m_type == "bool"); const bool visible = m_type.isBool();
m_checkBoxNot->setVisible(visible); m_checkBoxNot->setVisible(visible);
} }

View File

@@ -6,6 +6,8 @@
#include <bindingeditor/abstracteditordialog.h> #include <bindingeditor/abstracteditordialog.h>
#include <nodemetainfo.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QComboBox; class QComboBox;
class QCheckBox; class QCheckBox;
@@ -35,7 +37,7 @@ public:
void adjustProperties() override; void adjustProperties() override;
void setAllBindings(const QList<BindingOption> &bindings, const TypeName &type); void setAllBindings(const QList<BindingOption> &bindings, const NodeMetaInfo &type);
private: private:
void setupUIComponents(); void setupUIComponents();
@@ -53,7 +55,7 @@ private:
QCheckBox *m_checkBoxNot = nullptr; QCheckBox *m_checkBoxNot = nullptr;
QList<BindingOption> m_bindings; QList<BindingOption> m_bindings;
TypeName m_type; NodeMetaInfo m_type;
}; };
} }

View File

@@ -194,18 +194,17 @@ void ConnectionViewWidget::contextMenuEvent(QContextMenuEvent *event)
return; return;
const ModelNode node = property.parentModelNode(); const ModelNode node = property.parentModelNode();
const TypeName typeName = property.isDynamic() ? property.dynamicTypeName() auto model = node.model();
: node.metaInfo() const auto type = property.isDynamic()
.property(property.name()) ? model->metaInfo(property.dynamicTypeName())
.propertyType() : node.metaInfo().property(property.name()).propertyType();
.typeName();
const QString targetName = node.displayName() + "." + property.name(); const QString targetName = node.displayName() + "." + property.name();
m_bindingEditor->showWidget(); m_bindingEditor->showWidget();
m_bindingEditor->setBindingValue(property.expression()); m_bindingEditor->setBindingValue(property.expression());
m_bindingEditor->setModelNode(node); m_bindingEditor->setModelNode(node);
m_bindingEditor->setBackendValueTypeName(typeName); m_bindingEditor->setBackendValueType(type);
m_bindingEditor->setTargetName(targetName); m_bindingEditor->setTargetName(targetName);
m_bindingEditor->prepareBindings(); m_bindingEditor->prepareBindings();
m_bindingEditor->updateWindowName(); m_bindingEditor->updateWindowName();
@@ -242,11 +241,12 @@ void ConnectionViewWidget::contextMenuEvent(QContextMenuEvent *event)
return; return;
const QString targetName = node.displayName() + "." + abstractProperty.name(); const QString targetName = node.displayName() + "." + abstractProperty.name();
auto model = node.model();
m_dynamicEditor->showWidget(); m_dynamicEditor->showWidget();
m_dynamicEditor->setBindingValue(newExpression); m_dynamicEditor->setBindingValue(newExpression);
m_dynamicEditor->setModelNode(node); m_dynamicEditor->setModelNode(node);
m_dynamicEditor->setBackendValueTypeName(abstractProperty.dynamicTypeName()); m_dynamicEditor->setBackendValueType(
model->metaInfo(abstractProperty.dynamicTypeName()));
m_dynamicEditor->setTargetName(targetName); m_dynamicEditor->setTargetName(targetName);
m_dynamicEditor->prepareBindings(); m_dynamicEditor->prepareBindings();
m_dynamicEditor->updateWindowName(); m_dynamicEditor->updateWindowName();

View File

@@ -122,6 +122,7 @@ public:
bool hasNodeMetaInfo(const TypeName &typeName, int majorVersion = -1, int minorVersion = -1) const; bool hasNodeMetaInfo(const TypeName &typeName, int majorVersion = -1, int minorVersion = -1) const;
void setMetaInfo(const MetaInfo &metaInfo); void setMetaInfo(const MetaInfo &metaInfo);
NodeMetaInfo boolMetaInfo() const;
NodeMetaInfo flowViewFlowActionAreaMetaInfo() const; NodeMetaInfo flowViewFlowActionAreaMetaInfo() const;
NodeMetaInfo flowViewFlowDecisionMetaInfo() const; NodeMetaInfo flowViewFlowDecisionMetaInfo() const;
NodeMetaInfo flowViewFlowItemMetaInfo() const; NodeMetaInfo flowViewFlowItemMetaInfo() const;

View File

@@ -127,6 +127,7 @@ public:
bool isInteger() const; bool isInteger() const;
bool isLayoutable() const; bool isLayoutable() const;
bool isListOrGridView() const; bool isListOrGridView() const;
bool isNumber() const;
bool isQmlComponent() const; bool isQmlComponent() const;
bool isQtMultimediaSoundEffect() const; bool isQtMultimediaSoundEffect() const;
bool isQtObject() const; bool isQtObject() const;

View File

@@ -2240,6 +2240,31 @@ bool NodeMetaInfo::isListOrGridView() const
} }
} }
bool NodeMetaInfo::isNumber() const
{
if constexpr (useProjectStorage()) {
if (!isValid()) {
return false;
}
using namespace Storage::Info;
auto intId = m_projectStorage->builtinTypeId<int>();
auto uintId = m_projectStorage->builtinTypeId<uint>();
auto floatId = m_projectStorage->builtinTypeId<float>();
auto doubleId = m_projectStorage->builtinTypeId<double>();
return isTypeId(m_typeId, intId, uintId, floatId, doubleId);
} else {
if (!isValid()) {
return false;
}
auto type = simplifiedTypeName();
return type == "int" || type == "uint" || type == "float" || type == "double";
}
}
bool NodeMetaInfo::isQtQuickExtrasPicture() const bool NodeMetaInfo::isQtQuickExtrasPicture() const
{ {
if constexpr (useProjectStorage()) { if constexpr (useProjectStorage()) {

View File

@@ -2004,6 +2004,16 @@ void Model::setMetaInfo(const MetaInfo &metaInfo)
d->setMetaInfo(metaInfo); d->setMetaInfo(metaInfo);
} }
NodeMetaInfo Model::boolMetaInfo() const
{
if constexpr (useProjectStorage()) {
using namespace Storage::Info;
return createNodeMetaInfo<QML, BoolType>();
} else {
return metaInfo("QML.bool");
}
}
template<const auto &moduleName, const auto &typeName> template<const auto &moduleName, const auto &typeName>
NodeMetaInfo Model::createNodeMetaInfo() const NodeMetaInfo Model::createNodeMetaInfo() const
{ {

View File

@@ -120,6 +120,7 @@ inline constexpr char Texture[] = "Texture";
inline constexpr char TimelineAnimation[] = "TimelineAnimation"; inline constexpr char TimelineAnimation[] = "TimelineAnimation";
inline constexpr char Timeline[] = "Timeline"; inline constexpr char Timeline[] = "Timeline";
inline constexpr char Transition[] = "Transition"; inline constexpr char Transition[] = "Transition";
inline constexpr char UIntType[] = "uint";
inline constexpr char View3D[] = "View3D"; inline constexpr char View3D[] = "View3D";
inline constexpr char Window[] = "Window"; inline constexpr char Window[] = "Window";
inline constexpr char color[] = "color"; inline constexpr char color[] = "color";
@@ -146,99 +147,99 @@ struct CacheType : public BaseCacheType
template<typename ProjectStorage> template<typename ProjectStorage>
class CommonTypeCache class CommonTypeCache
{ {
using CommonTypes using CommonTypes = std::tuple<CacheType<FlowView, FlowActionArea>,
= std::tuple<CacheType<FlowView, FlowActionArea>, CacheType<FlowView, FlowDecision>,
CacheType<FlowView, FlowDecision>, CacheType<FlowView, FlowItem>,
CacheType<FlowView, FlowItem>, CacheType<FlowView, FlowTransition>,
CacheType<FlowView, FlowTransition>, CacheType<FlowView, FlowView>,
CacheType<FlowView, FlowView>, CacheType<FlowView, FlowWildcard>,
CacheType<FlowView, FlowWildcard>, CacheType<QML, BoolType>,
CacheType<QML, BoolType>, CacheType<QML, Component>,
CacheType<QML, Component>, CacheType<QML, DoubleType>,
CacheType<QML, DoubleType>, CacheType<QML, IntType>,
CacheType<QML, IntType>, CacheType<QML, QtObject>,
CacheType<QML, QtObject>, CacheType<QML, date>,
CacheType<QML, date>, CacheType<QML, string>,
CacheType<QML, string>, CacheType<QML, url>,
CacheType<QML, url>, CacheType<QML, var>,
CacheType<QML, var>, CacheType<QML_cppnative, FloatType>,
CacheType<QML_cppnative, FloatType>, CacheType<QML_cppnative, UIntType>,
CacheType<QtMultimedia, SoundEffect>, CacheType<QtMultimedia, SoundEffect>,
CacheType<QtQml_Models, ListElement>, CacheType<QtQml_Models, ListElement>,
CacheType<QtQml_Models, ListModel>, CacheType<QtQml_Models, ListModel>,
CacheType<QtQuick, BorderImage>, CacheType<QtQuick, BorderImage>,
CacheType<QtQuick, Connections>, CacheType<QtQuick, Connections>,
CacheType<QtQuick, GridView>, CacheType<QtQuick, GridView>,
CacheType<QtQuick, Image>, CacheType<QtQuick, Image>,
CacheType<QtQuick, Item>, CacheType<QtQuick, Item>,
CacheType<QtQuick, ListView>, CacheType<QtQuick, ListView>,
CacheType<QtQuick, Loader>, CacheType<QtQuick, Loader>,
CacheType<QtQuick, MouseArea>, CacheType<QtQuick, MouseArea>,
CacheType<QtQuick, Path>, CacheType<QtQuick, Path>,
CacheType<QtQuick, PathView>, CacheType<QtQuick, PathView>,
CacheType<QtQuick, PauseAnimation>, CacheType<QtQuick, PauseAnimation>,
CacheType<QtQuick, Positioner>, CacheType<QtQuick, Positioner>,
CacheType<QtQuick, PropertyAnimation>, CacheType<QtQuick, PropertyAnimation>,
CacheType<QtQuick, PropertyChanges>, CacheType<QtQuick, PropertyChanges>,
CacheType<QtQuick, Rectangle>, CacheType<QtQuick, Rectangle>,
CacheType<QtQuick, Repeater>, CacheType<QtQuick, Repeater>,
CacheType<QtQuick, State>, CacheType<QtQuick, State>,
CacheType<QtQuick, StateGroup>, CacheType<QtQuick, StateGroup>,
CacheType<QtQuick, Text>, CacheType<QtQuick, Text>,
CacheType<QtQuick, TextEdit>, CacheType<QtQuick, TextEdit>,
CacheType<QtQuick, Transition>, CacheType<QtQuick, Transition>,
CacheType<QtQuick, color>, CacheType<QtQuick, color>,
CacheType<QtQuick, font>, CacheType<QtQuick, font>,
CacheType<QtQuick, vector2d>, CacheType<QtQuick, vector2d>,
CacheType<QtQuick, vector3d>, CacheType<QtQuick, vector3d>,
CacheType<QtQuick, vector4d>, CacheType<QtQuick, vector4d>,
CacheType<QtQuick3D, BakedLightmap>, CacheType<QtQuick3D, BakedLightmap>,
CacheType<QtQuick3D, Buffer>, CacheType<QtQuick3D, Buffer>,
CacheType<QtQuick3D, Camera>, CacheType<QtQuick3D, Camera>,
CacheType<QtQuick3D, Command>, CacheType<QtQuick3D, Command>,
CacheType<QtQuick3D, CubeMapTexture>, CacheType<QtQuick3D, CubeMapTexture>,
CacheType<QtQuick3D, DefaultMaterial>, CacheType<QtQuick3D, DefaultMaterial>,
CacheType<QtQuick3D, Effect>, CacheType<QtQuick3D, Effect>,
CacheType<QtQuick3D, InstanceList>, CacheType<QtQuick3D, InstanceList>,
CacheType<QtQuick3D, InstanceListEntry>, CacheType<QtQuick3D, InstanceListEntry>,
CacheType<QtQuick3D, Light>, CacheType<QtQuick3D, Light>,
CacheType<QtQuick3D, Material>, CacheType<QtQuick3D, Material>,
CacheType<QtQuick3D, Model>, CacheType<QtQuick3D, Model>,
CacheType<QtQuick3D, Node>, CacheType<QtQuick3D, Node>,
CacheType<QtQuick3D, Pass>, CacheType<QtQuick3D, Pass>,
CacheType<QtQuick3D, PrincipledMaterial>, CacheType<QtQuick3D, PrincipledMaterial>,
CacheType<QtQuick3D, SceneEnvironment>, CacheType<QtQuick3D, SceneEnvironment>,
CacheType<QtQuick3D, SpecularGlossyMaterial>, CacheType<QtQuick3D, SpecularGlossyMaterial>,
CacheType<QtQuick3D, Shader>, CacheType<QtQuick3D, Shader>,
CacheType<QtQuick3D, Texture>, CacheType<QtQuick3D, Texture>,
CacheType<QtQuick3D, TextureInput>, CacheType<QtQuick3D, TextureInput>,
CacheType<QtQuick3D, View3D>, CacheType<QtQuick3D, View3D>,
CacheType<QtQuick3D_Particles3D, Affector3D>, CacheType<QtQuick3D_Particles3D, Affector3D>,
CacheType<QtQuick3D_Particles3D, Attractor3D>, CacheType<QtQuick3D_Particles3D, Attractor3D>,
CacheType<QtQuick3D_Particles3D, Model>, CacheType<QtQuick3D_Particles3D, Model>,
CacheType<QtQuick3D_Particles3D, Particle3D>, CacheType<QtQuick3D_Particles3D, Particle3D>,
CacheType<QtQuick3D_Particles3D, ParticleEmitter3D>, CacheType<QtQuick3D_Particles3D, ParticleEmitter3D>,
CacheType<QtQuick3D_Particles3D, SpriteParticle3D>, CacheType<QtQuick3D_Particles3D, SpriteParticle3D>,
CacheType<QtQuick3D_Particles3D_cppnative, QQuick3DParticleAbstractShape>, CacheType<QtQuick3D_Particles3D_cppnative, QQuick3DParticleAbstractShape>,
CacheType<QtQuick_Controls, Control>, CacheType<QtQuick_Controls, Control>,
CacheType<QtQuick_Controls, Popup>, CacheType<QtQuick_Controls, Popup>,
CacheType<QtQuick_Controls, SplitView>, CacheType<QtQuick_Controls, SplitView>,
CacheType<QtQuick_Controls, SwipeView>, CacheType<QtQuick_Controls, SwipeView>,
CacheType<QtQuick_Controls, TabBar>, CacheType<QtQuick_Controls, TabBar>,
CacheType<QtQuick_Controls, TextArea>, CacheType<QtQuick_Controls, TextArea>,
CacheType<QtQuick_Dialogs, Dialog>, CacheType<QtQuick_Dialogs, Dialog>,
CacheType<QtQuick_Extras, Picture>, CacheType<QtQuick_Extras, Picture>,
CacheType<QtQuick_Layouts, Layout>, CacheType<QtQuick_Layouts, Layout>,
CacheType<QtQuick_Studio_Components, GroupItem>, CacheType<QtQuick_Studio_Components, GroupItem>,
CacheType<QtQuick_Templates, Control>, CacheType<QtQuick_Templates, Control>,
CacheType<QtQuick_Timeline, Keyframe>, CacheType<QtQuick_Timeline, Keyframe>,
CacheType<QtQuick_Timeline, KeyframeGroup>, CacheType<QtQuick_Timeline, KeyframeGroup>,
CacheType<QtQuick_Timeline, Timeline>, CacheType<QtQuick_Timeline, Timeline>,
CacheType<QtQuick_Timeline, TimelineAnimation>, CacheType<QtQuick_Timeline, TimelineAnimation>,
CacheType<QtQuick_cppnative, QQuickStateOperation>, CacheType<QtQuick_cppnative, QQuickStateOperation>,
CacheType<Qt_SafeRenderer, SafePicture>, CacheType<Qt_SafeRenderer, SafePicture>,
CacheType<Qt_SafeRenderer, SafeRendererPicture>, CacheType<Qt_SafeRenderer, SafeRendererPicture>,
CacheType<QtQuick_Window, Window>>; CacheType<QtQuick_Window, Window>>;
public: public:
CommonTypeCache(const ProjectStorage &projectStorage) CommonTypeCache(const ProjectStorage &projectStorage)
@@ -283,30 +284,33 @@ public:
{ {
if constexpr (std::is_same_v<Type, double>) if constexpr (std::is_same_v<Type, double>)
return typeId<QML, DoubleType>(); return typeId<QML, DoubleType>();
if constexpr (std::is_same_v<Type, int>) else if constexpr (std::is_same_v<Type, int>)
return typeId<QML, IntType>(); return typeId<QML, IntType>();
if constexpr (std::is_same_v<Type, bool>) else if constexpr (std::is_same_v<Type, uint>)
return typeId<QML_cppnative, UIntType>();
else if constexpr (std::is_same_v<Type, bool>)
return typeId<QML, BoolType>(); return typeId<QML, BoolType>();
if constexpr (std::is_same_v<Type, float>) else if constexpr (std::is_same_v<Type, float>)
return typeId<QML_cppnative, FloatType>(); return typeId<QML_cppnative, FloatType>();
if constexpr (std::is_same_v<Type, QString>) else if constexpr (std::is_same_v<Type, QString>)
return typeId<QML, string>(); return typeId<QML, string>();
if constexpr (std::is_same_v<Type, QDateTime>) else if constexpr (std::is_same_v<Type, QDateTime>)
return typeId<QML, date>(); return typeId<QML, date>();
if constexpr (std::is_same_v<Type, QUrl>) else if constexpr (std::is_same_v<Type, QUrl>)
return typeId<QML, url>(); return typeId<QML, url>();
if constexpr (std::is_same_v<Type, QVariant>) else if constexpr (std::is_same_v<Type, QVariant>)
return typeId<QML, var>(); return typeId<QML, var>();
if constexpr (std::is_same_v<Type, QColor>) else if constexpr (std::is_same_v<Type, QColor>)
return typeId<QtQuick, color>(); return typeId<QtQuick, color>();
if constexpr (std::is_same_v<Type, QVector2D>) else if constexpr (std::is_same_v<Type, QVector2D>)
return typeId<QtQuick, vector2d>(); return typeId<QtQuick, vector2d>();
if constexpr (std::is_same_v<Type, QVector3D>) else if constexpr (std::is_same_v<Type, QVector3D>)
return typeId<QtQuick, vector3d>(); return typeId<QtQuick, vector3d>();
if constexpr (std::is_same_v<Type, QVector4D>) else if constexpr (std::is_same_v<Type, QVector4D>)
return typeId<QtQuick, vector4d>(); return typeId<QtQuick, vector4d>();
else else
return TypeId{}; static_assert(!std::is_same_v<Type, Type>, "built-in type not supported");
return TypeId{};
} }
private: private:

View File

@@ -2300,4 +2300,49 @@ TEST_F(NodeMetaInfo, invalid_source_id_has_no_external_type_names_for_source_id)
ASSERT_THAT(exportedTypeNames, IsEmpty()); ASSERT_THAT(exportedTypeNames, IsEmpty());
} }
TEST_F(NodeMetaInfo, float_is_a_number)
{
auto metaInfo = createMetaInfo("QML-cppnative", "float");
bool isType = metaInfo.isNumber();
ASSERT_THAT(isType, IsTrue());
}
TEST_F(NodeMetaInfo, double_is_a_number)
{
auto metaInfo = createMetaInfo(qmlModuleId, "double");
bool isType = metaInfo.isNumber();
ASSERT_THAT(isType, IsTrue());
}
TEST_F(NodeMetaInfo, int_is_a_number)
{
auto metaInfo = createMetaInfo(qmlModuleId, "int");
bool isType = metaInfo.isNumber();
ASSERT_THAT(isType, IsTrue());
}
TEST_F(NodeMetaInfo, uint_is_a_number)
{
auto metaInfo = createMetaInfo("QML-cppnative", "uint");
bool isType = metaInfo.isNumber();
ASSERT_THAT(isType, IsTrue());
}
TEST_F(NodeMetaInfo, default_is_not_number)
{
QmlDesigner::NodeMetaInfo metaInfo;
bool isType = metaInfo.isFloat();
ASSERT_THAT(isType, IsFalse());
}
} // namespace } // namespace