Skip to content

Commit

Permalink
Simplify serializing argument types for script proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Holecek <hluk@email.cz>
  • Loading branch information
hluk committed Apr 6, 2019
1 parent 3a57cee commit 88c7236
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions src/scriptable/scriptableproxy.cpp
Expand Up @@ -277,28 +277,6 @@ struct InputDialog {
QString defaultChoice; /// Default text for list widgets.
};

template<typename ...Ts>
class SlotArguments;

template<typename T, typename ...Ts>
class SlotArguments<T, Ts...> {
public:
static QByteArray arguments()
{
if ( std::is_same<QVariant, T>::value )
return "QVariant," + SlotArguments<Ts...>::arguments();

return QByteArray(QMetaType::typeName(qMetaTypeId<T>()))
+ "," + SlotArguments<Ts...>::arguments();
}
};

template<>
class SlotArguments<> {
public:
static QByteArray arguments() { return QByteArray(); }
};

class FunctionCallSerializer final {
public:
explicit FunctionCallSerializer(const char *functionName)
Expand All @@ -307,9 +285,13 @@ class FunctionCallSerializer final {
}

template<typename ...Ts>
FunctionCallSerializer &withSlotArguments(Ts...)
FunctionCallSerializer &withSlotArguments(Ts... arguments)
{
QByteArray args = SlotArguments<Ts...>::arguments();
QByteArray args;
for (const auto argType : std::initializer_list<const char *>{ argumentType(arguments)... }) {
args.append(argType);
args.append(',');
}
args.chop(1);
setSlotArgumentTypes(args);
return *this;
Expand All @@ -331,6 +313,15 @@ class FunctionCallSerializer final {
return { QVariant::fromValue(arguments)... };
}

template<typename T>
static const char *argumentType(const T &)
{
if ( std::is_same<QVariant, T>::value )
return "QVariant";

return QMetaType::typeName(qMetaTypeId<T>());
}

private:
void setSlotArgumentTypes(const QByteArray &args)
{
Expand Down

0 comments on commit 88c7236

Please sign in to comment.