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();
if (node.isValid()) {
m_backendValueTypeName = node.metaInfo()
.property(propertyEditorValue->name())
.propertyType()
.simplifiedTypeName();
m_backendValueType = node.metaInfo().property(propertyEditorValue->name()).propertyType();
QString nodeId = node.id();
if (nodeId.isEmpty())
@@ -102,9 +99,11 @@ void BindingEditor::setBackendValue(const QVariant &backendValue)
m_targetName = nodeId + "." + propertyEditorValue->name();
if (m_backendValueTypeName == "alias" || m_backendValueTypeName == "unknown")
if (!m_backendValueType || m_backendValueType.isAlias()) {
if (QmlObjectNode::isValidQmlObjectNode(node))
m_backendValueTypeName = QmlObjectNode(node).instanceType(propertyEditorValue->name());
m_backendValueType = node.model()->metaInfo(
QmlObjectNode(node).instanceType(propertyEditorValue->name()));
}
}
emit backendValueChanged();
@@ -135,7 +134,7 @@ void BindingEditor::setStateModelNode(const QVariant &stateModelNode)
m_modelNode = m_stateModelNode.value<QmlDesigner::ModelNode>();
if (m_modelNode.isValid())
m_backendValueTypeName = "bool";
m_backendValueType = m_modelNode.model()->boolMetaInfo();
emit stateModelNodeChanged();
}
@@ -153,9 +152,9 @@ void BindingEditor::setModelNode(const 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();
}
@@ -165,65 +164,80 @@ void BindingEditor::setTargetName(const QString &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()
{
if (!m_modelNode.isValid() || m_backendValueTypeName.isEmpty())
if (!m_modelNode.isValid() || !m_backendValueType) {
return;
}
const QList<QmlDesigner::ModelNode> allNodes = m_modelNode.view()->allModelNodes();
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) {
BindingEditorDialog::BindingOption binding;
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()));
}
}
//dynamic properties:
for (const BindingProperty &bindingProperty : objnode.bindingProperties()) {
if (bindingProperty.isValid()) {
if (bindingProperty.isDynamic()) {
const TypeName dynamicTypeName = bindingProperty.dynamicTypeName();
if (compareTypes(m_backendValueTypeName, dynamicTypeName))
auto model = bindingProperty.model();
const auto dynamicType = model->metaInfo(bindingProperty.dynamicTypeName());
if (compareTypes(m_backendValueType, dynamicType)) {
binding.properties.append(QString::fromUtf8(bindingProperty.name()));
}
}
}
}
for (const VariantProperty &variantProperty : objnode.variantProperties()) {
if (variantProperty.isValid()) {
if (variantProperty.isDynamic()) {
const TypeName dynamicTypeName = variantProperty.dynamicTypeName();
if (compareTypes(m_backendValueTypeName, dynamicTypeName))
auto model = variantProperty.model();
const auto dynamicType = model->metaInfo(variantProperty.dynamicTypeName());
if (compareTypes(m_backendValueType, dynamicType)) {
binding.properties.append(QString::fromUtf8(variantProperty.name()));
}
}
}
}
@@ -244,10 +258,11 @@ void BindingEditor::prepareBindings()
BindingEditorDialog::BindingOption binding;
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()));
}
}
if (!binding.properties.isEmpty()) {
@@ -260,15 +275,24 @@ void BindingEditor::prepareBindings()
}
if (!bindings.isEmpty() && !m_dialog.isNull())
m_dialog->setAllBindings(bindings, m_backendValueTypeName);
m_dialog->setAllBindings(bindings, m_backendValueType);
}
void BindingEditor::updateWindowName()
{
if (!m_dialog.isNull() && !m_backendValueTypeName.isEmpty()) {
const QString targetString = " ["
+ (m_targetName.isEmpty() ? QString() : (m_targetName + ": "))
+ QString::fromUtf8(m_backendValueTypeName) + "]";
if (!m_dialog.isNull() && m_backendValueType) {
QString targetString;
if constexpr (useProjectStorage()) {
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);
}

View File

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

View File

@@ -79,7 +79,7 @@ void BindingEditorDialog::adjustProperties()
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;
@@ -118,7 +118,7 @@ void BindingEditorDialog::setupComboBoxes()
void BindingEditorDialog::setupCheckBox()
{
const bool visible = (m_type == "bool");
const bool visible = m_type.isBool();
m_checkBoxNot->setVisible(visible);
}

View File

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

View File

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

View File

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

View File

@@ -127,6 +127,7 @@ public:
bool isInteger() const;
bool isLayoutable() const;
bool isListOrGridView() const;
bool isNumber() const;
bool isQmlComponent() const;
bool isQtMultimediaSoundEffect() 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
{
if constexpr (useProjectStorage()) {

View File

@@ -2004,6 +2004,16 @@ void Model::setMetaInfo(const MetaInfo &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>
NodeMetaInfo Model::createNodeMetaInfo() const
{

View File

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