diff --git a/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp b/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp index 158c838..35e3fcd 100644 --- a/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp +++ b/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp @@ -34,7 +34,7 @@ void* BaseQAbstractListModel::modelObject() return m_modelObject; } -QHash BaseQAbstractListModel::roleNames() const +QHash BaseQAbstractListModel::roleNames() const { QHash result; m_roleNamesCallback(m_modelObject, &result); diff --git a/DOtherSide/DOtherSide/BaseQAbstractListModel.h b/DOtherSide/DOtherSide/BaseQAbstractListModel.h index 972a848..84ffc1d 100644 --- a/DOtherSide/DOtherSide/BaseQAbstractListModel.h +++ b/DOtherSide/DOtherSide/BaseQAbstractListModel.h @@ -6,30 +6,28 @@ /// This class act as a base class for D and Nim QAbstractListModel class BaseQAbstractListModel : public QAbstractListModel { - public: - /// Constructor - BaseQAbstractListModel(void* modelObject, - RowCountCallback rowCountCallback, - DataCallback dataCallback, - RoleNamesCallback roleNamesCallback); +public: + /// Constructor + BaseQAbstractListModel(void* modelObject, + RowCountCallback rowCountCallback, + DataCallback dataCallback, + RoleNamesCallback roleNamesCallback); - /// Return the model's row count - virtual int rowCount(const QModelIndex& index = QModelIndex()) const override; + /// Return the model's row count + virtual int rowCount(const QModelIndex& index = QModelIndex()) const override; - /// Return the QVariant at the given index - virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; + /// Return the QVariant at the given index + virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - /// Return the dModelPointer - void* modelObject(); - - /// Return the roleNames - virtual QHash roleNames() const override; - - - - private: - void* m_modelObject; - RowCountCallback m_rowCountCallback; - DataCallback m_dataCallback; - RoleNamesCallback m_roleNamesCallback; + /// Return the dModelPointer + void* modelObject(); + + /// Return the roleNames + virtual QHash roleNames() const override; + +private: + void* m_modelObject; + RowCountCallback m_rowCountCallback; + DataCallback m_dataCallback; + RoleNamesCallback m_roleNamesCallback; }; diff --git a/DOtherSide/DOtherSide/DOtherSide.cpp b/DOtherSide/DOtherSide/DOtherSide.cpp index 3d52e08..fdf54c9 100644 --- a/DOtherSide/DOtherSide/DOtherSide.cpp +++ b/DOtherSide/DOtherSide/DOtherSide.cpp @@ -66,12 +66,12 @@ void dos_qapplication_quit() qApp->quit(); } -void dos_qqmlapplicationengine_create(void **vptr) +void dos_qqmlapplicationengine_create(void** vptr) { *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(vptr); engine->load(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QDir::separator() + QString(filename))); @@ -107,7 +107,7 @@ void dos_qquickview_delete(void* vptr) 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(vptr); 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); } -void dos_qvariant_create(void **vptr) +void dos_qvariant_create(void** vptr) { *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); } -void dos_qvariant_create_bool(void **vptr, bool value) +void dos_qvariant_create_bool(void** vptr, bool value) { *vptr = new QVariant(value); } @@ -186,7 +186,7 @@ void dos_qvariant_create_qvariant(void** vptr, void* other) *vptr = newQVariant; } -void dos_qvariant_create_qobject(void **vptr, void* value) +void dos_qvariant_create_qobject(void** vptr, void* value) { auto qobject = reinterpret_cast(value); auto variant = new QVariant(); @@ -218,7 +218,7 @@ void dos_qvariant_isnull(void* vptr, bool* isNull) *isNull = variant->isNull(); } -void dos_qvariant_delete(void *vptr) +void dos_qvariant_delete(void* vptr) { auto variant = reinterpret_cast(vptr); delete variant; @@ -314,7 +314,7 @@ void dos_qobject_create(void** vptr, void* dObjectPointer, DObjectCallback dObje *vptr = dynamicQObject; } -void dos_qobject_delete(void *vptr) +void dos_qobject_delete(void* vptr) { auto dynamicQObject = reinterpret_cast(vptr); dynamicQObject->disconnect(); @@ -438,9 +438,9 @@ void dos_qabstractlistmodel_create(void** vptr, DataCallback dataCallback, RoleNamesCallback roleNamesCallaback) { - auto model = new BaseQAbstractListModel(modelObject, - rowCountCallback, - dataCallback, + auto model = new BaseQAbstractListModel(modelObject, + rowCountCallback, + dataCallback, roleNamesCallaback); *vptr = model; } @@ -458,7 +458,7 @@ void dos_qhash_int_qbytearray_create(QHashIntQByteArrayVoidPtr* vptr) void dos_qhash_int_qbytearray_delete(QHashIntQByteArrayVoidPtr vptr) { - auto qHash = reinterpret_cast*>(vptr); + auto qHash = reinterpret_cast*>(vptr); delete qHash; } diff --git a/DOtherSide/DOtherSide/DOtherSide.h b/DOtherSide/DOtherSide/DOtherSide.h index bb2fdf7..204becc 100644 --- a/DOtherSide/DOtherSide/DOtherSide.h +++ b/DOtherSide/DOtherSide/DOtherSide.h @@ -47,15 +47,15 @@ void dos_chararray_create(char** ptr, int size); void dos_chararray_delete(char* ptr); // QVariant -void dos_qvariant_create(void **vptr); -void dos_qvariant_create_int(void **vptr, int value); -void dos_qvariant_create_bool(void **vptr, bool value); -void dos_qvariant_create_string(void **vptr, const char* value); -void dos_qvariant_create_qobject(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_double(void **vptr, double value); -void dos_qvariant_create_qabstractlistmodel(void **vptr, void* value); +void dos_qvariant_create(void** vptr); +void dos_qvariant_create_int(void** vptr, int value); +void dos_qvariant_create_bool(void** vptr, bool value); +void dos_qvariant_create_string(void** vptr, const char* value); +void dos_qvariant_create_qobject(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_double(void** vptr, double value); +void dos_qvariant_create_qabstractlistmodel(void** vptr, void* value); void dos_qvariant_toInt(void* vptr, int* value); void dos_qvariant_setInt(void* vptr, int 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_setQObject(void* vptr, void* value); void dos_qvariant_setQAbstractListModel(void* vptr, void* value); -void dos_qvariant_isnull(void *vptr, bool* isNull); -void dos_qvariant_delete(void *vptr); +void dos_qvariant_isnull(void* vptr, bool* isNull); +void dos_qvariant_delete(void* vptr); void dos_qvariant_assign(void* vptr, void* other); // QObject @@ -100,7 +100,7 @@ void dos_qobject_property_create(void* vptr, const char* readSlot, const char* writeSlot, const char* notifySignal); -void dos_qobject_delete(void *vptr); +void dos_qobject_delete(void* vptr); // QModelIndex void dos_qmodelindex_create(void** vptr); diff --git a/DOtherSide/DOtherSide/DOtherSideTypes.h b/DOtherSide/DOtherSide/DOtherSideTypes.h index b08c16d..16a88d9 100644 --- a/DOtherSide/DOtherSide/DOtherSideTypes.h +++ b/DOtherSide/DOtherSide/DOtherSideTypes.h @@ -1,7 +1,7 @@ #ifndef DOTHERSIDETYPES_H #define DOTHERSIDETYPES_H -// Raw data types +// Raw data types typedef int* IntPtr; typedef char* CharPtr; typedef const char* ConstCharPtr; @@ -16,8 +16,8 @@ typedef void* QHashIntQByteArrayVoidPtr; // Raw function types typedef void (*Function)(void*); typedef void (*DObjectCallback)(void*, void*, int, void**); -typedef void (*RowCountCallback) (void* model, QModelIndexVoidPtr index, IntPtr result); -typedef void (*DataCallback) (void* model, QModelIndexVoidPtr index, int role, QVariantVoidPtr result); -typedef void (*RoleNamesCallback) (void* model, QHashIntQByteArrayVoidPtr result); +typedef void (*RowCountCallback)(void* model, QModelIndexVoidPtr index, IntPtr result); +typedef void (*DataCallback)(void* model, QModelIndexVoidPtr index, int role, QVariantVoidPtr result); +typedef void (*RoleNamesCallback)(void* model, QHashIntQByteArrayVoidPtr result); #endif \ No newline at end of file diff --git a/DOtherSide/DynamicQObject/DynamicProperty.cpp b/DOtherSide/DynamicQObject/DynamicProperty.cpp index 7682490..7a5aa0d 100644 --- a/DOtherSide/DynamicQObject/DynamicProperty.cpp +++ b/DOtherSide/DynamicQObject/DynamicProperty.cpp @@ -56,20 +56,14 @@ DynamicProperty::DynamicProperty(const DynamicProperty& other) d.reset(new PropertyData(*other.d)); } -DynamicProperty&DynamicProperty::operator=(const DynamicProperty& other) +DynamicProperty& DynamicProperty::operator=(const DynamicProperty& other) { if (!other.d && d) - { d.reset(); - } else if (other.d && !d) - { d.reset(new PropertyData(*other.d)); - } else if (other.d && d) - { *d = *other.d; - } return *this; } diff --git a/DOtherSide/DynamicQObject/DynamicProperty.h b/DOtherSide/DynamicQObject/DynamicProperty.h index b99056a..d77c09f 100644 --- a/DOtherSide/DynamicQObject/DynamicProperty.h +++ b/DOtherSide/DynamicQObject/DynamicProperty.h @@ -23,7 +23,9 @@ public: QString name() const; QMetaType::Type type() const; - bool isValid() const { return d != nullptr; } + bool isValid() const { + return d != nullptr; + } bool isReadable() const; bool isWriteable() const; diff --git a/DOtherSide/DynamicQObject/DynamicQObject.cpp b/DOtherSide/DynamicQObject/DynamicQObject.cpp index 57705d8..ff8017f 100644 --- a/DOtherSide/DynamicQObject/DynamicQObject.cpp +++ b/DOtherSide/DynamicQObject/DynamicQObject.cpp @@ -21,8 +21,8 @@ bool DynamicQObject::registerSlot(const QString& name, const QMetaType::Type returnType, const QList& argumentsTypes, int& slotIndex) -{ - DynamicSlot slot (name, returnType, argumentsTypes); +{ + DynamicSlot slot(name, returnType, argumentsTypes); if (m_slotsBySignature.contains(slot.signature())) return false; @@ -33,16 +33,16 @@ bool DynamicQObject::registerSlot(const QString& name, auto afterSignalAdded = [](QMetaObjectBuilder&) {}; auto afterPropertyAdded = afterSignalAdded; - auto afterSlotAdded = [&slot, returnType](QMetaObjectBuilder& metaObjectBuilder) { + auto afterSlotAdded = [&slot, returnType](QMetaObjectBuilder & metaObjectBuilder) { QMetaMethodBuilder methodBuilder = metaObjectBuilder.addSlot(slot.signature()); methodBuilder.setReturnType(QMetaType::typeName(returnType)); methodBuilder.setAttributes(QMetaMethod::Scriptable); }; auto newMetaObject = recreateMetaObjectBuilder(m_metaObject.data() - , afterSignalAdded - , afterSlotAdded - , afterPropertyAdded); + , afterSignalAdded + , afterSlotAdded + , afterPropertyAdded); m_metaObject.reset(newMetaObject); @@ -61,7 +61,7 @@ bool DynamicQObject::registerSignal(const QString& name, const QList& args QVariantList argsCopy = args; - QVector arguments(argsCopy.size() + 1 ,0); + QVector arguments(argsCopy.size() + 1 , 0); arguments[0] = 0; for (int i = 0; i < argsCopy.size(); ++i) arguments[i + 1] = &argsCopy[i]; @@ -183,7 +183,7 @@ bool DynamicQObject::executeSlot(const DynamicSlot& slot, void** args) QList arguments; 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); @@ -205,7 +205,7 @@ QVariant DynamicQObject::executeSlot(const DynamicSlot& slot, const QList argumentsAsVoidPointers(numParametersPlusReturn); 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]; } @@ -256,7 +256,7 @@ bool DynamicQObject::writeProperty(const DynamicProperty& property, void** args) if (writeSlot.returnType() != QMetaType::Void) return false; - QVariant newValue (writeSlot.argumentTypeAt(0), args[0]); + QVariant newValue(writeSlot.argumentTypeAt(0), args[0]); executeSlot(writeSlot, {newValue}); } @@ -297,9 +297,9 @@ int DynamicQObject::qt_metacall(QMetaObject::Call callType, int index, void** a } QMetaObject* DynamicQObject::recreateMetaObjectBuilder(QMetaObject* currentMetaObject, - const std::function& afterSignalAdded, - const std::function& afterSlotAdded, - const std::function& afterPropertyAdded) + const std::function& afterSignalAdded, + const std::function& afterSlotAdded, + const std::function& afterPropertyAdded) { // Collect the current methods and signals QList signalsList; @@ -326,7 +326,7 @@ QMetaObject* DynamicQObject::recreateMetaObjectBuilder(QMetaObject* currentMetaO metaObjectBuilder.setClassName(currentMetaObject->className()); metaObjectBuilder.setSuperClass(currentMetaObject->superClass()); - foreach(auto& method, signalsList) + foreach (auto& method, signalsList) metaObjectBuilder.addMethod(method); // Call custom code to be executed after signal have been added diff --git a/DOtherSide/DynamicQObject/DynamicQObject.h b/DOtherSide/DynamicQObject/DynamicQObject.h index 00bf636..ce826fd 100644 --- a/DOtherSide/DynamicQObject/DynamicQObject.h +++ b/DOtherSide/DynamicQObject/DynamicQObject.h @@ -12,7 +12,7 @@ class QMetaObjectBuilder; /// This class implements a QObject to which signals, slots and properties can be added dynamically class DynamicQObject : public QObject { - typedef void (*Callback)(void*, void*, int, void **); + typedef void (*Callback)(void*, void*, int, void**); public: /// Constructor @@ -22,10 +22,14 @@ public: virtual ~DynamicQObject(); /// 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 - void setDObjectPointer(void* dObjectPointer) { m_dObjectPointer = dObjectPointer; } + void setDObjectPointer(void* dObjectPointer) { + m_dObjectPointer = dObjectPointer; + } /// Register a new signal bool registerSignal(const QString& name, @@ -49,10 +53,10 @@ public: bool emitSignal(const QString& name, const QList& argumentsValues); /// 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 - int qt_metacall(QMetaObject::Call, int, void **); + int qt_metacall(QMetaObject::Call, int, void**); private: 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 /// been added static QMetaObject* recreateMetaObjectBuilder(QMetaObject* currentMetaObject, - const std::function& afterSignalAdded, - const std::function& afterSlotAdded, - const std::function& afterPropertyAdded); + const std::function& afterSignalAdded, + const std::function& afterSlotAdded, + const std::function& afterPropertyAdded); QHash m_signalsByName; QHash m_signalsBySignature; diff --git a/DOtherSide/IntegrationTest/main.cpp b/DOtherSide/IntegrationTest/main.cpp index 11357ee..f0ac270 100644 --- a/DOtherSide/IntegrationTest/main.cpp +++ b/DOtherSide/IntegrationTest/main.cpp @@ -5,7 +5,7 @@ #include #include -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); diff --git a/Nim/Examples/AbstractItemModel/main.nim b/Nim/Examples/AbstractItemModel/main.nim index b913566..935e693 100644 --- a/Nim/Examples/AbstractItemModel/main.nim +++ b/Nim/Examples/AbstractItemModel/main.nim @@ -6,6 +6,7 @@ import tables type Roles {.pure.} = enum Name = cint(0) + MyQAbstractListModel = ref object of QAbstractListModel m_roleNames: Table[int, cstring] m_names: seq[string]