From 21e5e78876f48ba68bdaf47d133b0c1045ad56ab Mon Sep 17 00:00:00 2001 From: Atul R Date: Sun, 10 Nov 2019 12:30:26 +0100 Subject: [PATCH] Add qvariant object translation (#185) * working - translation of any wrapped object * clang format --- package.json | 2 +- src/cpp/include/nodegui/Extras/Utils/nutils.h | 4 ++++ .../nodegui/QtCore/QObject/qobject_macro.h | 2 -- .../QtGui/QApplication/qapplication_wrap.h | 5 +++++ .../QtGui/QClipboard/qclipboard_wrap.h | 2 ++ .../nodegui/QtGui/QCursor/qcursor_wrap.h | 2 ++ .../QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h | 5 ++++- .../include/nodegui/QtGui/QIcon/qicon_wrap.h | 2 ++ .../QtGui/QKeySequence/qkeysequence_wrap.h | 2 ++ .../nodegui/QtGui/QPixmap/qpixmap_wrap.h | 2 ++ .../nodegui/QtWidgets/QLayout/qlayout_macro.h | 3 ++- .../nodegui/core/Component/component_macro.h | 9 ++++++++- .../nodegui/core/Component/component_wrap.h | 16 ++++++++++++++++ .../nodegui/core/Events/eventwidget_macro.h | 5 +++-- src/cpp/lib/Extras/Utils/nutils.cpp | 19 +++++++++++++++++-- src/cpp/lib/QtCore/QObject/qobject_wrap.cpp | 1 + .../QtGui/QApplication/qapplication_wrap.cpp | 2 +- .../lib/QtGui/QClipboard/qclipboard_wrap.cpp | 1 + src/cpp/lib/QtGui/QCursor/qcursor_wrap.cpp | 1 + .../QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp | 3 +-- src/cpp/lib/QtGui/QIcon/qicon_wrap.cpp | 1 + .../QtGui/QKeySequence/qkeysequence_wrap.cpp | 1 + src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp | 1 + .../lib/QtWidgets/QAction/qaction_wrap.cpp | 4 ++-- .../QtWidgets/QCheckBox/qcheckbox_wrap.cpp | 1 + src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp | 1 + .../QGridLayout/qgridlayout_wrap.cpp | 1 + src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp | 1 + .../QtWidgets/QLineEdit/qlineedit_wrap.cpp | 1 + .../QMainWindow/qmainwindow_wrap.cpp | 1 + src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp | 1 + .../lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp | 1 + .../QPlainTextEdit/qplaintextedit_wrap.cpp | 1 + .../QProgressBar/qprogressbar_wrap.cpp | 1 + .../QRadioButton/qradiobutton_wrap.cpp | 1 + .../QScrollArea/qscrollarea_wrap.cpp | 2 +- .../QtWidgets/QShortcut/qshortcut_wrap.cpp | 4 ++-- .../lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp | 1 + .../QSystemTrayIcon/qsystemtrayicon_wrap.cpp | 5 ++--- .../QtWidgets/QTabWidget/qtabwidget_wrap.cpp | 1 + .../lib/QtWidgets/QWidget/qwidget_wrap.cpp | 1 + .../lib/core/FlexLayout/flexlayout_wrap.cpp | 1 + src/demo.ts | 3 +++ src/lib/QtCore/QObject.ts | 3 ++- 44 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 src/cpp/include/nodegui/core/Component/component_wrap.h diff --git a/package.json b/package.json index d1436854d..f233879d8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "license": "MIT", "private": false, "scripts": { - "dev": "npm run build && qode dist/demo.js", + "dev": "npm run build && qode --inspect dist/demo.js", "postinstall": "npm run build:addon", "build": "tsc && npm run build:addon", "build:addon": "cross-env CMAKE_BUILD_PARALLEL_LEVEL=8 cmake-js build", diff --git a/src/cpp/include/nodegui/Extras/Utils/nutils.h b/src/cpp/include/nodegui/Extras/Utils/nutils.h index 19601b7d5..75423097b 100644 --- a/src/cpp/include/nodegui/Extras/Utils/nutils.h +++ b/src/cpp/include/nodegui/Extras/Utils/nutils.h @@ -10,9 +10,13 @@ namespace extrautils { YGSize measureQtWidget(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode); + QVariant* convertToQVariant(Napi::Env& env, Napi::Value& value); + bool isNapiValueInt(Napi::Env& env, Napi::Value& num); +std::string getNapiObjectClassName(Napi::Object& object); + template void safeDelete(QPointer component) { if (component.isNull()) { diff --git a/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h b/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h index 761a7f2e0..656879aee 100644 --- a/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h +++ b/src/cpp/include/nodegui/QtCore/QObject/qobject_macro.h @@ -1,7 +1,6 @@ #pragma once #include "Extras/Utils/nutils.h" -#include "core/Component/component_macro.h" #include "core/Events/eventwidget_macro.h" /* @@ -53,7 +52,6 @@ #define QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(ComponentWrapName) \ \ EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(ComponentWrapName) \ - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE \ \ InstanceMethod("inherits", &ComponentWrapName::inherits), \ InstanceMethod("setProperty", &ComponentWrapName::setProperty), \ diff --git a/src/cpp/include/nodegui/QtGui/QApplication/qapplication_wrap.h b/src/cpp/include/nodegui/QtGui/QApplication/qapplication_wrap.h index 3db5b53c4..52bc7a096 100644 --- a/src/cpp/include/nodegui/QtGui/QApplication/qapplication_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QApplication/qapplication_wrap.h @@ -4,6 +4,9 @@ #include #include + +#include "core/Component/component_macro.h" + class QApplicationWrap : public Napi::ObjectWrap { private: QPointer instance; @@ -24,6 +27,8 @@ class QApplicationWrap : public Napi::ObjectWrap { Napi::Value exit(const Napi::CallbackInfo& info); Napi::Value setQuitOnLastWindowClosed(const Napi::CallbackInfo& info); Napi::Value quitOnLastWindowClosed(const Napi::CallbackInfo& info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; namespace StaticQApplicationWrapMethods { diff --git a/src/cpp/include/nodegui/QtGui/QClipboard/qclipboard_wrap.h b/src/cpp/include/nodegui/QtGui/QClipboard/qclipboard_wrap.h index 4ac34a537..edf48c685 100644 --- a/src/cpp/include/nodegui/QtGui/QClipboard/qclipboard_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QClipboard/qclipboard_wrap.h @@ -19,4 +19,6 @@ class QClipboardWrap : public Napi::ObjectWrap { Napi::Value clear(const Napi::CallbackInfo& info); Napi::Value setText(const Napi::CallbackInfo& info); Napi::Value text(const Napi::CallbackInfo& info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; diff --git a/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h b/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h index 8a8842b12..06c28666e 100644 --- a/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QCursor/qcursor_wrap.h @@ -20,4 +20,6 @@ class QCursorWrap : public Napi::ObjectWrap { // Wrapped methods Napi::Value pos(const Napi::CallbackInfo& info); Napi::Value setPos(const Napi::CallbackInfo& info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; diff --git a/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h b/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h index bbc07e753..240ad06f5 100644 --- a/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h @@ -5,6 +5,8 @@ #include +#include "core/Component/component_macro.h" + class QKeyEventWrap : public Napi::ObjectWrap { private: QKeyEvent* instance; @@ -18,5 +20,6 @@ class QKeyEventWrap : public Napi::ObjectWrap { static Napi::FunctionReference constructor; // wrapped methods Napi::Value text(const Napi::CallbackInfo& info); - // Napi::Value setFlexNode(const Napi::CallbackInfo& info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; \ No newline at end of file diff --git a/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h b/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h index 4f1f40016..6664bed77 100644 --- a/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QIcon/qicon_wrap.h @@ -21,4 +21,6 @@ class QIconWrap : public Napi::ObjectWrap { Napi::Value pixmap(const Napi::CallbackInfo& info); Napi::Value isMask(const Napi::CallbackInfo& info); Napi::Value setIsMask(const Napi::CallbackInfo& info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; diff --git a/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h b/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h index 1d9b7a8c4..9dcf08eb4 100644 --- a/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QKeySequence/qkeysequence_wrap.h @@ -19,4 +19,6 @@ class QKeySequenceWrap : public Napi::ObjectWrap { QKeySequence *getInternalInstance(); // Wrapped methods Napi::Value count(const Napi::CallbackInfo &info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; diff --git a/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h b/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h index 3d47ce18f..c2a45c548 100644 --- a/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QPixmap/qpixmap_wrap.h @@ -21,4 +21,6 @@ class QPixmapWrap : public Napi::ObjectWrap { Napi::Value load(const Napi::CallbackInfo& info); Napi::Value save(const Napi::CallbackInfo& info); Napi::Value scaled(const Napi::CallbackInfo& info); + + COMPONENT_WRAPPED_METHODS_DECLARATION }; diff --git a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h index ace071f60..39aedfca8 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_macro.h @@ -2,7 +2,7 @@ #include -#include "core/Component/component_macro.h" +#include "QtCore/QObject/qobject_macro.h" /* This macro adds common QLayout exported methods @@ -12,6 +12,7 @@ #ifndef QLAYOUT_WRAPPED_METHODS_DECLARATION #define QLAYOUT_WRAPPED_METHODS_DECLARATION \ + COMPONENT_WRAPPED_METHODS_DECLARATION \ \ Napi::Value activate(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ diff --git a/src/cpp/include/nodegui/core/Component/component_macro.h b/src/cpp/include/nodegui/core/Component/component_macro.h index 7da3d4efb..b57edc1d2 100644 --- a/src/cpp/include/nodegui/core/Component/component_macro.h +++ b/src/cpp/include/nodegui/core/Component/component_macro.h @@ -1,7 +1,14 @@ +#pragma once + #ifndef COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE #define COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE \ \ InstanceValue("type", Napi::String::New(env, "native")), +#endif -#endif // COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE +#ifndef COMPONENT_WRAPPED_METHODS_DECLARATION +#define COMPONENT_WRAPPED_METHODS_DECLARATION \ + public: \ + void* rawData = nullptr; +#endif \ No newline at end of file diff --git a/src/cpp/include/nodegui/core/Component/component_wrap.h b/src/cpp/include/nodegui/core/Component/component_wrap.h new file mode 100644 index 000000000..ef6e4b3ae --- /dev/null +++ b/src/cpp/include/nodegui/core/Component/component_wrap.h @@ -0,0 +1,16 @@ +/* + This wrapper can be used to get the value of the actual instance inside a + wrapper for any component exported + as long as the component wrapper has this macro + COMPONENT_WRAPPED_METHODS_DECLARATION and components this->rawData has been + assigned in the constructor +*/ +#pragma once + +#include + +#include "component_macro.h" + +class ComponentWrap : public Napi::ObjectWrap { + COMPONENT_WRAPPED_METHODS_DECLARATION +}; diff --git a/src/cpp/include/nodegui/core/Events/eventwidget_macro.h b/src/cpp/include/nodegui/core/Events/eventwidget_macro.h index 2481ab328..9b2ae11a7 100644 --- a/src/cpp/include/nodegui/core/Events/eventwidget_macro.h +++ b/src/cpp/include/nodegui/core/Events/eventwidget_macro.h @@ -2,6 +2,7 @@ #include +#include "core/Component/component_macro.h" #include "eventwidget.h" /* @@ -13,7 +14,7 @@ #ifndef EVENTWIDGET_WRAPPED_METHODS_DECLARATION #define EVENTWIDGET_WRAPPED_METHODS_DECLARATION \ - \ + COMPONENT_WRAPPED_METHODS_DECLARATION \ Napi::Value initNodeEventEmitter(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ this->instance->emitOnNode = \ @@ -39,7 +40,7 @@ #ifndef EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE #define EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ - \ + COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE \ InstanceMethod("initNodeEventEmitter", \ &WidgetWrapName::initNodeEventEmitter), \ InstanceMethod("subscribeToQtEvent", \ diff --git a/src/cpp/lib/Extras/Utils/nutils.cpp b/src/cpp/lib/Extras/Utils/nutils.cpp index 81f787b23..a17ee641c 100644 --- a/src/cpp/lib/Extras/Utils/nutils.cpp +++ b/src/cpp/lib/Extras/Utils/nutils.cpp @@ -1,9 +1,12 @@ #include "Extras/Utils/nutils.h" #include +#include #include #include +#include "core/Component/component_wrap.h" + YGSize extrautils::measureQtWidget(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) { @@ -37,6 +40,14 @@ bool extrautils::isNapiValueInt(Napi::Env& env, Napi::Value& num) { .Value(); } +std::string extrautils::getNapiObjectClassName(Napi::Object& object) { + return object.Get("constructor") + .As() + .Get("name") + .As() + .Utf8Value(); +} + QVariant* extrautils::convertToQVariant(Napi::Env& env, Napi::Value& value) { // Warning: Make sure you delete the QVariant fron this function upon use. if (value.IsBoolean()) { @@ -62,8 +73,12 @@ QVariant* extrautils::convertToQVariant(Napi::Env& env, Napi::Value& value) { // TODO: fix this return new QVariant(); } else if (value.IsObject()) { - // TODO: fix this - return new QVariant(); + Napi::Object object = value.As(); + std::string className = getNapiObjectClassName(object); + int typeId = QMetaType::type(className.c_str()); + ComponentWrap* componentWrap = + Napi::ObjectWrap::Unwrap(object); + return new QVariant(typeId, componentWrap->rawData); } else if (value.IsFunction()) { return new QVariant(); } else if (value.IsPromise()) { diff --git a/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp b/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp index a91825d86..ee8b886c2 100644 --- a/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp +++ b/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp @@ -37,4 +37,5 @@ QObjectWrap::QObjectWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } diff --git a/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp b/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp index 65b07c05c..4ea0360e0 100644 --- a/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp +++ b/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp @@ -2,7 +2,6 @@ #include "Extras/Utils/nutils.h" #include "QtGui/QClipboard/qclipboard_wrap.h" -#include "core/Component/component_macro.h" Napi::FunctionReference QApplicationWrap::constructor; int QApplicationWrap::argc = 0; @@ -42,6 +41,7 @@ QApplicationWrap::QApplicationWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QApplicationWrap::~QApplicationWrap() { if (this->_wasManuallyCreated) { diff --git a/src/cpp/lib/QtGui/QClipboard/qclipboard_wrap.cpp b/src/cpp/lib/QtGui/QClipboard/qclipboard_wrap.cpp index 307b05e00..15a66971f 100644 --- a/src/cpp/lib/QtGui/QClipboard/qclipboard_wrap.cpp +++ b/src/cpp/lib/QtGui/QClipboard/qclipboard_wrap.cpp @@ -29,6 +29,7 @@ QClipboardWrap::QClipboardWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Incorrect initialization of QClipboardWrap") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QClipboard* QClipboardWrap::getInternalInstance() { return this->instance; } diff --git a/src/cpp/lib/QtGui/QCursor/qcursor_wrap.cpp b/src/cpp/lib/QtGui/QCursor/qcursor_wrap.cpp index 410663fa4..6913e113f 100644 --- a/src/cpp/lib/QtGui/QCursor/qcursor_wrap.cpp +++ b/src/cpp/lib/QtGui/QCursor/qcursor_wrap.cpp @@ -33,6 +33,7 @@ QCursorWrap::QCursorWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QCursorWrap::~QCursorWrap() { this->instance.reset(); } diff --git a/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp b/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp index 31ba0086e..b63682971 100644 --- a/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp +++ b/src/cpp/lib/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp @@ -3,8 +3,6 @@ #include #include "Extras/Utils/nutils.h" -#include "core/Component/component_macro.h" -#include "deps/spdlog/spdlog.h" Napi::FunctionReference QKeyEventWrap::constructor; @@ -34,6 +32,7 @@ QKeyEventWrap::QKeyEventWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QKeyEventWrap::~QKeyEventWrap() { diff --git a/src/cpp/lib/QtGui/QIcon/qicon_wrap.cpp b/src/cpp/lib/QtGui/QIcon/qicon_wrap.cpp index 4556500fe..ed825f647 100644 --- a/src/cpp/lib/QtGui/QIcon/qicon_wrap.cpp +++ b/src/cpp/lib/QtGui/QIcon/qicon_wrap.cpp @@ -34,6 +34,7 @@ QIconWrap::QIconWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QIconWrap::~QIconWrap() { this->instance.reset(); } diff --git a/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp b/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp index 79ca2ff0f..bc4780504 100644 --- a/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp +++ b/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp @@ -32,6 +32,7 @@ QKeySequenceWrap::QKeySequenceWrap(const Napi::CallbackInfo &info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QKeySequenceWrap::~QKeySequenceWrap() { this->instance.reset(); } diff --git a/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp b/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp index 81951a606..c54ccad88 100644 --- a/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp +++ b/src/cpp/lib/QtGui/QPixmap/qpixmap_wrap.cpp @@ -38,6 +38,7 @@ QPixmapWrap::QPixmapWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QPixmapWrap::~QPixmapWrap() { this->instance.reset(); } diff --git a/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp b/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp index e629bffc1..a6b5457fd 100644 --- a/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp @@ -26,8 +26,7 @@ Napi::Object QActionWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("setChecked", &QActionWrap::setChecked), InstanceMethod("isSeparator", &QActionWrap::isSeparator), InstanceMethod("setSeparator", &QActionWrap::setSeparator), - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE - EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QActionWrap)}); + EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QActionWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; @@ -51,6 +50,7 @@ QActionWrap::QActionWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QActionWrap::~QActionWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp b/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp index 9d2ae714e..4b1cdc9df 100644 --- a/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp @@ -39,6 +39,7 @@ QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp b/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp index c4adac549..113b4c5e5 100644 --- a/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp @@ -43,6 +43,7 @@ QDialWrap::QDialWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its own size. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp b/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp index 5d246d62a..341563456 100644 --- a/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp @@ -37,6 +37,7 @@ QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } Napi::Value QGridLayoutWrap::addWidget(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp b/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp index 014fe39c5..f6ae331b3 100644 --- a/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp @@ -45,6 +45,7 @@ QLabelWrap::QLabelWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp b/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp index 1630563e9..fdcd0cd21 100644 --- a/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp @@ -42,6 +42,7 @@ QLineEditWrap::QLineEditWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp b/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp index 6c5efc646..07e315e60 100644 --- a/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp @@ -46,6 +46,7 @@ QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp b/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp index 32c775472..031f7d467 100644 --- a/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp @@ -40,6 +40,7 @@ QMenuWrap::QMenuWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp b/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp index 2981d8522..a5628730d 100644 --- a/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp @@ -45,6 +45,7 @@ QMenuBarWrap::QMenuBarWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp b/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp index 1628c20ab..b8eeabfc7 100644 --- a/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp @@ -52,6 +52,7 @@ QPlainTextEditWrap::QPlainTextEditWrap(const Napi::CallbackInfo &info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp b/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp index 837c0f948..9178a4e8d 100644 --- a/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp @@ -42,6 +42,7 @@ QProgressBarWrap::QProgressBarWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its own size. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp b/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp index 6250bace0..ef3b10560 100644 --- a/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp @@ -38,6 +38,7 @@ QRadioButtonWrap::QRadioButtonWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its own size. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp b/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp index 601b29b31..dcc42e3c4 100644 --- a/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp @@ -40,7 +40,7 @@ QScrollAreaWrap::QScrollAreaWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } - this->instance->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its own size. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp b/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp index bd9bbf00b..567a907ca 100644 --- a/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp @@ -18,8 +18,7 @@ Napi::Object QShortcutWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("setAutoRepeat", &QShortcutWrap::setAutoRepeat), InstanceMethod("setKey", &QShortcutWrap::setKey), InstanceMethod("setContext", &QShortcutWrap::setContext), - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE - EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QShortcutWrap)}); + EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QShortcutWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; @@ -41,6 +40,7 @@ QShortcutWrap::QShortcutWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QShortcutWrap::~QShortcutWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp b/src/cpp/lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp index cf733717e..8f0d90159 100644 --- a/src/cpp/lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp @@ -45,6 +45,7 @@ QSpinBoxWrap::QSpinBoxWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp b/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp index 12ca63ac1..b4aa7648d 100644 --- a/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp @@ -20,9 +20,7 @@ Napi::Object QSystemTrayIconWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("isVisible", &QSystemTrayIconWrap::isVisible), InstanceMethod("setToolTip", &QSystemTrayIconWrap::setToolTip), InstanceMethod("setContextMenu", &QSystemTrayIconWrap::setContextMenu), - - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE - EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QSystemTrayIconWrap)}); + EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QSystemTrayIconWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); return exports; @@ -50,6 +48,7 @@ QSystemTrayIconWrap::QSystemTrayIconWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } QSystemTrayIconWrap::~QSystemTrayIconWrap() { diff --git a/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp index c14a464d1..ade086838 100644 --- a/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp @@ -47,6 +47,7 @@ QTabWidgetWrap::QTabWidgetWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); // Adds measure function on yoga node so that widget size is calculated based // on its text also. YGNodeSetMeasureFunc(this->instance->getFlexNode(), diff --git a/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp index 7765b306a..5be778a33 100644 --- a/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp @@ -39,4 +39,5 @@ QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } diff --git a/src/cpp/lib/core/FlexLayout/flexlayout_wrap.cpp b/src/cpp/lib/core/FlexLayout/flexlayout_wrap.cpp index 5102899bc..2e9df2c01 100644 --- a/src/cpp/lib/core/FlexLayout/flexlayout_wrap.cpp +++ b/src/cpp/lib/core/FlexLayout/flexlayout_wrap.cpp @@ -41,6 +41,7 @@ FlexLayoutWrap::FlexLayoutWrap(const Napi::CallbackInfo& info) Napi::TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); } + this->rawData = this->getInternalInstance(); } Napi::Value FlexLayoutWrap::addWidget(const Napi::CallbackInfo& info) { diff --git a/src/demo.ts b/src/demo.ts index 244098799..460d3bca2 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -3,6 +3,7 @@ import { QWidget } from './lib/QtWidgets/QWidget'; import { FlexLayout } from './lib/core/FlexLayout'; import { QLabel } from './lib/QtWidgets/QLabel'; import { AlignmentFlag } from './lib/QtEnums'; +import { QPixmap } from './lib/QtGui/QPixmap'; const win = new QMainWindow(); const view = new QWidget(); @@ -23,6 +24,8 @@ world.setStyleSheet(` border: 1px solid blue; qproperty-alignment: AlignCenter; `); +const pixmap = new QPixmap('/Users/atulr/Project/nodegui/nodegui/extras/assets/kitchen.png'); +hello.setProperty('pixmap', pixmap); hello.setProperty('alignment', AlignmentFlag.AlignCenter); diff --git a/src/lib/QtCore/QObject.ts b/src/lib/QtCore/QObject.ts index b44c6fccc..16bebb0aa 100644 --- a/src/lib/QtCore/QObject.ts +++ b/src/lib/QtCore/QObject.ts @@ -8,7 +8,8 @@ export abstract class NodeObject extends EventWidget { return this.native.inherits(className); } setProperty(name: string, value: any): boolean { - return this.native.setProperty(name, value); + const finalValue = value.native || value; + return this.native.setProperty(name, finalValue); } setObjectName(objectName: string): void { this.native.setObjectName(objectName);