invoker testprogram added
This commit is contained in:
parent
34cd6e3754
commit
356966f4ca
49
playground/invoker/Invoker.cpp
Normal file
49
playground/invoker/Invoker.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/******************************************************************************
|
||||
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Invoker.h"
|
||||
|
||||
Invoker::Invoker( QObject* parent ):
|
||||
QObject( parent )
|
||||
{
|
||||
}
|
||||
|
||||
void Invoker::addCallback( const QObject* object,
|
||||
const QskMetaFunction& function )
|
||||
{
|
||||
m_callbacks += QskMetaCallback( object, function, Qt::DirectConnection );
|
||||
}
|
||||
|
||||
void Invoker::invoke( qreal realValue, int intValue )
|
||||
{
|
||||
for ( auto callback : qskAsConst( m_callbacks ) )
|
||||
{
|
||||
void* args[3] = { nullptr };
|
||||
|
||||
const auto types = callback.parameterTypes();
|
||||
|
||||
int i = 1;
|
||||
for ( auto type : types )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case QMetaType::Int:
|
||||
{
|
||||
args[i++] = reinterpret_cast< void* >( &intValue );
|
||||
break;
|
||||
}
|
||||
case QMetaType::Double:
|
||||
{
|
||||
args[i++] = reinterpret_cast< void* >( &realValue );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
callback.invoke( args );
|
||||
}
|
||||
}
|
34
playground/invoker/Invoker.h
Normal file
34
playground/invoker/Invoker.h
Normal file
@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef INVOKER_H
|
||||
#define INVOKER_H 1
|
||||
|
||||
#include <QskMetaFunction.h>
|
||||
#include <QskMetaCallback.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
class Invoker : public QObject
|
||||
{
|
||||
public:
|
||||
Invoker( QObject* parent = nullptr );
|
||||
|
||||
void addCallback( const QskMetaFunction& );
|
||||
void addCallback( const QObject*, const QskMetaFunction& );
|
||||
|
||||
void invoke( qreal d, int i );
|
||||
|
||||
private:
|
||||
QVector< QskMetaCallback > m_callbacks;
|
||||
};
|
||||
|
||||
inline void Invoker::addCallback( const QskMetaFunction& function )
|
||||
{
|
||||
addCallback( this, function );
|
||||
}
|
||||
|
||||
#endif
|
10
playground/invoker/invoker.pro
Normal file
10
playground/invoker/invoker.pro
Normal file
@ -0,0 +1,10 @@
|
||||
include( $${PWD}/../playground.pri )
|
||||
|
||||
TARGET = invoker
|
||||
|
||||
HEADERS += \
|
||||
Invoker.h
|
||||
|
||||
SOURCES += \
|
||||
Invoker.cpp \
|
||||
main.cpp
|
73
playground/invoker/main.cpp
Normal file
73
playground/invoker/main.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/******************************************************************************
|
||||
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Invoker.h"
|
||||
#include <QDebug>
|
||||
|
||||
static void debugValueI( int i )
|
||||
{
|
||||
qDebug() << i;
|
||||
}
|
||||
|
||||
static void debugValue( qreal d, int i )
|
||||
{
|
||||
qDebug() << d << i;
|
||||
}
|
||||
|
||||
class MyObject : public QObject
|
||||
{
|
||||
public:
|
||||
MyObject( QObject* parent = nullptr ):
|
||||
QObject( parent )
|
||||
{
|
||||
}
|
||||
|
||||
void print1( double d, int i ) const
|
||||
{
|
||||
qDebug() << d << i;
|
||||
}
|
||||
|
||||
void print2( int i, double d ) const
|
||||
{
|
||||
qDebug() << i << d;
|
||||
}
|
||||
|
||||
void print3( double d ) const
|
||||
{
|
||||
qDebug() << d;
|
||||
}
|
||||
|
||||
void print4( int i ) const
|
||||
{
|
||||
qDebug() << i;
|
||||
}
|
||||
};
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
Q_UNUSED( argc )
|
||||
Q_UNUSED( argv )
|
||||
|
||||
MyObject object;
|
||||
|
||||
Invoker invoker;
|
||||
|
||||
invoker.addCallback( debugValue );
|
||||
invoker.addCallback( debugValueI );
|
||||
invoker.addCallback( &object, &MyObject::print1 );
|
||||
invoker.addCallback( &object, &MyObject::print2 );
|
||||
invoker.addCallback( &object, &MyObject::print3 );
|
||||
invoker.addCallback( &object, &MyObject::print4 );
|
||||
invoker.addCallback( &object, []( double d, int i ) { qDebug() << d << i; } );
|
||||
invoker.addCallback( &object, []( int i, double d ) { qDebug() << i << d; } );
|
||||
invoker.addCallback( &object, []( double d ) { qDebug() << d; } );
|
||||
invoker.addCallback( []() { qDebug() << "HERE"; } );
|
||||
invoker.addCallback( [ = ]( double d, int i ) { qDebug() << d << i; } );
|
||||
invoker.addCallback( []( int i, double d ) { qDebug() << i << d; } );
|
||||
invoker.addCallback( []( int i ) { qDebug() << i; } );
|
||||
invoker.addCallback( []( double d ) { qDebug() << d; } );
|
||||
|
||||
invoker.invoke( 3.14, 35 );
|
||||
}
|
@ -4,5 +4,6 @@ TEMPLATE = subdirs
|
||||
|
||||
# qml
|
||||
SUBDIRS += \
|
||||
invoker \
|
||||
inputpanel \
|
||||
images
|
||||
|
Loading…
x
Reference in New Issue
Block a user