diff --git a/src/cpp/include/nodegui/Extras/Utils/nutils.h b/src/cpp/include/nodegui/Extras/Utils/nutils.h index 5142443ba..e7b54d11e 100644 --- a/src/cpp/include/nodegui/Extras/Utils/nutils.h +++ b/src/cpp/include/nodegui/Extras/Utils/nutils.h @@ -13,8 +13,7 @@ namespace extrautils { DLL_EXPORT QVariant* convertToQVariant(Napi::Env& env, Napi::Value& value); DLL_EXPORT bool isNapiValueInt(Napi::Env& env, Napi::Value& num); DLL_EXPORT std::string getNapiObjectClassName(Napi::Object& object); -DLL_EXPORT void* configureQWidget(QWidget* widget, YGNodeRef node, - bool isLeafNode = false); +DLL_EXPORT void* configureQWidget(QWidget* widget, bool isLeafNode = false); DLL_EXPORT void* configureQObject(QObject* object); DLL_EXPORT void* configureComponent(void* component); DLL_EXPORT uint64_t hashPointerTo53bit(const void* input); diff --git a/src/cpp/include/nodegui/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.h b/src/cpp/include/nodegui/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.h index 3f4ac5101..3bf7883ae 100644 --- a/src/cpp/include/nodegui/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.h @@ -14,7 +14,6 @@ class DLL_EXPORT QItemSelectionModelWrap private: QPointer instance; - bool disableDeletion; public: static Napi::Object init(Napi::Env env, Napi::Object exports); diff --git a/src/cpp/include/nodegui/QtCore/QMimeData/qmimedata_wrap.h b/src/cpp/include/nodegui/QtCore/QMimeData/qmimedata_wrap.h index e87b1d718..ca42191e0 100644 --- a/src/cpp/include/nodegui/QtCore/QMimeData/qmimedata_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QMimeData/qmimedata_wrap.h @@ -5,13 +5,13 @@ #include #include "Extras/Export/export.h" -#include "core/Component/component_macro.h" +#include "QtCore/QObject/qobject_macro.h" class DLL_EXPORT QMimeDataWrap : public Napi::ObjectWrap { - COMPONENT_WRAPPED_METHODS_DECLARATION + QOBJECT_WRAPPED_METHODS_DECLARATION private: - std::unique_ptr instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); diff --git a/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h b/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h index eaf50c5b2..0aca30b2e 100644 --- a/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h +++ b/src/cpp/include/nodegui/QtCore/QObject/qobject_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QObjectWrap : public Napi::ObjectWrap { QOBJECT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QObjectWrap(const Napi::CallbackInfo& info); ~QObjectWrap(); - NObject* getInternalInstance(); + QObject* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; static Napi::Object wrapFunc(Napi::Env env, QObject* qobject); diff --git a/src/cpp/include/nodegui/QtGui/QDrag/qdrag_wrap.h b/src/cpp/include/nodegui/QtGui/QDrag/qdrag_wrap.h index da688bd08..39d17f2ae 100644 --- a/src/cpp/include/nodegui/QtGui/QDrag/qdrag_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QDrag/qdrag_wrap.h @@ -22,13 +22,13 @@ class DLL_EXPORT QDragWrap : public Napi::ObjectWrap { // except that it is automatically cleared when the referenced object is // destroyed (unlike normal C++ pointers, which become "dangling pointers" in // such cases). T must be a subclass of QObject. - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QDragWrap(const Napi::CallbackInfo& info); ~QDragWrap(); - NDrag* getInternalInstance(); + QDrag* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; diff --git a/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h b/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h index 64d71e353..9e6781716 100644 --- a/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QAbstractItemView/qabstractitemview_macro.h @@ -145,9 +145,7 @@ Napi::Value selectionModel(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ QItemSelectionModel* model = this->instance->selectionModel(); \ - auto modelExt = Napi::External::New(env, model); \ - auto instance = QItemSelectionModelWrap::constructor.New({modelExt}); \ - return instance; \ + return WrapperCache::instance.getWrapper(env, model); \ } \ Napi::Value isPersistentEditorOpen(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ diff --git a/src/cpp/include/nodegui/QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h b/src/cpp/include/nodegui/QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h index 9bf5d3309..9bb8a13e8 100644 --- a/src/cpp/include/nodegui/QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h @@ -58,9 +58,7 @@ Napi::Value viewport(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ QWidget* viewPort = this->instance->viewport(); \ - NWidget* nviewPort = reinterpret_cast(viewPort); \ - auto instance = QWidgetWrap::constructor.New( \ - {Napi::External::New(env, nviewPort)}); \ + auto instance = WrapperCache::instance.getWrapper(env, viewPort); \ return instance; \ } diff --git a/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h b/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h index d4d118b77..d0b382a11 100644 --- a/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QAction/qaction_wrap.h @@ -11,14 +11,13 @@ class DLL_EXPORT QActionWrap : public Napi::ObjectWrap { QOBJECT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QActionWrap(const Napi::CallbackInfo& info); ~QActionWrap(); - NAction* getInternalInstance(); + QAction* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h index 09a6646f7..290b02108 100644 --- a/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QBoxLayout/qboxlayout_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QBoxLayoutWrap : public Napi::ObjectWrap { QLAYOUT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QBoxLayoutWrap(const Napi::CallbackInfo& info); ~QBoxLayoutWrap(); - NBoxLayout* getInternalInstance(); + QBoxLayout* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QButtonGroup/qbuttongroup_wrap.h b/src/cpp/include/nodegui/QtWidgets/QButtonGroup/qbuttongroup_wrap.h index 1f79b7722..5100dff6e 100644 --- a/src/cpp/include/nodegui/QtWidgets/QButtonGroup/qbuttongroup_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QButtonGroup/qbuttongroup_wrap.h @@ -9,13 +9,13 @@ #include "nbuttongroup.hpp" class DLL_EXPORT QButtonGroupWrap : public Napi::ObjectWrap { private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QButtonGroupWrap(const Napi::CallbackInfo& info); ~QButtonGroupWrap(); - NButtonGroup* getInternalInstance(); + QButtonGroup* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.h index 30cdd66cd..cf005eaac 100644 --- a/src/cpp/include/nodegui/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QCalendarWidgetWrap : public Napi::ObjectWrap { private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QCalendarWidgetWrap(const Napi::CallbackInfo &info); ~QCalendarWidgetWrap(); - NCalendarWidget *getInternalInstance(); + QCalendarWidget *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h index 67809fe2d..b15ae5f3a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QCheckBox/qcheckbox_wrap.h @@ -12,14 +12,13 @@ class DLL_EXPORT QCheckBoxWrap : public Napi::ObjectWrap { QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QCheckBoxWrap(const Napi::CallbackInfo& info); ~QCheckBoxWrap(); - NCheckBox* getInternalInstance(); + QCheckBox* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QColorDialog/qcolordialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QColorDialog/qcolordialog_wrap.h index 25a6479c4..968e5cca3 100644 --- a/src/cpp/include/nodegui/QtWidgets/QColorDialog/qcolordialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QColorDialog/qcolordialog_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QColorDialogWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QColorDialogWrap(const Napi::CallbackInfo& info); ~QColorDialogWrap(); - NColorDialog* getInternalInstance(); + QColorDialog* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h index c739d5046..e5ed8407a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QComboBox/qcombobox_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QComboBoxWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QComboBoxWrap(const Napi::CallbackInfo& info); ~QComboBoxWrap(); - NComboBox* getInternalInstance(); + QComboBox* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QDateEdit/qdateedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDateEdit/qdateedit_wrap.h index 37d09271e..9498d049f 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDateEdit/qdateedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QDateEdit/qdateedit_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QDateEditWrap : public Napi::ObjectWrap { QDATETIMEEDIT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QDateEditWrap(const Napi::CallbackInfo &info); ~QDateEditWrap(); - NDateEdit *getInternalInstance(); + QDateEdit *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.h index 7f6ffcc83..c994acdf7 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QDateTimeEditWrap : public Napi::ObjectWrap { QDATETIMEEDIT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QDateTimeEditWrap(const Napi::CallbackInfo &info); ~QDateTimeEditWrap(); - NDateTimeEdit *getInternalInstance(); + QDateTimeEdit *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h index f6fa9c4e6..d7e010fb2 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QDial/qdial_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QDialWrap : public Napi::ObjectWrap { QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QDialWrap(const Napi::CallbackInfo& info); ~QDialWrap(); - NDial* getInternalInstance(); + QDial* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QDialog/qdialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDialog/qdialog_wrap.h index 374ed1d96..5a144e8df 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDialog/qdialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QDialog/qdialog_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QDialogWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QDialogWrap(const Napi::CallbackInfo& info); ~QDialogWrap(); - NDialog* getInternalInstance(); + QDialog* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.h index 435aa3a2d..6d358bec3 100644 --- a/src/cpp/include/nodegui/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QDoubleSpinBoxWrap : public Napi::ObjectWrap { QABSTRACTSPINBOX_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QDoubleSpinBoxWrap(const Napi::CallbackInfo& info); ~QDoubleSpinBoxWrap(); - NDoubleSpinBox* getInternalInstance(); + QDoubleSpinBox* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QErrorMessage/qerrormessage_wrap.h b/src/cpp/include/nodegui/QtWidgets/QErrorMessage/qerrormessage_wrap.h index c9fa3981c..a5d984e47 100644 --- a/src/cpp/include/nodegui/QtWidgets/QErrorMessage/qerrormessage_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QErrorMessage/qerrormessage_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QErrorMessageWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QErrorMessageWrap(const Napi::CallbackInfo& info); ~QErrorMessageWrap(); - NErrorMessage* getInternalInstance(); + QErrorMessage* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h index 85ad21697..9f90ef19a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QFileDialog/qfiledialog_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QFileDialogWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QFileDialogWrap(const Napi::CallbackInfo& info); ~QFileDialogWrap(); - NFileDialog* getInternalInstance(); + QFileDialog* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QFontDialog/qfontdialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QFontDialog/qfontdialog_wrap.h index d6282f27f..c08b8e1ab 100644 --- a/src/cpp/include/nodegui/QtWidgets/QFontDialog/qfontdialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QFontDialog/qfontdialog_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QFontDialogWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QFontDialogWrap(const Napi::CallbackInfo& info); ~QFontDialogWrap(); - NFontDialog* getInternalInstance(); + QFontDialog* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QFrame/qframe_wrap.h b/src/cpp/include/nodegui/QtWidgets/QFrame/qframe_wrap.h index cdf8a05ae..c0b705d2d 100644 --- a/src/cpp/include/nodegui/QtWidgets/QFrame/qframe_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QFrame/qframe_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QFrameWrap : public Napi::ObjectWrap { QFRAME_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QFrameWrap(const Napi::CallbackInfo& info); ~QFrameWrap(); - NFrame* getInternalInstance(); + QFrame* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h index 483526296..8062ef33c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h @@ -5,6 +5,7 @@ #include #include "Extras/Export/export.h" +#include "Extras/Utils/nutils.h" #include "QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h" #include "ngraphicsblureffect.hpp" @@ -12,13 +13,13 @@ class DLL_EXPORT QGraphicsBlurEffectWrap : public Napi::ObjectWrap { QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QGraphicsBlurEffectWrap(const Napi::CallbackInfo& info); ~QGraphicsBlurEffectWrap(); - NGraphicsBlurEffect* getInternalInstance(); + QGraphicsBlurEffect* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h index 0eee0eaee..d6e3a3050 100644 --- a/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QGraphicsDropShadowEffectWrap : public Napi::ObjectWrap { QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QGraphicsDropShadowEffectWrap(const Napi::CallbackInfo& info); ~QGraphicsDropShadowEffectWrap(); - NGraphicsDropShadowEffect* getInternalInstance(); + QGraphicsDropShadowEffect* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h index 7d6df8112..d4e8f4cc6 100644 --- a/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QGridLayout/qgridlayout_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QGridLayoutWrap : public Napi::ObjectWrap { QLAYOUT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QGridLayoutWrap(const Napi::CallbackInfo& info); ~QGridLayoutWrap(); - NGridLayout* getInternalInstance(); + QGridLayout* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h index e0aaffff2..a2521b9a1 100644 --- a/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QGroupBox/qgroupbox_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QGroupBoxWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QGroupBoxWrap(const Napi::CallbackInfo& info); ~QGroupBoxWrap(); - NGroupBox* getInternalInstance(); + QGroupBox* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h b/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h index 2f21eaf24..f6b9281cf 100644 --- a/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h @@ -45,7 +45,6 @@ class DLL_EXPORT QHeaderViewWrap : public Napi::ObjectWrap { private: QPointer instance; - bool disableDeletion; public: static Napi::Object init(Napi::Env env, Napi::Object exports); diff --git a/src/cpp/include/nodegui/QtWidgets/QInputDialog/qinputdialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QInputDialog/qinputdialog_wrap.h index 71079fea5..20787251d 100644 --- a/src/cpp/include/nodegui/QtWidgets/QInputDialog/qinputdialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QInputDialog/qinputdialog_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QInputDialogWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QInputDialogWrap(const Napi::CallbackInfo& info); ~QInputDialogWrap(); - NInputDialog* getInternalInstance(); + QInputDialog* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // members diff --git a/src/cpp/include/nodegui/QtWidgets/QLCDNumber/qlcdnumber_wrap.h b/src/cpp/include/nodegui/QtWidgets/QLCDNumber/qlcdnumber_wrap.h index 218e2a1bb..0fb12240c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLCDNumber/qlcdnumber_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QLCDNumber/qlcdnumber_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QLCDNumberWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QLCDNumberWrap(const Napi::CallbackInfo& info); ~QLCDNumberWrap(); - NLCDNumber* getInternalInstance(); + QLCDNumber* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QLabel/qlabel_wrap.h b/src/cpp/include/nodegui/QtWidgets/QLabel/qlabel_wrap.h index 5d4e1d89a..c7e6529c5 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLabel/qlabel_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QLabel/qlabel_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QLabelWrap : public Napi::ObjectWrap { QFRAME_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QLabelWrap(const Napi::CallbackInfo& info); ~QLabelWrap(); - NLabel* getInternalInstance(); + QLabel* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h index 3d3e06de0..dffbb21df 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QLayout/qlayout_wrap.h @@ -13,13 +13,13 @@ class DLL_EXPORT QLayoutWrap : public Napi::ObjectWrap { QLAYOUT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: - static void init(Napi::Env env); + static void init(Napi::Env env, Napi::Object exports); QLayoutWrap(const Napi::CallbackInfo& info); ~QLayoutWrap(); - NLayout* getInternalInstance(); + QLayout* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h index d95e141bf..1d7e43189 100644 --- a/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QLineEdit/qlineedit_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QLineEditWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QLineEditWrap(const Napi::CallbackInfo& info); ~QLineEditWrap(); - NLineEdit* getInternalInstance(); + QLineEdit* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QListView/qlistview_wrap.h b/src/cpp/include/nodegui/QtWidgets/QListView/qlistview_wrap.h index ba0d07f58..6b3e5df27 100644 --- a/src/cpp/include/nodegui/QtWidgets/QListView/qlistview_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QListView/qlistview_wrap.h @@ -11,14 +11,13 @@ class DLL_EXPORT QListViewWrap : public Napi::ObjectWrap { QLISTVIEW_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QListViewWrap(const Napi::CallbackInfo& info); ~QListViewWrap(); - NListView* getInternalInstance(); + QListView* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QListWidget/qlistwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QListWidget/qlistwidget_wrap.h index 2dd7fe50e..684ded35e 100644 --- a/src/cpp/include/nodegui/QtWidgets/QListWidget/qlistwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QListWidget/qlistwidget_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QListWidgetWrap : public Napi::ObjectWrap { QLISTVIEW_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QListWidgetWrap(const Napi::CallbackInfo& info); ~QListWidgetWrap(); - NListWidget* getInternalInstance(); + QListWidget* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h index 056c707f9..2fbdb6eee 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMainWindow/qmainwindow_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QMainWindowWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QMainWindowWrap(const Napi::CallbackInfo& info); ~QMainWindowWrap(); - NMainWindow* getInternalInstance(); + QMainWindow* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp b/src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp index 0e70aa4df..6fca47757 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp +++ b/src/cpp/include/nodegui/QtWidgets/QMenu/nmenu.hpp @@ -17,10 +17,8 @@ class DLL_EXPORT NMenu : public QMenu, public NodeWidget { QObject::connect(this, &QMenu::triggered, [=](QAction* action) { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); - auto actionInstance = QActionWrap::constructor.New( - {Napi::External::New(env, action)}); - this->emitOnNode.Call( - {Napi::String::New(env, "triggered"), actionInstance}); + auto instance = WrapperCache::instance.getWrapper(env, action); + this->emitOnNode.Call({Napi::String::New(env, "triggered"), instance}); }); } }; diff --git a/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h index f45b158f5..88b599d68 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMenu/qmenu_wrap.h @@ -10,13 +10,13 @@ class DLL_EXPORT QMenuWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QMenuWrap(const Napi::CallbackInfo& info); ~QMenuWrap(); - NMenu* getInternalInstance(); + QMenu* getInternalInstance(); static Napi::FunctionReference constructor; // wrapped methods Napi::Value clear(const Napi::CallbackInfo& info); diff --git a/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h index dd04274ab..6ec6722e8 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMenuBar/qmenubar_wrap.h @@ -10,13 +10,13 @@ class DLL_EXPORT QMenuBarWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QMenuBarWrap(const Napi::CallbackInfo& info); ~QMenuBarWrap(); - NMenuBar* getInternalInstance(); + QMenuBar* getInternalInstance(); static Napi::FunctionReference constructor; // wrapped methods Napi::Value addMenu(const Napi::CallbackInfo& info); diff --git a/src/cpp/include/nodegui/QtWidgets/QMessageBox/qmessagebox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QMessageBox/qmessagebox_wrap.h index c21c7e883..6e7fc49c4 100644 --- a/src/cpp/include/nodegui/QtWidgets/QMessageBox/qmessagebox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QMessageBox/qmessagebox_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QMessageBoxWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QMessageBoxWrap(const Napi::CallbackInfo& info); ~QMessageBoxWrap(); - NMessageBox* getInternalInstance(); + QMessageBox* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h index b3627711c..b8d55b151 100644 --- a/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.h @@ -13,13 +13,13 @@ class DLL_EXPORT QPlainTextEditWrap : public Napi::ObjectWrap { QABSTRACTSCROLLAREA_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QPlainTextEditWrap(const Napi::CallbackInfo &info); ~QPlainTextEditWrap(); - NPlainTextEdit *getInternalInstance(); + QPlainTextEdit *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h index e19f97171..43316e46d 100644 --- a/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QProgressBar/qprogressbar_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QProgressBarWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QProgressBarWrap(const Napi::CallbackInfo& info); ~QProgressBarWrap(); - NProgressBar* getInternalInstance(); + QProgressBar* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QProgressDialog/qprogressdialog_wrap.h b/src/cpp/include/nodegui/QtWidgets/QProgressDialog/qprogressdialog_wrap.h index ca2e88153..73bcdcf9f 100644 --- a/src/cpp/include/nodegui/QtWidgets/QProgressDialog/qprogressdialog_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QProgressDialog/qprogressdialog_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QProgressDialogWrap : public Napi::ObjectWrap { QDIALOG_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QProgressDialogWrap(const Napi::CallbackInfo& info); ~QProgressDialogWrap(); - NProgressDialog* getInternalInstance(); + QProgressDialog* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h b/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h index 92f4bd660..824bfabd9 100644 --- a/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QPushButton/qpushbutton_wrap.h @@ -12,14 +12,13 @@ class DLL_EXPORT QPushButtonWrap : public Napi::ObjectWrap { QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QPushButtonWrap(const Napi::CallbackInfo& info); ~QPushButtonWrap(); - NPushButton* getInternalInstance(); + QPushButton* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h b/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h index bd2fc0be0..d8dd3fc32 100644 --- a/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QRadioButton/qradiobutton_wrap.h @@ -13,14 +13,13 @@ class DLL_EXPORT QRadioButtonWrap : public Napi::ObjectWrap { QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QRadioButtonWrap(const Napi::CallbackInfo& info); ~QRadioButtonWrap(); - NRadioButton* getInternalInstance(); + QRadioButton* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h b/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h index 2e6862503..3bca82c79 100644 --- a/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QScrollArea/qscrollarea_wrap.h @@ -11,20 +11,20 @@ class DLL_EXPORT QScrollAreaWrap : public Napi::ObjectWrap { QABSTRACTSCROLLAREA_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - YGNodeRef scrollNode; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QScrollAreaWrap(const Napi::CallbackInfo& info); ~QScrollAreaWrap(); - NScrollArea* getInternalInstance(); + QScrollArea* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods Napi::Value ensureVisible(const Napi::CallbackInfo& info); Napi::Value ensureWidgetVisible(const Napi::CallbackInfo& info); Napi::Value setWidget(const Napi::CallbackInfo& info); + Napi::Value widget(const Napi::CallbackInfo& info); Napi::Value takeWidget(const Napi::CallbackInfo& info); Napi::Value setViewportMargins(const Napi::CallbackInfo& info); Napi::Value viewportMargins(const Napi::CallbackInfo& info); diff --git a/src/cpp/include/nodegui/QtWidgets/QScrollBar/qscrollbar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QScrollBar/qscrollbar_wrap.h index ffd8c9a1c..434356ca0 100644 --- a/src/cpp/include/nodegui/QtWidgets/QScrollBar/qscrollbar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QScrollBar/qscrollbar_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QScrollBarWrap : public Napi::ObjectWrap { QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QScrollBarWrap(const Napi::CallbackInfo& info); ~QScrollBarWrap(); - NScrollBar* getInternalInstance(); + QScrollBar* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QShortcut/qshortcut_wrap.h b/src/cpp/include/nodegui/QtWidgets/QShortcut/qshortcut_wrap.h index 052f962dc..1c7bf5667 100644 --- a/src/cpp/include/nodegui/QtWidgets/QShortcut/qshortcut_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QShortcut/qshortcut_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QShortcutWrap : public Napi::ObjectWrap { QOBJECT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QShortcutWrap(const Napi::CallbackInfo& info); ~QShortcutWrap(); - NShortcut* getInternalInstance(); + QShortcut* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QSlider/qslider_wrap.h b/src/cpp/include/nodegui/QtWidgets/QSlider/qslider_wrap.h index 653ec702c..7bd811ee7 100644 --- a/src/cpp/include/nodegui/QtWidgets/QSlider/qslider_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QSlider/qslider_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QSliderWrap : public Napi::ObjectWrap { QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QSliderWrap(const Napi::CallbackInfo& info); ~QSliderWrap(); - NSlider* getInternalInstance(); + QSlider* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h b/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h index e26389542..ca1cb169f 100644 --- a/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QSpinBox/qspinbox_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QSpinBoxWrap : public Napi::ObjectWrap { QABSTRACTSPINBOX_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QSpinBoxWrap(const Napi::CallbackInfo &info); ~QSpinBoxWrap(); - NSpinBox *getInternalInstance(); + QSpinBox *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QSplitter/qsplitter_wrap.h b/src/cpp/include/nodegui/QtWidgets/QSplitter/qsplitter_wrap.h index bae681e0a..aac552267 100644 --- a/src/cpp/include/nodegui/QtWidgets/QSplitter/qsplitter_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QSplitter/qsplitter_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QSplitterWrap : public Napi::ObjectWrap { QFRAME_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QSplitterWrap(const Napi::CallbackInfo& info); ~QSplitterWrap(); - NSplitter* getInternalInstance(); + QSplitter* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QStackedWidget/qstackedwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QStackedWidget/qstackedwidget_wrap.h index e29fed9d6..acfba76db 100644 --- a/src/cpp/include/nodegui/QtWidgets/QStackedWidget/qstackedwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QStackedWidget/qstackedwidget_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QStackedWidgetWrap : public Napi::ObjectWrap { QFRAME_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QStackedWidgetWrap(const Napi::CallbackInfo &info); ~QStackedWidgetWrap(); - NStackedWidget *getInternalInstance(); + QStackedWidget *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.h b/src/cpp/include/nodegui/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.h index f4bbc5508..4a979896e 100644 --- a/src/cpp/include/nodegui/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.h @@ -10,13 +10,13 @@ class DLL_EXPORT QStandardItemModelWrap : public Napi::ObjectWrap { private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QStandardItemModelWrap(const Napi::CallbackInfo& info); ~QStandardItemModelWrap(); - NStandardItemModel* getInternalInstance(); + QStandardItemModel* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QStatusBar/qstatusbar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QStatusBar/qstatusbar_wrap.h index eaa6a774e..f02414cbc 100644 --- a/src/cpp/include/nodegui/QtWidgets/QStatusBar/qstatusbar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QStatusBar/qstatusbar_wrap.h @@ -12,7 +12,7 @@ class DLL_EXPORT QStatusBarWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); @@ -22,7 +22,7 @@ class DLL_EXPORT QStatusBarWrap : public Napi::ObjectWrap { QStatusBarWrap(const Napi::CallbackInfo &info); ~QStatusBarWrap(); - NStatusBar *getInternalInstance(); + QStatusBar *getInternalInstance(); // Wrapped methods Napi::Value addPermanentWidget(const Napi::CallbackInfo &info); diff --git a/src/cpp/include/nodegui/QtWidgets/QSvgWidget/qsvgwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QSvgWidget/qsvgwidget_wrap.h index ebe731ae6..3897a1e2c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QSvgWidget/qsvgwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QSvgWidget/qsvgwidget_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QSvgWidgetWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QSvgWidgetWrap(const Napi::CallbackInfo& info); ~QSvgWidgetWrap(); - NSvgWidget* getInternalInstance(); + QSvgWidget* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h b/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h index 1fcdf9695..2549b928c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QSystemTrayIconWrap : public Napi::ObjectWrap { QOBJECT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QSystemTrayIconWrap(const Napi::CallbackInfo& info); ~QSystemTrayIconWrap(); - NSystemTrayIcon* getInternalInstance(); + QSystemTrayIcon* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTabBar/qtabbar_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTabBar/qtabbar_wrap.h index ff7bfcbf2..2c338e25d 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTabBar/qtabbar_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTabBar/qtabbar_wrap.h @@ -11,14 +11,13 @@ class DLL_EXPORT QTabBarWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTabBarWrap(const Napi::CallbackInfo& info); ~QTabBarWrap(); - NTabBar* getInternalInstance(); + QTabBar* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTabWidget/qtabwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTabWidget/qtabwidget_wrap.h index b25b23550..f2ef97a9a 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTabWidget/qtabwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTabWidget/qtabwidget_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QTabWidgetWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTabWidgetWrap(const Napi::CallbackInfo &info); ~QTabWidgetWrap(); - NTabWidget *getInternalInstance(); + QTabWidget *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h b/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h index 70457e143..f5fd1a8be 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h @@ -181,15 +181,13 @@ Napi::Value horizontalHeader(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ auto header = this->instance->horizontalHeader(); \ - auto instance = QHeaderViewWrap::constructor.New( \ - {Napi::External::New(env, header)}); \ + auto instance = WrapperCache::instance.getWrapper(env, header); \ return instance; \ } \ Napi::Value verticalHeader(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ auto header = this->instance->verticalHeader(); \ - auto instance = QHeaderViewWrap::constructor.New( \ - {Napi::External::New(env, header)}); \ + auto instance = WrapperCache::instance.getWrapper(env, header); \ return instance; \ } diff --git a/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_wrap.h index 8d98a44bf..cef62d924 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_wrap.h @@ -11,14 +11,13 @@ class DLL_EXPORT QTableViewWrap : public Napi::ObjectWrap { QTABLEVIEW_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTableViewWrap(const Napi::CallbackInfo& info); ~QTableViewWrap(); - NTableView* getInternalInstance(); + QTableView* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h index 833fcd233..724e28c67 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTableWidget/qtablewidget_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QTableWidgetWrap : public Napi::ObjectWrap { QABSTRACTSCROLLAREA_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTableWidgetWrap(const Napi::CallbackInfo& info); ~QTableWidgetWrap(); - NTableWidget* getInternalInstance(); + QTableWidget* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTextBrowser/qtextbrowser_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTextBrowser/qtextbrowser_wrap.h index e72eabddf..33ad4494e 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTextBrowser/qtextbrowser_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTextBrowser/qtextbrowser_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QTextBrowserWrap : public Napi::ObjectWrap { QTEXTEDIT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTextBrowserWrap(const Napi::CallbackInfo& info); ~QTextBrowserWrap(); - NTextBrowser* getInternalInstance(); + QTextBrowser* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTextEdit/qtextedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTextEdit/qtextedit_wrap.h index a6173e4f6..68d4981a6 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTextEdit/qtextedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTextEdit/qtextedit_wrap.h @@ -11,13 +11,13 @@ class DLL_EXPORT QTextEditWrap : public Napi::ObjectWrap { QTEXTEDIT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTextEditWrap(const Napi::CallbackInfo& info); ~QTextEditWrap(); - NTextEdit* getInternalInstance(); + QTextEdit* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTimeEdit/qtimeedit_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTimeEdit/qtimeedit_wrap.h index fe322e4d4..a4761ba40 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTimeEdit/qtimeedit_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTimeEdit/qtimeedit_wrap.h @@ -12,13 +12,13 @@ class DLL_EXPORT QTimeEditWrap : public Napi::ObjectWrap { QDATETIMEEDIT_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QTimeEditWrap(const Napi::CallbackInfo &info); ~QTimeEditWrap(); - NTimeEdit *getInternalInstance(); + QTimeEdit *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QToolButton/ntoolbutton.hpp b/src/cpp/include/nodegui/QtWidgets/QToolButton/ntoolbutton.hpp index 45c0a94d0..bc966959d 100644 --- a/src/cpp/include/nodegui/QtWidgets/QToolButton/ntoolbutton.hpp +++ b/src/cpp/include/nodegui/QtWidgets/QToolButton/ntoolbutton.hpp @@ -21,11 +21,7 @@ class DLL_EXPORT NToolButton : public QToolButton, public NodeWidget { QObject::connect(this, &QToolButton::triggered, [=](QAction* action) { Napi::Env env = this->emitOnNode.Env(); Napi::HandleScope scope(env); - - // disable deletion of the native instance for these by passing true - auto instance = QActionWrap::constructor.New( - {Napi::External::New(env, action), - Napi::Boolean::New(env, true)}); + auto instance = WrapperCache::instance.getWrapper(env, action); this->emitOnNode.Call({Napi::String::New(env, "triggered"), instance}); }); } diff --git a/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h b/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h index fe3f765e7..94223291c 100644 --- a/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QToolButton/qtoolbutton_wrap.h @@ -12,14 +12,13 @@ class DLL_EXPORT QToolButtonWrap : public Napi::ObjectWrap { QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION private: - QPointer instance; - bool disableDeletion; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QToolButtonWrap(const Napi::CallbackInfo& info); ~QToolButtonWrap(); - NToolButton* getInternalInstance(); + QToolButton* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h index a94b9214f..d654813de 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QTreeWidget/qtreewidget_wrap.h @@ -11,7 +11,7 @@ class DLL_EXPORT QTreeWidgetWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); @@ -20,7 +20,7 @@ class DLL_EXPORT QTreeWidgetWrap : public Napi::ObjectWrap { ~QTreeWidgetWrap(); - NTreeWidget *getInternalInstance(); + QTreeWidget *getInternalInstance(); // class constructor static Napi::FunctionReference constructor; diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h index 0befba43a..fee82900b 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_wrap.h @@ -27,13 +27,13 @@ class DLL_EXPORT NodeWidgetWrap : public Napi::ObjectWrap { class DLL_EXPORT QWidgetWrap : public Napi::ObjectWrap { QWIDGET_WRAPPED_METHODS_DECLARATION private: - QPointer instance; + QPointer instance; public: static Napi::Object init(Napi::Env env, Napi::Object exports); QWidgetWrap(const Napi::CallbackInfo& info); ~QWidgetWrap(); - NWidget* getInternalInstance(); + QWidget* getInternalInstance(); // class constructor static Napi::FunctionReference constructor; // wrapped methods diff --git a/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h b/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h index b633c8890..013d16a5b 100644 --- a/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h +++ b/src/cpp/include/nodegui/core/WrapperCache/wrappercache.h @@ -4,6 +4,7 @@ #include #include +#include #include #include "Extras/Export/export.h" @@ -75,16 +76,33 @@ class DLL_EXPORT WrapperCache : public QObject { } } - QString className(qobject->metaObject()->className()); - if (this->wrapperRegistry.contains(className)) { - Napi::Object wrapper = this->wrapperRegistry[className](env, qobject); - store(env, ptrHash, qobject, wrapper, !keepAlive); - return wrapper; - } else { - qDebug() << "NodeGui: Unable to find wrapper for instance of class " - << className << ".\n\n"; + // Might have to climb up the class hierarchy looking for a wrapper type we + // support. This makes us immune to internal Qt subclasses, i.e. + // `QWidgetWindow` when `QWindow` was expected. + const QMetaObject* meta = qobject->metaObject(); + while (meta != nullptr) { + QString className(meta->className()); + if (this->wrapperRegistry.contains(className)) { + Napi::Object wrapper = this->wrapperRegistry[className](env, qobject); + store(env, ptrHash, qobject, wrapper, !keepAlive); + return wrapper; + } + meta = meta->superClass(); } + QMapIterator i(this->wrapperRegistry); + QString allQWrapperNames; + while (i.hasNext()) { + i.next(); + allQWrapperNames.append(i.key()); + allQWrapperNames.append(", "); + } + + qDebug() << "NodeGui: Unable to find wrapper for instance of C++ class " + << qobject->metaObject()->className() + << ". (The following C++ classes are recognized: " + << allQWrapperNames << ")"; + return env.Null(); } diff --git a/src/cpp/lib/Extras/Utils/nutils.cpp b/src/cpp/lib/Extras/Utils/nutils.cpp index b52d86f83..ed4990072 100644 --- a/src/cpp/lib/Extras/Utils/nutils.cpp +++ b/src/cpp/lib/Extras/Utils/nutils.cpp @@ -7,6 +7,7 @@ #include "core/Component/component_wrap.h" #include "core/FlexLayout/flexutils.h" +#include "core/YogaWidget/yogawidget.h" bool extrautils::isNapiValueInt(Napi::Env& env, Napi::Value& num) { return env.Global() @@ -101,12 +102,16 @@ QVariant* extrautils::convertToQVariant(Napi::Env& env, Napi::Value& value) { } void* extrautils::configureComponent(void* component) { return component; } + void* extrautils::configureQObject(QObject* object) { return configureComponent(object); } -void* extrautils::configureQWidget(QWidget* widget, YGNodeRef node, - bool isLeafNode) { - flexutils::configureFlexNode(widget, node, isLeafNode); + +void* extrautils::configureQWidget(QWidget* widget, bool isLeafNode) { + YogaWidget* yogaWidget = dynamic_cast(widget); + if (yogaWidget) { + flexutils::configureFlexNode(widget, yogaWidget->getFlexNode(), isLeafNode); + } return configureQObject(widget); } diff --git a/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp b/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp index b0aa9f2ea..ed6360671 100644 --- a/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp +++ b/src/cpp/lib/QtCore/QAbstractItemModel/qabstractitemmodel_wrap.cpp @@ -45,6 +45,7 @@ Napi::Object QAbstractItemModelWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QAbstractItemModelWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(NAbstractItemModel, QAbstractItemModelWrap); return exports; } @@ -58,7 +59,21 @@ QAbstractItemModelWrap::~QAbstractItemModelWrap() { QAbstractItemModelWrap::QAbstractItemModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->instance = new NAbstractItemModel(); + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NAbstractItemModel(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } + } else { + Napi::TypeError::New(env, + "NodeGui: QAbstractItemModelWrap: Wrong number of " + "arguments to constructor") + .ThrowAsJavaScriptException(); + } } Napi::Value QAbstractItemModelWrap::initNodeDispatcher( diff --git a/src/cpp/lib/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.cpp b/src/cpp/lib/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.cpp index f6ea1f900..e5df598ec 100644 --- a/src/cpp/lib/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.cpp +++ b/src/cpp/lib/QtCore/QItemSelectionModel/qitemselectionmodel_wrap.cpp @@ -38,6 +38,7 @@ Napi::Object QItemSelectionModelWrap::init(Napi::Env env, QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QItemSelectionModelWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QItemSelectionModel, QItemSelectionModelWrap); return exports; } @@ -46,20 +47,33 @@ QItemSelectionModel* QItemSelectionModelWrap::getInternalInstance() { } QItemSelectionModelWrap::~QItemSelectionModelWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } + extrautils::safeDelete(this->instance); } QItemSelectionModelWrap::QItemSelectionModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NItemSelectionModel(); - this->disableDeletion = false; + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + // Napi::Object parentObject = info[0].As(); + // QObjectWrap* parentObjectWrap = + // Napi::ObjectWrap::Unwrap(parentObject); + // this->instance = new + // NItemSelectionModel(parentObjectWrap->getInternalInstance()); + } } else { - this->instance = info[0].As>().Data(); - this->disableDeletion = true; + Napi::TypeError::New(env, + "NodeGui: QItemSelectionModelWrap: Wrong number of " + "arguments to constructor") + .ThrowAsJavaScriptException(); } } Napi::Value QItemSelectionModelWrap::columnIntersectsSelection( diff --git a/src/cpp/lib/QtCore/QMimeData/qmimedata_wrap.cpp b/src/cpp/lib/QtCore/QMimeData/qmimedata_wrap.cpp index c0ba24c27..6476be13e 100644 --- a/src/cpp/lib/QtCore/QMimeData/qmimedata_wrap.cpp +++ b/src/cpp/lib/QtCore/QMimeData/qmimedata_wrap.cpp @@ -10,7 +10,6 @@ Napi::Object QMimeDataWrap::init(Napi::Env env, Napi::Object exports) { char CLASSNAME[] = "QMimeData"; Napi::Function func = DefineClass(env, CLASSNAME, - {InstanceMethod("clear", &QMimeDataWrap::clear), InstanceMethod("hasColor", &QMimeDataWrap::hasColor), InstanceMethod("hasHtml", &QMimeDataWrap::hasHtml), @@ -25,43 +24,31 @@ Napi::Object QMimeDataWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("setUrls", &QMimeDataWrap::setUrls), InstanceMethod("text", &QMimeDataWrap::text), InstanceMethod("urls", &QMimeDataWrap::urls), - - COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QMimeDataWrap)}); + QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QMimeDataWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QMimeData, QMimeDataWrap); return exports; } -QMimeData* QMimeDataWrap::getInternalInstance() { return this->instance.get(); } +QMimeData* QMimeDataWrap::getInternalInstance() { return this->instance; } -QMimeDataWrap::~QMimeDataWrap() { this->instance.reset(); } +QMimeDataWrap::~QMimeDataWrap() { extrautils::safeDelete(this->instance); } QMimeDataWrap::QMimeDataWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::External eventObject = - info[0].As>(); - this->instance = std::make_unique(); - // Copy data to our instance - QMimeData* mimeReference = eventObject.Data(); - this->cloneFromMimeData(mimeReference); - // foreach(QString format, mimeReference->formats()) - // { - // // Retrieving data - // QByteArray data = mimeReference->data(format); - // // Checking for custom MIME types - // if(format.startsWith("application/x-qt")) - // { - // // Retrieving true format name - // int indexBegin = format.indexOf('"') + 1; - // int indexEnd = format.indexOf('"', indexBegin); - // format = format.mid(indexBegin, indexEnd - indexBegin); - // } - // this->instance->setData(format, data); - // } + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new QMimeData(); + } else if (argCount == 1 && info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); } else { - this->instance = std::make_unique(); + Napi::TypeError::New( + env, "NodeGui: QMimeDataWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureComponent(this->getInternalInstance()); } diff --git a/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp b/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp index 61aff178f..c138abedb 100644 --- a/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp +++ b/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp @@ -12,30 +12,31 @@ Napi::Object QObjectWrap::init(Napi::Env env, Napi::Object exports) { env, CLASSNAME, {QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QObjectWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); - QOBJECT_REGISTER_WRAPPER(NObject, QObjectWrap); + QOBJECT_REGISTER_WRAPPER(QObject, QObjectWrap); return exports; } -NObject* QObjectWrap::getInternalInstance() { return this->instance; } +QObject* QObjectWrap::getInternalInstance() { return this->instance; } QObjectWrap::~QObjectWrap() { extrautils::safeDelete(this->instance); } QObjectWrap::QObjectWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 1) { if (info[0].IsExternal()) { - this->instance = info[0].As>().Data(); + this->instance = info[0].As>().Data(); } else { Napi::Object parentObject = info[0].As(); QObjectWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NObject(parentWidgetWrap->getInternalInstance()); } - } else if (info.Length() == 0) { + } else if (argCount == 0) { this->instance = new NObject(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, "NodeGui: QObjectWrap: Wrong number of arguments") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp b/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp index 32739150b..112b34c86 100644 --- a/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp +++ b/src/cpp/lib/QtGui/QApplication/qapplication_wrap.cpp @@ -41,13 +41,15 @@ Napi::Object QApplicationWrap::init(Napi::Env env, Napi::Object exports) { QApplicationWrap::QApplicationWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 1) { this->instance = info[0].As>().Data(); - } else if (info.Length() == 0) { + } else if (argCount == 0) { this->instance = new NApplication(qode::qode_argc, qode::qode_argv); this->_wasManuallyCreated = true; } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QApplicationWrap: Wrong number of arguments") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureComponent(this->getInternalInstance()); diff --git a/src/cpp/lib/QtGui/QDrag/qdrag_wrap.cpp b/src/cpp/lib/QtGui/QDrag/qdrag_wrap.cpp index be3319195..0e80de3cc 100644 --- a/src/cpp/lib/QtGui/QDrag/qdrag_wrap.cpp +++ b/src/cpp/lib/QtGui/QDrag/qdrag_wrap.cpp @@ -32,21 +32,33 @@ Napi::Object QDragWrap::init(Napi::Env env, Napi::Object exports) { COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QDragWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QDrag, QDragWrap); return exports; } -NDrag* QDragWrap::getInternalInstance() { return this->instance; } +QDrag* QDragWrap::getInternalInstance() { return this->instance; } QDragWrap::QDragWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object wrap0_0 = info[0].As(); - QObjectWrap* wrap0_1 = Napi::ObjectWrap::Unwrap(wrap0_0); - QObject* dragSource = wrap0_1->getInternalInstance(); - this->instance = new NDrag(dragSource); + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NDrag(nullptr); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object sourceObject = info[0].As(); + QObjectWrap* sourceObjectWrap = + Napi::ObjectWrap::Unwrap(sourceObject); + this->instance = new NDrag(sourceObjectWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QDragWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureComponent(this->getInternalInstance()); diff --git a/src/cpp/lib/QtGui/QMovie/qmovie_wrap.cpp b/src/cpp/lib/QtGui/QMovie/qmovie_wrap.cpp index 5985af2ef..88ba4ce69 100644 --- a/src/cpp/lib/QtGui/QMovie/qmovie_wrap.cpp +++ b/src/cpp/lib/QtGui/QMovie/qmovie_wrap.cpp @@ -42,21 +42,27 @@ QMovieWrap::~QMovieWrap() { extrautils::safeDelete(this->instance); } QMovieWrap::QMovieWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - if (info[0].IsExternal()) { - this->instance = new NMovie(info[0].As>().Data()); - } else { - Napi::Object parentObject = info[0].As(); - QMovieWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NMovie(parentWidgetWrap->getInternalInstance()); - } - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NMovie(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + QObjectWrap* parentObjectWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NMovie(parentObjectWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QMovieWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } + QOBJECT_REGISTER_WRAPPER(QMovie, QMovieWrap); this->bufferDevice = QSharedPointer(new QBuffer); this->rawData = extrautils::configureQObject(this->getInternalInstance()); } diff --git a/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp b/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp index f3a8064e4..871182da7 100644 --- a/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp +++ b/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp @@ -26,7 +26,7 @@ QScreenWrap::QScreenWrap(const Napi::CallbackInfo& info) if (info[0].IsExternal()) { this->instance = info[0].As>().Data(); } else { - Napi::TypeError::New(env, "Incorrect initialization of QScreenWrap") + Napi::TypeError::New(env, "NodeGui: QScreenWrap: Incorrect initialization") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureComponent(this->getInternalInstance()); diff --git a/src/cpp/lib/QtGui/QStyle/qstyle_wrap.cpp b/src/cpp/lib/QtGui/QStyle/qstyle_wrap.cpp index 99efe1e1e..4ab3c4295 100644 --- a/src/cpp/lib/QtGui/QStyle/qstyle_wrap.cpp +++ b/src/cpp/lib/QtGui/QStyle/qstyle_wrap.cpp @@ -25,7 +25,8 @@ QStyleWrap::QStyleWrap(const Napi::CallbackInfo& info) if (info[0].IsExternal()) { this->instance = info[0].As>().Data(); } else { - Napi::TypeError::New(env, "Incorrect initialization of QStyleWrap") + Napi::TypeError::New( + env, "NodeGui: QStyleWrap: Incorrect initialization of QStyleWrap") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureComponent(this->getInternalInstance()); diff --git a/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp b/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp index 78fdc4333..fee76f489 100644 --- a/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp +++ b/src/cpp/lib/QtGui/QWindow/qwindow_wrap.cpp @@ -25,6 +25,7 @@ Napi::Object QWindowWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QWindowWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QWindow, QWindowWrap); return exports; } @@ -36,7 +37,8 @@ QWindowWrap::QWindowWrap(const Napi::CallbackInfo& info) if (info.Length() == 1 && info[0].IsExternal()) { this->instance = info[0].As>().Data(); } else { - Napi::TypeError::New(env, "Wrong number of arguments to QWindow.") + Napi::TypeError::New(env, + "NodeGui: QWindowWrap: Bad arguments to constructor.") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp b/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp index cc75c009f..7f6e2f462 100644 --- a/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QAction/qaction_wrap.cpp @@ -34,44 +34,40 @@ Napi::Object QActionWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QActionWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QAction, QActionWrap); return exports; } -NAction* QActionWrap::getInternalInstance() { return this->instance; } +QAction* QActionWrap::getInternalInstance() { return this->instance; } QActionWrap::QActionWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NAction(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + QObjectWrap* parentObjectWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NAction(parentObjectWrap->getInternalInstance()); } } else { - // --- regular cases --- - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NAction(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NAction(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - } + Napi::TypeError::New( + env, "NodeGui: QActionWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } + this->rawData = extrautils::configureQObject(this->getInternalInstance()); } -QActionWrap::~QActionWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QActionWrap::~QActionWrap() { extrautils::safeDelete(this->instance); } Napi::Value QActionWrap::setText(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); diff --git a/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp b/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp index 28e53f058..a42745ff2 100644 --- a/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp @@ -27,16 +27,19 @@ Napi::Object QBoxLayoutWrap::init(Napi::Env env, Napi::Object exports) { QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QBoxLayoutWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QBoxLayout, QBoxLayoutWrap); return exports; } -NBoxLayout* QBoxLayoutWrap::getInternalInstance() { return this->instance; } +QBoxLayout* QBoxLayoutWrap::getInternalInstance() { return this->instance; } + QBoxLayoutWrap::~QBoxLayoutWrap() { extrautils::safeDelete(this->instance); } QBoxLayoutWrap::QBoxLayoutWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 2) { + size_t argCount = info.Length(); + if (argCount == 2) { QBoxLayout::Direction dir = static_cast( info[0].As().Int32Value()); Napi::Object parentObject = info[1].As(); @@ -44,12 +47,17 @@ QBoxLayoutWrap::QBoxLayoutWrap(const Napi::CallbackInfo& info) Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NBoxLayout(dir, parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 1) { - QBoxLayout::Direction dir = static_cast( - info[0].As().Int32Value()); - this->instance = new NBoxLayout(dir); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + QBoxLayout::Direction dir = static_cast( + info[0].As().Int32Value()); + this->instance = new NBoxLayout(dir); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, "QBoxLayoutWrap: Wrong number of arguments") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QButtonGroup/qbuttongroup_wrap.cpp b/src/cpp/lib/QtWidgets/QButtonGroup/qbuttongroup_wrap.cpp index 143c41f62..1da2efaea 100644 --- a/src/cpp/lib/QtWidgets/QButtonGroup/qbuttongroup_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QButtonGroup/qbuttongroup_wrap.cpp @@ -27,25 +27,34 @@ Napi::Object QButtonGroupWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QButtonGroupWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QButtonGroup, QButtonGroupWrap); return exports; } -NButtonGroup* QButtonGroupWrap::getInternalInstance() { return this->instance; } +QButtonGroup* QButtonGroupWrap::getInternalInstance() { return this->instance; } QButtonGroupWrap::QButtonGroupWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NButtonGroup( - parentWidgetWrap - ->getInternalInstance()); // this sets the parent to current widget - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NButtonGroup(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NButtonGroup(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QButtonGroupWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.cpp index 99de9374b..0506189ea 100644 --- a/src/cpp/lib/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QCalendarWidget/qcalendarwidget_wrap.cpp @@ -28,10 +28,11 @@ Napi::Object QCalendarWidgetWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QCalendarWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QCalendarWidget, QCalendarWidgetWrap); return exports; } -NCalendarWidget *QCalendarWidgetWrap::getInternalInstance() { +QCalendarWidget *QCalendarWidgetWrap::getInternalInstance() { return this->instance; } @@ -42,22 +43,31 @@ QCalendarWidgetWrap::~QCalendarWidgetWrap() { QCalendarWidgetWrap::QCalendarWidgetWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap *parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NCalendarWidget( - parentWidgetWrap - ->getInternalInstance()); // this sets the parent to current widget - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NCalendarWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap *parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NCalendarWidget(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QCalendarWidgetWrap: Wrong number of " + "arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QCalendarWidgetWrap::monthShown(const Napi::CallbackInfo &info) { diff --git a/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp b/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp index d4297db49..87d5c5879 100644 --- a/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QCheckBox/qcheckbox_wrap.cpp @@ -17,44 +17,40 @@ Napi::Object QCheckBoxWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE(QCheckBoxWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QCheckBox, QCheckBoxWrap); return exports; } -NCheckBox* QCheckBoxWrap::getInternalInstance() { return this->instance; } +QCheckBox* QCheckBoxWrap::getInternalInstance() { return this->instance; } QCheckBoxWrap::QCheckBoxWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NCheckBox(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NCheckBox(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NCheckBox(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, "NodeGui: QCheckBoxWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } -QCheckBoxWrap::~QCheckBoxWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QCheckBoxWrap::~QCheckBoxWrap() { extrautils::safeDelete(this->instance); } Napi::Value QCheckBoxWrap::checkState(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); diff --git a/src/cpp/lib/QtWidgets/QColorDialog/qcolordialog_wrap.cpp b/src/cpp/lib/QtWidgets/QColorDialog/qcolordialog_wrap.cpp index b41c3440f..5fb1e1ad3 100644 --- a/src/cpp/lib/QtWidgets/QColorDialog/qcolordialog_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QColorDialog/qcolordialog_wrap.cpp @@ -27,10 +27,11 @@ Napi::Object QColorDialogWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QColorDialogWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QColorDialog, QColorDialogWrap); return exports; } -NColorDialog* QColorDialogWrap::getInternalInstance() { return this->instance; } +QColorDialog* QColorDialogWrap::getInternalInstance() { return this->instance; } QColorDialogWrap::~QColorDialogWrap() { extrautils::safeDelete(this->instance); @@ -39,21 +40,30 @@ QColorDialogWrap::~QColorDialogWrap() { QColorDialogWrap::QColorDialogWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - QWidget* parent = parentWidgetWrap->getInternalInstance(); - this->instance = new NColorDialog(parent); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NColorDialog(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NColorDialog(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QColorDialogWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QColorDialogWrap::selectedColor(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QComboBox/qcombobox_wrap.cpp b/src/cpp/lib/QtWidgets/QComboBox/qcombobox_wrap.cpp index 714e7402e..6af18286f 100644 --- a/src/cpp/lib/QtWidgets/QComboBox/qcombobox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QComboBox/qcombobox_wrap.cpp @@ -66,30 +66,39 @@ Napi::Object QComboBoxWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QComboBoxWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QComboBox, QComboBoxWrap); return exports; } -NComboBox* QComboBoxWrap::getInternalInstance() { return this->instance; } +QComboBox* QComboBoxWrap::getInternalInstance() { return this->instance; } + QComboBoxWrap::~QComboBoxWrap() { extrautils::safeDelete(this->instance); } QComboBoxWrap::QComboBoxWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - - this->instance = new NComboBox(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NComboBox(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NComboBox(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QComboBoxWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QComboBoxWrap::addItem(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QDateEdit/qdateedit_wrap.cpp b/src/cpp/lib/QtWidgets/QDateEdit/qdateedit_wrap.cpp index 93ea2fa5b..7bcd6edd2 100644 --- a/src/cpp/lib/QtWidgets/QDateEdit/qdateedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QDateEdit/qdateedit_wrap.cpp @@ -12,28 +12,37 @@ Napi::Object QDateEditWrap::init(Napi::Env env, Napi::Object exports) { {QDATETIMEEDIT_WRAPPED_METHODS_EXPORT_DEFINE(QDateEditWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QDateEdit, QDateEditWrap); return exports; } -NDateEdit* QDateEditWrap::getInternalInstance() { return this->instance; } +QDateEdit* QDateEditWrap::getInternalInstance() { return this->instance; } QDateEditWrap::QDateEditWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NDateEdit(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NDateEdit(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NDateEdit(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QDateEditWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QDateEditWrap::~QDateEditWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.cpp b/src/cpp/lib/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.cpp index 776e8bc2c..0082be0a7 100644 --- a/src/cpp/lib/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QDateTimeEdit/qdatetimeedit_wrap.cpp @@ -12,30 +12,41 @@ Napi::Object QDateTimeEditWrap::init(Napi::Env env, Napi::Object exports) { {QDATETIMEEDIT_WRAPPED_METHODS_EXPORT_DEFINE(QDateTimeEditWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QDateTimeEdit, QDateTimeEditWrap); return exports; } -NDateTimeEdit* QDateTimeEditWrap::getInternalInstance() { +QDateTimeEdit* QDateTimeEditWrap::getInternalInstance() { return this->instance; } QDateTimeEditWrap::QDateTimeEditWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NDateTimeEdit(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NDateTimeEdit(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NDateTimeEdit(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QDateTimeEditWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QDateTimeEditWrap::~QDateTimeEditWrap() { diff --git a/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp b/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp index be8b1c696..8c4ff98bc 100644 --- a/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp @@ -16,29 +16,37 @@ Napi::Object QDialWrap::init(Napi::Env env, Napi::Object exports) { {QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(QDialWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QDial, QDialWrap); return exports; } -NDial* QDialWrap::getInternalInstance() { return this->instance; } +QDial* QDialWrap::getInternalInstance() { return this->instance; } QDialWrap::QDialWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NDial(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NDial(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NDial(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QDialWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QDialWrap::~QDialWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QDialog/qdialog_wrap.cpp b/src/cpp/lib/QtWidgets/QDialog/qdialog_wrap.cpp index 0fa9bc0c0..a9faa1e2c 100644 --- a/src/cpp/lib/QtWidgets/QDialog/qdialog_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QDialog/qdialog_wrap.cpp @@ -11,33 +11,37 @@ Napi::Object QDialogWrap::init(Napi::Env env, Napi::Object exports) { env, CLASSNAME, {QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QDialogWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QDialog, QDialogWrap); return exports; } -NDialog *QDialogWrap::getInternalInstance() { return this->instance; } +QDialog *QDialogWrap::getInternalInstance() { return this->instance; } QDialogWrap::~QDialogWrap() { extrautils::safeDelete(this->instance); } QDialogWrap::QDialogWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NDialog(); + } else if (argCount == 1) { if (info[0].IsExternal()) { - this->instance = - new NDialog(info[0].As>().Data()); + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); - QDialogWrap *parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); + NodeWidgetWrap *parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NDialog(parentWidgetWrap->getInternalInstance()); } - } else if (info.Length() == 0) { - this->instance = new NDialog(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QDialogWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } diff --git a/src/cpp/lib/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.cpp b/src/cpp/lib/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.cpp index 55a6157c4..b3ab1d073 100644 --- a/src/cpp/lib/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QDoubleSpinBox/qdoublespinbox_wrap.cpp @@ -16,31 +16,41 @@ Napi::Object QDoubleSpinBoxWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTSPINBOX_WRAPPED_METHODS_EXPORT_DEFINE(QDoubleSpinBoxWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QDoubleSpinBox, QDoubleSpinBoxWrap); return exports; } -NDoubleSpinBox* QDoubleSpinBoxWrap::getInternalInstance() { +QDoubleSpinBox* QDoubleSpinBoxWrap::getInternalInstance() { return this->instance; } QDoubleSpinBoxWrap::QDoubleSpinBoxWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = - new NDoubleSpinBox(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NDoubleSpinBox(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NDoubleSpinBox(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QDoubleSpinBoxWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QDoubleSpinBoxWrap::~QDoubleSpinBoxWrap() { diff --git a/src/cpp/lib/QtWidgets/QErrorMessage/qerrormessage_wrap.cpp b/src/cpp/lib/QtWidgets/QErrorMessage/qerrormessage_wrap.cpp index 9cbb30cf7..a23f4551b 100644 --- a/src/cpp/lib/QtWidgets/QErrorMessage/qerrormessage_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QErrorMessage/qerrormessage_wrap.cpp @@ -16,10 +16,11 @@ Napi::Object QErrorMessageWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QErrorMessageWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QErrorMessage, QErrorMessageWrap); return exports; } -NErrorMessage* QErrorMessageWrap::getInternalInstance() { +QErrorMessage* QErrorMessageWrap::getInternalInstance() { return this->instance; } @@ -30,21 +31,30 @@ QErrorMessageWrap::~QErrorMessageWrap() { QErrorMessageWrap::QErrorMessageWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - QWidget* parent = parentWidgetWrap->getInternalInstance(); - this->instance = new NErrorMessage(parent); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NErrorMessage(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NErrorMessage(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QErrorMessageWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QErrorMessageWrap::showMessage(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QFileDialog/qfiledialog_wrap.cpp b/src/cpp/lib/QtWidgets/QFileDialog/qfiledialog_wrap.cpp index c3766f534..f3e38d31a 100644 --- a/src/cpp/lib/QtWidgets/QFileDialog/qfiledialog_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QFileDialog/qfiledialog_wrap.cpp @@ -24,16 +24,19 @@ Napi::Object QFileDialogWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QFileDialogWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QFileDialog, QFileDialogWrap); return exports; } -NFileDialog* QFileDialogWrap::getInternalInstance() { return this->instance; } +QFileDialog* QFileDialogWrap::getInternalInstance() { return this->instance; } + QFileDialogWrap::~QFileDialogWrap() { extrautils::safeDelete(this->instance); } QFileDialogWrap::QFileDialogWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 4) { + size_t argCount = info.Length(); + if (argCount == 4) { Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); @@ -45,15 +48,15 @@ QFileDialogWrap::QFileDialogWrap(const Napi::CallbackInfo& info) QString filter = QString::fromUtf8(info[3].As().Utf8Value().c_str()); this->instance = new NFileDialog(parent, caption, directory, filter); - } else if (info.Length() == 0) { + } else if (argCount == 0) { this->instance = new NFileDialog(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QFileDialogWrap: Wrong number of arguments") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QFileDialogWrap::supportedSchemes(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QFontDialog/qfontdialog_wrap.cpp b/src/cpp/lib/QtWidgets/QFontDialog/qfontdialog_wrap.cpp index 5194c9f15..bec840ae8 100644 --- a/src/cpp/lib/QtWidgets/QFontDialog/qfontdialog_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QFontDialog/qfontdialog_wrap.cpp @@ -18,31 +18,40 @@ Napi::Object QFontDialogWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QFontDialogWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QFontDialog, QFontDialogWrap); return exports; } -NFontDialog* QFontDialogWrap::getInternalInstance() { return this->instance; } +QFontDialog* QFontDialogWrap::getInternalInstance() { return this->instance; } QFontDialogWrap::~QFontDialogWrap() { extrautils::safeDelete(this->instance); } QFontDialogWrap::QFontDialogWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - QWidget* parent = parentWidgetWrap->getInternalInstance(); - this->instance = new NFontDialog(parent); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NFontDialog(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NFontDialog(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QFontDialogWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QFontDialogWrap::selectedFont(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QFrame/qframe_wrap.cpp b/src/cpp/lib/QtWidgets/QFrame/qframe_wrap.cpp index cb337b2a1..c32441204 100644 --- a/src/cpp/lib/QtWidgets/QFrame/qframe_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QFrame/qframe_wrap.cpp @@ -11,28 +11,37 @@ Napi::Object QFrameWrap::init(Napi::Env env, Napi::Object exports) { env, CLASSNAME, {QFRAME_WRAPPED_METHODS_EXPORT_DEFINE(QFrameWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QFrame, QFrameWrap); return exports; } -NFrame* QFrameWrap::getInternalInstance() { return this->instance; } +QFrame* QFrameWrap::getInternalInstance() { return this->instance; } QFrameWrap::~QFrameWrap() { extrautils::safeDelete(this->instance); } QFrameWrap::QFrameWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NFrame(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NFrame(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NFrame(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QFrameWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } diff --git a/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp b/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp index 0786be2a5..12d8e719a 100644 --- a/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp @@ -2,6 +2,7 @@ #include "Extras/Utils/nutils.h" #include "QtCore/QObject/qobject_wrap.h" +#include "QtWidgets/QWidget/qwidget_wrap.h" Napi::FunctionReference QGraphicsBlurEffectWrap::constructor; @@ -14,10 +15,11 @@ Napi::Object QGraphicsBlurEffectWrap::init(Napi::Env env, {QGRAPHICSEFFECT_WRAPPED_METHODS_EXPORT_DEFINE(QGraphicsBlurEffectWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QGraphicsBlurEffect, QGraphicsBlurEffectWrap); return exports; } -NGraphicsBlurEffect* QGraphicsBlurEffectWrap::getInternalInstance() { +QGraphicsBlurEffect* QGraphicsBlurEffectWrap::getInternalInstance() { return this->instance; } @@ -28,16 +30,26 @@ QGraphicsBlurEffectWrap::~QGraphicsBlurEffectWrap() { QGraphicsBlurEffectWrap::QGraphicsBlurEffectWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - QObjectWrap* parentObjectWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = - new NGraphicsBlurEffect(parentObjectWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NGraphicsBlurEffect(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NGraphicsBlurEffect(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QGraphicsBlurEffectWrap: Wrong number of " + "arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp b/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp index 51e3bd093..b7e9ebb0c 100644 --- a/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp @@ -2,6 +2,7 @@ #include "Extras/Utils/nutils.h" #include "QtCore/QObject/qobject_wrap.h" +#include "QtWidgets/QWidget/qwidget_wrap.h" Napi::FunctionReference QGraphicsDropShadowEffectWrap::constructor; @@ -15,10 +16,12 @@ Napi::Object QGraphicsDropShadowEffectWrap::init(Napi::Env env, QGraphicsDropShadowEffectWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QGraphicsDropShadowEffect, + QGraphicsDropShadowEffectWrap); return exports; } -NGraphicsDropShadowEffect* +QGraphicsDropShadowEffect* QGraphicsDropShadowEffectWrap::getInternalInstance() { return this->instance; } @@ -31,16 +34,28 @@ QGraphicsDropShadowEffectWrap::QGraphicsDropShadowEffectWrap( const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - QObjectWrap* parentObjectWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = - new NGraphicsDropShadowEffect(parentObjectWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NGraphicsDropShadowEffect(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = + info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NGraphicsDropShadowEffect( + parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QGraphicsDropShadowEffectWrap: Wrong number of " + "arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp b/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp index de09979fc..7786f61d3 100644 --- a/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp @@ -35,24 +35,36 @@ Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) { QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QGridLayoutWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QGridLayout, QGridLayoutWrap); return exports; } -NGridLayout* QGridLayoutWrap::getInternalInstance() { return this->instance; } +QGridLayout* QGridLayoutWrap::getInternalInstance() { return this->instance; } + QGridLayoutWrap::~QGridLayoutWrap() { extrautils::safeDelete(this->instance); } QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NGridLayout(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NGridLayout(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NGridLayout(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QGridLayoutWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp b/src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp index 2b90ed7ba..34bd58850 100644 --- a/src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp @@ -13,29 +13,38 @@ Napi::Object QGroupBoxWrap::init(Napi::Env env, Napi::Object exports) { Napi::Function func = DefineClass( env, CLASSNAME, {QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QGroupBoxWrap)}); constructor = Napi::Persistent(func); + QOBJECT_REGISTER_WRAPPER(QGroupBox, QGroupBoxWrap); exports.Set(CLASSNAME, func); return exports; } -NGroupBox* QGroupBoxWrap::getInternalInstance() { return this->instance; } +QGroupBox* QGroupBoxWrap::getInternalInstance() { return this->instance; } QGroupBoxWrap::QGroupBoxWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NGroupBox(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NGroupBox(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NGroupBox(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QGroupBoxWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } QGroupBoxWrap::~QGroupBoxWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp b/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp index 3bc9ef2d9..d9333fd05 100644 --- a/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp @@ -111,27 +111,21 @@ Napi::Object QHeaderViewWrap::init(Napi::Env env, Napi::Object exports) { }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QHeaderView, QHeaderViewWrap); return exports; } QHeaderView* QHeaderViewWrap::getInternalInstance() { return this->instance; } -QHeaderViewWrap::~QHeaderViewWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QHeaderViewWrap::~QHeaderViewWrap() { extrautils::safeDelete(this->instance); } QHeaderViewWrap::QHeaderViewWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - size_t len = info.Length(); - - this->disableDeletion = false; - if (len == 1) { + size_t argCount = info.Length(); + if (argCount == 1) { if (info[0].IsExternal()) { this->instance = info[0].As>().Data(); - this->disableDeletion = true; } else { int orientation = info[0].As().Int32Value(); this->instance = @@ -152,8 +146,8 @@ QHeaderViewWrap::QHeaderViewWrap(const Napi::CallbackInfo& info) this->rawData = nullptr; FlexItem* item = dynamic_cast(this->getInternalInstance()); if (item) { - this->rawData = extrautils::configureQWidget(this->getInternalInstance(), - item->getFlexNode(), false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } } diff --git a/src/cpp/lib/QtWidgets/QInputDialog/qinputdialog_wrap.cpp b/src/cpp/lib/QtWidgets/QInputDialog/qinputdialog_wrap.cpp index cdeec107d..0cc838c6d 100644 --- a/src/cpp/lib/QtWidgets/QInputDialog/qinputdialog_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QInputDialog/qinputdialog_wrap.cpp @@ -56,10 +56,12 @@ Napi::Object QInputDialogWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QInputDialogWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QInputDialog, QInputDialogWrap); return exports; } -NInputDialog* QInputDialogWrap::getInternalInstance() { return this->instance; } +QInputDialog* QInputDialogWrap::getInternalInstance() { return this->instance; } + QInputDialogWrap::~QInputDialogWrap() { extrautils::safeDelete(this->instance); } @@ -67,20 +69,30 @@ QInputDialogWrap::~QInputDialogWrap() { QInputDialogWrap::QInputDialogWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NInputDialog(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NInputDialog(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NInputDialog(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QInputDialogWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QInputDialogWrap::setCancelButtonText( diff --git a/src/cpp/lib/QtWidgets/QLCDNumber/qlcdnumber_wrap.cpp b/src/cpp/lib/QtWidgets/QLCDNumber/qlcdnumber_wrap.cpp index 33241d646..99f790cf5 100644 --- a/src/cpp/lib/QtWidgets/QLCDNumber/qlcdnumber_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QLCDNumber/qlcdnumber_wrap.cpp @@ -20,31 +20,41 @@ Napi::Object QLCDNumberWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("setOctMode", &QLCDNumberWrap::setOctMode), QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLCDNumberWrap)}); constructor = Napi::Persistent(func); + QOBJECT_REGISTER_WRAPPER(QLCDNumber, QLCDNumberWrap); exports.Set(CLASSNAME, func); return exports; } -NLCDNumber* QLCDNumberWrap::getInternalInstance() { return this->instance; } +QLCDNumber* QLCDNumberWrap::getInternalInstance() { return this->instance; } QLCDNumberWrap::~QLCDNumberWrap() { extrautils::safeDelete(this->instance); } QLCDNumberWrap::QLCDNumberWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NLCDNumber(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NLCDNumber(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NLCDNumber(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QLCDNumberWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QLCDNumberWrap::checkOverflow(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 59f614084..65b4298b3 100644 --- a/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp @@ -27,31 +27,46 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) { QFRAME_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QLabel, QLabelWrap); return exports; } -NLabel* QLabelWrap::getInternalInstance() { return this->instance; } +QLabel* QLabelWrap::getInternalInstance() { return this->instance; } QLabelWrap::~QLabelWrap() { extrautils::safeDelete(this->instance); } QLabelWrap::QLabelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NLabel(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NLabel(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NLabel(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QLabelWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - auto flexNode = this->getInternalInstance()->getFlexNode(); - YGNodeSetNodeType(flexNode, YGNodeType::YGNodeTypeText); + + YogaWidget* yogaWidget = + dynamic_cast(this->getInternalInstance()); + if (yogaWidget) { + auto flexNode = yogaWidget->getFlexNode(); + YGNodeSetNodeType(flexNode, YGNodeType::YGNodeTypeText); + } this->rawData = - extrautils::configureQWidget(this->getInternalInstance(), flexNode, true); + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QLabelWrap::setSelection(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QLayout/qlayout_wrap.cpp b/src/cpp/lib/QtWidgets/QLayout/qlayout_wrap.cpp index 8d616e135..97f35af4e 100644 --- a/src/cpp/lib/QtWidgets/QLayout/qlayout_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QLayout/qlayout_wrap.cpp @@ -3,16 +3,29 @@ #include "Extras/Utils/nutils.h" Napi::FunctionReference QLayoutWrap::constructor; -void QLayoutWrap::init(Napi::Env env) { +void QLayoutWrap::init(Napi::Env env, Napi::Object exports) { char CLASSNAME[] = "QLayout"; Napi::Function func = DefineClass( env, CLASSNAME, {QLAYOUT_WRAPPED_METHODS_EXPORT_DEFINE(QLayoutWrap)}); constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QLayout, QLayoutWrap); } -NLayout* QLayoutWrap::getInternalInstance() { return this->instance; } +QLayout* QLayoutWrap::getInternalInstance() { return this->instance; } QLayoutWrap::QLayoutWrap(const Napi::CallbackInfo& info) - : Napi::ObjectWrap(info) {} + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + size_t argCount = info.Length(); + if (argCount == 1 && info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + Napi::TypeError::New(env, "NodeGui: QLayoutWrap: Wrong number of arguments") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureQObject(this->getInternalInstance()); +} QLayoutWrap::~QLayoutWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp b/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp index 4581a5f6b..56eb00382 100644 --- a/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp @@ -40,28 +40,37 @@ Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QLineEdit, QLineEditWrap); return exports; } -NLineEdit* QLineEditWrap::getInternalInstance() { return this->instance; } +QLineEdit* QLineEditWrap::getInternalInstance() { return this->instance; } QLineEditWrap::QLineEditWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NLineEdit(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NLineEdit(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NLineEdit(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QLineEditWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QLineEditWrap::~QLineEditWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QListView/qlistview_wrap.cpp b/src/cpp/lib/QtWidgets/QListView/qlistview_wrap.cpp index c253f28ae..cedc6f575 100644 --- a/src/cpp/lib/QtWidgets/QListView/qlistview_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QListView/qlistview_wrap.cpp @@ -11,42 +11,38 @@ Napi::Object QListViewWrap::init(Napi::Env env, Napi::Object exports) { env, CLASSNAME, {QLISTVIEW_WRAPPED_METHODS_EXPORT_DEFINE(QListViewWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QListView, QListViewWrap); return exports; } -NListView* QListViewWrap::getInternalInstance() { return this->instance; } +QListView* QListViewWrap::getInternalInstance() { return this->instance; } -QListViewWrap::~QListViewWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QListViewWrap::~QListViewWrap() { extrautils::safeDelete(this->instance); } QListViewWrap::QListViewWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - // --- regular cases --- - if (info.Length() == 1) { + + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NListView(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NListView(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NListView(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, "NodeGui: QListViewWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } diff --git a/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp index dbed200be..b2a003c7c 100644 --- a/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp @@ -41,30 +41,40 @@ Napi::Object QListWidgetWrap::init(Napi::Env env, Napi::Object exports) { QLISTVIEW_WRAPPED_METHODS_EXPORT_DEFINE(QListWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QListWidget, QListWidgetWrap); return exports; } -NListWidget* QListWidgetWrap::getInternalInstance() { return this->instance; } +QListWidget* QListWidgetWrap::getInternalInstance() { return this->instance; } QListWidgetWrap::~QListWidgetWrap() { extrautils::safeDelete(this->instance); } QListWidgetWrap::QListWidgetWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NListWidget(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NListWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NListWidget(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QListWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QListWidgetWrap::addItem(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp b/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp index cb8299258..27038fb68 100644 --- a/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp @@ -67,22 +67,24 @@ QListWidgetItemWrap::QListWidgetItemWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { + size_t argCount = info.Length(); + if (argCount > 0 && info[0].IsExternal()) { // --- if external --- this->instance = info[0].As>().Data(); - if (info.Length() == 2) { + if (argCount == 2) { this->disableDeletion = info[1].As().Value(); } } else { // --- regular cases --- - if (info.Length() == 1) { + if (argCount == 1) { QString text = QString::fromUtf8(info[0].As().Utf8Value().c_str()); this->instance = new QListWidgetItem(text); - } else if (info.Length() == 0) { + } else if (argCount == 0) { this->instance = new QListWidgetItem(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QListWidgetItemWrap: Wrong number of arguments") .ThrowAsJavaScriptException(); } } diff --git a/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp b/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp index 677507be7..a5639273a 100644 --- a/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMainWindow/qmainwindow_wrap.cpp @@ -27,29 +27,39 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) { }); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QMainWindow, QMainWindowWrap); return exports; } -NMainWindow* QMainWindowWrap::getInternalInstance() { return this->instance; } +QMainWindow* QMainWindowWrap::getInternalInstance() { return this->instance; } QMainWindowWrap::~QMainWindowWrap() { extrautils::safeDelete(this->instance); } QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NMainWindow(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NMainWindow(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NMainWindow(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QMainWindowWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode()); + this->rawData = extrautils::configureQWidget(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 50964ef3b..a68dfa044 100644 --- a/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp @@ -23,28 +23,37 @@ Napi::Object QMenuWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMenuWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QMenu, QMenuWrap); return exports; } -NMenu* QMenuWrap::getInternalInstance() { return this->instance; } +QMenu* QMenuWrap::getInternalInstance() { return this->instance; } QMenuWrap::QMenuWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NMenu(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NMenu(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NMenu(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QMenuWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QMenuWrap::~QMenuWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp b/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp index 7b5b557cf..e063c3632 100644 --- a/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp @@ -21,32 +21,36 @@ Napi::Object QMenuBarWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMenuBarWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QMenuBar, QMenuBarWrap); return exports; } -NMenuBar* QMenuBarWrap::getInternalInstance() { return this->instance; } +QMenuBar* QMenuBarWrap::getInternalInstance() { return this->instance; } QMenuBarWrap::QMenuBarWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NMenuBar(); + } else if (argCount == 1) { if (info[0].IsExternal()) { - this->instance = - new NMenuBar(info[0].As>().Data()); + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NMenuBar(parentWidgetWrap->getInternalInstance()); } - } else if (info.Length() == 0) { - this->instance = new NMenuBar(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QMenuBarWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode()); + this->rawData = extrautils::configureQWidget(this->getInternalInstance()); } QMenuBarWrap::~QMenuBarWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QMessageBox/qmessagebox_wrap.cpp b/src/cpp/lib/QtWidgets/QMessageBox/qmessagebox_wrap.cpp index 2eba06311..edb3c3bcc 100644 --- a/src/cpp/lib/QtWidgets/QMessageBox/qmessagebox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QMessageBox/qmessagebox_wrap.cpp @@ -23,30 +23,41 @@ Napi::Object QMessageBoxWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QMessageBoxWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QMessageBox, QMessageBoxWrap); return exports; } -NMessageBox* QMessageBoxWrap::getInternalInstance() { return this->instance; } +QMessageBox* QMessageBoxWrap::getInternalInstance() { return this->instance; } + QMessageBoxWrap::~QMessageBoxWrap() { extrautils::safeDelete(this->instance); } QMessageBoxWrap::QMessageBoxWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NMessageBox(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NMessageBox(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NMessageBox(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QMessageBoxWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } this->instance->setStandardButtons(QMessageBox::NoButton); - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QMessageBoxWrap::setDefaultButton(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp b/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp index 944d068f4..bd6cd6c5d 100644 --- a/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp @@ -27,31 +27,41 @@ Napi::Object QPlainTextEditWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(QPlainTextEditWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QPlainTextEdit, QPlainTextEditWrap); return exports; } -NPlainTextEdit *QPlainTextEditWrap::getInternalInstance() { +QPlainTextEdit *QPlainTextEditWrap::getInternalInstance() { return this->instance; } QPlainTextEditWrap::QPlainTextEditWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap *parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = - new NPlainTextEdit(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NPlainTextEdit(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap *parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NPlainTextEdit(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QPlainTextEditWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QPlainTextEditWrap::~QPlainTextEditWrap() { diff --git a/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp b/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp index 5e514d31c..f7cf93c4a 100644 --- a/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp @@ -18,10 +18,11 @@ Napi::Object QProgressBarWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QProgressBar, QProgressBarWrap); return exports; } -NProgressBar* QProgressBarWrap::getInternalInstance() { return this->instance; } +QProgressBar* QProgressBarWrap::getInternalInstance() { return this->instance; } QProgressBarWrap::~QProgressBarWrap() { extrautils::safeDelete(this->instance); @@ -30,20 +31,30 @@ QProgressBarWrap::~QProgressBarWrap() { QProgressBarWrap::QProgressBarWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NProgressBar(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NProgressBar(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NProgressBar(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QProgressBarWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QProgressBarWrap::resetFormat(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QProgressDialog/qprogressdialog_wrap.cpp b/src/cpp/lib/QtWidgets/QProgressDialog/qprogressdialog_wrap.cpp index b3442dbf3..d3e82faa9 100644 --- a/src/cpp/lib/QtWidgets/QProgressDialog/qprogressdialog_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QProgressDialog/qprogressdialog_wrap.cpp @@ -20,10 +20,11 @@ Napi::Object QProgressDialogWrap::init(Napi::Env env, Napi::Object exports) { QDIALOG_WRAPPED_METHODS_EXPORT_DEFINE(QProgressDialogWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QProgressDialog, QProgressDialogWrap); return exports; } -NProgressDialog* QProgressDialogWrap::getInternalInstance() { +QProgressDialog* QProgressDialogWrap::getInternalInstance() { return this->instance; } @@ -34,21 +35,30 @@ QProgressDialogWrap::~QProgressDialogWrap() { QProgressDialogWrap::QProgressDialogWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - QWidget* parent = parentWidgetWrap->getInternalInstance(); - this->instance = new NProgressDialog(parent); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NProgressDialog(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NProgressDialog(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QProgressDialogWrap: Wrong number of " + "arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QProgressDialogWrap::cancel(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QPushButton/qpushbutton_wrap.cpp b/src/cpp/lib/QtWidgets/QPushButton/qpushbutton_wrap.cpp index 88b9d32c8..916714ce1 100644 --- a/src/cpp/lib/QtWidgets/QPushButton/qpushbutton_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QPushButton/qpushbutton_wrap.cpp @@ -16,44 +16,40 @@ Napi::Object QPushButtonWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QPushButton, QPushButtonWrap); return exports; } -NPushButton* QPushButtonWrap::getInternalInstance() { return this->instance; } +QPushButton* QPushButtonWrap::getInternalInstance() { return this->instance; } -QPushButtonWrap::~QPushButtonWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QPushButtonWrap::~QPushButtonWrap() { extrautils::safeDelete(this->instance); } QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NPushButton(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NPushButton(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NPushButton(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, + "NodeGui: QPushButtonWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QPushButtonWrap::setMenu(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp b/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp index 22cf2f72c..0e6ea18c5 100644 --- a/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp @@ -16,42 +16,41 @@ Napi::Object QRadioButtonWrap::init(Napi::Env env, Napi::Object exports) { {QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QRadioButton, QRadioButtonWrap); return exports; } -NRadioButton* QRadioButtonWrap::getInternalInstance() { return this->instance; } +QRadioButton* QRadioButtonWrap::getInternalInstance() { return this->instance; } QRadioButtonWrap::QRadioButtonWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NRadioButton(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NRadioButton(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NRadioButton(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, + "NodeGui: QRadioButtonWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QRadioButtonWrap::~QRadioButtonWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } + extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp b/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp index 1ea746c5b..934f3ef1d 100644 --- a/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp @@ -14,6 +14,7 @@ Napi::Object QScrollAreaWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("ensureWidgetVisible", &QScrollAreaWrap::ensureWidgetVisible), InstanceMethod("setWidget", &QScrollAreaWrap::setWidget), + InstanceMethod("widget", &QScrollAreaWrap::widget), InstanceMethod("takeWidget", &QScrollAreaWrap::takeWidget), InstanceMethod("setViewportMargins", &QScrollAreaWrap::setViewportMargins), @@ -21,38 +22,41 @@ Napi::Object QScrollAreaWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(QScrollAreaWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QScrollArea, QScrollAreaWrap); return exports; } -NScrollArea* QScrollAreaWrap::getInternalInstance() { return this->instance; } +QScrollArea* QScrollAreaWrap::getInternalInstance() { return this->instance; } -QScrollAreaWrap::~QScrollAreaWrap() { - extrautils::safeDelete(this->instance); - YGNodeFree(this->scrollNode); -} +QScrollAreaWrap::~QScrollAreaWrap() { extrautils::safeDelete(this->instance); } QScrollAreaWrap::QScrollAreaWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NScrollArea(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NScrollArea(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NScrollArea(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QScrollAreaWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->scrollNode = YGNodeNew(); - YGConfigSetUseWebDefaults(this->scrollNode->getConfig(), true); - FlexNodeContext* scrollNodeCtx = new FlexNodeContext(this->instance); - YGNodeSetContext(this->scrollNode, scrollNodeCtx); - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QScrollAreaWrap::ensureVisible(const Napi::CallbackInfo& info) { @@ -87,18 +91,31 @@ Napi::Value QScrollAreaWrap::setWidget(const Napi::CallbackInfo& info) { return env.Null(); } +Napi::Value QScrollAreaWrap::widget(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + QObject* widget = this->instance->widget(); + if (widget) { + return WrapperCache::instance.getWrapper(env, widget); + } else { + return env.Null(); + } +} + Napi::Value QScrollAreaWrap::takeWidget(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); - this->instance->takeWidget(); - // We will not return the value here since we are doing it in js side anyway - return env.Null(); + QObject* widget = this->instance->takeWidget(); + if (widget) { + return WrapperCache::instance.getWrapper(env, widget); + } else { + return env.Null(); + } } Napi::Value QScrollAreaWrap::setViewportMargins( const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); - NScrollArea* nScrollArea = qobject_cast(this->instance); - if (nScrollArea != nullptr) { + NScrollArea* nScrollArea = dynamic_cast(this->instance.data()); + if (nScrollArea) { int left = info[0].As().Int32Value(); int top = info[1].As().Int32Value(); int right = info[2].As().Int32Value(); @@ -110,17 +127,16 @@ Napi::Value QScrollAreaWrap::setViewportMargins( Napi::Value QScrollAreaWrap::viewportMargins(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); - NScrollArea* nScrollArea = qobject_cast(this->instance); - - QMargins margins; - if (nScrollArea != nullptr) { - margins = nScrollArea->viewportMargins(); + NScrollArea* nScrollArea = dynamic_cast(this->instance.data()); + if (nScrollArea) { + QMargins margins = nScrollArea->viewportMargins(); + Napi::Array resultNapi = Napi::Array::New(env, 4); + resultNapi[uint32_t(0)] = Napi::Number::From(env, margins.left()); + resultNapi[1] = Napi::Value::From(env, margins.top()); + resultNapi[2] = Napi::Value::From(env, margins.right()); + resultNapi[3] = Napi::Value::From(env, margins.bottom()); + return resultNapi; + } else { + return env.Null(); } - - Napi::Array resultNapi = Napi::Array::New(env, 4); - resultNapi[uint32_t(0)] = Napi::Number::From(env, margins.left()); - resultNapi[1] = Napi::Value::From(env, margins.top()); - resultNapi[2] = Napi::Value::From(env, margins.right()); - resultNapi[3] = Napi::Value::From(env, margins.bottom()); - return resultNapi; } diff --git a/src/cpp/lib/QtWidgets/QScrollBar/qscrollbar_wrap.cpp b/src/cpp/lib/QtWidgets/QScrollBar/qscrollbar_wrap.cpp index 75ad57ae7..df4f6d530 100644 --- a/src/cpp/lib/QtWidgets/QScrollBar/qscrollbar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QScrollBar/qscrollbar_wrap.cpp @@ -15,29 +15,38 @@ Napi::Object QScrollBarWrap::init(Napi::Env env, Napi::Object exports) { {QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(QScrollBarWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QScrollBar, QScrollBarWrap); return exports; } -NScrollBar* QScrollBarWrap::getInternalInstance() { return this->instance; } +QScrollBar* QScrollBarWrap::getInternalInstance() { return this->instance; } QScrollBarWrap::QScrollBarWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NScrollBar(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NScrollBar(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NScrollBar(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QScrollBarWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QScrollBarWrap::~QScrollBarWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp b/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp index f7bd8c582..ae8235f71 100644 --- a/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QShortcut/qshortcut_wrap.cpp @@ -21,21 +21,33 @@ Napi::Object QShortcutWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QShortcutWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QShortcut, QShortcutWrap); return exports; } -NShortcut* QShortcutWrap::getInternalInstance() { return this->instance; } +QShortcut* QShortcutWrap::getInternalInstance() { return this->instance; } QShortcutWrap::QShortcutWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NShortcut(parentWidgetWrap->getInternalInstance()); + size_t argCount = info.Length(); + + // Note: QShortcut object always need a parent or instance to wrap + + if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NShortcut(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QShortcutWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp b/src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp index 4b1aecea7..51bdbf5a2 100644 --- a/src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp @@ -15,29 +15,37 @@ Napi::Object QSliderWrap::init(Napi::Env env, Napi::Object exports) { {QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(QSliderWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QSlider, QSliderWrap); return exports; } -NSlider* QSliderWrap::getInternalInstance() { return this->instance; } +QSlider* QSliderWrap::getInternalInstance() { return this->instance; } QSliderWrap::QSliderWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NSlider(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NSlider(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NSlider(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QSliderWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QSliderWrap::~QSliderWrap() { 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 dc081a7d6..677fb0d04 100644 --- a/src/cpp/lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSpinBox/qspinbox_wrap.cpp @@ -15,28 +15,37 @@ Napi::Object QSpinBoxWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTSPINBOX_WRAPPED_METHODS_EXPORT_DEFINE(QSpinBoxWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QSpinBox, QSpinBoxWrap); return exports; } -NSpinBox* QSpinBoxWrap::getInternalInstance() { return this->instance; } +QSpinBox* QSpinBoxWrap::getInternalInstance() { return this->instance; } QSpinBoxWrap::QSpinBoxWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NSpinBox(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NSpinBox(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NSpinBox(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QSpinBoxWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QSpinBoxWrap::~QSpinBoxWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QSplitter/qsplitter_wrap.cpp b/src/cpp/lib/QtWidgets/QSplitter/qsplitter_wrap.cpp index c70a5f090..08aa13aeb 100644 --- a/src/cpp/lib/QtWidgets/QSplitter/qsplitter_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSplitter/qsplitter_wrap.cpp @@ -22,30 +22,39 @@ Napi::Object QSplitterWrap::init(Napi::Env env, Napi::Object exports) { QFRAME_WRAPPED_METHODS_EXPORT_DEFINE(QSplitterWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QSplitter, QSplitterWrap); return exports; } -NSplitter* QSplitterWrap::getInternalInstance() { return this->instance; } +QSplitter* QSplitterWrap::getInternalInstance() { return this->instance; } QSplitterWrap::~QSplitterWrap() { extrautils::safeDelete(this->instance); } QSplitterWrap::QSplitterWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NSplitter(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NSplitter(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NSplitter(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QSplitterWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QSplitterWrap::addWidget(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp index 8fe1f0f49..a7d6e5c00 100644 --- a/src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp @@ -21,10 +21,11 @@ Napi::Object QStackedWidgetWrap::init(Napi::Env env, Napi::Object exports) { QFRAME_WRAPPED_METHODS_EXPORT_DEFINE(QStackedWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QStackedWidget, QStackedWidgetWrap); return exports; } -NStackedWidget* QStackedWidgetWrap::getInternalInstance() { +QStackedWidget* QStackedWidgetWrap::getInternalInstance() { return this->instance; } @@ -35,22 +36,30 @@ QStackedWidgetWrap::~QStackedWidgetWrap() { QStackedWidgetWrap::QStackedWidgetWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NStackedWidget( - parentWidgetWrap - ->getInternalInstance()); // this sets the parent to current widget - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NStackedWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NStackedWidget(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QStackedWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QStackedWidgetWrap::addWidget(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QStandardItem/qstandarditem_wrap.cpp b/src/cpp/lib/QtWidgets/QStandardItem/qstandarditem_wrap.cpp index ec2af7a2f..761d71176 100644 --- a/src/cpp/lib/QtWidgets/QStandardItem/qstandarditem_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QStandardItem/qstandarditem_wrap.cpp @@ -37,20 +37,21 @@ QStandardItemWrap::QStandardItemWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { + size_t argCount = info.Length(); + if (argCount > 0 && info[0].IsExternal()) { this->instance = info[0].As>().Data(); - if (info.Length() == 2) { + if (argCount == 2) { this->disableDeletion = info[1].As().Value(); } } else { - if (info.Length() == 1) { + if (argCount == 1) { QString text = QString::fromUtf8(info[0].As().Utf8Value().c_str()); this->instance = new QStandardItem(text); - } else if (info.Length() == 0) { + } else if (argCount == 0) { this->instance = new QStandardItem(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, "QStandardItemWrap: Wrong number of arguments") .ThrowAsJavaScriptException(); } } diff --git a/src/cpp/lib/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.cpp b/src/cpp/lib/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.cpp index 5454aeea4..d0a5844c0 100644 --- a/src/cpp/lib/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QStandardItemModel/qstandarditemmodel_wrap.cpp @@ -22,27 +22,37 @@ Napi::Object QStandardItemModelWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QStandardItemModelWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QStandardItemModel, QStandardItemModelWrap); return exports; } -NStandardItemModel* QStandardItemModelWrap::getInternalInstance() { +QStandardItemModel* QStandardItemModelWrap::getInternalInstance() { return this->instance; } QStandardItemModelWrap::QStandardItemModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NStandardItemModel( - parentWidgetWrap - ->getInternalInstance()); // this sets the parent to current widget - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NStandardItemModel(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NStandardItemModel(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QStandardItemModelWrap: Wrong number of " + "arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QStatusBar/qstatusbar_wrap.cpp b/src/cpp/lib/QtWidgets/QStatusBar/qstatusbar_wrap.cpp index 06965262f..935811104 100644 --- a/src/cpp/lib/QtWidgets/QStatusBar/qstatusbar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QStatusBar/qstatusbar_wrap.cpp @@ -28,10 +28,11 @@ Napi::Object QStatusBarWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QStatusBarWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QStatusBar, QStatusBarWrap); return exports; } -NStatusBar *QStatusBarWrap::getInternalInstance() { return this->instance; } +QStatusBar *QStatusBarWrap::getInternalInstance() { return this->instance; } Napi::Value QStatusBarWrap::fromQStatusBar(Napi::Env env, QStatusBar *statusBar) { @@ -50,22 +51,29 @@ QStatusBarWrap::~QStatusBarWrap() { extrautils::safeDelete(this->instance); } QStatusBarWrap::QStatusBarWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap *parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - - this->instance = new NStatusBar(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NStatusBar(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap *parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NStatusBar(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QStatusBarWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QStatusBarWrap::addPermanentWidget(const Napi::CallbackInfo &info) { diff --git a/src/cpp/lib/QtWidgets/QSvgWidget/qsvgwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QSvgWidget/qsvgwidget_wrap.cpp index 52ca63adb..86539a9fa 100644 --- a/src/cpp/lib/QtWidgets/QSvgWidget/qsvgwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSvgWidget/qsvgwidget_wrap.cpp @@ -16,30 +16,40 @@ Napi::Object QSvgWidgetWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QSvgWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QSvgWidget, QSvgWidgetWrap); return exports; } -NSvgWidget* QSvgWidgetWrap::getInternalInstance() { return this->instance; } +QSvgWidget* QSvgWidgetWrap::getInternalInstance() { return this->instance; } QSvgWidgetWrap::~QSvgWidgetWrap() { extrautils::safeDelete(this->instance); } QSvgWidgetWrap::QSvgWidgetWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NSvgWidget(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NSvgWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NSvgWidget(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QSvgWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QSvgWidgetWrap::load(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp b/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp index 59d28d255..1f3ab8ff2 100644 --- a/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp @@ -25,27 +25,37 @@ Napi::Object QSystemTrayIconWrap::init(Napi::Env env, Napi::Object exports) { QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QSystemTrayIconWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QSystemTrayIcon, QSystemTrayIconWrap); return exports; } -NSystemTrayIcon* QSystemTrayIconWrap::getInternalInstance() { +QSystemTrayIcon* QSystemTrayIconWrap::getInternalInstance() { return this->instance; } QSystemTrayIconWrap::QSystemTrayIconWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NSystemTrayIcon( - parentWidgetWrap - ->getInternalInstance()); // this sets the parent to current widget - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NSystemTrayIcon(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NSystemTrayIcon(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New(env, + "NodeGui: QSystemTrayIconWrap: Wrong number of " + "arguments to constructor") .ThrowAsJavaScriptException(); } this->rawData = extrautils::configureQObject(this->getInternalInstance()); diff --git a/src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp b/src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp index e1f28d7a3..3cc804f30 100644 --- a/src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp @@ -43,44 +43,39 @@ Napi::Object QTabBarWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QTabBarWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTabBar, QTabBarWrap); return exports; } -NTabBar* QTabBarWrap::getInternalInstance() { return this->instance; } +QTabBar* QTabBarWrap::getInternalInstance() { return this->instance; } -QTabBarWrap::~QTabBarWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QTabBarWrap::~QTabBarWrap() { extrautils::safeDelete(this->instance); } QTabBarWrap::QTabBarWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - // --- regular cases --- - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NTabBar(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NTabBar(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NTabBar(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, "NodeGui: QTabBarWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QTabBarWrap::setAccessibleTabName(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp index 88f97df25..fa873bd85 100644 --- a/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp @@ -26,32 +26,40 @@ Napi::Object QTabWidgetWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QTabWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTabWidget, QTabWidgetWrap); return exports; } -NTabWidget* QTabWidgetWrap::getInternalInstance() { return this->instance; } +QTabWidget* QTabWidgetWrap::getInternalInstance() { return this->instance; } QTabWidgetWrap::~QTabWidgetWrap() { extrautils::safeDelete(this->instance); } QTabWidgetWrap::QTabWidgetWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTabWidget( - parentWidgetWrap - ->getInternalInstance()); // this sets the parent to current widget - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NTabWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NTabWidget(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QTabWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QTabWidgetWrap::addTab(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QTableView/qtableview_wrap.cpp b/src/cpp/lib/QtWidgets/QTableView/qtableview_wrap.cpp index 2fe5dfc6d..debf4c6ea 100644 --- a/src/cpp/lib/QtWidgets/QTableView/qtableview_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTableView/qtableview_wrap.cpp @@ -12,42 +12,38 @@ Napi::Object QTableViewWrap::init(Napi::Env env, Napi::Object exports) { {QTABLEVIEW_WRAPPED_METHODS_EXPORT_DEFINE(QTableViewWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTableView, QTableViewWrap); return exports; } -NTableView* QTableViewWrap::getInternalInstance() { return this->instance; } +QTableView* QTableViewWrap::getInternalInstance() { return this->instance; } -QTableViewWrap::~QTableViewWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QTableViewWrap::~QTableViewWrap() { extrautils::safeDelete(this->instance); } QTableViewWrap::QTableViewWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - // --- regular cases --- - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NTableView(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NTableView(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NTableView(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, + "NodeGui: QTableViewWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } diff --git a/src/cpp/lib/QtWidgets/QTableWidget/qtablewidget_wrap.cpp b/src/cpp/lib/QtWidgets/QTableWidget/qtablewidget_wrap.cpp index 090089512..3320a5823 100644 --- a/src/cpp/lib/QtWidgets/QTableWidget/qtablewidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTableWidget/qtablewidget_wrap.cpp @@ -86,10 +86,12 @@ Napi::Object QTableWidgetWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(QTableWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTableWidget, QTableWidgetWrap); return exports; } -NTableWidget* QTableWidgetWrap::getInternalInstance() { return this->instance; } +QTableWidget* QTableWidgetWrap::getInternalInstance() { return this->instance; } + QTableWidgetWrap::~QTableWidgetWrap() { extrautils::safeDelete(this->instance); } @@ -97,34 +99,43 @@ QTableWidgetWrap::~QTableWidgetWrap() { QTableWidgetWrap::QTableWidgetWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 2 || info.Length() == 3) { - int rows = info[0].As().Int32Value(); - int columns = info[1].As().Int32Value(); - if (info.Length() == 3) { - Napi::Object parentObject = info[2].As(); + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NTableWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTableWidget( - rows, columns, parentWidgetWrap->getInternalInstance()); - } else { - this->instance = new NTableWidget(rows, columns); + this->instance = + new NTableWidget(parentWidgetWrap->getInternalInstance()); } - - } else if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); + } else if (argCount == 2) { + int rows = info[0].As().Int32Value(); + int columns = info[1].As().Int32Value(); + this->instance = new NTableWidget(rows, columns); + } else if (argCount == 3) { + int rows = info[0].As().Int32Value(); + int columns = info[1].As().Int32Value(); + Napi::Object parentObject = info[2].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTableWidget(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NTableWidget(); + this->instance = new NTableWidget(rows, columns, + parentWidgetWrap->getInternalInstance()); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QTableWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } Napi::Value QTableWidgetWrap::selectedRanges(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.cpp b/src/cpp/lib/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.cpp index b8f75a4cd..626602d9b 100644 --- a/src/cpp/lib/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.cpp @@ -65,19 +65,20 @@ QTableWidgetItemWrap::~QTableWidgetItemWrap() { QTableWidgetItemWrap::QTableWidgetItemWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); + size_t argCount = info.Length(); this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { + if (argCount > 0 && info[0].IsExternal()) { // --- if external --- this->instance = info[0].As>().Data(); - if (info.Length() == 2) { + if (argCount == 2) { this->disableDeletion = info[1].As().Value(); } } else { - if (info.Length() == 1) { + if (argCount == 1) { QString text = QString::fromUtf8(info[0].As().Utf8Value().c_str()); this->instance = new QTableWidgetItem(text); - } else if (info.Length() == 0) { + } else if (argCount == 0) { this->instance = new QTableWidgetItem(); } else { Napi::TypeError::New(env, diff --git a/src/cpp/lib/QtWidgets/QTextBrowser/qtextbrowser_wrap.cpp b/src/cpp/lib/QtWidgets/QTextBrowser/qtextbrowser_wrap.cpp index cccc02e7e..cd0e4cd9d 100644 --- a/src/cpp/lib/QtWidgets/QTextBrowser/qtextbrowser_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTextBrowser/qtextbrowser_wrap.cpp @@ -30,28 +30,39 @@ Napi::Object QTextBrowserWrap::init(Napi::Env env, Napi::Object exports) { QTEXTEDIT_WRAPPED_METHODS_EXPORT_DEFINE(QTextBrowserWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTextBrowser, QTextBrowserWrap); return exports; } -NTextBrowser* QTextBrowserWrap::getInternalInstance() { return this->instance; } +QTextBrowser* QTextBrowserWrap::getInternalInstance() { return this->instance; } QTextBrowserWrap::QTextBrowserWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTextBrowser(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NTextBrowser(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NTextBrowser(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QTextBrowserWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QTextBrowserWrap::~QTextBrowserWrap() { diff --git a/src/cpp/lib/QtWidgets/QTextEdit/qtextedit_wrap.cpp b/src/cpp/lib/QtWidgets/QTextEdit/qtextedit_wrap.cpp index 9f7c00595..e0ae6c127 100644 --- a/src/cpp/lib/QtWidgets/QTextEdit/qtextedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTextEdit/qtextedit_wrap.cpp @@ -14,28 +14,37 @@ Napi::Object QTextEditWrap::init(Napi::Env env, Napi::Object exports) { env, CLASSNAME, {QTEXTEDIT_WRAPPED_METHODS_EXPORT_DEFINE(QTextEditWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTextEdit, QTextEditWrap); return exports; } -NTextEdit* QTextEditWrap::getInternalInstance() { return this->instance; } +QTextEdit* QTextEditWrap::getInternalInstance() { return this->instance; } QTextEditWrap::QTextEditWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTextEdit(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NTextEdit(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NTextEdit(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QTextEditWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QTextEditWrap::~QTextEditWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QTimeEdit/qtimeedit_wrap.cpp b/src/cpp/lib/QtWidgets/QTimeEdit/qtimeedit_wrap.cpp index b65ca8046..aad63c731 100644 --- a/src/cpp/lib/QtWidgets/QTimeEdit/qtimeedit_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTimeEdit/qtimeedit_wrap.cpp @@ -12,28 +12,37 @@ Napi::Object QTimeEditWrap::init(Napi::Env env, Napi::Object exports) { {QDATETIMEEDIT_WRAPPED_METHODS_EXPORT_DEFINE(QTimeEditWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTimeEdit, QTimeEditWrap); return exports; } -NTimeEdit* QTimeEditWrap::getInternalInstance() { return this->instance; } +QTimeEdit* QTimeEditWrap::getInternalInstance() { return this->instance; } QTimeEditWrap::QTimeEditWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTimeEdit(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NTimeEdit(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NTimeEdit(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QTimeEditWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QTimeEditWrap::~QTimeEditWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QToolButton/qtoolbutton_wrap.cpp b/src/cpp/lib/QtWidgets/QToolButton/qtoolbutton_wrap.cpp index e763fbf72..d809aa9d1 100644 --- a/src/cpp/lib/QtWidgets/QToolButton/qtoolbutton_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QToolButton/qtoolbutton_wrap.cpp @@ -18,43 +18,40 @@ Napi::Object QToolButtonWrap::init(Napi::Env env, Napi::Object exports) { QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE(QToolButtonWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QToolButton, QToolButtonWrap); return exports; } -NToolButton* QToolButtonWrap::getInternalInstance() { return this->instance; } +QToolButton* QToolButtonWrap::getInternalInstance() { return this->instance; } -QToolButtonWrap::~QToolButtonWrap() { - if (!this->disableDeletion) { - extrautils::safeDelete(this->instance); - } -} +QToolButtonWrap::~QToolButtonWrap() { extrautils::safeDelete(this->instance); } QToolButtonWrap::QToolButtonWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - this->disableDeletion = false; - if (info.Length() > 0 && info[0].IsExternal()) { - // --- if external --- - this->instance = info[0].As>().Data(); - if (info.Length() == 2) { - this->disableDeletion = info[1].As().Value(); - } - } else { - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NToolButton(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NToolButton(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { - this->instance = new NToolButton(); - } else { - Napi::TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); } + } else { + Napi::TypeError::New( + env, + "NodeGui: QToolButtonWrap: Wrong number of arguments to constructor") + .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } Napi::Value QToolButtonWrap::setMenu(const Napi::CallbackInfo& info) { diff --git a/src/cpp/lib/QtWidgets/QTreeWidget/qtreewidget_wrap.cpp b/src/cpp/lib/QtWidgets/QTreeWidget/qtreewidget_wrap.cpp index 618ee9740..19884ed7c 100644 --- a/src/cpp/lib/QtWidgets/QTreeWidget/qtreewidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTreeWidget/qtreewidget_wrap.cpp @@ -32,28 +32,38 @@ Napi::Object QTreeWidgetWrap::init(Napi::Env env, Napi::Object exports) { QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QTreeWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); + QOBJECT_REGISTER_WRAPPER(QTreeWidget, QTreeWidgetWrap); return exports; } -NTreeWidget* QTreeWidgetWrap::getInternalInstance() { return this->instance; } +QTreeWidget* QTreeWidgetWrap::getInternalInstance() { return this->instance; } QTreeWidgetWrap::QTreeWidgetWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { - Napi::Object parentObject = info[0].As(); - NodeWidgetWrap* parentWidgetWrap = - Napi::ObjectWrap::Unwrap(parentObject); - this->instance = new NTreeWidget(parentWidgetWrap->getInternalInstance()); - } else if (info.Length() == 0) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance this->instance = new NTreeWidget(); + } else if (argCount == 1) { + if (info[0].IsExternal()) { + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); + } else { + // --- Construct a new instance and pass a parent + Napi::Object parentObject = info[0].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NTreeWidget(parentWidgetWrap->getInternalInstance()); + } } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, + "NodeGui: QTreeWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - true); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), true); } QTreeWidgetWrap::~QTreeWidgetWrap() { extrautils::safeDelete(this->instance); } diff --git a/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp index 3d0976535..272a5db35 100644 --- a/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QWidget/qwidget_wrap.cpp @@ -12,34 +12,37 @@ Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) { env, CLASSNAME, {QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); - QOBJECT_REGISTER_WRAPPER(NWidget, QWidgetWrap); + QOBJECT_REGISTER_WRAPPER(QWidget, QWidgetWrap); return exports; } -NWidget *QWidgetWrap::getInternalInstance() { return this->instance; } +QWidget *QWidgetWrap::getInternalInstance() { return this->instance; } QWidgetWrap::~QWidgetWrap() { extrautils::safeDelete(this->instance); } QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) { Napi::Env env = info.Env(); - if (info.Length() == 1) { + size_t argCount = info.Length(); + if (argCount == 0) { + // --- Construct a new instance + this->instance = new NWidget(); + } else if (argCount == 1) { if (info[0].IsExternal()) { - this->instance = - new NWidget(info[0].As>().Data()); + // --- Wrap a given C++ instance + this->instance = info[0].As>().Data(); } else { + // --- Construct a new instance and pass a parent Napi::Object parentObject = info[0].As(); NodeWidgetWrap *parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); this->instance = new NWidget(parentWidgetWrap->getInternalInstance()); } - } else if (info.Length() == 0) { - this->instance = new NWidget(); } else { - Napi::TypeError::New(env, "Wrong number of arguments") + Napi::TypeError::New( + env, "NodeGui: QWidgetWrap: Wrong number of arguments to constructor") .ThrowAsJavaScriptException(); } - this->rawData = extrautils::configureQWidget( - this->getInternalInstance(), this->getInternalInstance()->getFlexNode(), - false); + this->rawData = + extrautils::configureQWidget(this->getInternalInstance(), false); } diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 90b135276..39609727a 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -122,16 +122,14 @@ #include "test/cachetestqobject_wrap.h" // These cant be instantiated in JS Side -void InitPrivateHelpers(Napi::Env env) { - qodeIntegration::integrate(); - QLayoutWrap::init(env); // Abstact class wrapper for pointing to any layout -} +void InitPrivateHelpers(Napi::Env env) { qodeIntegration::integrate(); } Napi::Object Main(Napi::Env env, Napi::Object exports) { InitPrivateHelpers(env); NUtilsWrap::init(env, exports); WrapperCache::init(env, exports); QApplicationWrap::init(env, exports); + QLayoutWrap::init(env, exports); QDateWrap::init(env, exports); QDateTimeWrap::init(env, exports); QMimeDataWrap::init(env, exports); diff --git a/src/lib/QtCore/QObject.ts b/src/lib/QtCore/QObject.ts index b3b4ad450..34899473f 100644 --- a/src/lib/QtCore/QObject.ts +++ b/src/lib/QtCore/QObject.ts @@ -21,8 +21,6 @@ export class QObject extends Ev super(native); wrapperCache.store(this); - - this.setNodeParent(parent); } inherits(className: string): boolean { diff --git a/src/lib/QtWidgets/QAbstractScrollArea.ts b/src/lib/QtWidgets/QAbstractScrollArea.ts index 7fb63a4ac..5e786404b 100644 --- a/src/lib/QtWidgets/QAbstractScrollArea.ts +++ b/src/lib/QtWidgets/QAbstractScrollArea.ts @@ -3,6 +3,7 @@ import { QFrame, QFrameSignals } from './QFrame'; import { ScrollBarPolicy } from '../QtEnums/ScrollBarPolicy'; import { QSize } from '../QtCore/QSize'; import { QScrollBar } from './QScrollBar'; +import { wrapperCache } from '../core/WrapperCache'; /** @@ -18,16 +19,11 @@ QAbstractScrollArea will list all methods and properties that are common to all */ export abstract class QAbstractScrollArea extends QFrame { - viewportWidget?: QWidget; setViewport(widget: QWidget): void { - this.viewportWidget = widget; this.native.setViewport(widget.native); } viewport(): QWidget { - if (!this.viewportWidget) { - this.viewportWidget = new QWidget(this.native.viewport()); - } - return this.viewportWidget; + return wrapperCache.getWrapper(this.native.viewport()) as QWidget; } maximumViewportSize(): QSize { return this.native.maximumViewportSize(); diff --git a/src/lib/QtWidgets/QAction.ts b/src/lib/QtWidgets/QAction.ts index d79e8ef90..096cc3ecc 100644 --- a/src/lib/QtWidgets/QAction.ts +++ b/src/lib/QtWidgets/QAction.ts @@ -9,6 +9,7 @@ import { ShortcutContext } from '../QtEnums'; import { QObject, QObjectSignals } from '../QtCore/QObject'; import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from '../QtCore/QVariant'; +import { wrapperCache } from '../core/WrapperCache'; /** @@ -34,11 +35,12 @@ export class QAction extends QObject { constructor(); constructor(native: NativeElement); constructor(parent: QWidget); - constructor(parent?: NativeElement | QWidget) { + constructor(arg?: NativeElement | QWidget) { let native: NativeElement; - if (checkIfNativeElement(parent)) { - native = parent as NativeElement; - } else if (parent) { + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else if (arg) { + const parent = arg as QWidget; native = new addon.QAction(parent.native); } else { native = new addon.QAction(); @@ -101,3 +103,4 @@ export interface QActionSignals extends QObjectSignals { hovered: () => void; toggled: (checked: boolean) => void; } +wrapperCache.registerWrapper('QActionWrap', QAction); diff --git a/src/lib/QtWidgets/QBoxLayout.ts b/src/lib/QtWidgets/QBoxLayout.ts index 5c57c4935..731939284 100644 --- a/src/lib/QtWidgets/QBoxLayout.ts +++ b/src/lib/QtWidgets/QBoxLayout.ts @@ -3,6 +3,8 @@ import { QWidget } from './QWidget'; import { QLayout, QLayoutSignals } from './QLayout'; import { NativeElement } from '../core/Component'; import { AlignmentFlag, Direction } from '../QtEnums'; +import { checkIfNativeElement } from '../utils/helpers'; +import { wrapperCache } from '../core/WrapperCache'; /** @@ -26,21 +28,19 @@ centralWidget.setLayout(boxLayout); ``` */ export class QBoxLayout extends QLayout { - childLayouts: Set; - constructor(dir: Direction, parent?: QWidget) { + constructor(arg: NativeElement | Direction, parent?: QWidget) { let native: NativeElement; - if (parent) { - native = new addon.QBoxLayout(dir, parent.native); + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else if (parent) { + native = new addon.QBoxLayout(arg as Direction, parent.native); } else { - native = new addon.QBoxLayout(dir); + native = new addon.QBoxLayout(arg as Direction); } super(native); - this.setNodeParent(parent); - this.childLayouts = new Set(); } - addLayout(layout: QLayout, stretch = 0): void { + addLayout(layout: QLayout, stretch = 0): void { this.native.addLayout(layout.native, stretch); - this.childLayouts.add(layout); } addSpacing(size: number): void { this.native.addSpacing(size); @@ -53,18 +53,15 @@ export class QBoxLayout extends QLayout { } addWidget(widget: QWidget, stretch = 0, alignment: AlignmentFlag = 0): void { this.native.addWidget(widget.native, stretch, alignment); - this.nodeChildren.add(widget); } insertWidget(index: number, widget: QWidget, stretch = 0): void { this.native.insertWidget(index, widget.native, stretch); - this.nodeChildren.add(widget); } direction(): Direction { return this.native.direction(); } insertLayout(index: number, layout: QLayout, stretch = 0): void { this.native.insertLayout(index, layout.native, stretch); - this.childLayouts.add(layout); } insertSpacing(index: number, size: number): void { this.native.insertSpacing(index, size); @@ -74,7 +71,6 @@ export class QBoxLayout extends QLayout { } removeWidget(widget: QWidget): void { this.native.removeWidget(widget.native); - this.nodeChildren.delete(widget); } setDirection(dir: Direction): void { this.native.setDirection(dir); @@ -86,5 +82,6 @@ export class QBoxLayout extends QLayout { return this.native.count(); } } +wrapperCache.registerWrapper('QBoxLayoutWrap', QBoxLayout); export type QBoxLayoutSignals = QLayoutSignals; diff --git a/src/lib/QtWidgets/QButtonGroup.ts b/src/lib/QtWidgets/QButtonGroup.ts index acfccc633..c18cd8e9d 100644 --- a/src/lib/QtWidgets/QButtonGroup.ts +++ b/src/lib/QtWidgets/QButtonGroup.ts @@ -1,31 +1,33 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NativeRawPointer } from '../core/Component'; +import { NativeElement, NativeRawPointer } from '../core/Component'; import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; +import { checkIfNativeElement } from '../utils/helpers'; +import { wrapperCache } from '../core/WrapperCache'; export interface QButtonGroupSignals extends QObjectSignals { buttonClicked: (id?: number) => void; } export class QButtonGroup extends QObject { - constructor(parent?: QWidget) { + constructor(arg?: NativeElement | QWidget) { let native; - if (parent) { + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else if (arg) { + const parent = arg as QWidget; native = new addon.QButtonGroup(parent.native); } else { native = new addon.QButtonGroup(); } super(native); - parent && parent.nodeChildren.add(this); } addButton(button: QAbstractButton, id = -1): void { this.native.addButton(button.native, id); - this.nodeChildren.add(button); } removeButton(button: QAbstractButton): void { this.native.removeButton(button.native); - this.nodeChildren.delete(button); } setExclusive(exculsive: boolean): void { this.native.setProperty('exclusive', exculsive); @@ -52,3 +54,4 @@ export class QButtonGroup extends QObject { return this.native.button(id); } } +wrapperCache.registerWrapper('QButtonGroupWrap', QButtonGroup); diff --git a/src/lib/QtWidgets/QCalendarWidget.ts b/src/lib/QtWidgets/QCalendarWidget.ts index 82c4f026f..b3cd0154d 100644 --- a/src/lib/QtWidgets/QCalendarWidget.ts +++ b/src/lib/QtWidgets/QCalendarWidget.ts @@ -3,6 +3,8 @@ import { QWidget, QWidgetSignals } from './QWidget'; import { NativeElement } from '../core/Component'; import { QDate } from '../QtCore/QDate'; import { DayOfWeek } from '../QtEnums'; +import { checkIfNativeElement } from '../utils/helpers'; +import { wrapperCache } from '../core/WrapperCache'; /** @@ -22,15 +24,17 @@ const calendarWidget = new QCalendarWidget(); ``` */ export class QCalendarWidget extends QWidget { - constructor(parent?: QWidget) { + constructor(arg?: NativeElement | QWidget) { let native: NativeElement; - if (parent) { + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else if (arg as QWidget) { + const parent = arg as QWidget; native = new addon.QCalendarWidget(parent.native); } else { native = new addon.QCalendarWidget(); } super(native); - this.setNodeParent(parent); } setDateEditAcceptDelay(delay: number): void { this.setProperty('dateEditAcceptDelay', delay); @@ -81,6 +85,7 @@ export class QCalendarWidget extends QWidget { return this.property('verticalHeaderFormat').toInt(); } } +wrapperCache.registerWrapper('QCalendarWidgetWrap', QCalendarWidget); export enum HorizontalHeaderFormat { NoHorizontalHeader, diff --git a/src/lib/QtWidgets/QCheckBox.ts b/src/lib/QtWidgets/QCheckBox.ts index 8507ade5f..eeddd433c 100644 --- a/src/lib/QtWidgets/QCheckBox.ts +++ b/src/lib/QtWidgets/QCheckBox.ts @@ -1,9 +1,10 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NativeElement, NativeRawPointer, Component } from '../core/Component'; +import { NativeElement, NativeRawPointer } from '../core/Component'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; import { checkIfNativeElement, checkIfNapiExternal } from '../utils/helpers'; import { CheckState } from '../QtEnums'; +import { wrapperCache } from '../core/WrapperCache'; /** @@ -25,23 +26,20 @@ checkbox.setText("Hello"); export class QCheckBox extends QAbstractButton { constructor(); constructor(parent: QWidget); - constructor(rawPointer: NativeRawPointer, disableNativeDeletion?: boolean); - constructor(arg?: QWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { + constructor(rawPointer: NativeRawPointer); + constructor(arg?: QWidget | NativeRawPointer | NativeElement) { let native; - let parent: Component | undefined; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (checkIfNapiExternal(arg)) { - native = new addon.QCheckBox(arg, disableNativeDeletion); + native = new addon.QCheckBox(arg); } else if (arg) { const parentWidget = arg as QWidget; native = new addon.QCheckBox(parentWidget.native); - parent = parentWidget; } else { native = new addon.QCheckBox(); } super(native); - parent && this.setNodeParent(parent); } setTristate(y = true): void { this.setProperty('tristate', y); @@ -56,6 +54,7 @@ export class QCheckBox extends QAbstractButton { this.native.setCheckState(state); } } +wrapperCache.registerWrapper('QCheckBoxWrap', QCheckBox); export interface QCheckBoxSignals extends QAbstractButtonSignals { stateChanged: (state: number) => void; diff --git a/src/lib/QtWidgets/QColorDialog.ts b/src/lib/QtWidgets/QColorDialog.ts index fcd6941cc..8699f5843 100644 --- a/src/lib/QtWidgets/QColorDialog.ts +++ b/src/lib/QtWidgets/QColorDialog.ts @@ -35,7 +35,6 @@ export class QColorDialog extends QDialog { native = new addon.QColorDialog(); } super(native); - parent && this.setNodeParent(parent); } setCurrentColor(color: QColor): void { this.setProperty('currentColor', color.native); diff --git a/src/lib/QtWidgets/QComboBox.ts b/src/lib/QtWidgets/QComboBox.ts index f25812da8..19b00ba06 100644 --- a/src/lib/QtWidgets/QComboBox.ts +++ b/src/lib/QtWidgets/QComboBox.ts @@ -45,7 +45,6 @@ export class QComboBox extends QWidget { native = new addon.QComboBox(); } super(native); - this.setNodeParent(parent); } // *** Public Functions *** addItem(icon: QIcon | undefined, text: string, userData: QVariant = new QVariant()): void { diff --git a/src/lib/QtWidgets/QDateEdit.ts b/src/lib/QtWidgets/QDateEdit.ts index a80e4ce3a..d1f9a9530 100644 --- a/src/lib/QtWidgets/QDateEdit.ts +++ b/src/lib/QtWidgets/QDateEdit.ts @@ -29,6 +29,5 @@ export class QDateEdit extends QDateTimeEdit { native = new addon.QDateEdit(); } super(native); - this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QDateTimeEdit.ts b/src/lib/QtWidgets/QDateTimeEdit.ts index b09d8360f..140569098 100644 --- a/src/lib/QtWidgets/QDateTimeEdit.ts +++ b/src/lib/QtWidgets/QDateTimeEdit.ts @@ -37,19 +37,15 @@ export class QDateTimeEdit extends QAbstractSpinBox { constructor(arg?: QWidget | NativeElement) { let native: NativeElement; - let parent: QWidget = null; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (arg) { - parent = arg as QWidget; + const parent = arg as QWidget; native = new addon.QDateTimeEdit(parent.native); } else { native = new addon.QDateTimeEdit(); } super(native); - if (parent != null) { - this.setNodeParent(parent); - } } setCalendarWidget(calendarWidget: QCalendarWidget): void { diff --git a/src/lib/QtWidgets/QDial.ts b/src/lib/QtWidgets/QDial.ts index 5fa4c8abd..8982bc018 100644 --- a/src/lib/QtWidgets/QDial.ts +++ b/src/lib/QtWidgets/QDial.ts @@ -30,7 +30,6 @@ export class QDial extends QAbstractSlider { native = new addon.QDial(); } super(native); - this.setNodeParent(parent); } notchSize(): number { return this.property('notchSize').toInt(); diff --git a/src/lib/QtWidgets/QDialog.ts b/src/lib/QtWidgets/QDialog.ts index fdf692670..26e22bd49 100644 --- a/src/lib/QtWidgets/QDialog.ts +++ b/src/lib/QtWidgets/QDialog.ts @@ -26,7 +26,6 @@ export class QDialog extends QW native = new addon.QDialog(); } super(native); - this.setNodeParent(parent); } setResult(i: number): void { diff --git a/src/lib/QtWidgets/QDoubleSpinBox.ts b/src/lib/QtWidgets/QDoubleSpinBox.ts index 589c96805..8e1fe54f9 100644 --- a/src/lib/QtWidgets/QDoubleSpinBox.ts +++ b/src/lib/QtWidgets/QDoubleSpinBox.ts @@ -28,7 +28,6 @@ export class QDoubleSpinBox extends QAbstractSpinBox { native = new addon.QDoubleSpinBox(); } super(native); - parent && this.setNodeParent(parent); } cleanText(): string { return this.property('cleanText').toString(); diff --git a/src/lib/QtWidgets/QErrorMessage.ts b/src/lib/QtWidgets/QErrorMessage.ts index 431a503be..03fee08b6 100644 --- a/src/lib/QtWidgets/QErrorMessage.ts +++ b/src/lib/QtWidgets/QErrorMessage.ts @@ -29,7 +29,6 @@ export class QErrorMessage extends QDialog { native = new addon.QErrorMessage(); } super(native); - parent && this.setNodeParent(parent); } showMessage(message: string): void { this.native.showMessage(message); diff --git a/src/lib/QtWidgets/QFileDialog.ts b/src/lib/QtWidgets/QFileDialog.ts index 0d5243f41..a5b0c55f4 100644 --- a/src/lib/QtWidgets/QFileDialog.ts +++ b/src/lib/QtWidgets/QFileDialog.ts @@ -38,7 +38,6 @@ export class QFileDialog extends QDialog { native = new addon.QFileDialog(); } super(native); - this.setNodeParent(parent); } supportedSchemes(): string[] { return this.native.supportedSchemes(); diff --git a/src/lib/QtWidgets/QFontDialog.ts b/src/lib/QtWidgets/QFontDialog.ts index f8c6bb308..41b9f1857 100644 --- a/src/lib/QtWidgets/QFontDialog.ts +++ b/src/lib/QtWidgets/QFontDialog.ts @@ -33,7 +33,6 @@ export class QFontDialog extends QDialog { native = new addon.QFontDialog(); } super(native); - parent && this.setNodeParent(parent); } setCurrentFont(font: QFont): void { this.setProperty('currentFont', font.native); diff --git a/src/lib/QtWidgets/QFrame.ts b/src/lib/QtWidgets/QFrame.ts index bac971517..aabdaaace 100644 --- a/src/lib/QtWidgets/QFrame.ts +++ b/src/lib/QtWidgets/QFrame.ts @@ -32,7 +32,6 @@ export class QFrame extends QWidg native = new addon.QFrame(); } super(native); - this.setNodeParent(parent); } setFrameRect(r: QRect): void { diff --git a/src/lib/QtWidgets/QGridLayout.ts b/src/lib/QtWidgets/QGridLayout.ts index 9672d8fe0..89485aed6 100644 --- a/src/lib/QtWidgets/QGridLayout.ts +++ b/src/lib/QtWidgets/QGridLayout.ts @@ -38,7 +38,6 @@ export class QGridLayout extends QLayout { native = new addon.QGridLayout(); } super(native); - this.setNodeParent(parent); } addLayout( @@ -54,11 +53,9 @@ export class QGridLayout extends QLayout { addWidget(widget: QWidget, row = 0, col = 0, rowSpan = 1, colSpan = 1, alignment: AlignmentFlag = 0): void { this.native.addWidget(widget.native, row, col, rowSpan, colSpan, alignment); - this.nodeChildren.add(widget); } removeWidget(widget: QWidget): void { this.native.removeWidget(widget.native); - this.nodeChildren.delete(widget); } columnStretch(column: number): number { return this.native.columnStretch(column); diff --git a/src/lib/QtWidgets/QGroupBox.ts b/src/lib/QtWidgets/QGroupBox.ts index 13f590a32..98e613f0a 100644 --- a/src/lib/QtWidgets/QGroupBox.ts +++ b/src/lib/QtWidgets/QGroupBox.ts @@ -48,7 +48,6 @@ export class QGroupBox extends QWidget { native = new addon.QGroupBox(); } super(native); - this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { this.setProperty('alignment', alignment); diff --git a/src/lib/QtWidgets/QHeaderView.ts b/src/lib/QtWidgets/QHeaderView.ts index 70f68f803..1ae937c71 100644 --- a/src/lib/QtWidgets/QHeaderView.ts +++ b/src/lib/QtWidgets/QHeaderView.ts @@ -24,7 +24,6 @@ export class QHeaderView { native = new addon.QInputDialog(); } super(native); - this.setNodeParent(parent); } setCancelButtonText(text: string): void { this.native.setCancelButtonText(text); diff --git a/src/lib/QtWidgets/QLCDNumber.ts b/src/lib/QtWidgets/QLCDNumber.ts index 79ee70293..53c1d6475 100644 --- a/src/lib/QtWidgets/QLCDNumber.ts +++ b/src/lib/QtWidgets/QLCDNumber.ts @@ -28,7 +28,6 @@ export class QLCDNumber extends QWidget { native = new addon.QLCDNumber(); } super(native); - parent && this.setNodeParent(parent); } setDigitCount(numDigits: number): void { this.setProperty('digitCount', numDigits); diff --git a/src/lib/QtWidgets/QLabel.ts b/src/lib/QtWidgets/QLabel.ts index b71c10679..0afcd2c86 100644 --- a/src/lib/QtWidgets/QLabel.ts +++ b/src/lib/QtWidgets/QLabel.ts @@ -40,7 +40,6 @@ export class QLabel extends QFrame { native = new addon.QLabel(); } super(native); - this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { this.setProperty('alignment', alignment); diff --git a/src/lib/QtWidgets/QLineEdit.ts b/src/lib/QtWidgets/QLineEdit.ts index 9fb2bc46d..3ad55ee80 100644 --- a/src/lib/QtWidgets/QLineEdit.ts +++ b/src/lib/QtWidgets/QLineEdit.ts @@ -30,7 +30,6 @@ export class QLineEdit extends QWidget { native = new addon.QLineEdit(); } super(native); - this.setNodeParent(parent); } // TODO: void addAction(QAction *action, QLineEdit::ActionPosition position) // TODO: QAction * addAction(const QIcon &icon, QLineEdit::ActionPosition position) diff --git a/src/lib/QtWidgets/QListView.ts b/src/lib/QtWidgets/QListView.ts index 745d131c7..1e0c26873 100644 --- a/src/lib/QtWidgets/QListView.ts +++ b/src/lib/QtWidgets/QListView.ts @@ -4,6 +4,7 @@ import { NativeElement } from '../core/Component'; import { QAbstractItemView, QAbstractItemViewSignals } from './QAbstractItemView'; import { QSize } from '../QtCore/QSize'; import { AlignmentFlag } from '../..'; +import { checkIfNativeElement } from '../utils/helpers'; /** @@ -21,15 +22,17 @@ const listview = new QListView(); ``` */ export class QListView extends QAbstractItemView { - constructor(parent?: QWidget) { + constructor(arg?: QWidget | NativeElement) { let native: NativeElement; - if (parent) { + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else if (arg != null) { + const parent = arg as QWidget; native = new addon.QListView(parent.native); } else { native = new addon.QListView(); } super(native); - parent && this.setNodeParent(parent); } setBatchSize(batchSize: number): void { this.setProperty('batchSize', batchSize); diff --git a/src/lib/QtWidgets/QListWidget.ts b/src/lib/QtWidgets/QListWidget.ts index a74b300ef..c7d1d0c88 100644 --- a/src/lib/QtWidgets/QListWidget.ts +++ b/src/lib/QtWidgets/QListWidget.ts @@ -43,7 +43,6 @@ export class QListWidget extends QListView { native = new addon.QListWidget(); } super(native); - parent && this.setNodeParent(parent); this.items = new Set(); } count(): number { diff --git a/src/lib/QtWidgets/QMainWindow.ts b/src/lib/QtWidgets/QMainWindow.ts index bd906c702..90b2710d7 100644 --- a/src/lib/QtWidgets/QMainWindow.ts +++ b/src/lib/QtWidgets/QMainWindow.ts @@ -44,14 +44,12 @@ export class QMainWindow extends QWidget { native = new addon.QMainWindow(); } super(native); - this.setNodeParent(parent); this.setLayout = (parentLayout: QLayout): void => { if (this.centralWidget) { this.centralWidget.setLayout(parentLayout); } else { this.native.setLayout(parentLayout.native); - super.layout = parentLayout; } }; } @@ -80,11 +78,11 @@ export class QMainWindow extends QWidget { setMenuWidget(menuWidget: QWidget): void { this.native.setMenuWidget(menuWidget.native); } - get layout(): QLayout | undefined { + layout(): QLayout | undefined { if (this.centralWidget) { - return this.centralWidget.layout; + return this.centralWidget.layout(); } - return super.layout; + return super.layout(); } center(): void { this.native.center(); diff --git a/src/lib/QtWidgets/QMenu.ts b/src/lib/QtWidgets/QMenu.ts index c9569ed06..e5f59ae8b 100644 --- a/src/lib/QtWidgets/QMenu.ts +++ b/src/lib/QtWidgets/QMenu.ts @@ -27,7 +27,6 @@ export class QMenu extends QWidget { native = new addon.QMenu(); } super(native); - this.setNodeParent(parent); } clear(): void { this.native.clear(); diff --git a/src/lib/QtWidgets/QMenuBar.ts b/src/lib/QtWidgets/QMenuBar.ts index e74e0c779..01a2f8ffc 100644 --- a/src/lib/QtWidgets/QMenuBar.ts +++ b/src/lib/QtWidgets/QMenuBar.ts @@ -28,18 +28,15 @@ export class QMenuBar extends QWidget { constructor(arg?: QWidget | NativeElement) { let native; - let parent; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (typeof arg === 'object') { native = new addon.QMenuBar(arg.native); - parent = arg as QWidget; } else { native = new addon.QMenuBar(); } super(native); this._menus = new Set(); - this.setNodeParent(parent); } addMenu(menu: QMenu | string): QMenu { if (typeof menu === 'string') { diff --git a/src/lib/QtWidgets/QMessageBox.ts b/src/lib/QtWidgets/QMessageBox.ts index 7c08774e3..c120b7be6 100644 --- a/src/lib/QtWidgets/QMessageBox.ts +++ b/src/lib/QtWidgets/QMessageBox.ts @@ -48,7 +48,6 @@ export class QMessageBox extends QDialog { native = new addon.QMessageBox(); } super(native); - this.setNodeParent(parent); } accept(): void { this.native.accept(); @@ -78,12 +77,10 @@ export class QMessageBox extends QDialog { setDefaultButton(button: QPushButton): void { this.native.setDefaultButton(button); - this.nodeChildren.add(button); } addButton(button: QAbstractButton, role: ButtonRole = ButtonRole.NoRole): void { this.native.addButton(button.native, role); - this.nodeChildren.add(button); } static about(parent: QWidget, title: string, text: string): void { diff --git a/src/lib/QtWidgets/QPlainTextEdit.ts b/src/lib/QtWidgets/QPlainTextEdit.ts index a620ab5b0..f1daa7b60 100644 --- a/src/lib/QtWidgets/QPlainTextEdit.ts +++ b/src/lib/QtWidgets/QPlainTextEdit.ts @@ -41,7 +41,6 @@ export class QPlainTextEdit extends QAbstractScrollArea { native = new addon.QPlainTextEdit(); } super(native); - this.setNodeParent(parent); } setPlainText(text: string | number): void { // react:✓ diff --git a/src/lib/QtWidgets/QProgressBar.ts b/src/lib/QtWidgets/QProgressBar.ts index c075e28a1..5b6a91012 100644 --- a/src/lib/QtWidgets/QProgressBar.ts +++ b/src/lib/QtWidgets/QProgressBar.ts @@ -28,7 +28,6 @@ export class QProgressBar extends QWidget { native = new addon.QProgressBar(); } super(native); - this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { this.setProperty('alignment', alignment); diff --git a/src/lib/QtWidgets/QProgressDialog.ts b/src/lib/QtWidgets/QProgressDialog.ts index 031d82e70..5226948e3 100644 --- a/src/lib/QtWidgets/QProgressDialog.ts +++ b/src/lib/QtWidgets/QProgressDialog.ts @@ -28,7 +28,6 @@ export class QProgressDialog extends QDialog { native = new addon.QProgressDialog(); } super(native); - parent && this.setNodeParent(parent); } setAutoClose(close: boolean): void { this.setProperty('autoClose', close); diff --git a/src/lib/QtWidgets/QPushButton.ts b/src/lib/QtWidgets/QPushButton.ts index dcdf7b724..c13aa042c 100644 --- a/src/lib/QtWidgets/QPushButton.ts +++ b/src/lib/QtWidgets/QPushButton.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NativeElement, NativeRawPointer, Component } from '../core/Component'; +import { NativeElement, NativeRawPointer } from '../core/Component'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; import { checkIfNativeElement, checkIfNapiExternal } from '../utils/helpers'; import { QMenu } from './QMenu'; @@ -27,7 +27,6 @@ export class QPushButton extends QAbstractButton { constructor(arg?: QWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { let native; - let parent: Component | undefined; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (checkIfNapiExternal(arg)) { @@ -35,12 +34,10 @@ export class QPushButton extends QAbstractButton { } else if (arg) { const parentWidget = arg as QWidget; native = new addon.QPushButton(parentWidget.native); - parent = parentWidget; } else { native = new addon.QPushButton(); } super(native); - parent && this.setNodeParent(parent); } setAutoDefault(auto: boolean): void { this.setProperty('autoDefault', auto); diff --git a/src/lib/QtWidgets/QRadioButton.ts b/src/lib/QtWidgets/QRadioButton.ts index a274eac9c..f0ee99cf1 100644 --- a/src/lib/QtWidgets/QRadioButton.ts +++ b/src/lib/QtWidgets/QRadioButton.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NativeElement, NativeRawPointer, Component } from '../core/Component'; +import { NativeElement, NativeRawPointer } from '../core/Component'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; import { checkIfNativeElement, checkIfNapiExternal } from '../utils/helpers'; @@ -25,7 +25,6 @@ radioButton.setText("Hello"); export class QRadioButton extends QAbstractButton { constructor(arg?: QWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { let native; - let parent: Component | undefined; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (checkIfNapiExternal(arg)) { @@ -33,12 +32,10 @@ export class QRadioButton extends QAbstractButton { } else if (arg) { const parentWidget = arg as QWidget; native = new addon.QRadioButton(parentWidget.native); - parent = parentWidget; } else { native = new addon.QRadioButton(); } super(native); - parent && this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QScrollArea.ts b/src/lib/QtWidgets/QScrollArea.ts index c601bd83f..1dc6eb8db 100644 --- a/src/lib/QtWidgets/QScrollArea.ts +++ b/src/lib/QtWidgets/QScrollArea.ts @@ -4,6 +4,7 @@ import { NativeElement } from '../core/Component'; import { QAbstractScrollArea, QAbstractScrollAreaSignals } from './QAbstractScrollArea'; import { AlignmentFlag } from '../QtEnums'; import { Margins } from '../utils/Margins'; +import { wrapperCache } from '../core/WrapperCache'; /** @@ -29,7 +30,6 @@ scrollArea.setWidget(imageLabel); ``` */ export class QScrollArea extends QAbstractScrollArea { - contentWidget?: QWidget | null; constructor(parent?: QWidget) { let native: NativeElement; if (parent) { @@ -38,7 +38,6 @@ export class QScrollArea extends QAbstractScrollArea { native = new addon.QScrollArea(); } super(native); - this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { this.setProperty('alignment', alignment); @@ -59,24 +58,13 @@ export class QScrollArea extends QAbstractScrollArea { this.native.ensureWidgetVisible(childWidget.native, xmargin, ymargin); } setWidget(widget: QWidget): void { - this.contentWidget = widget; this.native.setWidget(widget.native); } widget(): QWidget | null { - if (this.contentWidget) { - return this.contentWidget; - } - return null; + return wrapperCache.getWrapper(this.native.widget()) as QWidget; } takeWidget(): QWidget | null { - // react:✓ - const contentWidget = this.contentWidget; - this.contentWidget = null; - if (contentWidget) { - this.native.takeWidget(); - return contentWidget; - } - return null; + return wrapperCache.getWrapper(this.native.takeWidget()) as QWidget; } setViewportMargins(left: number, top: number, right: number, bottom: number): void { // Technically part of QAbstractScrollArea, but the C++ side has subclass specific diff --git a/src/lib/QtWidgets/QScrollBar.ts b/src/lib/QtWidgets/QScrollBar.ts index 36083d2f7..e3557473b 100644 --- a/src/lib/QtWidgets/QScrollBar.ts +++ b/src/lib/QtWidgets/QScrollBar.ts @@ -28,7 +28,6 @@ export class QScrollBar extends QAbstractSlider { native = new addon.QScrollBar(); } super(native); - this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QSlider.ts b/src/lib/QtWidgets/QSlider.ts index 9b2667c62..bb3c4e170 100644 --- a/src/lib/QtWidgets/QSlider.ts +++ b/src/lib/QtWidgets/QSlider.ts @@ -28,7 +28,6 @@ export class QSlider extends QAbstractSlider { native = new addon.QSlider(); } super(native); - this.setNodeParent(parent); } setTickInterval(ti: number): void { this.setProperty('tickInterval', ti); diff --git a/src/lib/QtWidgets/QSpinBox.ts b/src/lib/QtWidgets/QSpinBox.ts index 899efa74b..37b7462a9 100644 --- a/src/lib/QtWidgets/QSpinBox.ts +++ b/src/lib/QtWidgets/QSpinBox.ts @@ -27,7 +27,6 @@ export class QSpinBox extends QAbstractSpinBox { native = new addon.QSpinBox(); } super(native); - this.setNodeParent(parent); } cleanText(): string { return this.property('cleanText').toString(); diff --git a/src/lib/QtWidgets/QSplitter.ts b/src/lib/QtWidgets/QSplitter.ts index 807813cd5..5218eb658 100644 --- a/src/lib/QtWidgets/QSplitter.ts +++ b/src/lib/QtWidgets/QSplitter.ts @@ -43,7 +43,6 @@ export class QSplitter extends QFrame { native = new addon.QSplitter(); } super(native); - this.setNodeParent(parent); } addWidget(widget: QWidget): void { this.native.addWidget(widget.native); diff --git a/src/lib/QtWidgets/QStackedWidget.ts b/src/lib/QtWidgets/QStackedWidget.ts index a0c45831f..289d4feae 100644 --- a/src/lib/QtWidgets/QStackedWidget.ts +++ b/src/lib/QtWidgets/QStackedWidget.ts @@ -52,13 +52,11 @@ export class QStackedWidget extends QFrame { native = new addon.QStackedWidget(); } super(native); - this.setNodeParent(parent); } // *** Public Function *** addWidget(widget: QWidget): void { this.native.addWidget(widget.native); - this.nodeChildren.add(widget); widget.setFlexNodeSizeControlled(true); } count(): number { @@ -72,7 +70,6 @@ export class QStackedWidget extends QFrame { // TODO: int insertWidget(int index, QWidget *widget) removeWidget(widget: QWidget): void { this.native.removeWidget(widget.native); - this.nodeChildren.delete(widget); } // TODO: QWidget * widget(int index) const diff --git a/src/lib/QtWidgets/QStandardItemModel.ts b/src/lib/QtWidgets/QStandardItemModel.ts index 7928094f9..f0ed26305 100644 --- a/src/lib/QtWidgets/QStandardItemModel.ts +++ b/src/lib/QtWidgets/QStandardItemModel.ts @@ -16,7 +16,6 @@ export class QStandardItemModel extends QObject { native = new addon.QStandardItemModel(); } super(native); - parent && parent.nodeChildren.add(this); } item(row: number, column = 0): QStandardItem | void { const item = this.native.item(row, column); diff --git a/src/lib/QtWidgets/QStatusBar.ts b/src/lib/QtWidgets/QStatusBar.ts index 175b0ff91..08cbe9f44 100644 --- a/src/lib/QtWidgets/QStatusBar.ts +++ b/src/lib/QtWidgets/QStatusBar.ts @@ -35,7 +35,6 @@ export class QStatusBar extends QWidget { } super(native); - this.setNodeParent(parent); this.permanentWidgets = new Set(); this.widgets = new Set(); diff --git a/src/lib/QtWidgets/QSvgWidget.ts b/src/lib/QtWidgets/QSvgWidget.ts index b4bb4a8b9..fce3feb85 100644 --- a/src/lib/QtWidgets/QSvgWidget.ts +++ b/src/lib/QtWidgets/QSvgWidget.ts @@ -35,7 +35,6 @@ export class QSvgWidget extends QWidget { native = new addon.QSvgWidget(); } super(native); - parent && this.setNodeParent(parent); } load(file: string | Buffer): void { if (file instanceof Buffer) { diff --git a/src/lib/QtWidgets/QTabBar.ts b/src/lib/QtWidgets/QTabBar.ts index 944b87c1d..004a8e16f 100644 --- a/src/lib/QtWidgets/QTabBar.ts +++ b/src/lib/QtWidgets/QTabBar.ts @@ -34,7 +34,6 @@ export class QTabBar extends QWidget { native = new addon.QTabBar(); } super(native); - parent && this.setNodeParent(parent); } setAutoHide(hide: boolean): void { this.setProperty('autoHide', hide); diff --git a/src/lib/QtWidgets/QTabWidget.ts b/src/lib/QtWidgets/QTabWidget.ts index 247e0d284..27869568d 100644 --- a/src/lib/QtWidgets/QTabWidget.ts +++ b/src/lib/QtWidgets/QTabWidget.ts @@ -35,7 +35,6 @@ export class QTabWidget extends QWidget { native = new addon.QTabWidget(); } super(native); - this.setNodeParent(parent); this.tabs = []; } diff --git a/src/lib/QtWidgets/QTableView.ts b/src/lib/QtWidgets/QTableView.ts index 1aeab815e..734bdfb1a 100644 --- a/src/lib/QtWidgets/QTableView.ts +++ b/src/lib/QtWidgets/QTableView.ts @@ -28,7 +28,6 @@ export class QTableView e native = new addon.QTableView(); } super(native); - parent && this.setNodeParent(parent); } // *** Public Functions *** clearSpans(): void { diff --git a/src/lib/QtWidgets/QTableWidget.ts b/src/lib/QtWidgets/QTableWidget.ts index 63cf79260..dd1205d7c 100644 --- a/src/lib/QtWidgets/QTableWidget.ts +++ b/src/lib/QtWidgets/QTableWidget.ts @@ -47,7 +47,6 @@ export class QTableWidget extends QAbstractScrollArea { native = new addon.QTableWidget(rows, columns); } super(native); - this.setNodeParent(parent); this.items = new Set(); } selectedRanges(): Range[] { diff --git a/src/lib/QtWidgets/QTextBrowser.ts b/src/lib/QtWidgets/QTextBrowser.ts index ca22adb1a..7e4e67a55 100644 --- a/src/lib/QtWidgets/QTextBrowser.ts +++ b/src/lib/QtWidgets/QTextBrowser.ts @@ -30,7 +30,6 @@ export class QTextBrowser extends QTextEdit { native = new addon.QTextBrowser(); } super(native); - parent && this.setNodeParent(parent); } setOpenExternalLinks(open: boolean): void { this.setProperty('openExternalLinks', open); diff --git a/src/lib/QtWidgets/QTextEdit.ts b/src/lib/QtWidgets/QTextEdit.ts index fe1e6e74c..9c5ddf12c 100644 --- a/src/lib/QtWidgets/QTextEdit.ts +++ b/src/lib/QtWidgets/QTextEdit.ts @@ -37,7 +37,6 @@ export class QTextEdit exte native = new addon.QTextEdit(); } super(native); - parent && this.setNodeParent(parent); } setAcceptRichText(accept: boolean): void { diff --git a/src/lib/QtWidgets/QTimeEdit.ts b/src/lib/QtWidgets/QTimeEdit.ts index 69b2d3a2e..7c49aae6a 100644 --- a/src/lib/QtWidgets/QTimeEdit.ts +++ b/src/lib/QtWidgets/QTimeEdit.ts @@ -28,6 +28,5 @@ export class QTimeEdit extends QDateTimeEdit { native = new addon.QTimeEdit(); } super(native); - this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QToolButton.ts b/src/lib/QtWidgets/QToolButton.ts index 9fd78bbdd..cf8c24bd6 100644 --- a/src/lib/QtWidgets/QToolButton.ts +++ b/src/lib/QtWidgets/QToolButton.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { QWidget } from './QWidget'; -import { NativeElement, NativeRawPointer, Component } from '../core/Component'; +import { NativeElement, NativeRawPointer } from '../core/Component'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; import { ToolButtonStyle } from '../QtEnums/ToolButtonStyle'; import { ArrowType } from '../QtEnums/ArrowType'; @@ -31,7 +31,6 @@ export class QToolButton extends QAbstractButton { constructor(arg?: QWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { let native; - let parent: Component | undefined; if (checkIfNativeElement(arg)) { native = arg as NativeElement; } else if (checkIfNapiExternal(arg)) { @@ -39,12 +38,10 @@ export class QToolButton extends QAbstractButton { } else if (arg) { const parentWidget = arg as QWidget; native = new addon.QToolButton(parentWidget.native); - parent = parentWidget; } else { native = new addon.QToolButton(); } super(native); - parent && this.setNodeParent(parent); } setArrowType(type: ArrowType): void { this.setProperty('arrowType', type); diff --git a/src/lib/QtWidgets/QTreeWidget.ts b/src/lib/QtWidgets/QTreeWidget.ts index 27b38a218..10fc06032 100644 --- a/src/lib/QtWidgets/QTreeWidget.ts +++ b/src/lib/QtWidgets/QTreeWidget.ts @@ -60,7 +60,6 @@ export class QTreeWidget extends QAbstractScrollArea { native = new addon.QTreeWidget(); } super(native); - this.setNodeParent(parent); this.topLevelItems = new Set(); this.itemWidgets = new Map(); } diff --git a/src/lib/QtWidgets/QTreeWidgetItem.ts b/src/lib/QtWidgets/QTreeWidgetItem.ts index c8e931c28..1cb8cd193 100644 --- a/src/lib/QtWidgets/QTreeWidgetItem.ts +++ b/src/lib/QtWidgets/QTreeWidgetItem.ts @@ -8,7 +8,7 @@ import { CheckState, ItemDataRole } from '../QtEnums'; import { QVariantType, QVariant } from '../QtCore/QVariant'; /** - + > Creates an item for QTreeWidget. * **This class is a JS wrapper around Qt's [QTreeWidgetItem class](https://doc.qt.io/qt-5/qtreewidgetitem.html)** @@ -54,13 +54,11 @@ export class QTreeWidgetItem extends Component { constructor(strings: string[]); constructor(parent?: NativeElement | QTreeWidgetItem | QTreeWidget | string[], strings?: string[]) { let native: NativeElement; - let parentTreeWidgetItem: QTreeWidgetItem | QTreeWidget = null; if (checkIfNativeElement(parent)) { native = parent as NativeElement; } else { if (parent instanceof QTreeWidgetItem || parent instanceof QTreeWidget) { const type = parent instanceof QTreeWidgetItem ? 'item' : 'tree'; - parentTreeWidgetItem = parent; if (strings) { native = new addon.QTreeWidgetItem(parent.native, strings, type); } else { @@ -75,9 +73,6 @@ export class QTreeWidgetItem extends Component { } super(native); this.items = new Set(); - if (parentTreeWidgetItem != null) { - this.setNodeParent(parentTreeWidgetItem); - } } setText(column: number, text: string): void { this.native.setText(column, text); diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index d514a24c4..2b088b151 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -41,18 +41,15 @@ view.setLayout(new FlexLayout()); ``` */ export class QWidget extends YogaWidget { - _layout?: QLayout; _rawInlineStyle: string; type: string; - private _effect?: QGraphicsEffect | null; constructor(arg?: QWidget | NativeElement) { let native: NativeElement; - let parent: QWidget = null; if (checkIfNativeElement(arg)) { native = arg as NativeElement; - } else if (arg as QWidget) { - parent = arg as QWidget; + } else if (arg != null) { + const parent = arg as QWidget; native = new addon.QWidget(parent.native); } else { native = new addon.QWidget(); @@ -61,18 +58,22 @@ export class QWidget extends Yo this._rawInlineStyle = ''; this.type = 'widget'; - this.setNodeParent(parent); - this.setStyleSheet = memoizeOne(this.setStyleSheet); this.setInlineStyle = memoizeOne(this.setInlineStyle); this.setObjectName = memoizeOne(this.setObjectName); } - get layout(): QLayout | undefined { - return this._layout; + layout(): QLayout | null { + return wrapperCache.getWrapper(this.native.layout()) as QLayout; } - set layout(l: QLayout | undefined) { - this._layout = l; + setLayout(layout: QLayout): void { + this.native.setLayout(layout == null ? null : layout.native); + + const flexLayout = layout as FlexLayout; + if (flexLayout?.setFlexNode) { + //if flex layout set the flexnode + flexLayout.setFlexNode(this.getFlexNode()); + } } // *** Public Functions *** acceptDrops(): boolean { @@ -367,7 +368,6 @@ export class QWidget extends Yo this.native.setGeometry(x, y, w, h); } setGraphicsEffect(effect: QGraphicsEffect): void { - this._effect = effect; this.native.setGraphicsEffect(effect.native); } // TODO: void setInputMethodHints(Qt::InputMethodHints hints) @@ -380,15 +380,6 @@ export class QWidget extends Yo this.native.setStyleSheet(style); } } - setLayout(parentLayout: QLayout): void { - const flexLayout = parentLayout as FlexLayout; - this.native.setLayout(parentLayout.native); - if (flexLayout.setFlexNode) { - //if flex layout set the flexnode - flexLayout.setFlexNode(this.getFlexNode()); - } - this._layout = parentLayout; - } // TODO: void setLayoutDirection(Qt::LayoutDirection direction) // TODO: void setLocale(const QLocale &locale) // TODO: void setMask(const QBitmap &bitmap) @@ -661,3 +652,4 @@ export interface QWidgetSignals extends QObjectSignals { windowIconChanged: (iconNative: NativeElement) => void; customContextMenuRequested: (pos: { x: number; y: number }) => void; } +wrapperCache.registerWrapper('QWidgetWrap', QWidget); diff --git a/src/lib/core/Component.ts b/src/lib/core/Component.ts index d5dbe5407..9c62cb5d2 100644 --- a/src/lib/core/Component.ts +++ b/src/lib/core/Component.ts @@ -18,17 +18,8 @@ Its the root base class in NodeGui world. */ export abstract class Component { - nodeChildren: Set; - nodeParent?: Component; - native: NativeElement | null; - constructor(native: NativeElement) { this.native = native; - this.nodeChildren = new Set(); - } - setNodeParent(parent?: Component): void { - this.nodeParent = parent; - parent?.nodeChildren.add(this); } } diff --git a/src/lib/core/FlexLayout.ts b/src/lib/core/FlexLayout.ts index 2f8d56d57..d930489de 100644 --- a/src/lib/core/FlexLayout.ts +++ b/src/lib/core/FlexLayout.ts @@ -49,10 +49,9 @@ export class FlexLayout extends QLayout { addWidget(childWidget: QWidget, childFlexNode?: FlexNode): void { const childYogaNode = childFlexNode || childWidget.getFlexNode(); - if (this.nodeChildren.has(childWidget)) { + if (this.children().includes(childWidget)) { this.removeWidget(childWidget, childYogaNode); } - this.nodeChildren.add(childWidget); this.native.addWidget(childWidget.native, childYogaNode); } @@ -63,27 +62,16 @@ export class FlexLayout extends QLayout { beforeChildFlexNode?: FlexNode, ): void { const childYogaNode = childFlexNode || childWidget.getFlexNode(); - if (this.nodeChildren.has(childWidget)) { + if (this.children().includes(childWidget)) { this.removeWidget(childWidget, childYogaNode); } const beforeChildYogaNode = beforeChildFlexNode || beforeChildWidget.getFlexNode(); - - const widgetArr = Array.from(this.nodeChildren); - const beforeChildIndex = this.getChildIndex(beforeChildWidget); - if (beforeChildIndex !== -1) { - widgetArr.splice(beforeChildIndex, 0, childWidget); - } - this.nodeChildren = new Set(widgetArr); this.native.insertChildBefore(childWidget.native, beforeChildYogaNode, childYogaNode); } removeWidget(childWidget: QWidget, childFlexNode?: FlexNode): void { - if (!this.nodeChildren.has(childWidget)) { - return; - } const childYogaNode = childFlexNode || childWidget.getFlexNode(); this.native.removeWidget(childWidget.native, childYogaNode); - this.nodeChildren.delete(childWidget); } setFlexNode(flexNode: FlexNode): void { @@ -92,13 +80,12 @@ export class FlexLayout extends QLayout { } getChildIndex(childWidget: QWidget): number { - const widgetArr = Array.from(this.nodeChildren); - return widgetArr.indexOf(childWidget); + return this.children().indexOf(childWidget); } getNextSibling(childWidget: QWidget): QWidget | null { const childIndex = this.getChildIndex(childWidget); - const widgetArr = Array.from(this.nodeChildren); + const widgetArr = this.children(); if (childIndex !== -1) { return (widgetArr[childIndex + 1] as QWidget) || null; } diff --git a/src/lib/core/__test__/CacheTestQObject.ts b/src/lib/core/__test__/CacheTestQObject.ts index 3ee23ea0e..865102699 100644 --- a/src/lib/core/__test__/CacheTestQObject.ts +++ b/src/lib/core/__test__/CacheTestQObject.ts @@ -12,7 +12,6 @@ export class CacheTestQObject extends QObject { native = arg; } super(native); - this.native = native; } foo(): CacheTestQObject { diff --git a/src/lib/utils/helpers.ts b/src/lib/utils/helpers.ts index b786850c2..8c621ad4f 100644 --- a/src/lib/utils/helpers.ts +++ b/src/lib/utils/helpers.ts @@ -4,7 +4,7 @@ import addon from './addon'; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export function checkIfNativeElement(arg: any): boolean { const nativeArg = arg as NativeElement; - return typeof nativeArg === 'object' && nativeArg.type === 'native'; + return nativeArg != null && typeof nativeArg === 'object' && nativeArg.type === 'native'; } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types