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,35 +1653,75 @@ bool NodeMetaInfo::isSubclassOf(const NodeMetaInfo &metaInfo) const
|
||||
|
||||
bool NodeMetaInfo::isGraphicalItem() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
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 m_projectStorage->isBasedOn(m_typeId, positionerId, layoutId, splitViewId);
|
||||
|
||||
} 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
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -1690,19 +1730,46 @@ bool NodeMetaInfo::isAlias() const
|
||||
|
||||
bool NodeMetaInfo::isQmlComponent() const
|
||||
{
|
||||
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"
|
||||
|| 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
|
||||
{
|
||||
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
|
||||
{
|
||||
if (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QColor>());
|
||||
} else {
|
||||
if (!m_privateData)
|
||||
return false;
|
||||
|
||||
@@ -1710,9 +1777,14 @@ bool NodeMetaInfo::isColor() const
|
||||
|
||||
return type == "QColor" || type == "color";
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isBool() const
|
||||
{
|
||||
if (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<bool>());
|
||||
} else {
|
||||
if (!m_privateData)
|
||||
return false;
|
||||
|
||||
@@ -1720,9 +1792,14 @@ bool NodeMetaInfo::isBool() const
|
||||
|
||||
return type == "bool" || type == "boolean";
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isInteger() const
|
||||
{
|
||||
if (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<int>());
|
||||
} else {
|
||||
if (!m_privateData)
|
||||
return false;
|
||||
|
||||
@@ -1730,25 +1807,42 @@ bool NodeMetaInfo::isInteger() const
|
||||
|
||||
return type == "int" || type == "integer";
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isFloat() const
|
||||
{
|
||||
if (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
auto floatId = m_projectStorage->builtinTypeId<float>();
|
||||
auto doubleId = m_projectStorage->builtinTypeId<double>();
|
||||
|
||||
return isTypeId(m_typeId, floatId, doubleId);
|
||||
} else {
|
||||
if (!m_privateData)
|
||||
return false;
|
||||
|
||||
auto type = m_privateData->qualfiedTypeName();
|
||||
|
||||
return type == "qreal" || type == "double" || type == "float";
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isVariant() const
|
||||
{
|
||||
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
|
||||
{
|
||||
if (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QString>());
|
||||
} else {
|
||||
if (!m_privateData)
|
||||
return false;
|
||||
|
||||
@@ -1756,9 +1850,14 @@ bool NodeMetaInfo::isString() const
|
||||
|
||||
return type == "string" || type == "QString";
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isUrl() const
|
||||
{
|
||||
if (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
return isTypeId(m_typeId, m_projectStorage->builtinTypeId<QUrl>());
|
||||
} else {
|
||||
if (!m_privateData)
|
||||
return false;
|
||||
|
||||
@@ -1766,11 +1865,18 @@ bool NodeMetaInfo::isUrl() const
|
||||
|
||||
return type == "url" || type == "QUrl";
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isQtQuick3DTexture() const
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@@ -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<typename ProjectStorage>
|
||||
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, font>,
|
||||
CacheType<QtQuick, vector2d>,
|
||||
CacheType<QtQuick, vector3d>,
|
||||
CacheType<QtQuick, vector4d>,
|
||||
CacheType<QML, DoubleType>,
|
||||
CacheType<QML, var>,
|
||||
CacheType<QML, IntType>,
|
||||
CacheType<QML, BoolType>,
|
||||
CacheType<QML, string>,
|
||||
CacheType<QML, date>,
|
||||
CacheType<QML, date>,
|
||||
CacheType<QML, url>,
|
||||
CacheType<QMLNative, FloatType>>;
|
||||
CacheType<QtQuick, vector4d>,
|
||||
CacheType<QtQuick3D, Texture>,
|
||||
CacheType<QtQuick_Controls, Popup>,
|
||||
CacheType<QtQuick_Controls, SplitView>,
|
||||
CacheType<QtQuick_Dialogs, Dialog>,
|
||||
CacheType<QtQuick_Layouts, Layout>,
|
||||
CacheType<QtQuick_Window, Window>>;
|
||||
|
||||
public:
|
||||
CommonTypeCache(const ProjectStorage &projectStorage)
|
||||
|
@@ -248,6 +248,8 @@ public:
|
||||
template<typename... TypeIds>
|
||||
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);
|
||||
|
||||
for (TypeId currentTypeId : range) {
|
||||
|
Reference in New Issue
Block a user