Add many TODO comments, methods, and signals to QComboBox

This commit is contained in:
Simon Edwards 2021-09-25 11:12:03 +02:00
parent f92bd65407
commit c4d9a93e56
4 changed files with 347 additions and 34 deletions

View File

@ -15,6 +15,13 @@ class DLL_EXPORT NComboBox : public QComboBox, public NodeWidget {
virtual void connectSignalsToEventEmitter() {
QWIDGET_SIGNALS
// Qt Connects: Implement all signal connects here
QObject::connect(
this, QOverload<int>::of(&QComboBox::activated), [=](int index) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "activated"),
Napi::Number::From(env, index)});
});
QObject::connect(
this, QOverload<int>::of(&QComboBox::currentIndexChanged),
[=](int index) {
@ -38,5 +45,25 @@ class DLL_EXPORT NComboBox : public QComboBox, public NodeWidget {
this->emitOnNode.Call({Napi::String::New(env, "editTextChanged"),
Napi::String::New(env, text.toStdString())});
});
QObject::connect(
this, QOverload<int>::of(&QComboBox::highlighted), [=](int index) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "highlighted"),
Napi::Number::From(env, index)});
});
QObject::connect(this, &QComboBox::textActivated, [=](const QString &text) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "textActivated"),
Napi::String::New(env, text.toStdString())});
});
QObject::connect(
this, &QComboBox::textHighlighted, [=](const QString &text) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "textHighlighted"),
Napi::String::New(env, text.toStdString())});
});
}
};

View File

@ -40,4 +40,25 @@ class DLL_EXPORT QComboBoxWrap : public Napi::ObjectWrap<QComboBoxWrap> {
Napi::Value clear(const Napi::CallbackInfo& info);
Napi::Value setModel(const Napi::CallbackInfo& info);
Napi::Value setEditText(const Napi::CallbackInfo& info);
Napi::Value count(const Napi::CallbackInfo& info);
Napi::Value duplicatesEnabled(const Napi::CallbackInfo& info);
Napi::Value hasFrame(const Napi::CallbackInfo& info);
Napi::Value hidePopup(const Napi::CallbackInfo& info);
Napi::Value iconSize(const Napi::CallbackInfo& info);
Napi::Value maxCount(const Napi::CallbackInfo& info);
Napi::Value minimumContentsLength(const Napi::CallbackInfo& info);
Napi::Value modelColumn(const Napi::CallbackInfo& info);
Napi::Value rootModelIndex(const Napi::CallbackInfo& info);
Napi::Value setDuplicatesEnabled(const Napi::CallbackInfo& info);
Napi::Value setMinimumContentsLength(const Napi::CallbackInfo& info);
Napi::Value setModelColumn(const Napi::CallbackInfo& info);
Napi::Value setRootModelIndex(const Napi::CallbackInfo& info);
Napi::Value clearEditText(const Napi::CallbackInfo& info);
Napi::Value setFrame(const Napi::CallbackInfo& info);
Napi::Value setItemText(const Napi::CallbackInfo& info);
Napi::Value setMaxCount(const Napi::CallbackInfo& info);
Napi::Value showPopup(const Napi::CallbackInfo& info);
Napi::Value insertPolicy(const Napi::CallbackInfo& info);
Napi::Value setInsertPolicy(const Napi::CallbackInfo& info);
Napi::Value setIconSize(const Napi::CallbackInfo& info);
};

View File

@ -4,6 +4,7 @@
#include <QWidget>
#include "Extras/Utils/nutils.h"
#include "QtCore/QModelIndex/qmodelindex_wrap.h"
#include "QtCore/QVariant/qvariant_wrap.h"
#include "QtGui/QIcon/qicon_wrap.h"
#include "QtWidgets/QLineEdit/qlineedit_wrap.h"
@ -37,6 +38,31 @@ Napi::Object QComboBoxWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("clear", &QComboBoxWrap::clear),
InstanceMethod("setModel", &QComboBoxWrap::setModel),
InstanceMethod("setEditText", &QComboBoxWrap::setEditText),
InstanceMethod("count", &QComboBoxWrap::count),
InstanceMethod("duplicatesEnabled", &QComboBoxWrap::duplicatesEnabled),
InstanceMethod("hasFrame", &QComboBoxWrap::hasFrame),
InstanceMethod("hidePopup", &QComboBoxWrap::hidePopup),
InstanceMethod("iconSize", &QComboBoxWrap::iconSize),
InstanceMethod("maxCount", &QComboBoxWrap::maxCount),
InstanceMethod("minimumContentsLength",
&QComboBoxWrap::minimumContentsLength),
InstanceMethod("modelColumn", &QComboBoxWrap::modelColumn),
InstanceMethod("rootModelIndex", &QComboBoxWrap::rootModelIndex),
InstanceMethod("setDuplicatesEnabled",
&QComboBoxWrap::setDuplicatesEnabled),
InstanceMethod("setMinimumContentsLength",
&QComboBoxWrap::setMinimumContentsLength),
InstanceMethod("setModelColumn", &QComboBoxWrap::setModelColumn),
InstanceMethod("setRootModelIndex", &QComboBoxWrap::setRootModelIndex),
InstanceMethod("clearEditText", &QComboBoxWrap::clearEditText),
InstanceMethod("setFrame", &QComboBoxWrap::setFrame),
InstanceMethod("setItemText", &QComboBoxWrap::setItemText),
InstanceMethod("setMaxCount", &QComboBoxWrap::setMaxCount),
InstanceMethod("showPopup", &QComboBoxWrap::showPopup),
InstanceMethod("insertPolicy", &QComboBoxWrap::insertPolicy),
InstanceMethod("setInsertPolicy", &QComboBoxWrap::setInsertPolicy),
InstanceMethod("sizeAdjustPolicy", &QComboBoxWrap::sizeAdjustPolicy),
InstanceMethod("setIconSize", &QComboBoxWrap::setIconSize),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QComboBoxWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -269,3 +295,154 @@ Napi::Value QComboBoxWrap::setEditText(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QComboBoxWrap::count(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int result = this->instance->count();
return Napi::Number::New(env, result);
}
Napi::Value QComboBoxWrap::duplicatesEnabled(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool result = this->instance->duplicatesEnabled();
return Napi::Boolean::New(env, result);
}
Napi::Value QComboBoxWrap::hasFrame(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool result = this->instance->hasFrame();
return Napi::Boolean::New(env, result);
}
Napi::Value QComboBoxWrap::hidePopup(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->hidePopup();
return env.Null();
}
Napi::Value QComboBoxWrap::iconSize(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QSize result = this->instance->iconSize();
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QComboBoxWrap::maxCount(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int result = this->instance->maxCount();
return Napi::Number::New(env, result);
}
Napi::Value QComboBoxWrap::minimumContentsLength(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int result = this->instance->minimumContentsLength();
return Napi::Number::New(env, result);
}
Napi::Value QComboBoxWrap::modelColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int result = this->instance->modelColumn();
return Napi::Number::New(env, result);
}
Napi::Value QComboBoxWrap::rootModelIndex(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndex result = this->instance->rootModelIndex();
auto resultInstance = QModelIndexWrap::constructor.New(
{Napi::External<QModelIndex>::New(env, new QModelIndex(result))});
return resultInstance;
}
Napi::Value QComboBoxWrap::setDuplicatesEnabled(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool enable = info[0].As<Napi::Boolean>().Value();
this->instance->setDuplicatesEnabled(enable);
return env.Null();
}
Napi::Value QComboBoxWrap::setMinimumContentsLength(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int characters = info[0].As<Napi::Number>().Int32Value();
this->instance->setMinimumContentsLength(characters);
return env.Null();
}
Napi::Value QComboBoxWrap::setModelColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int visibleColumn = info[0].As<Napi::Number>().Int32Value();
this->instance->setModelColumn(visibleColumn);
return env.Null();
}
Napi::Value QComboBoxWrap::setRootModelIndex(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* indexWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* index = indexWrap->getInternalInstance();
this->instance->setRootModelIndex(*index);
return env.Null();
}
Napi::Value QComboBoxWrap::clearEditText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->clearEditText();
return env.Null();
}
Napi::Value QComboBoxWrap::setFrame(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool f = info[0].As<Napi::Boolean>().Value();
this->instance->setFrame(f);
return env.Null();
}
Napi::Value QComboBoxWrap::setItemText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int index = info[0].As<Napi::Number>().Int32Value();
std::string textNapiText = info[1].As<Napi::String>().Utf8Value();
QString text = QString::fromUtf8(textNapiText.c_str());
this->instance->setItemText(index, text);
return env.Null();
}
Napi::Value QComboBoxWrap::setMaxCount(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int max = info[0].As<Napi::Number>().Int32Value();
this->instance->setMaxCount(max);
return env.Null();
}
Napi::Value QComboBoxWrap::showPopup(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->showPopup();
return env.Null();
}
Napi::Value QComboBoxWrap::insertPolicy(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QComboBox::InsertPolicy result = this->instance->insertPolicy();
return Napi::Number::New(env, static_cast<uint>(result));
}
Napi::Value QComboBoxWrap::setInsertPolicy(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QComboBox::InsertPolicy policy = static_cast<QComboBox::InsertPolicy>(
info[0].As<Napi::Number>().Int32Value());
this->instance->setInsertPolicy(policy);
return env.Null();
}
Napi::Value QComboBoxWrap::setIconSize(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QSizeWrap* sizeWrap =
Napi::ObjectWrap<QSizeWrap>::Unwrap(info[0].As<Napi::Object>());
QSize* size = sizeWrap->getInternalInstance();
this->instance->setIconSize(*size);
return env.Null();
}

View File

@ -5,9 +5,11 @@ import { SizeAdjustPolicy } from '../QtEnums';
import { QIcon } from '../QtGui/QIcon';
import { QVariant } from '../QtCore/QVariant';
import { QStandardItemModel } from './QStandardItemModel';
import { QSize } from '../QtCore/QSize';
import { QModelIndex } from '../QtCore/QModelIndex';
/**
> Create and control a selectable drop down menu.
* **This class is a JS wrapper around Qt's [QComboBox class](https://doc.qt.io/qt-5/qcombobox.html)**
@ -49,6 +51,7 @@ export class QComboBox extends NodeWidget<QComboBoxSignals> {
this.native = native;
this.setNodeParent(parent);
}
// *** Public Functions ***
addItem(icon: QIcon | undefined, text: string, userData: QVariant = new QVariant()): void {
if (icon) {
this.native.addItem(icon.native, text, userData.native);
@ -56,6 +59,34 @@ export class QComboBox extends NodeWidget<QComboBoxSignals> {
this.native.addItem(text, userData.native);
}
}
addItems(texts: string[]): void {
this.native.addItems(texts);
}
// TODO: QCompleter * completer() const
count(): number {
return this.native.count();
}
// TODO: QVariant currentData(int role = Qt::UserRole) const
currentIndex(): number {
return this.native.currentIndex();
}
currentText(): string {
return this.native.currentText();
}
duplicatesEnabled(): boolean {
return this.native.duplicatesEnabled();
}
// TODO: int findData(const QVariant &data, int role = Qt::UserRole, Qt::MatchFlags flags = static_cast<Qt::MatchFlags>(Qt::MatchExactly|Qt::MatchCaseSensitive)) const
// TODO: int findText(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly|Qt::MatchCaseSensitive) const
hasFrame(): boolean {
return this.native.hasFrame();
}
hidePopup(): void {
this.native.hidePopup();
}
iconSize(): QSize {
return new QSize(this.native.iconSize());
}
insertItem(index: number, icon: QIcon | undefined, text: string, userData: QVariant = new QVariant()): void {
if (icon) {
this.native.insertItem(index, icon.native, text, userData.native);
@ -63,59 +94,113 @@ export class QComboBox extends NodeWidget<QComboBoxSignals> {
this.native.insertItem(index, text, userData.native);
}
}
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();
}
currentText(): string {
return this.native.currentText();
insertPolicy(): InsertPolicy {
return this.native.insertPolicy();
}
insertSeparator(index: number): void {
this.native.insertSeparator(index);
}
itemText(index: number): string {
return this.native.itemText(index);
isEditable(): boolean {
return this.native.isEditable();
}
itemData(index: number): QVariant {
return new QVariant(this.native.itemData(index));
}
removeItem(index: number): void {
this.native.removeItem(index);
// TODO: QAbstractItemDelegate * itemDelegate() const
// TODO: QIcon itemIcon(int index) const
itemText(index: number): string {
return this.native.itemText(index);
}
sizeAdjustPolicy(): number {
return this.native.sizeAdjustPolicy();
}
setSizeAdjustPolicy(policy: SizeAdjustPolicy): void {
this.native.setSizeAdjustPolicy(policy);
// TODO: QLineEdit * lineEdit() const
maxCount(): number {
return this.native.maxCount();
}
maxVisibleItems(): number {
return this.native.maxVisibleItems();
}
setMaxVisibleItems(index: number): void {
this.native.setMaxVisibleItems(index);
minimumContentsLength(): number {
return this.native.minimumContentsLength();
}
isEditable(): boolean {
return this.native.isEditable();
// TODO: QAbstractItemModel * model() const
modelColumn(): number {
return this.native.modelColumn();
}
removeItem(index: number): void {
this.native.removeItem(index);
}
rootModelIndex(): QModelIndex {
return new QModelIndex(this.native.rootModelIndex());
}
// TODO: void setCompleter(QCompleter *completer)
setDuplicatesEnabled(enable: boolean): void {
this.native.setDuplicatesEnabled(enable);
}
setEditable(editable: boolean): void {
this.native.setEditable(editable);
}
setFrame(showFrame: boolean): void {
this.native.setFrame(showFrame);
}
setIconSize(size: QSize): void {
this.native.setIconSize(size);
}
setInsertPolicy(policy: InsertPolicy): void {
this.native.setInsertPolicy(policy);
}
// TODO: void setItemData(int index, const QVariant &value, int role = Qt::UserRole)
// TODO: void setItemDelegate(QAbstractItemDelegate *delegate)
// TODO: void setItemIcon(int index, const QIcon &icon)
setItemText(index: number, text: string): void {
this.native.setItemText(index, text);
}
// TODO: void setLineEdit(QLineEdit *edit)
setMaxCount(max: number): void {
this.native.setMaxCount(max);
}
setMaxVisibleItems(index: number): void {
this.native.setMaxVisibleItems(index);
}
setMinimumContentsLength(characters: number): void {
this.native.setMinimumContentsLength(characters);
}
setModel(model: QStandardItemModel): void {
this.native.setModel(model.native);
}
setModelColumn(visibleColumn: number): void {
this.native.setModelColumn(visibleColumn);
}
setRootModelIndex(index: QModelIndex): void {
this.native.setRootModelIndex(index.native);
}
setSizeAdjustPolicy(policy: SizeAdjustPolicy): void {
this.native.setSizeAdjustPolicy(policy);
}
sizeAdjustPolicy(): number {
return this.native.sizeAdjustPolicy();
}
// TODO: void setValidator(const QValidator *validator)
// TODO: void setView(QAbstractItemView *itemView)
showPopup(): void {
this.native.showPopup();
}
// TODO: const QValidator * validator() const
// TODO: QAbstractItemView * view() const
// *** Public Slots ***
clear(): void {
this.native.clear();
}
setCurrentText(text: string): void {
this.setProperty('currentText', text);
clearEditText(): void {
this.native.clearEditText();
}
setCurrentIndex(index: number): void {
this.setProperty('currentIndex', index);
}
setModel(model: QStandardItemModel): void {
this.native.setModel(model.native);
setCurrentText(text: string): void {
this.setProperty('currentText', text);
}
setEditText(text: string): void {
this.native.setEditText(text);
@ -123,18 +208,21 @@ export class QComboBox extends NodeWidget<QComboBoxSignals> {
}
export enum InsertPolicy {
NoInsert,
InsertAtTop,
InsertAtCurrent,
InsertAtBottom,
InsertAfterCurrent,
InsertBeforeCurrent,
InsertAlphabetically,
NoInsert = 0,
InsertAtTop = 1,
InsertAtCurrent = 2,
InsertAtBottom = 3,
InsertAfterCurrent = 4,
InsertBeforeCurrent = 5,
InsertAlphabetically = 6,
}
export interface QComboBoxSignals extends QWidgetSignals {
//List all Signals below
activated: (index: number) => void;
currentIndexChanged: (index: number) => void;
currentTextChanged: (text: string) => void;
editTextChanged: (text: string) => void;
highlighted: (index: number) => void;
textActivated: (text: string) => void;
textHighlighted: (text: string) => void;
}