Changes unique_ptr to qpointer for qobjects since they can be managed by other parent objects. This fixes double memory free. (#182)
This commit is contained in:
parent
3c57b550df
commit
382f2d7da6
@ -1,8 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "core/FlexLayout/flexlayout.h"
|
||||
|
||||
namespace extrautils {
|
||||
YGSize measureQtWidget(YGNodeRef node, float width, YGMeasureMode widthMode,
|
||||
float height, YGMeasureMode heightMode);
|
||||
template <typename T>
|
||||
void safeDelete(QPointer<T> component) {
|
||||
if (component.isNull()) {
|
||||
delete component;
|
||||
}
|
||||
}
|
||||
} // namespace extrautils
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
#include <napi.h>
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <QPointer>
|
||||
class QApplicationWrap : public Napi::ObjectWrap<QApplicationWrap> {
|
||||
private:
|
||||
QApplication* instance;
|
||||
QPointer<QApplication> instance;
|
||||
static int argc;
|
||||
static char** argv;
|
||||
bool _wasManuallyCreated = false;
|
||||
|
||||
@ -2,12 +2,13 @@
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "naction.hpp"
|
||||
|
||||
class QActionWrap : public Napi::ObjectWrap<QActionWrap> {
|
||||
private:
|
||||
NAction* instance;
|
||||
QPointer<NAction> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -5,10 +5,11 @@
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "ncheckbox.hpp"
|
||||
#include <QPointer>
|
||||
|
||||
class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap> {
|
||||
private:
|
||||
std::unique_ptr<NCheckBox> instance;
|
||||
QPointer<NCheckBox> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,13 +3,15 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QAbstractSlider/qabstractslider_macro.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "ndial.hpp"
|
||||
|
||||
class QDialWrap : public Napi::ObjectWrap<QDialWrap> {
|
||||
private:
|
||||
std::unique_ptr<NDial> instance;
|
||||
QPointer<NDial> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -4,12 +4,13 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QLayout/qlayout_macro.h"
|
||||
|
||||
class QGridLayoutWrap : public Napi::ObjectWrap<QGridLayoutWrap> {
|
||||
private:
|
||||
std::unique_ptr<QGridLayout> instance;
|
||||
QPointer<QGridLayout> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nlabel.hpp"
|
||||
|
||||
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap> {
|
||||
private:
|
||||
std::unique_ptr<NLabel> instance;
|
||||
QPointer<NLabel> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -4,13 +4,14 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QLayout/qlayout_macro.h"
|
||||
|
||||
// ABSTRACT CLASS
|
||||
class QLayoutWrap : public Napi::ObjectWrap<QLayoutWrap> {
|
||||
private:
|
||||
std::unique_ptr<QLayout> instance;
|
||||
QPointer<QLayout> instance;
|
||||
|
||||
public:
|
||||
static void init(Napi::Env env);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nlineedit.hpp"
|
||||
|
||||
class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap> {
|
||||
private:
|
||||
std::unique_ptr<NLineEdit> instance;
|
||||
QPointer<NLineEdit> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nmainwindow.hpp"
|
||||
|
||||
class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap> {
|
||||
private:
|
||||
std::unique_ptr<NMainWindow> instance;
|
||||
QPointer<NMainWindow> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,11 +3,13 @@
|
||||
#include <nodegui/QtWidgets/QWidget/qwidget_macro.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "nmenu.hpp"
|
||||
|
||||
class QMenuWrap : public Napi::ObjectWrap<QMenuWrap> {
|
||||
private:
|
||||
std::unique_ptr<NMenu> instance;
|
||||
QPointer<NMenu> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,11 +3,13 @@
|
||||
#include <nodegui/QtWidgets/QWidget/qwidget_macro.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "nmenubar.hpp"
|
||||
|
||||
class QMenuBarWrap : public Napi::ObjectWrap<QMenuBarWrap> {
|
||||
private:
|
||||
std::unique_ptr<NMenuBar> instance;
|
||||
QPointer<NMenuBar> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,13 +3,15 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nplaintextedit.hpp"
|
||||
|
||||
class QPlainTextEditWrap : public Napi::ObjectWrap<QPlainTextEditWrap> {
|
||||
private:
|
||||
std::unique_ptr<NPlainTextEdit> instance;
|
||||
QPointer<NPlainTextEdit> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nprogressbar.hpp"
|
||||
|
||||
class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap> {
|
||||
private:
|
||||
std::unique_ptr<NProgressBar> instance;
|
||||
QPointer<NProgressBar> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,13 +3,15 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "npushbutton.hpp"
|
||||
|
||||
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
|
||||
private:
|
||||
std::unique_ptr<NPushButton> instance;
|
||||
QPointer<NPushButton> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nradiobutton.hpp"
|
||||
|
||||
class QRadioButtonWrap : public Napi::ObjectWrap<QRadioButtonWrap> {
|
||||
private:
|
||||
std::unique_ptr<NRadioButton> instance;
|
||||
QPointer<NRadioButton> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h"
|
||||
#include "nscrollarea.hpp"
|
||||
|
||||
class QScrollAreaWrap : public Napi::ObjectWrap<QScrollAreaWrap> {
|
||||
private:
|
||||
std::unique_ptr<NScrollArea> instance;
|
||||
QPointer<NScrollArea> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -2,12 +2,14 @@
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nshortcut.hpp"
|
||||
|
||||
class QShortcutWrap : public Napi::ObjectWrap<QShortcutWrap> {
|
||||
private:
|
||||
NShortcut* instance;
|
||||
QPointer<NShortcut> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,13 +3,15 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nspinbox.hpp"
|
||||
|
||||
class QSpinBoxWrap : public Napi::ObjectWrap<QSpinBoxWrap> {
|
||||
private:
|
||||
std::unique_ptr<NSpinBox> instance;
|
||||
QPointer<NSpinBox> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -2,12 +2,13 @@
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nsystemtrayicon.hpp"
|
||||
|
||||
class QSystemTrayIconWrap : public Napi::ObjectWrap<QSystemTrayIconWrap> {
|
||||
private:
|
||||
NSystemTrayIcon* instance;
|
||||
QPointer<NSystemTrayIcon> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -2,13 +2,15 @@
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QTabWidget/ntabwidget.hpp"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
|
||||
class QTabWidgetWrap : public Napi::ObjectWrap<QTabWidgetWrap> {
|
||||
private:
|
||||
NTabWidget *instance;
|
||||
QPointer<NTabWidget> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nwidget.hpp"
|
||||
|
||||
class QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap> {
|
||||
private:
|
||||
std::unique_ptr<NWidget> instance;
|
||||
QPointer<NWidget> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
#include <napi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QLayout/qlayout_macro.h"
|
||||
#include "flexlayout.h"
|
||||
|
||||
class FlexLayoutWrap : public Napi::ObjectWrap<FlexLayoutWrap> {
|
||||
private:
|
||||
std::unique_ptr<FlexLayout> instance;
|
||||
QPointer<FlexLayout> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
|
||||
#include "core/FlexLayout/flexitem.h"
|
||||
|
||||
@ -25,4 +25,4 @@ YGSize extrautils::measureQtWidget(YGNodeRef node, float width,
|
||||
}
|
||||
}
|
||||
return YGSize{width, height};
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ QApplicationWrap::QApplicationWrap(const Napi::CallbackInfo& info)
|
||||
}
|
||||
QApplicationWrap::~QApplicationWrap() {
|
||||
if (this->_wasManuallyCreated) {
|
||||
delete this->instance;
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "QtWidgets/QAction/qaction_wrap.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
@ -45,9 +44,7 @@ QActionWrap::QActionWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NAction(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NAction(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NAction();
|
||||
} else {
|
||||
@ -56,10 +53,7 @@ QActionWrap::QActionWrap(const Napi::CallbackInfo& info)
|
||||
}
|
||||
}
|
||||
|
||||
QActionWrap::~QActionWrap() {
|
||||
// delete this->instance; This will be destroyed by the qmenu (since it takes
|
||||
// the ownership)
|
||||
}
|
||||
QActionWrap::~QActionWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QActionWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
@ -116,7 +110,6 @@ Napi::Value QActionWrap::setShortcutContext(const Napi::CallbackInfo& info) {
|
||||
int shortCutContext = shortcutContextEnum.Int32Value();
|
||||
this->instance->setShortcutContext(
|
||||
static_cast<Qt::ShortcutContext>(shortCutContext));
|
||||
qDebug() << "shortCutContext: " << shortCutContext;
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ Napi::Object QCheckBoxWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NCheckBox* QCheckBoxWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NCheckBox* QCheckBoxWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QCheckBoxWrap>(info) {
|
||||
@ -32,11 +32,9 @@ QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NCheckBox>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NCheckBox(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NCheckBox>();
|
||||
this->instance = new NCheckBox();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -47,7 +45,7 @@ QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QCheckBoxWrap::~QCheckBoxWrap() { this->instance.reset(); }
|
||||
QCheckBoxWrap::~QCheckBoxWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QCheckBoxWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -25,7 +25,7 @@ Napi::Object QDialWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NDial* QDialWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NDial* QDialWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QDialWrap::QDialWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QDialWrap>(info) {
|
||||
@ -36,11 +36,9 @@ QDialWrap::QDialWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NDial>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NDial(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NDial>();
|
||||
this->instance = new NDial();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -51,7 +49,7 @@ QDialWrap::QDialWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QDialWrap::~QDialWrap() { this->instance.reset(); }
|
||||
QDialWrap::~QDialWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QDialWrap::setNotchesVisible(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -18,9 +18,8 @@ Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
QGridLayout* QGridLayoutWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
QGridLayout* QGridLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
QGridLayoutWrap::~QGridLayoutWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QGridLayoutWrap>(info) {
|
||||
@ -31,19 +30,15 @@ QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<QGridLayout>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new QGridLayout(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<QGridLayout>();
|
||||
this->instance = new QGridLayout();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QGridLayoutWrap::~QGridLayoutWrap() { this->instance.reset(); }
|
||||
|
||||
Napi::Value QGridLayoutWrap::addWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtGui/QPixmap/qpixmap_wrap.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
|
||||
Napi::FunctionReference QLabelWrap::constructor;
|
||||
|
||||
Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
@ -26,7 +25,9 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NLabel* QLabelWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NLabel* QLabelWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QLabelWrap::~QLabelWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
QLabelWrap::QLabelWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QLabelWrap>(info) {
|
||||
@ -37,11 +38,9 @@ QLabelWrap::QLabelWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NLabel>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NLabel(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NLabel>();
|
||||
this->instance = new NLabel();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -52,8 +51,6 @@ QLabelWrap::QLabelWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QLabelWrap::~QLabelWrap() { this->instance.reset(); }
|
||||
|
||||
Napi::Value QLabelWrap::setWordWrap(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "QtWidgets/QLayout/qlayout_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
Napi::FunctionReference QLayoutWrap::constructor;
|
||||
|
||||
void QLayoutWrap::init(Napi::Env env) {
|
||||
@ -9,7 +10,7 @@ void QLayoutWrap::init(Napi::Env env) {
|
||||
constructor = Napi::Persistent(func);
|
||||
}
|
||||
|
||||
QLayout* QLayoutWrap::getInternalInstance() { return this->instance.get(); }
|
||||
QLayout* QLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QLayoutWrap::QLayoutWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QLayoutWrap>(info) {
|
||||
@ -17,4 +18,4 @@ QLayoutWrap::QLayoutWrap(const Napi::CallbackInfo& info)
|
||||
Napi::HandleScope scope(env);
|
||||
}
|
||||
|
||||
QLayoutWrap::~QLayoutWrap() { this->instance.reset(); }
|
||||
QLayoutWrap::~QLayoutWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
@ -24,7 +24,7 @@ Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NLineEdit* QLineEditWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NLineEdit* QLineEditWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QLineEditWrap::QLineEditWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QLineEditWrap>(info) {
|
||||
@ -35,11 +35,9 @@ QLineEditWrap::QLineEditWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NLineEdit>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NLineEdit(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NLineEdit>();
|
||||
this->instance = new NLineEdit();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -50,7 +48,7 @@ QLineEditWrap::QLineEditWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QLineEditWrap::~QLineEditWrap() { this->instance.reset(); }
|
||||
QLineEditWrap::~QLineEditWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QLineEditWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -26,9 +26,9 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NMainWindow* QMainWindowWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
NMainWindow* QMainWindowWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QMainWindowWrap::~QMainWindowWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QMainWindowWrap>(info) {
|
||||
@ -39,19 +39,15 @@ QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NMainWindow>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NMainWindow(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NMainWindow>();
|
||||
this->instance = new NMainWindow();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QMainWindowWrap::~QMainWindowWrap() { this->instance.reset(); }
|
||||
|
||||
Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -22,7 +22,7 @@ Napi::Object QMenuWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NMenu* QMenuWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NMenu* QMenuWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QMenuWrap::QMenuWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QMenuWrap>(info) {
|
||||
@ -33,11 +33,9 @@ QMenuWrap::QMenuWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NMenu>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NMenu(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NMenu>();
|
||||
this->instance = new NMenu();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -48,7 +46,7 @@ QMenuWrap::QMenuWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QMenuWrap::~QMenuWrap() { this->instance.reset(); }
|
||||
QMenuWrap::~QMenuWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QMenuWrap::setTitle(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -22,7 +22,7 @@ Napi::Object QMenuBarWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NMenuBar* QMenuBarWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NMenuBar* QMenuBarWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QMenuBarWrap::QMenuBarWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QMenuBarWrap>(info) {
|
||||
@ -31,18 +31,16 @@ QMenuBarWrap::QMenuBarWrap(const Napi::CallbackInfo& info)
|
||||
|
||||
if (info.Length() == 1) {
|
||||
if (info[0].IsExternal()) {
|
||||
this->instance = std::unique_ptr<NMenuBar>(
|
||||
info[0].As<Napi::External<NMenuBar>>().Data());
|
||||
this->instance =
|
||||
new NMenuBar(info[0].As<Napi::External<NMenuBar>>().Data());
|
||||
} else {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NMenuBar>(
|
||||
parentWidgetWrap->getInternalInstance()); // this sets the parent to
|
||||
// current widget
|
||||
this->instance = new NMenuBar(parentWidgetWrap->getInternalInstance());
|
||||
}
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NMenuBar>();
|
||||
this->instance = new NMenuBar();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -53,7 +51,7 @@ QMenuBarWrap::QMenuBarWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QMenuBarWrap::~QMenuBarWrap() { this->instance.reset(); }
|
||||
QMenuBarWrap::~QMenuBarWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QMenuBarWrap::addMenu(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -32,7 +32,7 @@ Napi::Object QPlainTextEditWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
}
|
||||
|
||||
NPlainTextEdit *QPlainTextEditWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QPlainTextEditWrap::QPlainTextEditWrap(const Napi::CallbackInfo &info)
|
||||
@ -44,11 +44,10 @@ QPlainTextEditWrap::QPlainTextEditWrap(const Napi::CallbackInfo &info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap *parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NPlainTextEdit>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance =
|
||||
new NPlainTextEdit(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NPlainTextEdit>();
|
||||
this->instance = new NPlainTextEdit();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -59,7 +58,9 @@ QPlainTextEditWrap::QPlainTextEditWrap(const Napi::CallbackInfo &info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QPlainTextEditWrap::~QPlainTextEditWrap() { this->instance.reset(); }
|
||||
QPlainTextEditWrap::~QPlainTextEditWrap() {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
|
||||
Napi::Value QPlainTextEditWrap::setPlainText(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -24,9 +24,7 @@ Napi::Object QProgressBarWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NProgressBar* QProgressBarWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
NProgressBar* QProgressBarWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QProgressBarWrap::QProgressBarWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QProgressBarWrap>(info) {
|
||||
@ -37,11 +35,9 @@ QProgressBarWrap::QProgressBarWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NProgressBar>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NProgressBar(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NProgressBar>();
|
||||
this->instance = new NProgressBar();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -52,7 +48,9 @@ QProgressBarWrap::QProgressBarWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QProgressBarWrap::~QProgressBarWrap() { this->instance.reset(); }
|
||||
QProgressBarWrap::~QProgressBarWrap() {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
|
||||
Napi::Value QProgressBarWrap::setValue(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -20,9 +20,7 @@ Napi::Object QPushButtonWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NPushButton* QPushButtonWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
NPushButton* QPushButtonWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QPushButtonWrap>(info) {
|
||||
@ -33,11 +31,9 @@ QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NPushButton>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NPushButton(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NPushButton>();
|
||||
this->instance = new NPushButton();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -48,7 +44,7 @@ QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QPushButtonWrap::~QPushButtonWrap() { this->instance.reset(); }
|
||||
QPushButtonWrap::~QPushButtonWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -20,9 +20,7 @@ Napi::Object QRadioButtonWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NRadioButton* QRadioButtonWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
NRadioButton* QRadioButtonWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QRadioButtonWrap::QRadioButtonWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QRadioButtonWrap>(info) {
|
||||
@ -33,11 +31,9 @@ QRadioButtonWrap::QRadioButtonWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NRadioButton>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NRadioButton(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NRadioButton>();
|
||||
this->instance = new NRadioButton();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -48,7 +44,9 @@ QRadioButtonWrap::QRadioButtonWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QRadioButtonWrap::~QRadioButtonWrap() { this->instance.reset(); }
|
||||
QRadioButtonWrap::~QRadioButtonWrap() {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
|
||||
Napi::Value QRadioButtonWrap::setText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -22,9 +22,7 @@ Napi::Object QScrollAreaWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NScrollArea* QScrollAreaWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
NScrollArea* QScrollAreaWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QScrollAreaWrap::QScrollAreaWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QScrollAreaWrap>(info) {
|
||||
@ -35,18 +33,16 @@ QScrollAreaWrap::QScrollAreaWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NScrollArea>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NScrollArea(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NScrollArea>();
|
||||
this->instance = new NScrollArea();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QScrollAreaWrap::~QScrollAreaWrap() { this->instance.reset(); }
|
||||
QScrollAreaWrap::~QScrollAreaWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QScrollAreaWrap::setWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "QtWidgets/QShortcut/qshortcut_wrap.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
@ -37,19 +36,14 @@ QShortcutWrap::QShortcutWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NShortcut(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NShortcut(parentWidgetWrap->getInternalInstance());
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QShortcutWrap::~QShortcutWrap() {
|
||||
// delete this->instance; This will be destroyed by the qmenu (since it takes
|
||||
// the ownership)
|
||||
}
|
||||
QShortcutWrap::~QShortcutWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QShortcutWrap::setEnabled(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
@ -85,6 +79,5 @@ Napi::Value QShortcutWrap::setContext(const Napi::CallbackInfo& info) {
|
||||
Napi::Number shortcutContextEnum = info[0].As<Napi::Number>();
|
||||
int shortCutContext = shortcutContextEnum.Int32Value();
|
||||
this->instance->setContext(static_cast<Qt::ShortcutContext>(shortCutContext));
|
||||
qDebug() << "shortCutContext: " << shortCutContext;
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ Napi::Object QSpinBoxWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NSpinBox* QSpinBoxWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NSpinBox* QSpinBoxWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QSpinBoxWrap::QSpinBoxWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QSpinBoxWrap>(info) {
|
||||
@ -38,11 +38,9 @@ QSpinBoxWrap::QSpinBoxWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NSpinBox>(
|
||||
parentWidgetWrap
|
||||
->getInternalInstance()); // this sets the parent to current widget
|
||||
this->instance = new NSpinBox(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NSpinBox>();
|
||||
this->instance = new NSpinBox();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
@ -53,7 +51,7 @@ QSpinBoxWrap::QSpinBoxWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QSpinBoxWrap::~QSpinBoxWrap() { this->instance.reset(); }
|
||||
QSpinBoxWrap::~QSpinBoxWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
Napi::Value QSpinBoxWrap::setPrefix(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -52,7 +52,9 @@ QSystemTrayIconWrap::QSystemTrayIconWrap(const Napi::CallbackInfo& info)
|
||||
}
|
||||
}
|
||||
|
||||
QSystemTrayIconWrap::~QSystemTrayIconWrap() { delete this->instance; }
|
||||
QSystemTrayIconWrap::~QSystemTrayIconWrap() {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
|
||||
Napi::Value QSystemTrayIconWrap::show(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
@ -27,6 +27,8 @@ Napi::Object QTabWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
|
||||
NTabWidget* QTabWidgetWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QTabWidgetWrap::~QTabWidgetWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
QTabWidgetWrap::QTabWidgetWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QTabWidgetWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
@ -51,8 +53,6 @@ QTabWidgetWrap::QTabWidgetWrap(const Napi::CallbackInfo& info)
|
||||
&extrautils::measureQtWidget);
|
||||
}
|
||||
|
||||
QTabWidgetWrap::~QTabWidgetWrap() { delete this->instance; }
|
||||
|
||||
Napi::Value QTabWidgetWrap::addTab(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -15,7 +15,9 @@ Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
NWidget* QWidgetWrap::getInternalInstance() { return this->instance.get(); }
|
||||
NWidget* QWidgetWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QWidgetWrap::~QWidgetWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QWidgetWrap>(info) {
|
||||
@ -23,22 +25,18 @@ QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info)
|
||||
Napi::HandleScope scope(env);
|
||||
if (info.Length() == 1) {
|
||||
if (info[0].IsExternal()) {
|
||||
this->instance = std::unique_ptr<NWidget>(
|
||||
info[0].As<Napi::External<NWidget>>().Data());
|
||||
this->instance =
|
||||
new NWidget(info[0].As<Napi::External<NWidget>>().Data());
|
||||
} else {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = std::make_unique<NWidget>(
|
||||
parentWidgetWrap->getInternalInstance()); // this sets the parent to
|
||||
// current widget
|
||||
this->instance = new NWidget(parentWidgetWrap->getInternalInstance());
|
||||
}
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<NWidget>();
|
||||
this->instance = new NWidget();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QWidgetWrap::~QWidgetWrap() { this->instance.reset(); }
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "core/FlexLayout/flexlayout.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWidget>
|
||||
|
||||
#include "core/YogaWidget/yogawidget.h"
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
|
||||
#include "core/FlexLayout/flexlayout_wrap.h"
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
@ -20,9 +21,9 @@ Napi::Object FlexLayoutWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
FlexLayout* FlexLayoutWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
FlexLayout* FlexLayoutWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
FlexLayoutWrap::~FlexLayoutWrap() { extrautils::safeDelete(this->instance); }
|
||||
|
||||
FlexLayoutWrap::FlexLayoutWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<FlexLayoutWrap>(info) {
|
||||
@ -33,18 +34,15 @@ FlexLayoutWrap::FlexLayoutWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance =
|
||||
std::make_unique<FlexLayout>(parentWidgetWrap->getInternalInstance());
|
||||
this->instance = new FlexLayout(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<FlexLayout>();
|
||||
this->instance = new FlexLayout();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
FlexLayoutWrap::~FlexLayoutWrap() { this->instance.reset(); }
|
||||
|
||||
Napi::Value FlexLayoutWrap::addWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -23,6 +23,7 @@ world.setStyleSheet(`
|
||||
border: 1px solid blue;
|
||||
qproperty-alignment: AlignCenter;
|
||||
`);
|
||||
|
||||
if (view.layout) {
|
||||
view.layout.addWidget(hello);
|
||||
view.layout.addWidget(world);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user