-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjulia_signals.cpp
More file actions
73 lines (63 loc) · 1.67 KB
/
julia_signals.cpp
File metadata and controls
73 lines (63 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <QDebug>
#include <QMetaObject>
#include <QQmlEngine>
#include <QString>
#include <QVariant>
#include <QVariantList>
#include "application_manager.hpp"
#include "julia_signals.hpp"
#include "jlqml.hpp"
namespace qmlwrap
{
namespace detail
{
// This is needed because QGenericArgument is a weak reference to a value, so the value needs to exist as long as the QGenericArgument instance
struct argument_wrapper
{
virtual ~argument_wrapper() {}
};
template<typename T>
struct argument_wrapper_impl : public argument_wrapper
{
T value;
};
template<std::size_t... Is>
struct ApplyVectorArgs
{
void operator()(QObject* o, const char* signal_name, const QVariantList& args)
{
if(sizeof...(Is) == args.size())
{
if(!QMetaObject::invokeMethod(o, signal_name, Q_ARG(QVariant, args[Is])...))
{
throw std::runtime_error("Error emitting or finding signal " + std::string(signal_name));
}
}
else
{
ApplyVectorArgs<Is..., sizeof...(Is)>()(o, signal_name, args);
}
}
};
// end recursion
template<>
struct ApplyVectorArgs<0,1,2,3,4,5,6,7,8,9,10>
{
void operator()(QObject* o, const char* signal_name, const QVariantList& args)
{
throw std::runtime_error("Too many arguments for signal " + std::string(signal_name));
}
};
}
JuliaSignals::JuliaSignals(QQuickItem* parent) : QQuickItem(parent)
{
ApplicationManager::instance().julia_api()->setJuliaSignals(this);
}
JuliaSignals::~JuliaSignals()
{
}
void JuliaSignals::emit_signal(const char* signal_name, const QVariantList& args)
{
detail::ApplyVectorArgs<>()(this, signal_name, args);
}
} // namespace qmlwrap