From 5415fa35768f6537478719bb732d74efa297da4c Mon Sep 17 00:00:00 2001 From: Shubham Zanwar Date: Thu, 20 Feb 2020 13:02:44 +0530 Subject: [PATCH] improv: return the index of the last added tab (#405) * widgets(tabs): return the index of the last added tab * widgets(tabs): returning the index of the newly added tab * demo: using the tab component in the demo to verify * lint: fixing lint --- src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp | 7 ++++--- src/lib/QtWidgets/QTabWidget.ts | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp b/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp index d4f4b4f61..50ae0d7e1 100644 --- a/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp +++ b/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp @@ -65,9 +65,10 @@ Napi::Value QTabWidgetWrap::addTab(const Napi::CallbackInfo& info) { Napi::ObjectWrap::Unwrap(pageObject); QIconWrap* iconWrap = Napi::ObjectWrap::Unwrap(iconObject); - this->instance->addTab(pageObjectWrap->getInternalInstance(), - *iconWrap->getInternalInstance(), label.c_str()); - return env.Null(); + int index = + this->instance->addTab(pageObjectWrap->getInternalInstance(), + *iconWrap->getInternalInstance(), label.c_str()); + return Napi::Number::New(env, index); } Napi::Value QTabWidgetWrap::setTabPosition(const Napi::CallbackInfo& info) { diff --git a/src/lib/QtWidgets/QTabWidget.ts b/src/lib/QtWidgets/QTabWidget.ts index b99440946..e66e74ce2 100644 --- a/src/lib/QtWidgets/QTabWidget.ts +++ b/src/lib/QtWidgets/QTabWidget.ts @@ -42,10 +42,11 @@ export class QTabWidget extends NodeWidget { this.native = native; } - addTab(page: NodeWidget, icon: QIcon, label: string): void { - this.native.addTab(page.native, icon.native, label); + addTab(page: NodeWidget, icon: QIcon, label: string): number { + const index = this.native.addTab(page.native, icon.native, label); this.tabs.push(page); page.setFlexNodeSizeControlled(true); + return index; } setTabPosition(tabPosition: TabPosition): void {