#include "qgridlayout_wrap.h" #include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h" #include "src/cpp/Extras/Utils/nutils.h" Napi::FunctionReference QGridLayoutWrap::constructor; Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "QGridLayout"; Napi::Function func = DefineClass(env, CLASSNAME, { InstanceMethod("addWidget", &QGridLayoutWrap::addWidget), QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QGridLayoutWrap) }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; } QGridLayout* QGridLayoutWrap::getInternalInstance() { return this->instance; } QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); if(info.Length() == 1) { Napi::Object parentObject = info[0].As(); QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new QGridLayout(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget }else if (info.Length() == 0){ this->instance = new QGridLayout(); }else { Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException(); } } QGridLayoutWrap::~QGridLayoutWrap() { delete this->instance; } Napi::Value QGridLayoutWrap::addWidget(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); Napi::Object qwidgetObject = info[0].As(); QWidgetWrap* widget = Napi::ObjectWrap::Unwrap(qwidgetObject); this->instance->addWidget(widget->getInternalInstance()); return env.Null(); }