2018-02-26 09:09:21 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskMetaCallback.h"
|
|
|
|
#include <QObject>
|
2018-02-27 17:47:23 +01:00
|
|
|
#include <QVector>
|
2018-02-26 09:09:21 +01:00
|
|
|
|
|
|
|
QskMetaCallback::QskMetaCallback( const QObject* object,
|
2018-02-27 17:47:23 +01:00
|
|
|
const QMetaMethod& method, Qt::ConnectionType connectionType ):
|
2018-02-26 09:09:21 +01:00
|
|
|
m_object( const_cast< QObject* >( object ) ),
|
2018-02-28 08:37:40 +01:00
|
|
|
m_method( new QMetaMethod( method ) ),
|
2018-02-26 09:09:21 +01:00
|
|
|
m_type( MetaMethod ),
|
|
|
|
m_connectionType( static_cast< ushort >( connectionType & ~Qt::UniqueConnection ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskMetaCallback::QskMetaCallback( const QObject* object,
|
|
|
|
const QskMetaFunction& function, Qt::ConnectionType connectionType ):
|
|
|
|
m_object( const_cast< QObject* >( object ) ),
|
2018-02-28 08:37:40 +01:00
|
|
|
m_function( new QskMetaFunction( function ) ),
|
2018-02-26 09:09:21 +01:00
|
|
|
m_type( MetaFunction ),
|
|
|
|
m_connectionType( static_cast< ushort >( connectionType & ~Qt::UniqueConnection ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskMetaCallback::QskMetaCallback( const QskMetaCallback& other ):
|
|
|
|
m_object( other.m_object ),
|
|
|
|
m_function(),
|
|
|
|
m_type( Invalid ),
|
|
|
|
m_connectionType( other.m_connectionType )
|
|
|
|
{
|
|
|
|
if ( other.m_type != m_type )
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
m_type = other.m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( m_type )
|
|
|
|
{
|
|
|
|
case MetaMethod:
|
2018-02-28 08:37:40 +01:00
|
|
|
m_method = new QMetaMethod( *other.m_method );
|
2018-02-26 09:09:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MetaFunction:
|
2018-02-28 08:37:40 +01:00
|
|
|
m_function = new QskMetaFunction( *other.m_function );
|
2018-02-26 09:09:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QskMetaCallback::~QskMetaCallback()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
QskMetaCallback& QskMetaCallback::operator=( const QskMetaCallback& other )
|
|
|
|
{
|
|
|
|
m_object = other.m_object;
|
|
|
|
m_connectionType = other.m_connectionType;
|
|
|
|
|
|
|
|
if ( other.m_type != m_type )
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
m_type = other.m_type;
|
|
|
|
}
|
|
|
|
|
2018-02-28 08:37:40 +01:00
|
|
|
if ( other.m_type != Invalid )
|
2018-02-26 09:09:21 +01:00
|
|
|
{
|
2018-02-28 08:37:40 +01:00
|
|
|
if ( other.m_type == MetaMethod )
|
|
|
|
m_method = new QMetaMethod( *other.m_method );
|
|
|
|
else
|
|
|
|
m_function = new QskMetaFunction( *other.m_function );
|
2018-02-26 09:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-02-27 17:47:23 +01:00
|
|
|
void QskMetaCallback::setConnectionType( Qt::ConnectionType connectionType )
|
|
|
|
{
|
|
|
|
m_connectionType = connectionType;
|
|
|
|
}
|
|
|
|
|
2018-02-26 09:09:21 +01:00
|
|
|
void QskMetaCallback::reset()
|
|
|
|
{
|
|
|
|
switch( m_type )
|
|
|
|
{
|
|
|
|
case MetaMethod:
|
2018-02-28 08:37:40 +01:00
|
|
|
delete m_method;
|
|
|
|
m_method = nullptr;
|
2018-02-26 09:09:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MetaFunction:
|
2018-02-28 08:37:40 +01:00
|
|
|
delete m_function;
|
|
|
|
m_function = nullptr;
|
2018-02-26 09:09:21 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_type = Invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector< int > QskMetaCallback::parameterTypes() const
|
|
|
|
{
|
|
|
|
QVector< int > paramTypes;
|
|
|
|
|
|
|
|
switch( m_type )
|
|
|
|
{
|
|
|
|
case MetaMethod:
|
|
|
|
{
|
2018-02-28 08:37:40 +01:00
|
|
|
const int paramCount = m_method->parameterCount();
|
2018-02-26 09:09:21 +01:00
|
|
|
|
|
|
|
paramTypes.reserve( paramCount );
|
|
|
|
for ( int i = 0; i < paramCount; i++ )
|
2018-02-28 08:37:40 +01:00
|
|
|
paramTypes += m_method->parameterType( i );
|
2018-02-26 09:09:21 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MetaFunction:
|
|
|
|
{
|
2018-02-28 08:37:40 +01:00
|
|
|
auto types = m_function->parameterTypes();
|
2018-02-26 09:09:21 +01:00
|
|
|
if ( types )
|
|
|
|
{
|
|
|
|
while ( *types )
|
|
|
|
paramTypes += *types++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return paramTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QskMetaCallback::invoke( void* args[] )
|
|
|
|
{
|
|
|
|
auto object = const_cast< QObject* >( m_object.data() );
|
|
|
|
|
|
|
|
switch( m_type )
|
|
|
|
{
|
|
|
|
case MetaMethod:
|
|
|
|
{
|
|
|
|
if ( object )
|
2018-02-28 08:37:40 +01:00
|
|
|
QskMetaCall::invoke( object, *m_method, args, connectionType() );
|
2018-02-26 09:09:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MetaFunction:
|
|
|
|
{
|
2018-02-28 08:37:40 +01:00
|
|
|
m_function->invoke( object, args, connectionType() );
|
2018-02-26 09:09:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|