This commit is contained in:
Filippo Cucchetto 2016-01-16 11:29:35 +01:00
parent 39c0c94a24
commit 28f9898573
6 changed files with 44 additions and 9 deletions

View File

@ -17,8 +17,11 @@ namespace DOS
class DosQObjectImpl : public QAbstractDynamicMetaObject, public IDosQObject
{
public:
using ParentMetaCall = std::function<int(QMetaObject::Call, int, void **)>;
/// Constructor
DosQObjectImpl(QObject* parent,
ParentMetaCall parentMetaCall,
OnMetaObject onMetaObject,
OnSlotExecuted onSlotExecuted);
@ -37,6 +40,7 @@ private:
bool writeProperty(int index, void** args);
QObject* m_parent;
const ParentMetaCall m_parentMetaCall;
const OnMetaObject m_onMetaObject;
const OnSlotExecuted m_onSlotExecuted;
};

View File

@ -1,6 +1,16 @@
#include "DOtherSide/DosQAbstractListModel.h"
#include "DOtherSide/DosQObjectImpl.h"
namespace
{
DOS::DosQObjectImpl::ParentMetaCall createParentMetaCall(QAbstractListModel* parent)
{
return [parent](QMetaObject::Call callType, int index, void** args)->int {
return parent->QAbstractListModel::qt_metacall(callType, index, args);
};
}
}
namespace DOS
{
@ -14,7 +24,7 @@ DosQAbstractListModel::DosQAbstractListModel(void *modelObject,
RoleNamesCallback roleNamesCallback,
FlagsCallback flagsCallback,
HeaderDataCallback headerDataCallback)
: m_impl(new DosQObjectImpl(this, std::move(onMetaObject), std::move(onSlotExecuted)))
: m_impl(new DosQObjectImpl(this, ::createParentMetaCall(this), std::move(onMetaObject), std::move(onSlotExecuted)))
, m_modelObject(std::move(modelObject))
, m_rowCountCallback(std::move(rowCountCallback))
, m_columnCountCallback(std::move(columnCountCallback))

View File

@ -5,11 +5,21 @@
#include <QtCore/QMetaMethod>
#include <QtCore/QDebug>
namespace
{
DOS::DosQObjectImpl::ParentMetaCall createParentMetaCall(QObject* parent)
{
return [parent](QMetaObject::Call callType, int index, void** args) -> int {
return parent->QObject::qt_metacall(callType, index, args);
};
}
}
namespace DOS
{
DosQObject::DosQObject(OnMetaObject onMetaObject, OnSlotExecuted onSlotExecuted)
: m_impl(new DosQObjectImpl(this, std::move(onMetaObject), std::move(onSlotExecuted)))
: m_impl(new DosQObjectImpl(this, ::createParentMetaCall(this), std::move(onMetaObject), std::move(onSlotExecuted)))
{}
bool DosQObject::emitSignal(const QString &name, const std::vector<QVariant> &args)

View File

@ -8,9 +8,11 @@ namespace DOS
{
DosQObjectImpl::DosQObjectImpl(QObject* parent,
ParentMetaCall parentMetaCall,
OnMetaObject onMetaObject,
OnSlotExecuted onSlotExecuted)
: m_parent(std::move(parent))
, m_parentMetaCall(std::move(parentMetaCall))
, m_onMetaObject(std::move(onMetaObject))
, m_onSlotExecuted(std::move(onSlotExecuted))
{
@ -36,7 +38,7 @@ bool DosQObjectImpl::emitSignal(const QString &name, const std::vector<QVariant>
int DosQObjectImpl::metaCall(QMetaObject::Call callType, int index, void **args)
{
index = m_parent->QObject::qt_metacall(callType, index, args);
index = m_parentMetaCall(callType, index, args);
if (index < 0)
return index;

View File

@ -5,5 +5,9 @@ ApplicationWindow {
width: 100
height: 100
objectName: "testWindow"
Component.onCompleted: visible = true
Component.onCompleted: {
visible = true
console.log(testObject)
console.log(testObject.name)
}
}

View File

@ -11,7 +11,7 @@
#include <QQuickWindow>
#include <QQmlApplicationEngine>
#include <QQuickItem>
#include <QQmlContext>
// DOtherSide
#include "DOtherSide/DOtherSide.h"
#include "DOtherSide/DosQObject.h"
@ -212,8 +212,6 @@ int main(int argc, char* argv[])
slotDefinitions,
propertyDefinitions);
// auto mo = std::make_shared<DosQObjectMetaObject>();
auto moh = std::make_unique<DosIQMetaObjectHolder>(mo);
auto omo = [&]() -> DosIQMetaObjectHolder* { return moh.get(); };
@ -241,7 +239,14 @@ int main(int argc, char* argv[])
<< testObject.property("name").toString().toStdString() << std::endl
<< value.toStdString() << std::endl;
return success ? 0 : 1;
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("testObject", QVariant::fromValue<QObject*>(&testObject));
engine.load(QUrl("qrc:///main.qml"));
return app.exec();
}
#include "test_dotherside.moc"