add addItems() and insertItems() to QComboBox (#253)
This commit is contained in:
parent
14ea41b1d9
commit
a3aa6ea44a
@ -23,6 +23,8 @@ class QComboBoxWrap : public Napi::ObjectWrap<QComboBoxWrap> {
|
||||
// wrapped methods
|
||||
Napi::Value addItem(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertItem(const Napi::CallbackInfo& info);
|
||||
Napi::Value addItems(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertItems(const Napi::CallbackInfo& info);
|
||||
Napi::Value currentIndex(const Napi::CallbackInfo& info);
|
||||
Napi::Value currentText(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertSeparator(const Napi::CallbackInfo& info);
|
||||
|
||||
@ -15,6 +15,8 @@ Napi::Object QComboBoxWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("addItem", &QComboBoxWrap::addItem),
|
||||
InstanceMethod("insertItem", &QComboBoxWrap::insertItem),
|
||||
InstanceMethod("addItems", &QComboBoxWrap::addItems),
|
||||
InstanceMethod("insertItems", &QComboBoxWrap::insertItems),
|
||||
InstanceMethod("currentIndex", &QComboBoxWrap::currentIndex),
|
||||
InstanceMethod("currentText", &QComboBoxWrap::currentText),
|
||||
InstanceMethod("insertSeparator", &QComboBoxWrap::insertSeparator),
|
||||
@ -79,6 +81,39 @@ Napi::Value QComboBoxWrap::insertItem(const Napi::CallbackInfo& info) {
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QComboBoxWrap::addItems(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Array textsNapi = info[0].As<Napi::Array>();
|
||||
QList<QString> list;
|
||||
for (int i = 0; i < textsNapi.Length(); i++) {
|
||||
Napi::Value textNapi = textsNapi[i];
|
||||
list.append(textNapi.As<Napi::String>().Utf8Value().c_str());
|
||||
}
|
||||
QStringList texts = QStringList(list);
|
||||
|
||||
this->instance->addItems(texts);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QComboBoxWrap::insertItems(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
Napi::Array textsNapi = info[1].As<Napi::Array>();
|
||||
QList<QString> list;
|
||||
for (int i = 0; i < textsNapi.Length(); i++) {
|
||||
Napi::Value textNapi = textsNapi[i];
|
||||
list.append(textNapi.As<Napi::String>().Utf8Value().c_str());
|
||||
}
|
||||
QStringList texts = QStringList(list);
|
||||
|
||||
this->instance->insertItems(index, texts);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QComboBoxWrap::currentIndex(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { QMainWindow, QPushButton, QLabel, QWidget, FlexLayout } from './index';
|
||||
import { QMainWindow, QPushButton, QLabel, QWidget, FlexLayout, QComboBox, QComboBoxEvents } from './index';
|
||||
|
||||
const win = new QMainWindow();
|
||||
const center = new QWidget();
|
||||
@ -9,9 +9,15 @@ button.setText('Hello');
|
||||
const hello = new QLabel();
|
||||
hello.setText('hello text');
|
||||
|
||||
const combo = new QComboBox();
|
||||
combo.addItems(['text1', 'text2', 'text3'])
|
||||
combo.insertItems(1,['insert1', 'insert2', 'insert3'])
|
||||
combo.addEventListener(QComboBoxEvents.currentTextChanged, (text)=>hello.setText(text))
|
||||
|
||||
center.setLayout(new FlexLayout());
|
||||
center.layout?.addWidget(button);
|
||||
center.layout?.addWidget(hello);
|
||||
center.layout?.addWidget(combo);
|
||||
|
||||
win.setCentralWidget(center);
|
||||
win.show();
|
||||
|
||||
@ -29,6 +29,12 @@ export class QComboBox extends NodeWidget {
|
||||
insertItem(index: number, text: string): void {
|
||||
this.native.insertItem(index, text);
|
||||
}
|
||||
addItems(texts: string[]): void {
|
||||
this.native.addItems(texts);
|
||||
}
|
||||
insertItems(index:number, texts: string[]): void {
|
||||
this.native.insertItems(index, texts);
|
||||
}
|
||||
currentIndex(): number {
|
||||
return this.native.currentIndex();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user