Skip to content

Commit 436ee84

Browse files
committed
convert list type
1 parent 07435b4 commit 436ee84

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

libs/core/include/quite/meta/meta_types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct MapType
4646

4747
struct ListType
4848
{
49+
TypeId id;
50+
std::string name;
4951
TypeId value_type;
5052
};
5153

libs/core/src/meta/meta_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ auto fmt::formatter<quite::meta::MapType>::format(const quite::meta::MapType &ty
5454
auto fmt::formatter<quite::meta::ListType>::format(const quite::meta::ListType &type, format_context &ctx) const
5555
-> format_context::iterator
5656
{
57-
return fmt::format_to(ctx.out(), "ListType(type_id={})", type.value_type);
57+
return fmt::format_to(ctx.out(), "ListType(name={}, id={}, type_id={})", type.name, type.id, type.value_type);
5858
}
5959

6060
auto fmt::formatter<quite::meta::EnumType>::format(const quite::meta::EnumType &type, format_context &ctx) const

libs/probeqt/qt_meta_registry.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QMetaObject>
44
#include <QMetaProperty>
55
#include <QMetaType>
6+
#include <QSequentialIterable>
67
#include <ranges>
78
#include <entt/meta/resolve.hpp>
89
#include <quite/logger.hpp>
@@ -74,6 +75,23 @@ Result<meta::Type> convert_enum_type(QMetaType type)
7475
return meta_enum;
7576
}
7677

78+
Result<meta::Type> convert_list_type(QMetaType list_type, QMetaType containing_type)
79+
{
80+
LOG_DEBUG(qt_meta_registry, "List type '{}' with containing type '{}'", list_type.name(), containing_type.name());
81+
82+
return meta::ListType{.id = static_cast<meta::TypeId>(list_type.id()),
83+
.name = list_type.name(),
84+
.value_type = static_cast<meta::TypeId>(containing_type.id())};
85+
}
86+
87+
Result<meta::Type> convert_map_type(QMetaType containing_type)
88+
{
89+
LOG_DEBUG(qt_meta_registry, "Map type: ");
90+
return make_error_result<meta::Type>(
91+
ErrorCode::failed_precondition,
92+
fmt::format("Could not create a meta map type from'{}'", containing_type.name()));
93+
}
94+
7795
Result<meta::Type> convert_object_type(QMetaType type)
7896
{
7997
QVariant meta_type_instance;
@@ -85,9 +103,12 @@ Result<meta::Type> convert_object_type(QMetaType type)
85103
// TODO convert to either list or map types
86104
if (meta_type_instance.canConvert<QVariantList>())
87105
{
106+
const auto iterable = meta_type_instance.value<QSequentialIterable>();
107+
return convert_list_type(type, iterable.metaContainer().valueMetaType());
88108
}
89109
if (meta_type_instance.canConvert<QVariantMap>())
90110
{
111+
return convert_map_type(type);
91112
}
92113
return make_error_result<meta::Type>(
93114
ErrorCode::failed_precondition,

0 commit comments

Comments
 (0)