diff --git a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp index 0fa54c4da76..5cfcd525dd1 100644 --- a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp +++ b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp @@ -1653,34 +1653,74 @@ bool NodeMetaInfo::isSubclassOf(const NodeMetaInfo &metaInfo) const bool NodeMetaInfo::isGraphicalItem() const { - return isSubclassOf("QtQuick.Item") || isSubclassOf("QtQuick.Window.Window") - || isSubclassOf("QtQuick.Dialogs.Dialog") || isSubclassOf("QtQuick.Controls.Popup"); + if constexpr (useProjectStorage()) { + using namespace Storage::Info; + auto itemId = m_projectStorage->commonTypeId(); + auto windowId = m_projectStorage->commonTypeId(); + auto dialogId = m_projectStorage->commonTypeId(); + auto popupId = m_projectStorage->commonTypeId(); + + return m_projectStorage->isBasedOn(m_typeId, itemId, windowId, dialogId, popupId); + } else { + return isSubclassOf("QtQuick.Item") || isSubclassOf("QtQuick.Window.Window") + || isSubclassOf("QtQuick.Dialogs.Dialog") || isSubclassOf("QtQuick.Controls.Popup"); + } } bool NodeMetaInfo::isQmlItem() const { - return isSubclassOf("QtQuick.QtObject") || isSubclassOf("QtQml.QtObject"); + if constexpr (useProjectStorage()) { + using namespace Storage::Info; + return m_projectStorage->isBasedOn(m_typeId, m_projectStorage->commonTypeId()); + } else { + return isSubclassOf("QtQuick.QtObject") || isSubclassOf("QtQml.QtObject"); + } } bool NodeMetaInfo::isLayoutable() const { - if (isSubclassOf(".QDeclarativeBasePositioner")) - return true; //QtQuick 1 + if constexpr (useProjectStorage()) { + using namespace Storage::Info; + auto positionerId = m_projectStorage->commonTypeId(); + auto layoutId = m_projectStorage->commonTypeId(); + auto splitViewId = m_projectStorage->commonTypeId(); - return isSubclassOf("QtQuick.Positioner") || isSubclassOf("QtQuick.Layouts.Layout") - || isSubclassOf("QtQuick.Controls.SplitView"); + return m_projectStorage->isBasedOn(m_typeId, positionerId, layoutId, splitViewId); + + } else { + if (isSubclassOf(".QDeclarativeBasePositioner")) + return true; //QtQuick 1 + + return isSubclassOf("QtQuick.Positioner") || isSubclassOf("QtQuick.Layouts.Layout") + || isSubclassOf("QtQuick.Controls.SplitView"); + } } bool NodeMetaInfo::isView() const { - return isValid() - && (isSubclassOf("QtQuick.ListView") || isSubclassOf("QtQuick.GridView") - || isSubclassOf("QtQuick.PathView")); + if constexpr (useProjectStorage()) { + using namespace Storage::Info; + auto listViewId = m_projectStorage->commonTypeId(); + auto gridViewId = m_projectStorage->commonTypeId(); + auto pathViewId = m_projectStorage->commonTypeId(); + return m_projectStorage->isBasedOn(m_typeId, listViewId, gridViewId, pathViewId); + } else { + return isValid() + && (isSubclassOf("QtQuick.ListView") || isSubclassOf("QtQuick.GridView") + || isSubclassOf("QtQuick.PathView")); + } } bool NodeMetaInfo::isTabView() const { - return isSubclassOf("QtQuick.Controls.TabView"); + if constexpr (useProjectStorage()) { + using namespace Storage::Info; + + return m_projectStorage->isBasedOn(m_typeId, + m_projectStorage->commonTypeId()); + } else { + return isSubclassOf("QtQuick.Controls.TabView"); + } } bool NodeMetaInfo::isAlias() const @@ -1690,86 +1730,152 @@ bool NodeMetaInfo::isAlias() const bool NodeMetaInfo::isQmlComponent() const { - auto type = m_privateData->qualfiedTypeName(); + if constexpr (useProjectStorage()) { + using namespace Storage::Info; + return m_projectStorage->isBasedOn(m_typeId, m_projectStorage->commonTypeId()); + } else { + auto type = m_privateData->qualfiedTypeName(); - return type == "Component" || type == "Qt.Component" || type == "QtQuick.Component" - || type == "QtQml.Component" || type == ".QQmlComponent" || type == "QQmlComponent"; + return type == "Component" || type == "Qt.Component" || type == "QtQuick.Component" + || type == "QtQml.Component" || type == ".QQmlComponent" + || type == "QQmlComponent"; + } } +namespace { + +template +bool isTypeId(TypeId typeId, TypeIds... otherTypeIds) +{ + static_assert(((std::is_same_v) &&...), "Parameter must be a TypeId!"); + + return ((typeId == otherTypeIds) || ...); +} + +} // namespace + bool NodeMetaInfo::isFont() const { - return m_privateData && m_privateData->qualfiedTypeName() == "font"; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->commonTypeId()); + } else { + return m_privateData && m_privateData->qualfiedTypeName() == "font"; + } } bool NodeMetaInfo::isColor() const { - if (!m_privateData) - return false; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->builtinTypeId()); + } else { + if (!m_privateData) + return false; - auto type = m_privateData->qualfiedTypeName(); + auto type = m_privateData->qualfiedTypeName(); - return type == "QColor" || type == "color"; + return type == "QColor" || type == "color"; + } } bool NodeMetaInfo::isBool() const { - if (!m_privateData) - return false; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->builtinTypeId()); + } else { + if (!m_privateData) + return false; - auto type = m_privateData->qualfiedTypeName(); + auto type = m_privateData->qualfiedTypeName(); - return type == "bool" || type == "boolean"; + return type == "bool" || type == "boolean"; + } } bool NodeMetaInfo::isInteger() const { - if (!m_privateData) - return false; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->builtinTypeId()); + } else { + if (!m_privateData) + return false; - auto type = m_privateData->qualfiedTypeName(); + auto type = m_privateData->qualfiedTypeName(); - return type == "int" || type == "integer"; + return type == "int" || type == "integer"; + } } bool NodeMetaInfo::isFloat() const { - if (!m_privateData) - return false; + if (useProjectStorage()) { + using namespace Storage::Info; + auto floatId = m_projectStorage->builtinTypeId(); + auto doubleId = m_projectStorage->builtinTypeId(); - auto type = m_privateData->qualfiedTypeName(); + return isTypeId(m_typeId, floatId, doubleId); + } else { + if (!m_privateData) + return false; - return type == "qreal" || type == "double" || type == "float"; - ; + auto type = m_privateData->qualfiedTypeName(); + + return type == "qreal" || type == "double" || type == "float"; + } } bool NodeMetaInfo::isVariant() const { - return m_privateData && m_privateData->qualfiedTypeName() == "QVariant"; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->builtinTypeId()); + } else { + return m_privateData && m_privateData->qualfiedTypeName() == "QVariant"; + } } bool NodeMetaInfo::isString() const { - if (!m_privateData) - return false; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->builtinTypeId()); + } else { + if (!m_privateData) + return false; - auto type = m_privateData->qualfiedTypeName(); + auto type = m_privateData->qualfiedTypeName(); - return type == "string" || type == "QString"; + return type == "string" || type == "QString"; + } } bool NodeMetaInfo::isUrl() const { - if (!m_privateData) - return false; + if (useProjectStorage()) { + using namespace Storage::Info; + return isTypeId(m_typeId, m_projectStorage->builtinTypeId()); + } else { + if (!m_privateData) + return false; - auto type = m_privateData->qualfiedTypeName(); + auto type = m_privateData->qualfiedTypeName(); - return type == "url" || type == "QUrl"; + return type == "url" || type == "QUrl"; + } } bool NodeMetaInfo::isQtQuick3DTexture() const { - return m_privateData && m_privateData->qualfiedTypeName() == "QtQuick3D.Texture"; + if (useProjectStorage()) { + using namespace Storage::Info; + return m_projectStorage->isBasedOn(m_typeId, + m_projectStorage->commonTypeId()); + } else { + return m_privateData && m_privateData->qualfiedTypeName() == "QtQuick3D.Texture"; + } } bool NodeMetaInfo::isEnumeration() const diff --git a/src/plugins/qmldesigner/designercore/projectstorage/commontypecache.h b/src/plugins/qmldesigner/designercore/projectstorage/commontypecache.h index 9ce183efe17..14ecbc726f6 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/commontypecache.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/commontypecache.h @@ -43,19 +43,40 @@ QT_END_NAMESPACE namespace QmlDesigner::Storage::Info { -inline constexpr char QtQuick[] = "QtQuick"; -inline constexpr char QML[] = "QML"; inline constexpr char QMLNative[] = "QML-cppnative"; -inline constexpr char Item[] = "Item"; -inline constexpr char DoubleType[] = "double"; -inline constexpr char IntType[] = "int"; +inline constexpr char QML[] = "QML"; +inline constexpr char QtQml[] = "QtQml"; +inline constexpr char QtQuick3D[] = "QtQuick3D"; +inline constexpr char QtQuick[] = "QtQuick"; +inline constexpr char QtQuick_Controls[] = "QtQuick.Controls"; +inline constexpr char QtQuick_Dialogs[] = "QtQuick.Dialogs"; +inline constexpr char QtQuick_Layouts[] = "QtQuick.Layouts"; +inline constexpr char QtQuick_Window[] = "QtQuick.Window"; + inline constexpr char BoolType[] = "bool"; +inline constexpr char Component[] = "Component"; +inline constexpr char Dialog[] = "Dialog"; +inline constexpr char DoubleType[] = "double"; inline constexpr char FloatType[] = "float"; -inline constexpr char var[] = "var"; -inline constexpr char string[] = "string"; -inline constexpr char date[] = "date"; -inline constexpr char url[] = "url"; +inline constexpr char GridView[] = "GridView"; +inline constexpr char IntType[] = "int"; +inline constexpr char Item[] = "Item"; +inline constexpr char Layout[] = "Layout"; +inline constexpr char ListView[] = "ListView"; +inline constexpr char PathView[] = "PathView"; +inline constexpr char Popup[] = "Popup"; +inline constexpr char Positioner[] = "Positioner"; +inline constexpr char QtObject[] = "QtObject"; +inline constexpr char SplitView[] = "SplitView"; +inline constexpr char TabView[] = "TabView"; +inline constexpr char Texture[] = "Texture"; +inline constexpr char Window[] = "Window"; inline constexpr char color[] = "color"; +inline constexpr char date[] = "date"; +inline constexpr char font[] = "font"; +inline constexpr char string[] = "string"; +inline constexpr char url[] = "url"; +inline constexpr char var[] = "var"; inline constexpr char vector2d[] = "vector2d"; inline constexpr char vector3d[] = "vector3d"; inline constexpr char vector4d[] = "vector4d"; @@ -70,20 +91,35 @@ struct CacheType template class CommonTypeCache { - using CommonTypes = std::tuple, + using CommonTypes = std::tuple, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, CacheType, + CacheType, CacheType, CacheType, CacheType, - CacheType, - CacheType, - CacheType, - CacheType, - CacheType, - CacheType, - CacheType, - CacheType, - CacheType>; + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType, + CacheType>; public: CommonTypeCache(const ProjectStorage &projectStorage) diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 752ad8fe842..2fc7a76338b 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -248,6 +248,8 @@ public: template bool isBasedOn(TypeId typeId, TypeIds... baseTypeIds) const { + static_assert(((std::is_same_v) &&...), "Parameter must be a TypeId!"); + auto range = selectPrototypeAndSelfIdsStatement.template rangeWithTransaction(typeId); for (TypeId currentTypeId : range) {