Less caching in QMainWindow
This commit is contained in:
parent
bfa531f1f4
commit
5191892950
@ -22,6 +22,7 @@ class DLL_EXPORT QMainWindowWrap : public Napi::ObjectWrap<QMainWindowWrap> {
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
Napi::Value centralWidget(const Napi::CallbackInfo& info);
|
||||
Napi::Value setCentralWidget(const Napi::CallbackInfo& info);
|
||||
Napi::Value takeCentralWidget(const Napi::CallbackInfo& info);
|
||||
Napi::Value setMenuBar(const Napi::CallbackInfo& info);
|
||||
|
||||
@ -16,15 +16,15 @@ Napi::Object QMainWindowWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("setCentralWidget", &QMainWindowWrap::setCentralWidget),
|
||||
InstanceMethod("centralWidget", &QMainWindowWrap::centralWidget),
|
||||
InstanceMethod("takeCentralWidget", &QMainWindowWrap::takeCentralWidget),
|
||||
InstanceMethod("setMenuBar", &QMainWindowWrap::setMenuBar),
|
||||
InstanceMethod("menuBar", &QMainWindowWrap::menuBar),
|
||||
InstanceMethod("setMenuWidget", &QMainWindowWrap::setMenuWidget),
|
||||
InstanceMethod("center", &QMainWindowWrap::center),
|
||||
InstanceMethod("setStatusBar", &QMainWindowWrap::setStatusBar),
|
||||
InstanceMethod("statusBar", &QMainWindowWrap::statusBar),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)
|
||||
|
||||
});
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QMainWindowWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
QOBJECT_REGISTER_WRAPPER(QMainWindow, QMainWindowWrap);
|
||||
@ -67,15 +67,32 @@ Napi::Value QMainWindowWrap::setCentralWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Object widgetObject = info[0].As<Napi::Object>();
|
||||
NodeWidgetWrap* centralWidget =
|
||||
Napi::ObjectWrap<NodeWidgetWrap>::Unwrap(widgetObject);
|
||||
this->instance->setCentralWidget(centralWidget->getInternalInstance());
|
||||
if (centralWidget != nullptr) {
|
||||
this->instance->setCentralWidget(centralWidget->getInternalInstance());
|
||||
} else {
|
||||
this->instance->setCentralWidget(nullptr);
|
||||
}
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::centralWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
QWidget* widget = this->instance->centralWidget();
|
||||
if (widget) {
|
||||
return WrapperCache::instance.getWrapper(env, widget);
|
||||
} else {
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::takeCentralWidget(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
this->instance->takeCentralWidget();
|
||||
// We will not return the value here since we are doing it in js side anyway
|
||||
return env.Null();
|
||||
QWidget* widget = this->instance->takeCentralWidget();
|
||||
if (widget) {
|
||||
return WrapperCache::instance.getWrapper(env, widget);
|
||||
} else {
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::setMenuBar(const Napi::CallbackInfo& info) {
|
||||
@ -129,6 +146,19 @@ Napi::Value QMainWindowWrap::setStatusBar(const Napi::CallbackInfo& info) {
|
||||
Napi::Value QMainWindowWrap::statusBar(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
QStatusBar* statusBar = this->instance->statusBar();
|
||||
|
||||
return QStatusBarWrap::fromQStatusBar(env, statusBar);
|
||||
if (statusBar) {
|
||||
return WrapperCache::instance.getWrapper(env, statusBar);
|
||||
} else {
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
Napi::Value QMainWindowWrap::menuBar(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
QMenuBar* menuBar = this->instance->menuBar();
|
||||
if (menuBar) {
|
||||
return WrapperCache::instance.getWrapper(env, menuBar);
|
||||
} else {
|
||||
return env.Null();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@ import { QLayout } from './QLayout';
|
||||
import { QMenuBar } from './QMenuBar';
|
||||
import { QStatusBar } from './QStatusBar';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { wrapperCache } from '../core/WrapperCache';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
|
||||
/**
|
||||
|
||||
@ -32,55 +34,58 @@ QMainWindow needs to have a central widget set before other widgets can be added
|
||||
Once a central widget is set you can add children/layout to the central widget.
|
||||
*/
|
||||
export class QMainWindow extends QWidget<QMainWindowSignals> {
|
||||
public centralWidget?: QWidget | null;
|
||||
private _menuBar?: QMenuBar;
|
||||
private _statusBar?: QStatusBar | null;
|
||||
// TODO
|
||||
constructor(parent?: QWidget) {
|
||||
constructor(arg?: QWidget<QWidgetSignals> | 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.QMainWindow(parent.native);
|
||||
} else {
|
||||
native = new addon.QMainWindow();
|
||||
}
|
||||
super(native);
|
||||
|
||||
this.setLayout = (parentLayout: QLayout): void => {
|
||||
if (this.centralWidget) {
|
||||
this.centralWidget.setLayout(parentLayout);
|
||||
} else {
|
||||
this.native.setLayout(parentLayout.native);
|
||||
}
|
||||
};
|
||||
}
|
||||
setLayout(parentLayout: QLayout): void {
|
||||
const centralWidget = this.centralWidget();
|
||||
if (centralWidget) {
|
||||
centralWidget.setLayout(parentLayout);
|
||||
} else {
|
||||
super.setLayout(parentLayout);
|
||||
}
|
||||
}
|
||||
setCentralWidget(widget: QWidget): void {
|
||||
this.native.setCentralWidget(widget.native);
|
||||
this.centralWidget = widget;
|
||||
this.centralWidget.setFlexNodeSizeControlled(true);
|
||||
const centralWidget = this.centralWidget();
|
||||
if (centralWidget) {
|
||||
centralWidget.setFlexNodeSizeControlled(true);
|
||||
}
|
||||
}
|
||||
centralWidget(): QWidget {
|
||||
return wrapperCache.getWrapper(this.native.centralWidget()) as QWidget;
|
||||
}
|
||||
takeCentralWidget(): QWidget | null {
|
||||
const centralWidget = this.centralWidget;
|
||||
const centralWidget = this.centralWidget();
|
||||
this.centralWidget = null;
|
||||
if (centralWidget) {
|
||||
centralWidget.setFlexNodeSizeControlled(false);
|
||||
this.native.takeCentralWidget();
|
||||
return centralWidget;
|
||||
return wrapperCache.getWrapper(this.native.takeCentralWidget()) as QWidget;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
setMenuBar(menuBar: QMenuBar): void {
|
||||
this.native.setMenuBar(menuBar.native);
|
||||
this._menuBar = menuBar;
|
||||
}
|
||||
menuBar(): QMenuBar | undefined {
|
||||
return this._menuBar;
|
||||
return wrapperCache.getWrapper(this.native.menuBar()) as QMenuBar;
|
||||
}
|
||||
setMenuWidget(menuWidget: QWidget): void {
|
||||
this.native.setMenuWidget(menuWidget.native);
|
||||
}
|
||||
layout(): QLayout | undefined {
|
||||
if (this.centralWidget) {
|
||||
return this.centralWidget.layout();
|
||||
const centralWidget = this.centralWidget();
|
||||
if (centralWidget) {
|
||||
return centralWidget.layout();
|
||||
}
|
||||
return super.layout();
|
||||
}
|
||||
@ -94,24 +99,20 @@ export class QMainWindow extends QWidget<QMainWindowSignals> {
|
||||
* @param statusBar The status bar.
|
||||
*/
|
||||
setStatusBar(statusBar: QStatusBar): void {
|
||||
this.native.setStatusBar(statusBar.native);
|
||||
this._statusBar = statusBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the status bar from the main window.
|
||||
*/
|
||||
removeStatusBar(): void {
|
||||
this.native.setStatusBar(null);
|
||||
this._statusBar = null;
|
||||
if (statusBar != null) {
|
||||
this.native.setStatusBar(statusBar.native);
|
||||
} else {
|
||||
this.native.setStatusBar(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status bar for the main window.
|
||||
*/
|
||||
statusBar(): QStatusBar {
|
||||
return new QStatusBar(this.native.statusBar());
|
||||
return wrapperCache.getWrapper(this.native.statusBar()) as QStatusBar;
|
||||
}
|
||||
}
|
||||
wrapperCache.registerWrapper('QMainWindowWrap', QMainWindow);
|
||||
|
||||
export type QMainWindowSignals = QWidgetSignals;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user