// Copyright (C) 2024 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include "../luaengine.h" #include #include #include #include namespace Lua::Internal { using FilePathOrString = std::variant; inline Utils::FilePath toFilePath(const FilePathOrString &v) { return std::visit( [](auto &&arg) -> Utils::FilePath { using T = std::decay_t; if constexpr (std::is_same_v) return Utils::FilePath::fromUserInput(arg); else return arg; }, v); } using IconFilePathOrString = std::variant, Utils::FilePath, QString>; inline std::shared_ptr toIcon(const IconFilePathOrString &v) { return std::visit( [](auto &&arg) -> std::shared_ptr { using T = std::decay_t; if constexpr (std::is_same_v>) return arg; else return std::make_shared(toFilePath(arg)); }, v); } inline void mirrorEnum(sol::table &&target, QMetaEnum metaEnum, const QString &name = {}) { sol::table luaEnumTable = target.create( name.isEmpty() ? QString::fromUtf8(metaEnum.name()) : name, metaEnum.keyCount()); for (int i = 0; i < metaEnum.keyCount(); ++i) luaEnumTable.set(metaEnum.key(i), metaEnum.value(i)); }; inline void mirrorEnum(sol::table &target, QMetaEnum metaEnum, const QString &name = {}) { sol::table luaEnumTable = target.create( name.isEmpty() ? QString::fromUtf8(metaEnum.name()) : name, metaEnum.keyCount()); for (int i = 0; i < metaEnum.keyCount(); ++i) luaEnumTable.set(metaEnum.key(i), metaEnum.value(i)); }; template inline QFlags tableToFlags(const sol::table &table) noexcept { static_assert(std::is_enum::value, "Enum type required"); QFlags flags; for (const auto& kv : table) flags.setFlag(static_cast(kv.second.as())); return flags; } class InfoBarCleaner { QList openInfoBars; public: ~InfoBarCleaner(); void infoBarEntryAdded(const Utils::Id &id) { openInfoBars.append(id); } }; } // namespace Lua::Internal