diff --git a/src/cpp/include/nodegui/QtCore/QAbstractItemModel/nabstractitemmodel.hpp b/src/cpp/include/nodegui/QtCore/QAbstractItemModel/nabstractitemmodel.hpp index b85750829..6e3d68fc5 100644 --- a/src/cpp/include/nodegui/QtCore/QAbstractItemModel/nabstractitemmodel.hpp +++ b/src/cpp/include/nodegui/QtCore/QAbstractItemModel/nabstractitemmodel.hpp @@ -2,115 +2,142 @@ #include #include "Extras/Export/export.h" +#include "QtCore/QModelIndex/qmodelindex_wrap.h" #include "QtCore/QObject/qobject_macro.h" #include "core/NodeWidget/nodewidget.h" -#include "QtCore/QModelIndex/qmodelindex_wrap.h" - #include "napi.h" -class DLL_EXPORT NAbstractItemModel : public QAbstractItemModel, public EventWidget { +class DLL_EXPORT NAbstractItemModel : public QAbstractItemModel, + public EventWidget { Q_OBJECT EVENTWIDGET_IMPLEMENTATIONS(QAbstractItemModel) public: Napi::FunctionReference dispatchOnNode; - void connectSignalsToEventEmitter() { - // Qt Connects: Implement all signal connects here - QOBJECT_SIGNALS - } + void connectSignalsToEventEmitter(){ + // Qt Connects: Implement all signal connects here + QOBJECT_SIGNALS} - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override { + QModelIndex index(int row, int column, + const QModelIndex& parent = QModelIndex()) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto parentModelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(parent))}); + auto parentModelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(parent))}); Napi::Value modelIndexNapiWrap = this->dispatchOnNode.Call( - {Napi::String::New(env, "index"), Napi::Value::From(env, row), Napi::Value::From(env, column), parentModelIndexWrap}); + {Napi::String::New(env, "index"), Napi::Value::From(env, row), + Napi::Value::From(env, column), parentModelIndexWrap}); - QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap(modelIndexNapiWrap.As()); + QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap( + modelIndexNapiWrap.As()); QModelIndex* newIndex = modelIndexWrap->getInternalInstance(); return *newIndex; } - QModelIndex parent(const QModelIndex &child) const override { + QModelIndex parent(const QModelIndex& child) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto childModelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(child))}); - Napi::Value modelIndexNapiWrap = this->dispatchOnNode.Call({Napi::String::New(env, "parent"), childModelIndexWrap}); + auto childModelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(child))}); + Napi::Value modelIndexNapiWrap = this->dispatchOnNode.Call( + {Napi::String::New(env, "parent"), childModelIndexWrap}); - QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap(modelIndexNapiWrap.As()); + QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap( + modelIndexNapiWrap.As()); QModelIndex* parentIndex = modelIndexWrap->getInternalInstance(); return *parentIndex; } - int rowCount(const QModelIndex &parent = QModelIndex()) const override { + int rowCount(const QModelIndex& parent = QModelIndex()) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto modelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(parent))}); - Napi::Value result = this->dispatchOnNode.Call({Napi::String::New(env, "rowCount"), modelIndexWrap}); + auto modelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(parent))}); + Napi::Value result = this->dispatchOnNode.Call( + {Napi::String::New(env, "rowCount"), modelIndexWrap}); return result.As().Int32Value(); } - int columnCount(const QModelIndex &parent = QModelIndex()) const override { + int columnCount(const QModelIndex& parent = QModelIndex()) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto modelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(parent))}); - Napi::Value result = this->dispatchOnNode.Call({Napi::String::New(env, "columnCount"), modelIndexWrap}); + auto modelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(parent))}); + Napi::Value result = this->dispatchOnNode.Call( + {Napi::String::New(env, "columnCount"), modelIndexWrap}); return result.As().Int32Value(); } - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override { + QVariant data(const QModelIndex& index, + int role = Qt::DisplayRole) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto modelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(index))}); + auto modelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(index))}); auto roleValue = Napi::Value::From(env, role); - Napi::Value variantJsObject = this->dispatchOnNode.Call({Napi::String::New(env, "data"), modelIndexWrap, roleValue}); + Napi::Value variantJsObject = this->dispatchOnNode.Call( + {Napi::String::New(env, "data"), modelIndexWrap, roleValue}); - QVariantWrap* variantWrap = Napi::ObjectWrap::Unwrap(variantJsObject.As()); + QVariantWrap* variantWrap = Napi::ObjectWrap::Unwrap( + variantJsObject.As()); QVariant* variant = variantWrap->getInternalInstance(); return *variant; } - Qt::ItemFlags flags(const QModelIndex &index) const override { + Qt::ItemFlags flags(const QModelIndex& index) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto modelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(index))}); - Napi::Value numberJs = this->dispatchOnNode.Call({Napi::String::New(env, "flags"), modelIndexWrap}); + auto modelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(index))}); + Napi::Value numberJs = this->dispatchOnNode.Call( + {Napi::String::New(env, "flags"), modelIndexWrap}); - auto result = static_cast(numberJs.As().Uint32Value()); + auto result = + static_cast(numberJs.As().Uint32Value()); return result; } - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override { + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); auto sectionValue = Napi::Value::From(env, static_cast(section)); - auto orientationValue = Napi::Value::From(env, static_cast(orientation)); + auto orientationValue = + Napi::Value::From(env, static_cast(orientation)); auto roleValue = Napi::Value::From(env, static_cast(role)); - Napi::Value variantJsObject = this->dispatchOnNode.Call({Napi::String::New(env, "headerData"), sectionValue, orientationValue, roleValue}); + Napi::Value variantJsObject = + this->dispatchOnNode.Call({Napi::String::New(env, "headerData"), + sectionValue, orientationValue, roleValue}); - QVariantWrap* variantWrap = Napi::ObjectWrap::Unwrap(variantJsObject.As()); + QVariantWrap* variantWrap = Napi::ObjectWrap::Unwrap( + variantJsObject.As()); QVariant* variant = variantWrap->getInternalInstance(); return *variant; } - bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override { + bool setData(const QModelIndex& index, const QVariant& value, + int role = Qt::EditRole) override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto modelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(index))}); - auto valueWrap = QVariantWrap::constructor.New({Napi::External::New(env, new QVariant(value))}); + auto modelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(index))}); + auto valueWrap = QVariantWrap::constructor.New( + {Napi::External::New(env, new QVariant(value))}); auto roleValue = Napi::Value::From(env, role); - Napi::Value booleanJs = this->dispatchOnNode.Call({Napi::String::New(env, "setData"), modelIndexWrap, valueWrap, roleValue}); + Napi::Value booleanJs = + this->dispatchOnNode.Call({Napi::String::New(env, "setData"), + modelIndexWrap, valueWrap, roleValue}); return booleanJs.As().Value(); } @@ -119,14 +146,17 @@ class DLL_EXPORT NAbstractItemModel : public QAbstractItemModel, public EventWid return createIndex(row, column); } - QModelIndex buddy(const QModelIndex &index) const override { + QModelIndex buddy(const QModelIndex& index) const override { Napi::Env env = this->dispatchOnNode.Env(); Napi::HandleScope scope(env); - auto indexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(index))}); - Napi::Value buddyIndexNapiWrap = this->dispatchOnNode.Call({Napi::String::New(env, "buddy"), indexWrap}); + auto indexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(index))}); + Napi::Value buddyIndexNapiWrap = + this->dispatchOnNode.Call({Napi::String::New(env, "buddy"), indexWrap}); - QModelIndexWrap* buddyIndexWrap = Napi::ObjectWrap::Unwrap(buddyIndexNapiWrap.As()); + QModelIndexWrap* buddyIndexWrap = Napi::ObjectWrap::Unwrap( + buddyIndexNapiWrap.As()); QModelIndex* buddyIndex = buddyIndexWrap->getInternalInstance(); return *buddyIndex; } diff --git a/src/cpp/include/nodegui/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.h b/src/cpp/include/nodegui/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.h index cbaeb61ec..9eb9e88de 100644 --- a/src/cpp/include/nodegui/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.h @@ -8,12 +8,13 @@ #include "QtCore/QObject/qobject_macro.h" #include "nabstractitemmodel.hpp" - -class DLL_EXPORT QAbstractItemModelWrap : public Napi::ObjectWrap { +class DLL_EXPORT QAbstractItemModelWrap + : public Napi::ObjectWrap { QOBJECT_WRAPPED_METHODS_DECLARATION private: QPointer instance; + public: static Napi::Object init(Napi::Env env, Napi::Object exports); QAbstractItemModelWrap(const Napi::CallbackInfo& info); diff --git a/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h b/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h index b4a6497b0..7cabe5c07 100644 --- a/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h @@ -1,7 +1,7 @@ #pragma once -#include "QtCore/QModelIndex/qmodelindex_wrap.h" #include "QtCore/QAbstractItemModel/qabstractitemmodel_wrap.h" +#include "QtCore/QModelIndex/qmodelindex_wrap.h" #include "QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h" #include "QtWidgets/QWidget/qwidget_wrap.h" @@ -96,7 +96,7 @@ Napi::Object modelObject = info[0].As(); \ QAbstractItemModelWrap* modelWrap = \ Napi::ObjectWrap::Unwrap(modelObject); \ - QAbstractItemView* instance= this->instance; \ + QAbstractItemView* instance = this->instance; \ instance->setModel(modelWrap->getInternalInstance()); \ return env.Null(); \ } diff --git a/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp b/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp index 04af1dece..900a56bdd 100644 --- a/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp +++ b/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp @@ -3,7 +3,6 @@ #include "Extras/Utils/nutils.h" - Napi::FunctionReference QAbstractItemModelWrap::constructor; Napi::Object QAbstractItemModelWrap::init(Napi::Env env, Napi::Object exports) { @@ -11,21 +10,27 @@ Napi::Object QAbstractItemModelWrap::init(Napi::Env env, Napi::Object exports) { char CLASSNAME[] = "QAbstractItemModel"; Napi::Function func = DefineClass( env, CLASSNAME, - {InstanceMethod("initNodeDispatcher", &QAbstractItemModelWrap::initNodeDispatcher), - InstanceMethod("hasIndex", &QAbstractItemModelWrap::hasIndex), - InstanceMethod("createIndex", &QAbstractItemModelWrap::createIndex), - InstanceMethod("_super_flags", &QAbstractItemModelWrap::_super_flags), - InstanceMethod("emitDataChanged", &QAbstractItemModelWrap::emitDataChanged), - InstanceMethod("checkIndex", &QAbstractItemModelWrap::checkIndex), - InstanceMethod("_super_buddy", &QAbstractItemModelWrap::_super_buddy), - QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QAbstractItemModelWrap)}); + {InstanceMethod("initNodeDispatcher", + &QAbstractItemModelWrap::initNodeDispatcher), + InstanceMethod("hasIndex", &QAbstractItemModelWrap::hasIndex), + InstanceMethod("createIndex", &QAbstractItemModelWrap::createIndex), + InstanceMethod("_super_flags", &QAbstractItemModelWrap::_super_flags), + InstanceMethod("emitDataChanged", + &QAbstractItemModelWrap::emitDataChanged), + InstanceMethod("checkIndex", &QAbstractItemModelWrap::checkIndex), + InstanceMethod("_super_buddy", &QAbstractItemModelWrap::_super_buddy), + QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QAbstractItemModelWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; } -NAbstractItemModel* QAbstractItemModelWrap::getInternalInstance() { return this->instance; } -QAbstractItemModelWrap::~QAbstractItemModelWrap() { extrautils::safeDelete(this->instance); } +NAbstractItemModel* QAbstractItemModelWrap::getInternalInstance() { + return this->instance; +} +QAbstractItemModelWrap::~QAbstractItemModelWrap() { + extrautils::safeDelete(this->instance); +} QAbstractItemModelWrap::QAbstractItemModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { @@ -35,9 +40,11 @@ QAbstractItemModelWrap::QAbstractItemModelWrap(const Napi::CallbackInfo& info) this->instance = new NAbstractItemModel(); } -Napi::Value QAbstractItemModelWrap::initNodeDispatcher(const Napi::CallbackInfo& info) { +Napi::Value QAbstractItemModelWrap::initNodeDispatcher( + const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); - this->instance->dispatchOnNode = Napi::Persistent(info[0].As()); + this->instance->dispatchOnNode = + Napi::Persistent(info[0].As()); return env.Null(); } @@ -47,14 +54,17 @@ Napi::Value QAbstractItemModelWrap::hasIndex(const Napi::CallbackInfo& info) { int row = info[0].As().Int32Value(); int column = info[1].As().Int32Value(); - QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap(info[2].As()); + QModelIndexWrap* modelIndexWrap = + Napi::ObjectWrap::Unwrap(info[2].As()); QModelIndex* parentIndex = modelIndexWrap->getInternalInstance(); - auto result = Napi::Value::From(env, this->instance->hasIndex(row, column, *parentIndex)); + auto result = Napi::Value::From( + env, this->instance->hasIndex(row, column, *parentIndex)); return result; } -Napi::Value QAbstractItemModelWrap::createIndex(const Napi::CallbackInfo& info) { +Napi::Value QAbstractItemModelWrap::createIndex( + const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); @@ -63,30 +73,39 @@ Napi::Value QAbstractItemModelWrap::createIndex(const Napi::CallbackInfo& info) QModelIndex resultIndex = this->instance->_protected_createIndex(row, column); - auto resultModelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(resultIndex))}); + auto resultModelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(resultIndex))}); return resultModelIndexWrap; } -Napi::Value QAbstractItemModelWrap::_super_flags(const Napi::CallbackInfo& info) { +Napi::Value QAbstractItemModelWrap::_super_flags( + const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap(info[0].As()); + QModelIndexWrap* modelIndexWrap = + Napi::ObjectWrap::Unwrap(info[0].As()); QModelIndex* index = modelIndexWrap->getInternalInstance(); - auto result = Napi::Value::From(env, static_cast(this->instance->QAbstractItemModel::flags(*index))); + auto result = Napi::Value::From( + env, + static_cast(this->instance->QAbstractItemModel::flags(*index))); return result; } -Napi::Value QAbstractItemModelWrap::emitDataChanged(const Napi::CallbackInfo& info) { +Napi::Value QAbstractItemModelWrap::emitDataChanged( + const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - QModelIndexWrap* topLeftModelIndexWrap = Napi::ObjectWrap::Unwrap(info[0].As()); + QModelIndexWrap* topLeftModelIndexWrap = + Napi::ObjectWrap::Unwrap(info[0].As()); QModelIndex* topLeftIndex = topLeftModelIndexWrap->getInternalInstance(); - QModelIndexWrap* bottomRightModelIndexWrap = Napi::ObjectWrap::Unwrap(info[1].As()); - QModelIndex* bottomRightIndex = bottomRightModelIndexWrap->getInternalInstance(); + QModelIndexWrap* bottomRightModelIndexWrap = + Napi::ObjectWrap::Unwrap(info[1].As()); + QModelIndex* bottomRightIndex = + bottomRightModelIndexWrap->getInternalInstance(); Napi::Array rolesNapi = info[2].As(); QVector roles(rolesNapi.Length()); @@ -104,22 +123,27 @@ Napi::Value QAbstractItemModelWrap::checkIndex(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap(info[0].As()); + QModelIndexWrap* modelIndexWrap = + Napi::ObjectWrap::Unwrap(info[0].As()); QModelIndex* index = modelIndexWrap->getInternalInstance(); - auto result = Napi::Value::From(env, static_cast(this->instance->checkIndex(*index))); + auto result = Napi::Value::From( + env, static_cast(this->instance->checkIndex(*index))); return result; } -Napi::Value QAbstractItemModelWrap::_super_buddy(const Napi::CallbackInfo& info) { +Napi::Value QAbstractItemModelWrap::_super_buddy( + const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - QModelIndexWrap* modelIndexWrap = Napi::ObjectWrap::Unwrap(info[0].As()); + QModelIndexWrap* modelIndexWrap = + Napi::ObjectWrap::Unwrap(info[0].As()); QModelIndex* index = modelIndexWrap->getInternalInstance(); auto resultIndex = this->instance->QAbstractItemModel::buddy(*index); - auto resultModelIndexWrap = QModelIndexWrap::constructor.New({Napi::External::New(env, new QModelIndex(resultIndex))}); + auto resultModelIndexWrap = QModelIndexWrap::constructor.New( + {Napi::External::New(env, new QModelIndex(resultIndex))}); return resultModelIndexWrap; }