// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include "projectstoragetypes.h" #include #include #include #include QT_BEGIN_NAMESPACE class QColor; class QDateTime; class QString; class QUrl; class QVariant; class QVector2D; class QVector3D; class QVector4D; QT_END_NAMESPACE namespace QmlDesigner::Storage::Info { inline constexpr char Affector3D[] = "Affector3D"; inline constexpr char Attractor3D[] = "Attractor3D"; inline constexpr char BakedLightmap[] = "BakedLightmap"; inline constexpr char BoolType[] = "bool"; inline constexpr char BorderImage[] = "BorderImage"; inline constexpr char Buffer[] = "Buffer"; inline constexpr char Camera[] = "Camera"; inline constexpr char Command[] = "Command"; inline constexpr char Component[] = "Component"; inline constexpr char Connections[] = "Connections"; inline constexpr char Control[] = "Control"; inline constexpr char CubeMapTexture[] = "CubeMapTexture"; inline constexpr char DefaultMaterial[] = "DefaultMaterial"; inline constexpr char Dialog[] = "Dialog"; inline constexpr char DirectionalLight[] = "DirectionalLight"; inline constexpr char DoubleType[] = "double"; inline constexpr char Effect[] = "Effect"; inline constexpr char FloatType[] = "float"; inline constexpr char FlowActionArea[] = "FlowActionArea"; inline constexpr char FlowDecision[] = "FlowDecision"; inline constexpr char FlowItem[] = "FlowItem"; inline constexpr char FlowTransition[] = "FlowTransition"; inline constexpr char FlowView[] = "FlowView"; inline constexpr char FlowWildcard[] = "FlowWildcard"; inline constexpr char GridView[] = "GridView"; inline constexpr char GroupItem[] = "GroupItem"; inline constexpr char Image[] = "Image"; inline constexpr char InstanceListEntry[] = "InstanceListEntry"; inline constexpr char InstanceList[] = "InstanceList"; inline constexpr char IntType[] = "int"; inline constexpr char Item[] = "Item"; inline constexpr char JsonListModel[] = "JsonListModel"; inline constexpr char KeyframeGroup[] = "KeyframeGroup"; inline constexpr char Keyframe[] = "Keyframe"; inline constexpr char Layout[] = "Layout"; inline constexpr char Light[] = "Light"; inline constexpr char ListElement[] = "ListElement"; inline constexpr char ListModel[] = "ListModel"; inline constexpr char ListView[] = "ListView"; inline constexpr char Loader[] = "Loader"; inline constexpr char Material[] = "Material"; inline constexpr char Model[] = "Model"; inline constexpr char MouseArea[] = "MouseArea"; inline constexpr char Node[] = "Node"; inline constexpr char OrthographicCamera[] = "OrthographicCamera"; inline constexpr char Particle3D[] = "Particle3D"; inline constexpr char ParticleEmitter3D[] = "ParticleEmitter3D"; inline constexpr char Pass[] = "Pass"; inline constexpr char PathView[] = "PathView"; inline constexpr char Path[] = "Path"; inline constexpr char PauseAnimation[] = "PauseAnimation"; inline constexpr char PerspectiveCamera[] = "PerspectiveCamera"; inline constexpr char Picture[] = "Picture"; inline constexpr char PointLight[] = "PointLight"; inline constexpr char Popup[] = "Popup"; inline constexpr char Positioner[] = "Positioner"; inline constexpr char PrincipledMaterial[] = "PrincipledMaterial"; inline constexpr char PropertyAnimation[] = "PropertyAnimation"; inline constexpr char PropertyChanges[] = "PropertyChanges"; inline constexpr char QML[] = "QML"; inline constexpr char QML_cppnative[] = "QML-cppnative"; inline constexpr char QQuick3DParticleAbstractShape[] = "QQuick3DParticleAbstractShape"; inline constexpr char QQuickStateOperation[] = "QQuickStateOperation"; inline constexpr char QtMultimedia[] = "QtMultimedia"; inline constexpr char QtObject[] = "QtObject"; inline constexpr char QtQml[] = "QtQml"; inline constexpr char QtQml_Models[] = "QtQml.Models"; inline constexpr char QtQml_XmlListModel[] = "QtQml.XmlListModel"; inline constexpr char QtQuick3D[] = "QtQuick3D"; inline constexpr char QtQuick3D_Particles3D[] = "QtQuick3D.Particles3D"; inline constexpr char QtQuick3D_Particles3D_cppnative[] = "QtQuick3D.Particles3D-cppnative"; inline constexpr char QtQuick[] = "QtQuick"; inline constexpr char QtQuick_Controls[] = "QtQuick.Controls"; inline constexpr char QtQuick_Dialogs[] = "QtQuick.Dialogs"; inline constexpr char QtQuick_Extras[] = "QtQuick.Extras"; inline constexpr char QtQuick_Layouts[] = "QtQuick.Layouts"; inline constexpr char QtQuick_Studio_Components[] = "QtQuick.Studio.Components"; inline constexpr char QtQuick_Templates[] = "QtQuick.Templates"; inline constexpr char QtQuick_Timeline[] = "QtQuick.Timeline"; inline constexpr char QtQuick_Window[] = "QtQuick.Window"; inline constexpr char QtQuick_cppnative[] = "QtQuick-cppnative"; inline constexpr char Qt_SafeRenderer[] = "Qt.SafeRenderer"; inline constexpr char Rectangle[] = "Rectangle"; inline constexpr char Repeater[] = "Repeater"; inline constexpr char SafePicture[] = "SafePicture"; inline constexpr char SafeRendererPicture[] = "SafeRendererPicture"; inline constexpr char SceneEnvironment[] = "SceneEnvironment"; inline constexpr char Shader[] = "Shader"; inline constexpr char SoundEffect[] = "SoundEffect"; inline constexpr char SpecularGlossyMaterial[] = "SpecularGlossyMaterial"; inline constexpr char SplitView[] = "SplitView"; inline constexpr char SpotLight[] = "SpotLight"; inline constexpr char SpriteParticle3D[] = "SpriteParticle3D"; inline constexpr char StateGroup[] = "StateGroup"; inline constexpr char State[] = "State"; inline constexpr char SwipeView[] = "SwipeView"; inline constexpr char TabBar[] = "TabBar"; inline constexpr char TextArea[] = "TextArea"; inline constexpr char TextEdit[] = "TextEdit"; inline constexpr char Text[] = "Text"; inline constexpr char TextureInput[] = "TextureInput"; 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 XmlListModelRole[] = "XmlListModelRole"; 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"; struct BaseCacheType { QmlDesigner::ModuleId moduleId; QmlDesigner::TypeId typeId; }; template struct CacheType : public BaseCacheType { }; template class CommonTypeCache { 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, 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, 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) : m_projectStorage{projectStorage} { m_typesWithoutProperties.fill(TypeId{}); } CommonTypeCache(const CommonTypeCache &) = delete; CommonTypeCache &operator=(const CommonTypeCache &) = delete; CommonTypeCache(CommonTypeCache &&) = default; CommonTypeCache &operator=(CommonTypeCache &&) = default; void resetTypeIds() { std::apply([](auto &...type) { ((type.typeId = QmlDesigner::TypeId{}), ...); }, m_types); updateTypeIdsWithoutProperties(); } void clearForTestsOnly() { std::apply([](auto &...type) { ((type.typeId = QmlDesigner::TypeId{}), ...); }, m_types); std::fill(std::begin(m_typesWithoutProperties), std ::end(m_typesWithoutProperties), TypeId{}); } template TypeId typeId() const { auto &type = std::get>(m_types); if (type.typeId) return type.typeId; return refreshTypedId(type, moduleName, typeName); } template TypeId builtinTypeId() const { return typeId(); } template TypeId builtinTypeId() const { if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else if constexpr (std::is_same_v) return typeId(); else static_assert(!std::is_same_v, "built-in type not supported"); return TypeId{}; } const TypeIdsWithoutProperties &typeIdsWithoutProperties() const { return m_typesWithoutProperties; } private: TypeId refreshTypedId(BaseCacheType &type, ::Utils::SmallStringView moduleName, ::Utils::SmallStringView typeName) const { if (!type.moduleId) type.moduleId = m_projectStorage.moduleId(moduleName); type.typeId = m_projectStorage.typeId(type.moduleId, typeName, Storage::Version{}); return type.typeId; } TypeId refreshTypedIdWithoutTransaction(BaseCacheType &type, ::Utils::SmallStringView moduleName, ::Utils::SmallStringView typeName) const { if (!type.moduleId) type.moduleId = m_projectStorage.fetchModuleIdUnguarded(moduleName); type.typeId = m_projectStorage.fetchTypeIdByModuleIdAndExportedName(type.moduleId, typeName); return type.typeId; } template void setupTypeIdsWithoutProperties(const TypeId (&typeIds)[size]) { static_assert(size == std::tuple_size_v, "array size must match type id count!"); std::copy(std::begin(typeIds), std::end(typeIds), std::begin(m_typesWithoutProperties)); } template TypeId typeIdWithoutTransaction() const { auto &type = std::get>(m_types); if (type.typeId) return type.typeId; return refreshTypedIdWithoutTransaction(type, moduleName, typeName); } void updateTypeIdsWithoutProperties() { setupTypeIdsWithoutProperties({typeIdWithoutTransaction(), typeIdWithoutTransaction(), typeIdWithoutTransaction(), typeIdWithoutTransaction(), typeIdWithoutTransaction(), typeIdWithoutTransaction(), typeIdWithoutTransaction(), typeIdWithoutTransaction()}); } private: const ProjectStorage &m_projectStorage; mutable CommonTypes m_types; TypeIdsWithoutProperties m_typesWithoutProperties; }; } // namespace QmlDesigner::Storage::Info