QLineEdit

This commit is contained in:
Kakul Gupta 2019-06-03 19:02:31 +02:00
parent 3e9a230404
commit 539b343007
6 changed files with 93 additions and 0 deletions

View File

@ -25,6 +25,7 @@
"../src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp",
"../src/cpp/QtWidgets/QProgressBar/qprogressbar_wrap.cpp",
"../src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp",
"../src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.cpp",
],
}
]

View File

@ -6,6 +6,7 @@ import { QPushButton } from "./src/lib/QtWidgets/QPushButton";
import { QCheckBox } from "./src/lib/QtWidgets/QCheckBox";
import { QProgressBar } from "./src/lib/QtWidgets/QProgressBar";
import { QRadioButton } from "./src/lib/QtWidgets/QRadioButton";
import { QLineEdit } from "./src/lib/QtWidgets/QLineEdit";
const win = new QMainWindow();
const view = new QWidget();
@ -29,12 +30,15 @@ const progressbar = new QProgressBar();
const radiobutton = new QRadioButton();
const lineedit = new QLineEdit();
gridLayout.addWidget(label);
gridLayout.addWidget(label2);
gridLayout.addWidget(button1);
gridLayout.addWidget(checkbox);
gridLayout.addWidget(progressbar);
gridLayout.addWidget(radiobutton);
gridLayout.addWidget(lineedit);
view.setLayout(gridLayout);

View File

@ -0,0 +1,47 @@
#include "qlineedit_wrap.h"
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
#include "src/cpp/Extras/Utils/utils.h"
#include <QWidget>
Napi::FunctionReference QLineEditWrap::constructor;
Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QLineEdit";
Napi::Function func = DefineClass(env, CLASSNAME, {
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QLineEdit* QLineEditWrap::getInternalInstance() {
return this->instance;
}
QLineEditWrap::QLineEditWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QLineEditWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if(info.Length() == 1) {
if(info[0].IsObject()){
Napi::Object object_parent = info[0].As<Napi::Object>();
QWidgetWrap* w_parent = Napi::ObjectWrap<QWidgetWrap>::Unwrap(object_parent);
this->instance = new QLineEdit(w_parent->getInternalInstance()); //this sets the parent to current widget
}else{
extrautils::throwTypeError(env, "Wrong type of arguments");
}
}else if (info.Length() == 0){
this->instance = new QLineEdit();
}else {
extrautils::throwTypeError(env, "Wrong number of arguments");
}
}
QLineEditWrap::~QLineEditWrap() {
delete this->instance;
}

View File

@ -0,0 +1,22 @@
#ifndef QLINEEDIT_WRAP_H
#define QLINEEDIT_WRAP_H
#include <napi.h>
#include <QLineEdit>
#include "src/cpp/QtGui/QWidget/qwidget_macro.h"
class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
private:
QLineEdit* instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QLineEditWrap(const Napi::CallbackInfo& info);
~QLineEditWrap();
QLineEdit* getInternalInstance();
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
QWIDGET_WRAPPED_METHODS_DECLARATION
};
#endif

View File

@ -8,6 +8,7 @@
#include "src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h"
#include "src/cpp/QtWidgets/QProgressBar/qprogressbar_wrap.h"
#include "src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h"
#include "src/cpp/QtWidgets/QLineEdit/qlineedit_wrap.h"
#include <napi.h>
//private : will not be accessibe in js
@ -25,6 +26,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
QCheckBoxWrap::init(env, exports);
QProgressBarWrap::init(env, exports);
QRadioButtonWrap::init(env, exports);
QLineEditWrap::init(env, exports);
return QLabelWrap::init(env, exports);
}

View File

@ -0,0 +1,17 @@
import addon from "../../core/addon";
import { NodeWidget } from "../../QtGui/QWidget";
import { QLayout } from "../QLayout";
export class QLineEdit extends NodeWidget {
native: any;
layout?: QLayout;
constructor(parent?: NodeWidget) {
super();
if (parent) {
this.native = new addon.QLineEdit(parent.native);
this.parent = parent;
} else {
this.native = new addon.QLineEdit();
}
}
}