improv: adding the ability to change the tab text (#421)

* adding the setTabText to the QTabWidgetWrap definition

* implementing the setTabText funciton in the cpp module

* implementing the setTabText in the ts module

* adding a demo for the tab text change feature

* fixing lint issues

* exporting the QSettings enums
This commit is contained in:
Shubham Zanwar 2020-02-25 14:06:58 +05:30 committed by GitHub
parent 9e1e8e576c
commit 57cf0d4836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 2 deletions

View File

@ -27,4 +27,5 @@ class DLL_EXPORT QTabWidgetWrap : public Napi::ObjectWrap<QTabWidgetWrap> {
Napi::Value currentIndex(const Napi::CallbackInfo &info);
Napi::Value removeTab(const Napi::CallbackInfo &info);
Napi::Value setTabsClosable(const Napi::CallbackInfo &info);
Napi::Value setTabText(const Napi::CallbackInfo &info);
};

View File

@ -15,6 +15,7 @@ Napi::Object QTabWidgetWrap::init(Napi::Env env, Napi::Object exports) {
env, CLASSNAME,
{InstanceMethod("addTab", &QTabWidgetWrap::addTab),
InstanceMethod("setTabPosition", &QTabWidgetWrap::setTabPosition),
InstanceMethod("setTabText", &QTabWidgetWrap::setTabText),
InstanceMethod("setCurrentIndex", &QTabWidgetWrap::setCurrentIndex),
InstanceMethod("currentIndex", &QTabWidgetWrap::currentIndex),
InstanceMethod("removeTab", &QTabWidgetWrap::removeTab),
@ -80,6 +81,16 @@ Napi::Value QTabWidgetWrap::setTabPosition(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QTabWidgetWrap::setTabText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int tabIndex = info[0].As<Napi::Number>().Int32Value();
Napi::String napiLabel = info[1].As<Napi::String>();
std::string label = napiLabel.Utf8Value();
this->instance->setTabText(tabIndex, label.c_str());
return env.Null();
}
Napi::Value QTabWidgetWrap::setCurrentIndex(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

View File

@ -94,6 +94,7 @@ export { QPoint } from './lib/QtCore/QPoint';
export { QColor } from './lib/QtGui/QColor';
export { QTime } from './lib/QtCore/QTime';
export { QUrl, ParsingMode } from './lib/QtCore/QUrl';
export { Format, Scope, QSettings } from './lib/QtCore/QSettings';
// Layouts:
export { QBoxLayout, QBoxLayoutSignals } from './lib/QtWidgets/QBoxLayout';
export { QGridLayout, QGridLayoutSignals } from './lib/QtWidgets/QGridLayout';

View File

@ -2,7 +2,7 @@ import { NativeElement, Component } from '../core/Component';
import addon from '../utils/addon';
import { QVariant } from './QVariant';
enum Format {
export enum Format {
NativeFormat = 0,
Registry32Format = 2,
Registry64Format = 3,
@ -10,7 +10,7 @@ enum Format {
InvalidFormat = 16,
}
enum Scope {
export enum Scope {
UserScope = 0,
SystemScope = 1,
}

View File

@ -53,6 +53,10 @@ export class QTabWidget extends NodeWidget<QTabWidgetSignals> {
this.native.setTabPosition(tabPosition);
}
setTabText(tabIndex: number, tabText: string): void {
this.native.setTabText(tabIndex, tabText);
}
setCurrentIndex(index: number): void {
this.native.setCurrentIndex(index);
}