Fixes to problems with meta-types

This commit is contained in:
ksuprynowicz 2022-08-15 23:19:13 +02:00
parent 33c8607e15
commit 50a6a63cc3
8 changed files with 43 additions and 15 deletions

View file

@ -1,6 +1,7 @@
//
// Created by Bradley Austin Davis on 2019/05/14
// Copyright 2013-2019 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -9,15 +10,24 @@
#include "PerformanceScriptingInterface.h"
#include <ScriptEngineCast.h>
#include "../Application.h"
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager){
auto scriptEngine = manager->engine().get();
scriptRegisterMetaType(scriptEngine, scriptValueFromEnumClass<PerformanceScriptingInterface::PerformancePreset>, scriptValueToEnumClass<PerformanceScriptingInterface::PerformancePreset>, "PerformancePreset");
scriptRegisterMetaType(scriptEngine, scriptValueFromEnumClass<PerformanceScriptingInterface::RefreshRateProfile>, scriptValueToEnumClass<PerformanceScriptingInterface::RefreshRateProfile>, "RefreshRateProfile");
});
std::once_flag PerformanceScriptingInterface::registry_flag;
PerformanceScriptingInterface::PerformanceScriptingInterface() {
std::call_once(registry_flag, [] {
qmlRegisterType<PerformanceScriptingInterface>("PerformanceEnums", 1, 0, "PerformanceEnums");
qRegisterMetaType<PerformanceScriptingInterface::PerformancePreset>("PerformanceScriptingInterface::PerformancePreset");
qRegisterMetaType<PerformanceScriptingInterface::RefreshRateProfile>("PerformanceScriptingInterface::RefreshRateProfile");
//qRegisterMetaType<PerformanceScriptingInterface::PerformancePreset>("PerformanceScriptingInterface::PerformancePreset");
//qRegisterMetaType<PerformanceScriptingInterface::RefreshRateProfile>("PerformanceScriptingInterface::RefreshRateProfile");
});
}

View file

@ -1,6 +1,7 @@
//
// Created by Bradley Austin Davis on 2019/05/14
// Copyright 2013-2019 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -55,7 +56,7 @@ public:
* @typedef {number} Performance.PerformancePreset
*/
// PerformanceManager PerformancePreset tri state level enums
enum PerformancePreset {
enum class PerformancePreset {
UNKNOWN = PerformanceManager::PerformancePreset::UNKNOWN,
LOW_POWER = PerformanceManager::PerformancePreset::LOW_POWER,
LOW = PerformanceManager::PerformancePreset::LOW,
@ -82,7 +83,7 @@ public:
* @typedef {number} Performance.RefreshRateProfile
*/
// Must match RefreshRateManager enums
enum RefreshRateProfile {
enum class RefreshRateProfile {
ECO = RefreshRateManager::RefreshRateProfile::ECO,
INTERACTIVE = RefreshRateManager::RefreshRateProfile::INTERACTIVE,
REALTIME = RefreshRateManager::RefreshRateProfile::REALTIME,

View file

@ -1,6 +1,7 @@
//
// Created by Nissim Hadar on 2018/12/28
// Copyright 2013-2016 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -12,6 +13,7 @@
#include <platform/Platform.h>
#include <platform/Profiler.h>
#include <ScriptEngineCast.h>
#ifdef Q_OS_WIN
#include <Windows.h>
@ -19,6 +21,12 @@
#include <sstream>
#endif
STATIC_SCRIPT_INITIALIZER(+[](ScriptManager* manager){
auto scriptEngine = manager->engine().get();
scriptRegisterMetaType(scriptEngine, scriptValueFromEnumClass<PlatformInfoScriptingInterface::PlatformTier>, scriptValueToEnumClass<PlatformInfoScriptingInterface::PlatformTier>, "PlatformTier");
});
PlatformInfoScriptingInterface* PlatformInfoScriptingInterface::getInstance() {
static PlatformInfoScriptingInterface sharedInstance;
return &sharedInstance;

View file

@ -1,6 +1,7 @@
//
// Created by Nissim Hadar on 2018/12/28
// Copyright 2013-2016 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -45,7 +46,7 @@ public:
* @typedef {number} PlatformInfo.PlatformTier
*/
// Platform tier enum type
enum PlatformTier {
enum class PlatformTier {
UNKNOWN = platform::Profiler::Tier::UNKNOWN,
LOW = platform::Profiler::Tier::LOW,
MID = platform::Profiler::Tier::MID,

View file

@ -4,6 +4,7 @@
//
// Created by Brad Hefta-Gaub on 1/28/14.
// Copyright 2014 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -21,10 +22,10 @@
#include "WheelEvent.h"
void registerEventTypes(ScriptEngine* engine) {
scriptRegisterMetaType(engine, KeyEvent::toScriptValue, KeyEvent::fromScriptValue);
scriptRegisterMetaType(engine, MouseEvent::toScriptValue, MouseEvent::fromScriptValue);
scriptRegisterMetaType(engine, PointerEvent::toScriptValue, PointerEvent::fromScriptValue);
scriptRegisterMetaType(engine, TouchEvent::toScriptValue, TouchEvent::fromScriptValue);
scriptRegisterMetaType(engine, WheelEvent::toScriptValue, WheelEvent::fromScriptValue);
scriptRegisterMetaType(engine, SpatialEvent::toScriptValue, SpatialEvent::fromScriptValue);
scriptRegisterMetaType(engine, KeyEvent::toScriptValue, KeyEvent::fromScriptValue, "KeyEvent");
scriptRegisterMetaType(engine, MouseEvent::toScriptValue, MouseEvent::fromScriptValue, "MouseEvent");
scriptRegisterMetaType(engine, PointerEvent::toScriptValue, PointerEvent::fromScriptValue, "PointerEvent");
scriptRegisterMetaType(engine, TouchEvent::toScriptValue, TouchEvent::fromScriptValue, "TouchEvent");
scriptRegisterMetaType(engine, WheelEvent::toScriptValue, WheelEvent::fromScriptValue, "WheelEvent");
scriptRegisterMetaType(engine, SpatialEvent::toScriptValue, SpatialEvent::fromScriptValue, "SpatialEvent");
}

View file

@ -4,6 +4,7 @@
//
// Created by Stephen Birarda on 2014-06-30.
// Copyright 2014 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -18,7 +19,7 @@
#include "ScriptValue.h"
void registerMIDIMetaTypes(ScriptEngine* engine) {
scriptRegisterMetaType(engine, midiEventToScriptValue, midiEventFromScriptValue);
scriptRegisterMetaType(engine, midiEventToScriptValue, midiEventFromScriptValue, "MIDIEvent");
}
const QString MIDI_DELTA_TIME_PROP_NAME = "deltaTime";
@ -41,4 +42,4 @@ bool midiEventFromScriptValue(const ScriptValue &object, MIDIEvent& event) {
event.data1 = object.property(MIDI_DATA_1_PROP_NAME).toVariant().toUInt();
event.data2 = object.property(MIDI_DATA_2_PROP_NAME).toVariant().toUInt();
return true;
}
}

View file

@ -4,6 +4,7 @@
//
// Created by Brad Hefta-Gaub on 1/28/14.
// Copyright 2014 High Fidelity, Inc.
// Copyright 2022 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -44,7 +45,7 @@ MenuItemProperties::MenuItemProperties(const QString& menuName, const QString& m
}
void registerMenuItemProperties(ScriptEngine* engine) {
scriptRegisterMetaType(engine, menuItemPropertiesToScriptValue, menuItemPropertiesFromScriptValue);
scriptRegisterMetaType(engine, menuItemPropertiesToScriptValue, menuItemPropertiesFromScriptValue, "MenuItemProperties");
}
ScriptValue menuItemPropertiesToScriptValue(ScriptEngine* engine, const MenuItemProperties& properties) {

View file

@ -76,7 +76,12 @@ int scriptRegisterMetaType(ScriptEngine* eng,
if (strlen(name) > 0) { // make sure it's registered
id = qRegisterMetaType<T>(name);
} else {
id = qRegisterMetaType<T>();
if (!QMetaType::fromType<T>().name().isNull()) {
qDebug() << "scriptRegisterMetaType: " << QMetaType::fromType<T>().name();
id = qRegisterMetaType<T>(QMetaType::fromType<T>().name());
}else{
id = qRegisterMetaType<T>();
}
}
eng->registerCustomType(id, reinterpret_cast<ScriptEngine::MarshalFunction>(toScriptValue),
reinterpret_cast<ScriptEngine::DemarshalFunction>(fromScriptValue));