Reformatted the code
This commit is contained in:
parent
27db2ef854
commit
8e36e4d957
|
@ -34,7 +34,7 @@ void* BaseQAbstractListModel::modelObject()
|
||||||
return m_modelObject;
|
return m_modelObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int,QByteArray> BaseQAbstractListModel::roleNames() const
|
QHash<int, QByteArray> BaseQAbstractListModel::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> result;
|
QHash<int, QByteArray> result;
|
||||||
m_roleNamesCallback(m_modelObject, &result);
|
m_roleNamesCallback(m_modelObject, &result);
|
||||||
|
|
|
@ -6,30 +6,28 @@
|
||||||
/// This class act as a base class for D and Nim QAbstractListModel
|
/// This class act as a base class for D and Nim QAbstractListModel
|
||||||
class BaseQAbstractListModel : public QAbstractListModel
|
class BaseQAbstractListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
BaseQAbstractListModel(void* modelObject,
|
BaseQAbstractListModel(void* modelObject,
|
||||||
RowCountCallback rowCountCallback,
|
RowCountCallback rowCountCallback,
|
||||||
DataCallback dataCallback,
|
DataCallback dataCallback,
|
||||||
RoleNamesCallback roleNamesCallback);
|
RoleNamesCallback roleNamesCallback);
|
||||||
|
|
||||||
/// Return the model's row count
|
/// Return the model's row count
|
||||||
virtual int rowCount(const QModelIndex& index = QModelIndex()) const override;
|
virtual int rowCount(const QModelIndex& index = QModelIndex()) const override;
|
||||||
|
|
||||||
/// Return the QVariant at the given index
|
/// Return the QVariant at the given index
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
/// Return the dModelPointer
|
/// Return the dModelPointer
|
||||||
void* modelObject();
|
void* modelObject();
|
||||||
|
|
||||||
/// Return the roleNames
|
/// Return the roleNames
|
||||||
virtual QHash<int, QByteArray> roleNames() const override;
|
virtual QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void* m_modelObject;
|
||||||
private:
|
RowCountCallback m_rowCountCallback;
|
||||||
void* m_modelObject;
|
DataCallback m_dataCallback;
|
||||||
RowCountCallback m_rowCountCallback;
|
RoleNamesCallback m_roleNamesCallback;
|
||||||
DataCallback m_dataCallback;
|
|
||||||
RoleNamesCallback m_roleNamesCallback;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,12 +66,12 @@ void dos_qapplication_quit()
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qqmlapplicationengine_create(void **vptr)
|
void dos_qqmlapplicationengine_create(void** vptr)
|
||||||
{
|
{
|
||||||
*vptr = new QQmlApplicationEngine();
|
*vptr = new QQmlApplicationEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qqmlapplicationengine_load(void *vptr, const char *filename)
|
void dos_qqmlapplicationengine_load(void* vptr, const char* filename)
|
||||||
{
|
{
|
||||||
QQmlApplicationEngine* engine = reinterpret_cast<QQmlApplicationEngine*>(vptr);
|
QQmlApplicationEngine* engine = reinterpret_cast<QQmlApplicationEngine*>(vptr);
|
||||||
engine->load(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QDir::separator() + QString(filename)));
|
engine->load(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QDir::separator() + QString(filename)));
|
||||||
|
@ -107,7 +107,7 @@ void dos_qquickview_delete(void* vptr)
|
||||||
delete view;
|
delete view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qquickview_source(void *vptr, char** result, int* length)
|
void dos_qquickview_source(void* vptr, char** result, int* length)
|
||||||
{
|
{
|
||||||
QQuickView* view = reinterpret_cast<QQuickView*>(vptr);
|
QQuickView* view = reinterpret_cast<QQuickView*>(vptr);
|
||||||
QUrl url = view->source();
|
QUrl url = view->source();
|
||||||
|
@ -158,17 +158,17 @@ void dos_qqmlcontext_setcontextproperty(void* vptr, const char* name, void* valu
|
||||||
context->setContextProperty(QString::fromUtf8(name), *variant);
|
context->setContextProperty(QString::fromUtf8(name), *variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qvariant_create(void **vptr)
|
void dos_qvariant_create(void** vptr)
|
||||||
{
|
{
|
||||||
*vptr = new QVariant();
|
*vptr = new QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qvariant_create_int(void **vptr, int value)
|
void dos_qvariant_create_int(void** vptr, int value)
|
||||||
{
|
{
|
||||||
*vptr = new QVariant(value);
|
*vptr = new QVariant(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qvariant_create_bool(void **vptr, bool value)
|
void dos_qvariant_create_bool(void** vptr, bool value)
|
||||||
{
|
{
|
||||||
*vptr = new QVariant(value);
|
*vptr = new QVariant(value);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ void dos_qvariant_create_qvariant(void** vptr, void* other)
|
||||||
*vptr = newQVariant;
|
*vptr = newQVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qvariant_create_qobject(void **vptr, void* value)
|
void dos_qvariant_create_qobject(void** vptr, void* value)
|
||||||
{
|
{
|
||||||
auto qobject = reinterpret_cast<QObject*>(value);
|
auto qobject = reinterpret_cast<QObject*>(value);
|
||||||
auto variant = new QVariant();
|
auto variant = new QVariant();
|
||||||
|
@ -218,7 +218,7 @@ void dos_qvariant_isnull(void* vptr, bool* isNull)
|
||||||
*isNull = variant->isNull();
|
*isNull = variant->isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qvariant_delete(void *vptr)
|
void dos_qvariant_delete(void* vptr)
|
||||||
{
|
{
|
||||||
auto variant = reinterpret_cast<QVariant*>(vptr);
|
auto variant = reinterpret_cast<QVariant*>(vptr);
|
||||||
delete variant;
|
delete variant;
|
||||||
|
@ -314,7 +314,7 @@ void dos_qobject_create(void** vptr, void* dObjectPointer, DObjectCallback dObje
|
||||||
*vptr = dynamicQObject;
|
*vptr = dynamicQObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dos_qobject_delete(void *vptr)
|
void dos_qobject_delete(void* vptr)
|
||||||
{
|
{
|
||||||
auto dynamicQObject = reinterpret_cast<DynamicQObject*>(vptr);
|
auto dynamicQObject = reinterpret_cast<DynamicQObject*>(vptr);
|
||||||
dynamicQObject->disconnect();
|
dynamicQObject->disconnect();
|
||||||
|
@ -458,7 +458,7 @@ void dos_qhash_int_qbytearray_create(QHashIntQByteArrayVoidPtr* vptr)
|
||||||
|
|
||||||
void dos_qhash_int_qbytearray_delete(QHashIntQByteArrayVoidPtr vptr)
|
void dos_qhash_int_qbytearray_delete(QHashIntQByteArrayVoidPtr vptr)
|
||||||
{
|
{
|
||||||
auto qHash = reinterpret_cast<QHash<int,QByteArray>*>(vptr);
|
auto qHash = reinterpret_cast<QHash<int, QByteArray>*>(vptr);
|
||||||
delete qHash;
|
delete qHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,15 +47,15 @@ void dos_chararray_create(char** ptr, int size);
|
||||||
void dos_chararray_delete(char* ptr);
|
void dos_chararray_delete(char* ptr);
|
||||||
|
|
||||||
// QVariant
|
// QVariant
|
||||||
void dos_qvariant_create(void **vptr);
|
void dos_qvariant_create(void** vptr);
|
||||||
void dos_qvariant_create_int(void **vptr, int value);
|
void dos_qvariant_create_int(void** vptr, int value);
|
||||||
void dos_qvariant_create_bool(void **vptr, bool value);
|
void dos_qvariant_create_bool(void** vptr, bool value);
|
||||||
void dos_qvariant_create_string(void **vptr, const char* value);
|
void dos_qvariant_create_string(void** vptr, const char* value);
|
||||||
void dos_qvariant_create_qobject(void **vptr, void* value);
|
void dos_qvariant_create_qobject(void** vptr, void* value);
|
||||||
void dos_qvariant_create_qvariant(void **vptr, void* value);
|
void dos_qvariant_create_qvariant(void** vptr, void* value);
|
||||||
void dos_qvariant_create_float(void **vptr, float value);
|
void dos_qvariant_create_float(void** vptr, float value);
|
||||||
void dos_qvariant_create_double(void **vptr, double value);
|
void dos_qvariant_create_double(void** vptr, double value);
|
||||||
void dos_qvariant_create_qabstractlistmodel(void **vptr, void* value);
|
void dos_qvariant_create_qabstractlistmodel(void** vptr, void* value);
|
||||||
void dos_qvariant_toInt(void* vptr, int* value);
|
void dos_qvariant_toInt(void* vptr, int* value);
|
||||||
void dos_qvariant_setInt(void* vptr, int value);
|
void dos_qvariant_setInt(void* vptr, int value);
|
||||||
void dos_qvariant_toBool(void* vptr, bool* value);
|
void dos_qvariant_toBool(void* vptr, bool* value);
|
||||||
|
@ -68,8 +68,8 @@ void dos_qvariant_toString(void* vptr, char** ptr, int* size);
|
||||||
void dos_qvariant_setString(void* vptr, const char* value);
|
void dos_qvariant_setString(void* vptr, const char* value);
|
||||||
void dos_qvariant_setQObject(void* vptr, void* value);
|
void dos_qvariant_setQObject(void* vptr, void* value);
|
||||||
void dos_qvariant_setQAbstractListModel(void* vptr, void* value);
|
void dos_qvariant_setQAbstractListModel(void* vptr, void* value);
|
||||||
void dos_qvariant_isnull(void *vptr, bool* isNull);
|
void dos_qvariant_isnull(void* vptr, bool* isNull);
|
||||||
void dos_qvariant_delete(void *vptr);
|
void dos_qvariant_delete(void* vptr);
|
||||||
void dos_qvariant_assign(void* vptr, void* other);
|
void dos_qvariant_assign(void* vptr, void* other);
|
||||||
|
|
||||||
// QObject
|
// QObject
|
||||||
|
@ -100,7 +100,7 @@ void dos_qobject_property_create(void* vptr,
|
||||||
const char* readSlot,
|
const char* readSlot,
|
||||||
const char* writeSlot,
|
const char* writeSlot,
|
||||||
const char* notifySignal);
|
const char* notifySignal);
|
||||||
void dos_qobject_delete(void *vptr);
|
void dos_qobject_delete(void* vptr);
|
||||||
|
|
||||||
// QModelIndex
|
// QModelIndex
|
||||||
void dos_qmodelindex_create(void** vptr);
|
void dos_qmodelindex_create(void** vptr);
|
||||||
|
|
|
@ -16,8 +16,8 @@ typedef void* QHashIntQByteArrayVoidPtr;
|
||||||
// Raw function types
|
// Raw function types
|
||||||
typedef void (*Function)(void*);
|
typedef void (*Function)(void*);
|
||||||
typedef void (*DObjectCallback)(void*, void*, int, void**);
|
typedef void (*DObjectCallback)(void*, void*, int, void**);
|
||||||
typedef void (*RowCountCallback) (void* model, QModelIndexVoidPtr index, IntPtr result);
|
typedef void (*RowCountCallback)(void* model, QModelIndexVoidPtr index, IntPtr result);
|
||||||
typedef void (*DataCallback) (void* model, QModelIndexVoidPtr index, int role, QVariantVoidPtr result);
|
typedef void (*DataCallback)(void* model, QModelIndexVoidPtr index, int role, QVariantVoidPtr result);
|
||||||
typedef void (*RoleNamesCallback) (void* model, QHashIntQByteArrayVoidPtr result);
|
typedef void (*RoleNamesCallback)(void* model, QHashIntQByteArrayVoidPtr result);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -56,20 +56,14 @@ DynamicProperty::DynamicProperty(const DynamicProperty& other)
|
||||||
d.reset(new PropertyData(*other.d));
|
d.reset(new PropertyData(*other.d));
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicProperty&DynamicProperty::operator=(const DynamicProperty& other)
|
DynamicProperty& DynamicProperty::operator=(const DynamicProperty& other)
|
||||||
{
|
{
|
||||||
if (!other.d && d)
|
if (!other.d && d)
|
||||||
{
|
|
||||||
d.reset();
|
d.reset();
|
||||||
}
|
|
||||||
else if (other.d && !d)
|
else if (other.d && !d)
|
||||||
{
|
|
||||||
d.reset(new PropertyData(*other.d));
|
d.reset(new PropertyData(*other.d));
|
||||||
}
|
|
||||||
else if (other.d && d)
|
else if (other.d && d)
|
||||||
{
|
|
||||||
*d = *other.d;
|
*d = *other.d;
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,9 @@ public:
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QMetaType::Type type() const;
|
QMetaType::Type type() const;
|
||||||
|
|
||||||
bool isValid() const { return d != nullptr; }
|
bool isValid() const {
|
||||||
|
return d != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool isReadable() const;
|
bool isReadable() const;
|
||||||
bool isWriteable() const;
|
bool isWriteable() const;
|
||||||
|
|
|
@ -22,7 +22,7 @@ bool DynamicQObject::registerSlot(const QString& name,
|
||||||
const QList<QMetaType::Type>& argumentsTypes,
|
const QList<QMetaType::Type>& argumentsTypes,
|
||||||
int& slotIndex)
|
int& slotIndex)
|
||||||
{
|
{
|
||||||
DynamicSlot slot (name, returnType, argumentsTypes);
|
DynamicSlot slot(name, returnType, argumentsTypes);
|
||||||
|
|
||||||
if (m_slotsBySignature.contains(slot.signature()))
|
if (m_slotsBySignature.contains(slot.signature()))
|
||||||
return false;
|
return false;
|
||||||
|
@ -33,16 +33,16 @@ bool DynamicQObject::registerSlot(const QString& name,
|
||||||
auto afterSignalAdded = [](QMetaObjectBuilder&) {};
|
auto afterSignalAdded = [](QMetaObjectBuilder&) {};
|
||||||
auto afterPropertyAdded = afterSignalAdded;
|
auto afterPropertyAdded = afterSignalAdded;
|
||||||
|
|
||||||
auto afterSlotAdded = [&slot, returnType](QMetaObjectBuilder& metaObjectBuilder) {
|
auto afterSlotAdded = [&slot, returnType](QMetaObjectBuilder & metaObjectBuilder) {
|
||||||
QMetaMethodBuilder methodBuilder = metaObjectBuilder.addSlot(slot.signature());
|
QMetaMethodBuilder methodBuilder = metaObjectBuilder.addSlot(slot.signature());
|
||||||
methodBuilder.setReturnType(QMetaType::typeName(returnType));
|
methodBuilder.setReturnType(QMetaType::typeName(returnType));
|
||||||
methodBuilder.setAttributes(QMetaMethod::Scriptable);
|
methodBuilder.setAttributes(QMetaMethod::Scriptable);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data()
|
auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data()
|
||||||
, afterSignalAdded
|
, afterSignalAdded
|
||||||
, afterSlotAdded
|
, afterSlotAdded
|
||||||
, afterPropertyAdded);
|
, afterPropertyAdded);
|
||||||
|
|
||||||
m_metaObject.reset(newMetaObject);
|
m_metaObject.reset(newMetaObject);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ bool DynamicQObject::registerSignal(const QString& name, const QList<QMetaType::
|
||||||
m_signalsByName.insertMulti(signal.name(), signal);
|
m_signalsByName.insertMulti(signal.name(), signal);
|
||||||
m_signalsBySignature[signal.signature()] = signal;
|
m_signalsBySignature[signal.signature()] = signal;
|
||||||
|
|
||||||
auto afterSignalAdded = [&signal](QMetaObjectBuilder& metaObjectBuilder) {
|
auto afterSignalAdded = [&signal](QMetaObjectBuilder & metaObjectBuilder) {
|
||||||
QMetaMethodBuilder methodBuilder = metaObjectBuilder.addSignal(signal.signature());
|
QMetaMethodBuilder methodBuilder = metaObjectBuilder.addSignal(signal.signature());
|
||||||
methodBuilder.setReturnType(QMetaType::typeName(QMetaType::Void));
|
methodBuilder.setReturnType(QMetaType::typeName(QMetaType::Void));
|
||||||
methodBuilder.setAccess(QMetaMethod::Public);
|
methodBuilder.setAccess(QMetaMethod::Public);
|
||||||
|
@ -71,9 +71,9 @@ bool DynamicQObject::registerSignal(const QString& name, const QList<QMetaType::
|
||||||
auto afterPropertyAdded = afterSlotAdded;
|
auto afterPropertyAdded = afterSlotAdded;
|
||||||
|
|
||||||
auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data()
|
auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data()
|
||||||
, afterSignalAdded
|
, afterSignalAdded
|
||||||
, afterSlotAdded
|
, afterSlotAdded
|
||||||
, afterPropertyAdded);
|
, afterPropertyAdded);
|
||||||
|
|
||||||
m_metaObject.reset(newMetaObject);
|
m_metaObject.reset(newMetaObject);
|
||||||
|
|
||||||
|
@ -101,9 +101,9 @@ bool DynamicQObject::registerProperty(const QString& name,
|
||||||
|
|
||||||
m_propertiesByName.insert(name.toUtf8(), property);
|
m_propertiesByName.insert(name.toUtf8(), property);
|
||||||
|
|
||||||
auto afterSignalAdded = [](QMetaObjectBuilder& metaObjectBuilder) {};
|
auto afterSignalAdded = [](QMetaObjectBuilder & metaObjectBuilder) {};
|
||||||
auto afterSlotAdded = [](QMetaObjectBuilder& metaObjectBuilder) {};
|
auto afterSlotAdded = [](QMetaObjectBuilder & metaObjectBuilder) {};
|
||||||
auto afterPropertyAdded = [name, type, notifySignal](QMetaObjectBuilder& metaObjectBuilder)
|
auto afterPropertyAdded = [name, type, notifySignal](QMetaObjectBuilder & metaObjectBuilder)
|
||||||
{
|
{
|
||||||
int signalIndex = -1;
|
int signalIndex = -1;
|
||||||
if (notifySignal.isValid())
|
if (notifySignal.isValid())
|
||||||
|
@ -125,16 +125,16 @@ bool DynamicQObject::registerProperty(const QString& name,
|
||||||
|
|
||||||
auto typeName = QMetaType::typeName(type);
|
auto typeName = QMetaType::typeName(type);
|
||||||
auto builder = metaObjectBuilder.addProperty(name.toUtf8(),
|
auto builder = metaObjectBuilder.addProperty(name.toUtf8(),
|
||||||
QMetaObject::normalizedType(typeName),
|
QMetaObject::normalizedType(typeName),
|
||||||
signalIndex);
|
signalIndex);
|
||||||
if (signalIndex == -1)
|
if (signalIndex == -1)
|
||||||
builder.setConstant(true);
|
builder.setConstant(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data()
|
auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data()
|
||||||
, afterSignalAdded
|
, afterSignalAdded
|
||||||
, afterSlotAdded
|
, afterSlotAdded
|
||||||
, afterPropertyAdded);
|
, afterPropertyAdded);
|
||||||
m_metaObject.reset(newMetaObject);
|
m_metaObject.reset(newMetaObject);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ bool DynamicQObject::emitSignal(const QString& name, const QList<QVariant>& args
|
||||||
|
|
||||||
QVariantList argsCopy = args;
|
QVariantList argsCopy = args;
|
||||||
|
|
||||||
QVector<void*> arguments(argsCopy.size() + 1 ,0);
|
QVector<void*> arguments(argsCopy.size() + 1 , 0);
|
||||||
arguments[0] = 0;
|
arguments[0] = 0;
|
||||||
for (int i = 0; i < argsCopy.size(); ++i)
|
for (int i = 0; i < argsCopy.size(); ++i)
|
||||||
arguments[i + 1] = &argsCopy[i];
|
arguments[i + 1] = &argsCopy[i];
|
||||||
|
@ -183,7 +183,7 @@ bool DynamicQObject::executeSlot(const DynamicSlot& slot, void** args)
|
||||||
|
|
||||||
QList<QVariant> arguments;
|
QList<QVariant> arguments;
|
||||||
for (int i = 0; i < slot.argumentsTypes().count(); ++i)
|
for (int i = 0; i < slot.argumentsTypes().count(); ++i)
|
||||||
arguments << QVariant(slot.argumentTypeAt(i), args[i+1]);
|
arguments << QVariant(slot.argumentTypeAt(i), args[i + 1]);
|
||||||
|
|
||||||
QVariant result = executeSlot(slot, arguments);
|
QVariant result = executeSlot(slot, arguments);
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ QVariant DynamicQObject::executeSlot(const DynamicSlot& slot, const QList<QVaria
|
||||||
std::vector<void*> argumentsAsVoidPointers(numParametersPlusReturn);
|
std::vector<void*> argumentsAsVoidPointers(numParametersPlusReturn);
|
||||||
|
|
||||||
for (int i = 0; i < numParametersPlusReturn; ++i) {
|
for (int i = 0; i < numParametersPlusReturn; ++i) {
|
||||||
argumentsAsVariants[i] = i == 0 ? QVariant() : args[i-1];
|
argumentsAsVariants[i] = i == 0 ? QVariant() : args[i - 1];
|
||||||
argumentsAsVoidPointers[i] = &argumentsAsVariants[i];
|
argumentsAsVoidPointers[i] = &argumentsAsVariants[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ bool DynamicQObject::writeProperty(const DynamicProperty& property, void** args)
|
||||||
if (writeSlot.returnType() != QMetaType::Void)
|
if (writeSlot.returnType() != QMetaType::Void)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QVariant newValue (writeSlot.argumentTypeAt(0), args[0]);
|
QVariant newValue(writeSlot.argumentTypeAt(0), args[0]);
|
||||||
executeSlot(writeSlot, {newValue});
|
executeSlot(writeSlot, {newValue});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,9 +297,9 @@ int DynamicQObject::qt_metacall(QMetaObject::Call callType, int index, void** a
|
||||||
}
|
}
|
||||||
|
|
||||||
QMetaObject* DynamicQObject::recreateMetaObjectBuilder(QMetaObject* currentMetaObject,
|
QMetaObject* DynamicQObject::recreateMetaObjectBuilder(QMetaObject* currentMetaObject,
|
||||||
const std::function<void(QMetaObjectBuilder&)>& afterSignalAdded,
|
const std::function<void(QMetaObjectBuilder&)>& afterSignalAdded,
|
||||||
const std::function<void(QMetaObjectBuilder&)>& afterSlotAdded,
|
const std::function<void(QMetaObjectBuilder&)>& afterSlotAdded,
|
||||||
const std::function<void(QMetaObjectBuilder&)>& afterPropertyAdded)
|
const std::function<void(QMetaObjectBuilder&)>& afterPropertyAdded)
|
||||||
{
|
{
|
||||||
// Collect the current methods and signals
|
// Collect the current methods and signals
|
||||||
QList<QMetaMethod> signalsList;
|
QList<QMetaMethod> signalsList;
|
||||||
|
@ -326,7 +326,7 @@ QMetaObject* DynamicQObject::recreateMetaObjectBuilder(QMetaObject* currentMetaO
|
||||||
metaObjectBuilder.setClassName(currentMetaObject->className());
|
metaObjectBuilder.setClassName(currentMetaObject->className());
|
||||||
metaObjectBuilder.setSuperClass(currentMetaObject->superClass());
|
metaObjectBuilder.setSuperClass(currentMetaObject->superClass());
|
||||||
|
|
||||||
foreach(auto& method, signalsList)
|
foreach (auto& method, signalsList)
|
||||||
metaObjectBuilder.addMethod(method);
|
metaObjectBuilder.addMethod(method);
|
||||||
|
|
||||||
// Call custom code to be executed after signal have been added
|
// Call custom code to be executed after signal have been added
|
||||||
|
|
|
@ -12,7 +12,7 @@ class QMetaObjectBuilder;
|
||||||
/// This class implements a QObject to which signals, slots and properties can be added dynamically
|
/// This class implements a QObject to which signals, slots and properties can be added dynamically
|
||||||
class DynamicQObject : public QObject
|
class DynamicQObject : public QObject
|
||||||
{
|
{
|
||||||
typedef void (*Callback)(void*, void*, int, void **);
|
typedef void (*Callback)(void*, void*, int, void**);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
@ -22,10 +22,14 @@ public:
|
||||||
virtual ~DynamicQObject();
|
virtual ~DynamicQObject();
|
||||||
|
|
||||||
/// Sets the function to be called from C++ to D or Nimrod
|
/// Sets the function to be called from C++ to D or Nimrod
|
||||||
void setDObjectCallback(Callback callback) { m_dObjectCallback = callback; }
|
void setDObjectCallback(Callback callback) {
|
||||||
|
m_dObjectCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the D or Nimrod object that owns this DynamicQObject
|
/// Sets the D or Nimrod object that owns this DynamicQObject
|
||||||
void setDObjectPointer(void* dObjectPointer) { m_dObjectPointer = dObjectPointer; }
|
void setDObjectPointer(void* dObjectPointer) {
|
||||||
|
m_dObjectPointer = dObjectPointer;
|
||||||
|
}
|
||||||
|
|
||||||
/// Register a new signal
|
/// Register a new signal
|
||||||
bool registerSignal(const QString& name,
|
bool registerSignal(const QString& name,
|
||||||
|
@ -49,10 +53,10 @@ public:
|
||||||
bool emitSignal(const QString& name, const QList<QVariant>& argumentsValues);
|
bool emitSignal(const QString& name, const QList<QVariant>& argumentsValues);
|
||||||
|
|
||||||
/// Return the QMetaObject for this DynamicQObject
|
/// Return the QMetaObject for this DynamicQObject
|
||||||
virtual const QMetaObject *metaObject() const;
|
virtual const QMetaObject* metaObject() const;
|
||||||
|
|
||||||
/// The qt metacall. Called from Qt when a signals, slot or property is invoked
|
/// The qt metacall. Called from Qt when a signals, slot or property is invoked
|
||||||
int qt_metacall(QMetaObject::Call, int, void **);
|
int qt_metacall(QMetaObject::Call, int, void**);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool executeSlot(const DynamicSlot& slot, void** args);
|
bool executeSlot(const DynamicSlot& slot, void** args);
|
||||||
|
@ -67,9 +71,9 @@ private:
|
||||||
/// The creation is customizable by injecting custom code after signals and slots have
|
/// The creation is customizable by injecting custom code after signals and slots have
|
||||||
/// been added
|
/// been added
|
||||||
static QMetaObject* recreateMetaObjectBuilder(QMetaObject* currentMetaObject,
|
static QMetaObject* recreateMetaObjectBuilder(QMetaObject* currentMetaObject,
|
||||||
const std::function<void(QMetaObjectBuilder&)>& afterSignalAdded,
|
const std::function<void(QMetaObjectBuilder&)>& afterSignalAdded,
|
||||||
const std::function<void(QMetaObjectBuilder&)>& afterSlotAdded,
|
const std::function<void(QMetaObjectBuilder&)>& afterSlotAdded,
|
||||||
const std::function<void(QMetaObjectBuilder&)>& afterPropertyAdded);
|
const std::function<void(QMetaObjectBuilder&)>& afterPropertyAdded);
|
||||||
|
|
||||||
QHash<QString, DynamicSignal> m_signalsByName;
|
QHash<QString, DynamicSignal> m_signalsByName;
|
||||||
QHash<QByteArray, DynamicSignal> m_signalsBySignature;
|
QHash<QByteArray, DynamicSignal> m_signalsBySignature;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <DynamicQObject.h>
|
#include <DynamicQObject.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import tables
|
||||||
type
|
type
|
||||||
Roles {.pure.} = enum
|
Roles {.pure.} = enum
|
||||||
Name = cint(0)
|
Name = cint(0)
|
||||||
|
|
||||||
MyQAbstractListModel = ref object of QAbstractListModel
|
MyQAbstractListModel = ref object of QAbstractListModel
|
||||||
m_roleNames: Table[int, cstring]
|
m_roleNames: Table[int, cstring]
|
||||||
m_names: seq[string]
|
m_names: seq[string]
|
||||||
|
|
Loading…
Reference in New Issue