forked from qt-creator/qt-creator
QmlDesigner: is... function use project storage
Task-number: QDS-7379 Change-Id: I68e434b58b00aea94cdab9d86f38bfb779a2e6dd Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
0982e668e7
commit
f6d71d61d7
@@ -1653,34 +1653,74 @@ bool NodeMetaInfo::isSubclassOf(const NodeMetaInfo &metaInfo) const
|
|||||||
|
|
||||||
bool NodeMetaInfo::isGraphicalItem() const
|
bool NodeMetaInfo::isGraphicalItem() const
|
||||||
{
|
{
|
||||||
return isSubclassOf("QtQuick.Item") || isSubclassOf("QtQuick.Window.Window")
|
if constexpr (useProjectStorage()) {
|
||||||
|| isSubclassOf("QtQuick.Dialogs.Dialog") || isSubclassOf("QtQuick.Controls.Popup");
|
using namespace Storage::Info;
|
||||||
|
auto itemId = m_projectStorage->commonTypeId<QtQuick, Item>();
|
||||||
|
auto windowId = m_projectStorage->commonTypeId<QtQuick_Window, Window>();
|
||||||
|
auto dialogId = m_projectStorage->commonTypeId<QtQuick_Dialogs, Dialog>();
|
||||||
|
auto popupId = m_projectStorage->commonTypeId<QtQuick_Controls, Popup>();
|
||||||
|
|
||||||
|
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
|
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<QML, QtObject>());
|
||||||
|
} else {
|
||||||
|
return isSubclassOf("QtQuick.QtObject") || isSubclassOf("QtQml.QtObject");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeMetaInfo::isLayoutable() const
|
bool NodeMetaInfo::isLayoutable() const
|
||||||
{
|
{
|
||||||
if (isSubclassOf("<cpp>.QDeclarativeBasePositioner"))
|
if constexpr (useProjectStorage()) {
|
||||||
return true; //QtQuick 1
|
using namespace Storage::Info;
|
||||||
|
auto positionerId = m_projectStorage->commonTypeId<QtQuick, Positioner>();
|
||||||
|
auto layoutId = m_projectStorage->commonTypeId<QtQuick_Layouts, Layout>();
|
||||||
|
auto splitViewId = m_projectStorage->commonTypeId<QtQuick_Controls, SplitView>();
|
||||||
|
|
||||||
return isSubclassOf("QtQuick.Positioner") || isSubclassOf("QtQuick.Layouts.Layout")
|
return m_projectStorage->isBasedOn(m_typeId, positionerId, layoutId, splitViewId);
|
||||||
|| isSubclassOf("QtQuick.Controls.SplitView");
|
|
||||||
|
} else {
|
||||||
|
if (isSubclassOf("<cpp>.QDeclarativeBasePositioner"))
|
||||||
|
return true; //QtQuick 1
|
||||||
|
|
||||||
|
return isSubclassOf("QtQuick.Positioner") || isSubclassOf("QtQuick.Layouts.Layout")
|
||||||
|
|| isSubclassOf("QtQuick.Controls.SplitView");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeMetaInfo::isView() const
|
bool NodeMetaInfo::isView() const
|
||||||
{
|
{
|
||||||
return isValid()
|
if constexpr (useProjectStorage()) {
|
||||||
&& (isSubclassOf("QtQuick.ListView") || isSubclassOf("QtQuick.GridView")
|
using namespace Storage::Info;
|
||||||
|| isSubclassOf("QtQuick.PathView"));
|
auto listViewId = m_projectStorage->commonTypeId<QtQuick, ListView>();
|
||||||
|
auto gridViewId = m_projectStorage->commonTypeId<QtQuick, GridView>();
|
||||||
|
auto pathViewId = m_projectStorage->commonTypeId<QtQuick, PathView>();
|
||||||
|
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
|
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<QtQuick, TabView>());
|
||||||
|
} else {
|
||||||
|
return isSubclassOf("QtQuick.Controls.TabView");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeMetaInfo::isAlias() const
|
bool NodeMetaInfo::isAlias() const
|
||||||
@@ -1690,86 +1730,152 @@ bool NodeMetaInfo::isAlias() const
|
|||||||
|
|
||||||
bool NodeMetaInfo::isQmlComponent() 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<QML, Component>());
|
||||||
|
} else {
|
||||||
|
auto type = m_privateData->qualfiedTypeName();
|
||||||
|
|
||||||
return type == "Component" || type == "Qt.Component" || type == "QtQuick.Component"
|
return type == "Component" || type == "Qt.Component" || type == "QtQuick.Component"
|
||||||
|| type == "QtQml.Component" || type == "<cpp>.QQmlComponent" || type == "QQmlComponent";
|
|| type == "QtQml.Component" || type == "<cpp>.QQmlComponent"
|
||||||
|
|| type == "QQmlComponent";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template<typename... TypeIds>
|
||||||
|
bool isTypeId(TypeId typeId, TypeIds... otherTypeIds)
|
||||||
|
{
|
||||||
|
static_assert(((std::is_same_v<TypeId, TypeIds>) &&...), "Parameter must be a TypeId!");
|
||||||
|
|
||||||
|
return ((typeId == otherTypeIds) || ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
bool NodeMetaInfo::isFont() const
|
bool NodeMetaInfo::isFont() const
|
||||||
{
|
{
|
||||||
return m_privateData && m_privateData->qualfiedTypeName() == "font";
|
if (useProjectStorage()) {
|
||||||
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->commonTypeId<QtQuick, font>());
|
||||||
|
} else {
|
||||||
|
return m_privateData && m_privateData->qualfiedTypeName() == "font";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeMetaInfo::isColor() const
|
bool NodeMetaInfo::isColor() const
|
||||||
{
|
{
|
||||||
if (!m_privateData)
|
if (useProjectStorage()) {
|
||||||
return false;
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QColor>());
|
||||||
|
} 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
|
bool NodeMetaInfo::isBool() const
|
||||||
{
|
{
|
||||||
if (!m_privateData)
|
if (useProjectStorage()) {
|
||||||
return false;
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<bool>());
|
||||||
|
} 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
|
bool NodeMetaInfo::isInteger() const
|
||||||
{
|
{
|
||||||
if (!m_privateData)
|
if (useProjectStorage()) {
|
||||||
return false;
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<int>());
|
||||||
|
} 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
|
bool NodeMetaInfo::isFloat() const
|
||||||
{
|
{
|
||||||
if (!m_privateData)
|
if (useProjectStorage()) {
|
||||||
return false;
|
using namespace Storage::Info;
|
||||||
|
auto floatId = m_projectStorage->builtinTypeId<float>();
|
||||||
|
auto doubleId = m_projectStorage->builtinTypeId<double>();
|
||||||
|
|
||||||
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
|
bool NodeMetaInfo::isVariant() const
|
||||||
{
|
{
|
||||||
return m_privateData && m_privateData->qualfiedTypeName() == "QVariant";
|
if (useProjectStorage()) {
|
||||||
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QVariant>());
|
||||||
|
} else {
|
||||||
|
return m_privateData && m_privateData->qualfiedTypeName() == "QVariant";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeMetaInfo::isString() const
|
bool NodeMetaInfo::isString() const
|
||||||
{
|
{
|
||||||
if (!m_privateData)
|
if (useProjectStorage()) {
|
||||||
return false;
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QString>());
|
||||||
|
} 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
|
bool NodeMetaInfo::isUrl() const
|
||||||
{
|
{
|
||||||
if (!m_privateData)
|
if (useProjectStorage()) {
|
||||||
return false;
|
using namespace Storage::Info;
|
||||||
|
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QUrl>());
|
||||||
|
} 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
|
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<QtQuick3D, Texture>());
|
||||||
|
} else {
|
||||||
|
return m_privateData && m_privateData->qualfiedTypeName() == "QtQuick3D.Texture";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodeMetaInfo::isEnumeration() const
|
bool NodeMetaInfo::isEnumeration() const
|
||||||
|
@@ -43,19 +43,40 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace QmlDesigner::Storage::Info {
|
namespace QmlDesigner::Storage::Info {
|
||||||
|
|
||||||
inline constexpr char QtQuick[] = "QtQuick";
|
|
||||||
inline constexpr char QML[] = "QML";
|
|
||||||
inline constexpr char QMLNative[] = "QML-cppnative";
|
inline constexpr char QMLNative[] = "QML-cppnative";
|
||||||
inline constexpr char Item[] = "Item";
|
inline constexpr char QML[] = "QML";
|
||||||
inline constexpr char DoubleType[] = "double";
|
inline constexpr char QtQml[] = "QtQml";
|
||||||
inline constexpr char IntType[] = "int";
|
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 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 FloatType[] = "float";
|
||||||
inline constexpr char var[] = "var";
|
inline constexpr char GridView[] = "GridView";
|
||||||
inline constexpr char string[] = "string";
|
inline constexpr char IntType[] = "int";
|
||||||
inline constexpr char date[] = "date";
|
inline constexpr char Item[] = "Item";
|
||||||
inline constexpr char url[] = "url";
|
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 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 vector2d[] = "vector2d";
|
||||||
inline constexpr char vector3d[] = "vector3d";
|
inline constexpr char vector3d[] = "vector3d";
|
||||||
inline constexpr char vector4d[] = "vector4d";
|
inline constexpr char vector4d[] = "vector4d";
|
||||||
@@ -70,20 +91,35 @@ struct CacheType
|
|||||||
template<typename ProjectStorage>
|
template<typename ProjectStorage>
|
||||||
class CommonTypeCache
|
class CommonTypeCache
|
||||||
{
|
{
|
||||||
using CommonTypes = std::tuple<CacheType<QtQuick, Item>,
|
using CommonTypes = std::tuple<CacheType<QML, BoolType>,
|
||||||
|
CacheType<QML, Component>,
|
||||||
|
CacheType<QML, DoubleType>,
|
||||||
|
CacheType<QML, IntType>,
|
||||||
|
CacheType<QML, QtObject>,
|
||||||
|
CacheType<QML, date>,
|
||||||
|
CacheType<QML, date>,
|
||||||
|
CacheType<QML, string>,
|
||||||
|
CacheType<QML, url>,
|
||||||
|
CacheType<QML, var>,
|
||||||
|
CacheType<QMLNative, FloatType>,
|
||||||
|
CacheType<QtQuick, GridView>,
|
||||||
|
CacheType<QtQuick, Item>,
|
||||||
|
CacheType<QtQuick, ListView>,
|
||||||
|
CacheType<QtQuick, PathView>,
|
||||||
|
CacheType<QtQuick, Positioner>,
|
||||||
|
CacheType<QtQuick, TabView>,
|
||||||
CacheType<QtQuick, color>,
|
CacheType<QtQuick, color>,
|
||||||
|
CacheType<QtQuick, font>,
|
||||||
CacheType<QtQuick, vector2d>,
|
CacheType<QtQuick, vector2d>,
|
||||||
CacheType<QtQuick, vector3d>,
|
CacheType<QtQuick, vector3d>,
|
||||||
CacheType<QtQuick, vector4d>,
|
CacheType<QtQuick, vector4d>,
|
||||||
CacheType<QML, DoubleType>,
|
CacheType<QtQuick, vector4d>,
|
||||||
CacheType<QML, var>,
|
CacheType<QtQuick3D, Texture>,
|
||||||
CacheType<QML, IntType>,
|
CacheType<QtQuick_Controls, Popup>,
|
||||||
CacheType<QML, BoolType>,
|
CacheType<QtQuick_Controls, SplitView>,
|
||||||
CacheType<QML, string>,
|
CacheType<QtQuick_Dialogs, Dialog>,
|
||||||
CacheType<QML, date>,
|
CacheType<QtQuick_Layouts, Layout>,
|
||||||
CacheType<QML, date>,
|
CacheType<QtQuick_Window, Window>>;
|
||||||
CacheType<QML, url>,
|
|
||||||
CacheType<QMLNative, FloatType>>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommonTypeCache(const ProjectStorage &projectStorage)
|
CommonTypeCache(const ProjectStorage &projectStorage)
|
||||||
|
@@ -248,6 +248,8 @@ public:
|
|||||||
template<typename... TypeIds>
|
template<typename... TypeIds>
|
||||||
bool isBasedOn(TypeId typeId, TypeIds... baseTypeIds) const
|
bool isBasedOn(TypeId typeId, TypeIds... baseTypeIds) const
|
||||||
{
|
{
|
||||||
|
static_assert(((std::is_same_v<TypeId, TypeIds>) &&...), "Parameter must be a TypeId!");
|
||||||
|
|
||||||
auto range = selectPrototypeAndSelfIdsStatement.template rangeWithTransaction<TypeId>(typeId);
|
auto range = selectPrototypeAndSelfIdsStatement.template rangeWithTransaction<TypeId>(typeId);
|
||||||
|
|
||||||
for (TypeId currentTypeId : range) {
|
for (TypeId currentTypeId : range) {
|
||||||
|
Reference in New Issue
Block a user