Now all widgets gets all public methods of QWidget

This commit is contained in:
Atul R 2019-05-27 21:40:32 +02:00
parent 8459fc47fe
commit 8fccb3847e
12 changed files with 91 additions and 134 deletions

View File

@ -5,6 +5,7 @@
"targets": [
{
"target_name": "qtnode",
'include_dirs': ['<(module_root_dir)'],
"sources": [
"../src/cpp/main.cpp",
# non-wrapped cpps

View File

@ -0,0 +1,58 @@
#ifndef QWIDGET_MACRO_H
#define QWIDGET_MACRO_H
#include "../../QtWidgets/QLayout/qlayout_wrap.h"
#define QWIDGET_WRAPPED_METHODS_DECLARATION \
\
Napi::Value show(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->show(); \
return env.Null(); \
} \
\
Napi::Value resize(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Number width = info[0].As<Napi::Number>(); \
Napi::Number height = info[1].As<Napi::Number>(); \
this->instance->resize(width.Int32Value(), height.Int32Value()); \
return env.Null(); \
} \
\
Napi::Value close(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->close(); \
return env.Null(); \
} \
\
Napi::Value setLayout(const Napi::CallbackInfo& info){ \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Object layoutObject = info[0].As<Napi::Object>(); \
QLayoutWrap* layoutParent = Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject); \
this->instance->setLayout(layoutParent->getInternalInstance()); \
return env.Null(); \
} \
\
Napi::Value setStyleSheet(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::String text = info[0].As<Napi::String>(); \
std::string style = text.Utf8Value(); \
this->instance->setStyleSheet(style.c_str()); \
return env.Null(); \
}
#define QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
\
InstanceMethod("show", &WidgetWrapName::show), \
InstanceMethod("resize",&WidgetWrapName::resize), \
InstanceMethod("close",&WidgetWrapName::close), \
InstanceMethod("setLayout",&WidgetWrapName::setLayout), \
InstanceMethod("setStyleSheet",&WidgetWrapName::setStyleSheet), \
#endif

View File

@ -8,11 +8,7 @@ Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QWidget";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("show", &QWidgetWrap::show),
InstanceMethod("resize",&QWidgetWrap::resize),
InstanceMethod("close",&QWidgetWrap::close),
InstanceMethod("setLayout",&QWidgetWrap::setLayout),
InstanceMethod("setStyleSheet",&QWidgetWrap::setStyleSheet),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -46,54 +42,3 @@ QWidgetWrap::~QWidgetWrap() {
delete this->instance;
}
Napi::Value QWidgetWrap::show(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->show();
return env.Null();
}
Napi::Value QWidgetWrap::resize(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number width = info[0].As<Napi::Number>();
Napi::Number height = info[1].As<Napi::Number>();
this->instance->resize(width.Int32Value(), height.Int32Value());
return env.Null();
}
Napi::Value QWidgetWrap::close(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->close();
return env.Null();
}
Napi::Value QWidgetWrap::setLayout(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object layoutObject = info[0].As<Napi::Object>();
QLayoutWrap* layoutParent = Napi::ObjectWrap<QLayoutWrap>::Unwrap(layoutObject);
this->instance->setLayout(layoutParent->getInternalInstance());
return env.Null();
}
Napi::Value QWidgetWrap::setStyleSheet(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String text = info[0].As<Napi::String>();
std::string style = text.Utf8Value();
this->instance->setStyleSheet(style.c_str());
return env.Null();
}

View File

@ -1,6 +1,7 @@
#ifndef QWIDGET_WRAP_H
#define QWIDGET_WRAP_H
#include "qwidget_macro.h"
#include <napi.h>
#include <QWidget>
@ -15,11 +16,7 @@ class QWidgetWrap : public Napi::ObjectWrap<QWidgetWrap>{
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value show(const Napi::CallbackInfo& info);
Napi::Value resize(const Napi::CallbackInfo& info);
Napi::Value close(const Napi::CallbackInfo& info);
Napi::Value setLayout(const Napi::CallbackInfo& info);
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};
#endif

View File

@ -12,7 +12,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setWordWrap", &QLabelWrap::setWordWrap),
InstanceMethod("setText", &QLabelWrap::setText),
InstanceMethod("setStyleSheet", &QLabelWrap::setStyleSheet)
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -67,13 +67,3 @@ Napi::Value QLabelWrap::setText(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QLabelWrap::setStyleSheet(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String text = info[0].As<Napi::String>();
std::string style = text.Utf8Value();
this->instance->setStyleSheet(style.c_str());
return env.Null();
}

View File

@ -2,6 +2,7 @@
#define QLABEL_WRAP_H
#include <napi.h>
#include <QLabel>
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
private:
@ -16,7 +17,8 @@ class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
//wrapped methods
Napi::Value setWordWrap(const Napi::CallbackInfo& info);
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};
#endif

View File

@ -8,10 +8,7 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QMainWindow";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setStyleSheet", &QMainWindowWrap::setStyleSheet),
InstanceMethod("show", &QMainWindowWrap::show),
InstanceMethod("resize",&QMainWindowWrap::resize),
InstanceMethod("close",&QMainWindowWrap::close),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
InstanceMethod("setCentralWidget",&QMainWindowWrap::setCentralWidget),
});
constructor = Napi::Persistent(func);
@ -46,46 +43,6 @@ QMainWindowWrap::~QMainWindowWrap() {
delete this->instance;
}
Napi::Value QMainWindowWrap::setStyleSheet(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String text = info[0].As<Napi::String>();
std::string style = text.Utf8Value();
this->instance->setStyleSheet(style.c_str());
return env.Null();
}
Napi::Value QMainWindowWrap::show(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->show();
return env.Null();
}
Napi::Value QMainWindowWrap::resize(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number width = info[0].As<Napi::Number>();
Napi::Number height = info[1].As<Napi::Number>();
this->instance->resize(width.Int32Value(), height.Int32Value());
return env.Null();
}
Napi::Value QMainWindowWrap::close(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->close();
return env.Null();
}
Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info){
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

View File

@ -3,6 +3,7 @@
#include <napi.h>
#include <QMainWindow>
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
class QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap>{
private:
@ -16,11 +17,9 @@ public:
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
Napi::Value show(const Napi::CallbackInfo& info);
Napi::Value resize(const Napi::CallbackInfo& info);
Napi::Value close(const Napi::CallbackInfo& info);
Napi::Value setCentralWidget(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};
#endif

View File

@ -8,8 +8,8 @@ Napi::Object QPushButtonWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QPushButton";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setStyleSheet", &QPushButtonWrap::setStyleSheet),
InstanceMethod("setText", &QPushButtonWrap::setText),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPushButtonWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -43,17 +43,6 @@ QPushButtonWrap::~QPushButtonWrap() {
delete this->instance;
}
Napi::Value QPushButtonWrap::setStyleSheet(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String text = info[0].As<Napi::String>();
std::string style = text.Utf8Value();
this->instance->setStyleSheet(style.c_str());
// this->instance->repaint();
return env.Null();
}
Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();

View File

@ -2,6 +2,7 @@
#define QPUSHBUTTON_WRAP_H
#include <napi.h>
#include <QPushButton>
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
private:
@ -14,9 +15,10 @@ class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap> {
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value setStyleSheet(const Napi::CallbackInfo& info);
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value setEventListener(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};
#endif

View File

@ -0,0 +1,6 @@
#include "flexitem.h"
FlexItem::FlexItem()
{
}

View File

@ -0,0 +1,11 @@
#ifndef FLEXITEM_H
#define FLEXITEM_H
class FlexItem
{
public:
FlexItem();
};
#endif // FLEXITEM_H