Implement QGridLayout.addLayout()

This commit is contained in:
Simon Edwards 2021-08-04 20:29:44 +02:00
parent 87e6531c65
commit d3f6d6d092
3 changed files with 34 additions and 2 deletions

View File

@ -22,6 +22,7 @@ class DLL_EXPORT QGridLayoutWrap : public Napi::ObjectWrap<QGridLayoutWrap> {
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value addLayout(const Napi::CallbackInfo& info);
Napi::Value addWidget(const Napi::CallbackInfo& info);
Napi::Value removeWidget(const Napi::CallbackInfo& info);
Napi::Value columnStretch(const Napi::CallbackInfo& info);

View File

@ -10,7 +10,8 @@ Napi::Object QGridLayoutWrap::init(Napi::Env env, Napi::Object exports) {
char CLASSNAME[] = "QGridLayout";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("addWidget", &QGridLayoutWrap::addWidget),
{InstanceMethod("addLayout", &QGridLayoutWrap::addLayout),
InstanceMethod("addWidget", &QGridLayoutWrap::addWidget),
InstanceMethod("removeWidget", &QGridLayoutWrap::removeWidget),
InstanceMethod("columnStretch", &QGridLayoutWrap::columnStretch),
InstanceMethod("rowStretch", &QGridLayoutWrap::rowStretch),
@ -59,6 +60,23 @@ QGridLayoutWrap::QGridLayoutWrap(const Napi::CallbackInfo& info)
this->rawData = extrautils::configureQObject(this->getInternalInstance());
}
Napi::Value QGridLayoutWrap::addLayout(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object qlayoutObject = info[0].As<Napi::Object>();
QLayoutWrap* layout = Napi::ObjectWrap<QLayoutWrap>::Unwrap(qlayoutObject);
int row = info[1].As<Napi::Number>().Int32Value();
int column = info[2].As<Napi::Number>().Int32Value();
int rowSpan = info[3].As<Napi::Number>().Int32Value();
int columnSpan = info[4].As<Napi::Number>().Int32Value();
Qt::Alignment alignment =
static_cast<Qt::Alignment>(info[5].As<Napi::Number>().Int32Value());
this->instance->addLayout(layout->getInternalInstance(), row, column, rowSpan,
columnSpan, alignment);
return env.Null();
}
Napi::Value QGridLayoutWrap::addWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

View File

@ -2,9 +2,10 @@ import addon from '../utils/addon';
import { NodeWidget } from './QWidget';
import { NodeLayout, QLayoutSignals } from './QLayout';
import { NativeElement } from '../core/Component';
import { AlignmentFlag } from '../QtEnums';
/**
> The QGridLayout class lays out widgets in a grid.
* **This class is a JS wrapper around Qt's [QGridLayout](https://doc.qt.io/qt-5/qgridlayout.html)**
@ -43,6 +44,18 @@ export class QGridLayout extends NodeLayout<QGridLayoutSignals> {
this.setNodeParent(parent);
this.native = native;
}
addLayout(
layout: NodeLayout<any>,
row: number,
column: number,
rowSpan = 1,
columnSpan = 1,
alignment = AlignmentFlag.AlignLeft,
): void {
this.native.addLayout(layout.native, row, column, rowSpan, columnSpan, alignment);
}
addWidget(widget: NodeWidget<any>, row = 0, col = 0, rowSpan = 1, colSpan = 1): void {
this.native.addWidget(widget.native, row, col, rowSpan, colSpan);
this.nodeChildren.add(widget);