Add QListWidget Support (#320)

This commit is contained in:
feng8848 2019-12-31 23:12:01 +08:00 committed by Atul R
parent db4dfa30df
commit f409eeb7b0
19 changed files with 1636 additions and 5 deletions

View File

@ -49,6 +49,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QKeySequence/qkeysequence_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QMovie/qmovie_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtGui/QStyle/qstyle_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QModelIndex/qmodelindex_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QObject/qobject_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QVariant/qvariant_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtCore/QSize/qsize_wrap.cpp"
@ -59,6 +60,8 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QBoxLayout/qboxlayout_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QComboBox/qcombobox_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QFileDialog/qfiledialog_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTableWidget/qtablewidget_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QPainter/qpainter_wrap.cpp"
@ -96,6 +99,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QCheckBox/ncheckbox.hpp"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QDial/ndial.hpp"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QFileDialog/nfiledialog.hpp"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QListWidget/nlistwidget.hpp"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTableWidget/ntablewidget.hpp"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QLineEdit/nlineedit.hpp"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QMainWindow/nmainwindow.hpp"

View File

@ -0,0 +1,35 @@
#pragma once
#include <napi.h>
#include <QModelIndex>
#include "core/Component/component_macro.h"
class QModelIndexWrap : public Napi::ObjectWrap<QModelIndexWrap> {
private:
std::unique_ptr<QModelIndex> instance;
public:
static Napi::FunctionReference constructor;
static Napi::Object init(Napi::Env env, Napi::Object exports);
QModelIndexWrap(const Napi::CallbackInfo& info);
~QModelIndexWrap();
QModelIndex* getInternalInstance();
// Wrapped methods
Napi::Value column(const Napi::CallbackInfo& info);
Napi::Value data(const Napi::CallbackInfo& info);
Napi::Value flags(const Napi::CallbackInfo& info);
Napi::Value isValid(const Napi::CallbackInfo& info);
Napi::Value parent(const Napi::CallbackInfo& info);
Napi::Value row(const Napi::CallbackInfo& info);
Napi::Value sibling(const Napi::CallbackInfo& info);
Napi::Value siblingAtColumn(const Napi::CallbackInfo& info);
Napi::Value siblingAtRow(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};
namespace StaticQModelIndexWrapMethods {
Napi::Value fromQVariant(const Napi::CallbackInfo& info);
} // namespace StaticQModelIndexWrapMethods

View File

@ -0,0 +1,121 @@
#pragma once
#include "QtCore/QModelIndex/qmodelindex_wrap.h"
#include "QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
/*
This macro adds common QAbstractItemView exported methods
The exported methods are taken into this macro to avoid writing them in each
and every widget we export.
*/
#ifndef QABSTRACTITEMVIEW_WRAPPED_METHODS_DECLARATION
#define QABSTRACTITEMVIEW_WRAPPED_METHODS_DECLARATION \
QABSTRACTSCROLLAREA_WRAPPED_METHODS_DECLARATION \
Napi::Value setCurrentIndex(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Object indexObject = info[0].As<Napi::Object>(); \
QModelIndexWrap* indexWrap = \
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(indexObject); \
this->instance->setCurrentIndex(*indexWrap->getInternalInstance()); \
return env.Null(); \
} \
Napi::Value currentIndex(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
QModelIndex current = this->instance->currentIndex(); \
auto instance = QModelIndexWrap::constructor.New( \
{Napi::External<QModelIndex>::New(env, new QModelIndex(current))}); \
return instance; \
} \
Napi::Value setIndexWidget(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Object indexObject = info[0].As<Napi::Object>(); \
Napi::Object widgetObject = info[1].As<Napi::Object>(); \
QModelIndexWrap* indexWrap = \
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(indexObject); \
QWidgetWrap* widgetWrap = \
Napi::ObjectWrap<QWidgetWrap>::Unwrap(widgetObject); \
this->instance->setIndexWidget(*indexWrap->getInternalInstance(), \
widgetWrap->getInternalInstance()); \
return env.Null(); \
} \
Napi::Value indexWidget(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
Napi::Object indexObject = info[0].As<Napi::Object>(); \
QModelIndexWrap* indexWrap = \
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(indexObject); \
QWidget* widget = \
this->instance->indexWidget(*indexWrap->getInternalInstance()); \
auto instance = QWidgetWrap::constructor.New( \
{Napi::External<QWidget>::New(env, widget), \
Napi::Boolean::New(env, true)}); \
return instance; \
} \
Napi::Value resetHorizontalScrollMode(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->resetHorizontalScrollMode(); \
return env.Null(); \
} \
Napi::Value resetVerticalScrollMode(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->resetVerticalScrollMode(); \
return env.Null(); \
} \
Napi::Value rootIndex(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
QModelIndex root = this->instance->rootIndex(); \
auto instance = QModelIndexWrap::constructor.New( \
{Napi::External<QModelIndex>::New(env, new QModelIndex(root))}); \
return instance; \
} \
Napi::Value scrollToBottom(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->scrollToBottom(); \
return env.Null(); \
} \
Napi::Value scrollToTop(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->scrollToTop(); \
return env.Null(); \
}
#endif // QABSTRACTITEMVIEW_WRAPPED_METHODS_DECLARATION
#ifndef QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE
#define QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
InstanceMethod("setCurrentIndex", &WidgetWrapName::setCurrentIndex), \
InstanceMethod("currentIndex", &WidgetWrapName::currentIndex), \
InstanceMethod("setIndexWidget", &WidgetWrapName::setIndexWidget), \
InstanceMethod("indexWidget", &WidgetWrapName::indexWidget), \
InstanceMethod("resetHorizontalScrollMode", \
&WidgetWrapName::resetHorizontalScrollMode), \
InstanceMethod("resetVerticalScrollMode", \
&WidgetWrapName::resetVerticalScrollMode), \
InstanceMethod("rootIndex", &WidgetWrapName::rootIndex), \
InstanceMethod("scrollToBottom", &WidgetWrapName::scrollToBottom), \
InstanceMethod("scrollToTop", &WidgetWrapName::scrollToTop),
#endif // QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE
#ifndef QABSTRACTITEMVIEW_SIGNALS
#define QABSTRACTITEMVIEW_SIGNALS \
QABSTRACTSCROLLAREA_SIGNALS \
QObject::connect(this, &QAbstractItemView::viewportEntered, [=]() { \
Napi::Env env = this->emitOnNode.Env(); \
Napi::HandleScope scope(env); \
this->emitOnNode.Call({Napi::String::New(env, "viewportEntered")}); \
});
#endif // QABSTRACTITEMVIEW_SIGNALS

View File

@ -7,7 +7,7 @@
class NLayout : public QLayout, public EventWidget {
Q_OBJECT
public:
EVENTWIDGET_IMPLEMENTATIONS(NLayout)
EVENTWIDGET_IMPLEMENTATIONS(QLayout)
using QLayout::QLayout;
void connectSignalsToEventEmitter() { QLAYOUT_SIGNALS }
};

View File

@ -0,0 +1,53 @@
#pragma once
#include <QListView>
#include <QSize>
#include "QtWidgets/QAbstractItemView/qabstractitemview_macro.h"
/*
This macro adds common QListView exported methods
The exported methods are taken into this macro to avoid writing them in each
and every widget we export.
*/
#ifndef QListView_WRAPPED_METHODS_DECLARATION
#define QListView_WRAPPED_METHODS_DECLARATION \
QABSTRACTITEMVIEW_WRAPPED_METHODS_DECLARATION \
Napi::Value clearPropertyFlags(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
this->instance->clearPropertyFlags(); \
return env.Null(); \
} \
Napi::Value setRowHidden(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
int row = info[0].As<Napi::Number>().Int32Value(); \
int hide = info[1].As<Napi::Boolean>().Value(); \
this->instance->setRowHidden(row, hide); \
return env.Null(); \
} \
Napi::Value isRowHidden(const Napi::CallbackInfo& info) { \
Napi::Env env = info.Env(); \
Napi::HandleScope scope(env); \
int row = info[0].As<Napi::Number>().Int32Value(); \
return Napi::Boolean::New(env, this->instance->isRowHidden(row)); \
}
#endif // QListView_WRAPPED_METHODS_DECLARATION
#ifndef QListView_WRAPPED_METHODS_EXPORT_DEFINE
#define QListView_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
InstanceMethod("clearPropertyFlags", &WidgetWrapName::clearPropertyFlags), \
InstanceMethod("setRowHidden", &WidgetWrapName::setRowHidden), \
InstanceMethod("isRowHidden", &WidgetWrapName::isRowHidden),
#endif // QListView_WRAPPED_METHODS_EXPORT_DEFINE
#ifndef QListView_SIGNALS
#define QListView_SIGNALS QABSTRACTITEMVIEW_SIGNALS
#endif // QListView_SIGNALS

View File

@ -0,0 +1,40 @@
#pragma once
#include <napi.h>
#include <QListWidget>
#include "QtWidgets/QListView/qlistview_macro.h"
#include "QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.h"
#include "core/NodeWidget/nodewidget.h"
class NListWidget : public QListWidget, public NodeWidget {
Q_OBJECT
NODEWIDGET_IMPLEMENTATIONS(QListWidget)
public:
using QListWidget::QListWidget;
void connectSignalsToEventEmitter() {
QObject::connect(
this, &QListWidget::currentRowChanged, [=](int currentRow) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "currentRowChanged"),
Napi::Number::New(env, currentRow)});
});
QObject::connect(this, &QListWidget::currentTextChanged,
[=](const QString &currentText) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call(
{Napi::String::New(env, "currentTextChanged"),
Napi::String::New(env, currentText.toStdString())});
});
QObject::connect(this, &QListWidget::itemSelectionChanged, [=]() {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "itemSelectionChanged")});
});
QListView_SIGNALS
}
};

View File

@ -0,0 +1,47 @@
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QPointer>
#include "Extras/Utils/nutils.h"
#include "QtWidgets/QListView/qlistview_macro.h"
#include "QtWidgets/QListWidget/nlistwidget.hpp"
class QListWidgetWrap : public Napi::ObjectWrap<QListWidgetWrap> {
private:
QPointer<NListWidget> instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QListWidgetWrap(const Napi::CallbackInfo& info);
~QListWidgetWrap();
NListWidget* getInternalInstance();
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value addItem(const Napi::CallbackInfo& info);
Napi::Value addItems(const Napi::CallbackInfo& info);
Napi::Value closePersistentEditor(const Napi::CallbackInfo& info);
Napi::Value currentItem(const Napi::CallbackInfo& info);
Napi::Value editItem(const Napi::CallbackInfo& info);
Napi::Value insertItem(const Napi::CallbackInfo& info);
Napi::Value insertItems(const Napi::CallbackInfo& info);
Napi::Value isPersistentEditorOpen(const Napi::CallbackInfo& info);
Napi::Value item(const Napi::CallbackInfo& info);
Napi::Value itemAt(const Napi::CallbackInfo& info);
Napi::Value itemWidget(const Napi::CallbackInfo& info);
Napi::Value openPersistentEditor(const Napi::CallbackInfo& info);
Napi::Value removeItemWidget(const Napi::CallbackInfo& info);
Napi::Value row(const Napi::CallbackInfo& info);
Napi::Value setCurrentItem(const Napi::CallbackInfo& info);
Napi::Value setItemWidget(const Napi::CallbackInfo& info);
Napi::Value sortItems(const Napi::CallbackInfo& info);
Napi::Value takeItem(const Napi::CallbackInfo& info);
Napi::Value visualItemRect(const Napi::CallbackInfo& info);
Napi::Value clear(const Napi::CallbackInfo& info);
Napi::Value scrollToItem(const Napi::CallbackInfo& info);
QListView_WRAPPED_METHODS_DECLARATION
};

View File

@ -0,0 +1,48 @@
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QListWidgetItem>
#include "Extras/Utils/nutils.h"
#include "core/Component/component_wrap.h"
class QListWidgetItemWrap : public Napi::ObjectWrap<QListWidgetItemWrap> {
private:
QListWidgetItem* instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QListWidgetItemWrap(const Napi::CallbackInfo& info);
~QListWidgetItemWrap();
QListWidgetItem* getInternalInstance();
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value setCheckState(const Napi::CallbackInfo& info);
Napi::Value checkState(const Napi::CallbackInfo& info);
Napi::Value data(const Napi::CallbackInfo& info);
Napi::Value setFlags(const Napi::CallbackInfo& info);
Napi::Value flags(const Napi::CallbackInfo& info);
Napi::Value setIcon(const Napi::CallbackInfo& info);
Napi::Value icon(const Napi::CallbackInfo& info);
Napi::Value setHidden(const Napi::CallbackInfo& info);
Napi::Value isHidden(const Napi::CallbackInfo& info);
Napi::Value setSelected(const Napi::CallbackInfo& info);
Napi::Value isSelected(const Napi::CallbackInfo& info);
Napi::Value setSizeHint(const Napi::CallbackInfo& info);
Napi::Value sizeHint(const Napi::CallbackInfo& info);
Napi::Value setStatusTip(const Napi::CallbackInfo& info);
Napi::Value statusTip(const Napi::CallbackInfo& info);
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value text(const Napi::CallbackInfo& info);
Napi::Value setTextAlignment(const Napi::CallbackInfo& info);
Napi::Value textAlignment(const Napi::CallbackInfo& info);
Napi::Value setToolTip(const Napi::CallbackInfo& info);
Napi::Value toolTip(const Napi::CallbackInfo& info);
Napi::Value setWhatsThis(const Napi::CallbackInfo& info);
Napi::Value whatsThis(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};

View File

@ -0,0 +1,137 @@
#include "QtCore/QModelIndex/qmodelindex_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtCore/QVariant/qvariant_wrap.h"
Napi::FunctionReference QModelIndexWrap::constructor;
Napi::Object QModelIndexWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QModelIndex";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("column", &QModelIndexWrap::column),
InstanceMethod("data", &QModelIndexWrap::data),
InstanceMethod("flags", &QModelIndexWrap::flags),
InstanceMethod("isValid", &QModelIndexWrap::isValid),
InstanceMethod("parent", &QModelIndexWrap::parent),
InstanceMethod("row", &QModelIndexWrap::row),
InstanceMethod("sibling", &QModelIndexWrap::sibling),
InstanceMethod("siblingAtColumn", &QModelIndexWrap::siblingAtColumn),
InstanceMethod("siblingAtRow", &QModelIndexWrap::siblingAtRow),
StaticMethod("fromQVariant",
&StaticQModelIndexWrapMethods::fromQVariant),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QModelIndexWrap::QModelIndexWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QModelIndexWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 0) {
this->instance = std::make_unique<QModelIndex>();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureComponent(this->getInternalInstance());
}
QModelIndexWrap::~QModelIndexWrap() { this->instance.reset(); }
QModelIndex* QModelIndexWrap::getInternalInstance() {
return this->instance.get();
}
Napi::Value QModelIndexWrap::column(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return Napi::Value::From(env, this->instance->column());
}
Napi::Value QModelIndexWrap::data(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int role = info[0].As<Napi::Number>().Int32Value();
QVariant data = this->instance->data(role);
auto instance = QVariantWrap::constructor.New(
{Napi::External<QVariant>::New(env, new QVariant(data))});
return instance;
}
Napi::Value QModelIndexWrap::flags(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Qt::ItemFlags flags = this->instance->flags();
return Napi::Value::From(env, static_cast<int>(flags));
}
Napi::Value QModelIndexWrap::isValid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return Napi::Value::From(env, this->instance->isValid());
}
Napi::Value QModelIndexWrap::parent(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndex parent = this->instance->parent();
auto instance = QModelIndexWrap::constructor.New(
{Napi::External<QModelIndex>::New(env, new QModelIndex(parent))});
return instance;
}
Napi::Value QModelIndexWrap::row(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return Napi::Value::From(env, this->instance->row());
}
Napi::Value QModelIndexWrap::sibling(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
int column = info[1].As<Napi::Number>().Int32Value();
QModelIndex sibling = this->instance->sibling(row, column);
auto instance = QModelIndexWrap::constructor.New(
{Napi::External<QModelIndex>::New(env, new QModelIndex(sibling))});
return instance;
}
Napi::Value QModelIndexWrap::siblingAtColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
QModelIndex index = this->instance->siblingAtColumn(column);
auto instance = QModelIndexWrap::constructor.New(
{Napi::External<QModelIndex>::New(env, new QModelIndex(index))});
return instance;
}
Napi::Value QModelIndexWrap::siblingAtRow(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
QModelIndex index = this->instance->siblingAtRow(row);
auto instance = QModelIndexWrap::constructor.New(
{Napi::External<QModelIndex>::New(env, new QModelIndex(index))});
return instance;
}
Napi::Value StaticQModelIndexWrapMethods::fromQVariant(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object variantObject = info[0].As<Napi::Object>();
QVariantWrap* variantWrap =
Napi::ObjectWrap<QVariantWrap>::Unwrap(variantObject);
QVariant* variant = variantWrap->getInternalInstance();
QModelIndex index = variant->value<QModelIndex>();
auto instance = QModelIndexWrap::constructor.New(
{Napi::External<QModelIndex>::New(env, new QModelIndex(index))});
return instance;
}

View File

@ -0,0 +1,320 @@
#include "QtWidgets/QListWidget/qlistwidget_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtCore/QRect/qrect_wrap.h"
#include "QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
Napi::FunctionReference QListWidgetWrap::constructor;
Napi::Object QListWidgetWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QListWidget";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("addItem", &QListWidgetWrap::addItem),
InstanceMethod("addItems", &QListWidgetWrap::addItems),
InstanceMethod("closePersistentEditor",
&QListWidgetWrap::closePersistentEditor),
InstanceMethod("currentItem", &QListWidgetWrap::currentItem),
InstanceMethod("editItem", &QListWidgetWrap::editItem),
InstanceMethod("insertItem", &QListWidgetWrap::insertItem),
InstanceMethod("insertItems", &QListWidgetWrap::insertItems),
InstanceMethod("isPersistentEditorOpen",
&QListWidgetWrap::isPersistentEditorOpen),
InstanceMethod("item", &QListWidgetWrap::item),
InstanceMethod("itemAt", &QListWidgetWrap::itemAt),
InstanceMethod("itemWidget", &QListWidgetWrap::itemWidget),
InstanceMethod("openPersistentEditor",
&QListWidgetWrap::openPersistentEditor),
InstanceMethod("removeItemWidget", &QListWidgetWrap::removeItemWidget),
InstanceMethod("row", &QListWidgetWrap::row),
InstanceMethod("setCurrentItem", &QListWidgetWrap::setCurrentItem),
InstanceMethod("setItemWidget", &QListWidgetWrap::setItemWidget),
InstanceMethod("sortItems", &QListWidgetWrap::sortItems),
InstanceMethod("takeItem", &QListWidgetWrap::takeItem),
InstanceMethod("visualItemRect", &QListWidgetWrap::visualItemRect),
InstanceMethod("clear", &QListWidgetWrap::clear),
InstanceMethod("scrollToItem", &QListWidgetWrap::scrollToItem),
QListView_WRAPPED_METHODS_EXPORT_DEFINE(QListWidgetWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
NListWidget* QListWidgetWrap::getInternalInstance() { return this->instance; }
QListWidgetWrap::~QListWidgetWrap() { extrautils::safeDelete(this->instance); }
QListWidgetWrap::QListWidgetWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QListWidgetWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 1) {
Napi::Object parentObject = info[0].As<Napi::Object>();
QWidgetWrap* parentWidgetWrap =
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
this->instance = new NListWidget(parentWidgetWrap->getInternalInstance());
} else if (info.Length() == 0) {
this->instance = new NListWidget();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureQWidget(
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
true);
}
Napi::Value QListWidgetWrap::addItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->addItem(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::addItems(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Array labelsNapi = info[0].As<Napi::Array>();
QStringList labels;
for (int i = 0; i < labelsNapi.Length(); i++) {
Napi::Value labelNapi = labelsNapi[i];
labels.append(
QString::fromUtf8(labelNapi.As<Napi::String>().Utf8Value().c_str()));
}
this->instance->addItems(labels);
return env.Null();
}
Napi::Value QListWidgetWrap::closePersistentEditor(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->closePersistentEditor(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::currentItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QListWidgetItem* item = this->instance->currentItem();
auto instance = QListWidgetItemWrap::constructor.New(
{Napi::External<QListWidgetItem>::New(env, item),
Napi::Boolean::New(env, true)});
return instance;
}
Napi::Value QListWidgetWrap::editItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->editItem(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::insertItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
Napi::Object itemObject = info[1].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->insertItem(row, itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::insertItems(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
Napi::Array labelsNapi = info[1].As<Napi::Array>();
QStringList labels;
for (int i = 0; i < labelsNapi.Length(); i++) {
Napi::Value labelNapi = labelsNapi[i];
labels.append(
QString::fromUtf8(labelNapi.As<Napi::String>().Utf8Value().c_str()));
}
this->instance->insertItems(row, labels);
return env.Null();
}
Napi::Value QListWidgetWrap::isPersistentEditorOpen(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
bool open =
this->instance->isPersistentEditorOpen(itemWrap->getInternalInstance());
return Napi::Value::From(env, open);
}
Napi::Value QListWidgetWrap::item(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
QListWidgetItem* item = this->instance->item(row);
auto instance = QListWidgetItemWrap::constructor.New(
{Napi::External<QListWidgetItem>::New(env, item),
Napi::Boolean::New(env, true)});
return instance;
}
Napi::Value QListWidgetWrap::itemAt(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int x = info[0].As<Napi::Number>().Int32Value();
int y = info[1].As<Napi::Number>().Int32Value();
QListWidgetItem* item = this->instance->itemAt(x, y);
auto instance = QListWidgetItemWrap::constructor.New(
{Napi::External<QListWidgetItem>::New(env, item),
Napi::Boolean::New(env, true)});
return instance;
}
Napi::Value QListWidgetWrap::itemWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
QWidget* widget = this->instance->itemWidget(itemWrap->getInternalInstance());
auto instance =
QWidgetWrap::constructor.New({Napi::External<QWidget>::New(env, widget),
Napi::Boolean::New(env, true)});
return instance;
}
Napi::Value QListWidgetWrap::openPersistentEditor(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->openPersistentEditor(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::removeItemWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->removeItemWidget(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::row(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
int row = this->instance->row(itemWrap->getInternalInstance());
return Napi::Value::From(env, row);
}
Napi::Value QListWidgetWrap::setCurrentItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
this->instance->setCurrentItem(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::setItemWidget(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
Napi::Object widgetObject = info[1].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
QWidgetWrap* widgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(widgetObject);
this->instance->setItemWidget(itemWrap->getInternalInstance(),
widgetWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetWrap::sortItems(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int order = info[0].As<Napi::Number>().Int32Value();
this->instance->sortItems(static_cast<Qt::SortOrder>(order));
return env.Null();
}
Napi::Value QListWidgetWrap::takeItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->takeItem(row);
return env.Null();
}
Napi::Value QListWidgetWrap::visualItemRect(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
QRect rect = this->instance->visualItemRect(itemWrap->getInternalInstance());
auto rectWrap = QRectWrap::constructor.New(
{Napi::External<QRect>::New(env, new QRect(rect))});
return rectWrap;
}
Napi::Value QListWidgetWrap::clear(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->clear();
return env.Null();
}
Napi::Value QListWidgetWrap::scrollToItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QListWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QListWidgetItemWrap>::Unwrap(itemObject);
int hint = info[1].As<Napi::Number>().Int32Value();
this->instance->scrollToItem(
itemWrap->getInternalInstance(),
static_cast<QAbstractItemView::ScrollHint>(hint));
return env.Null();
}

View File

@ -0,0 +1,268 @@
#include "QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtCore/QSize/qsize_wrap.h"
#include "QtGui/QIcon/qicon_wrap.h"
#include "core/Component/component_wrap.h"
Napi::FunctionReference QListWidgetItemWrap::constructor;
Napi::Object QListWidgetItemWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QListWidgetItem";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("setCheckState", &QListWidgetItemWrap::setCheckState),
InstanceMethod("checkState", &QListWidgetItemWrap::checkState),
InstanceMethod("data", &QListWidgetItemWrap::data),
InstanceMethod("setFlags", &QListWidgetItemWrap::setFlags),
InstanceMethod("flags", &QListWidgetItemWrap::flags),
InstanceMethod("setIcon", &QListWidgetItemWrap::setIcon),
InstanceMethod("icon", &QListWidgetItemWrap::icon),
InstanceMethod("setHidden", &QListWidgetItemWrap::setHidden),
InstanceMethod("isHidden", &QListWidgetItemWrap::isHidden),
InstanceMethod("setSelected", &QListWidgetItemWrap::setSelected),
InstanceMethod("isSelected", &QListWidgetItemWrap::isSelected),
InstanceMethod("setSizeHint", &QListWidgetItemWrap::setSizeHint),
InstanceMethod("sizeHint", &QListWidgetItemWrap::sizeHint),
InstanceMethod("setStatusTip", &QListWidgetItemWrap::setStatusTip),
InstanceMethod("statusTip", &QListWidgetItemWrap::statusTip),
InstanceMethod("setText", &QListWidgetItemWrap::setText),
InstanceMethod("text", &QListWidgetItemWrap::text),
InstanceMethod("setTextAlignment",
&QListWidgetItemWrap::setTextAlignment),
InstanceMethod("textAlignment", &QListWidgetItemWrap::textAlignment),
InstanceMethod("setToolTip", &QListWidgetItemWrap::setToolTip),
InstanceMethod("toolTip", &QListWidgetItemWrap::toolTip),
InstanceMethod("setWhatsThis", &QListWidgetItemWrap::setWhatsThis),
InstanceMethod("whatsThis", &QListWidgetItemWrap::whatsThis),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QListWidgetItem* QListWidgetItemWrap::getInternalInstance() {
return this->instance;
}
QListWidgetItemWrap::~QListWidgetItemWrap() { delete this->instance; }
QListWidgetItemWrap::QListWidgetItemWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QListWidgetItemWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 1) {
QString text =
QString::fromUtf8(info[0].As<Napi::String>().Utf8Value().c_str());
this->instance = new QListWidgetItem(text);
} else if (info.Length() == 0) {
this->instance = new QListWidgetItem();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureComponent(this->getInternalInstance());
}
Napi::Value QListWidgetItemWrap::setCheckState(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int state = info[0].As<Napi::Number>().Int32Value();
this->instance->setCheckState(static_cast<Qt::CheckState>(state));
return env.Null();
}
Napi::Value QListWidgetItemWrap::checkState(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int state = static_cast<int>(this->instance->checkState());
return Napi::Value::From(env, state);
}
Napi::Value QListWidgetItemWrap::data(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int role = info[0].As<Napi::Number>().Int32Value();
QVariant data = this->instance->data(role);
auto instance = QVariantWrap::constructor.New(
{Napi::External<QVariant>::New(env, new QVariant(data))});
return instance;
}
Napi::Value QListWidgetItemWrap::setFlags(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int flags = info[0].As<Napi::Number>().Int32Value();
this->instance->setFlags(static_cast<Qt::ItemFlags>(flags));
return env.Null();
}
Napi::Value QListWidgetItemWrap::flags(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int flags = static_cast<int>(this->instance->flags());
return Napi::Value::From(env, flags);
}
Napi::Value QListWidgetItemWrap::setIcon(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object iconObject = info[0].As<Napi::Object>();
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject);
this->instance->setIcon(*iconWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetItemWrap::icon(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QIcon icon = this->instance->icon();
auto instance = QIconWrap::constructor.New(
{Napi::External<QIcon>::New(env, new QIcon(icon))});
return instance;
}
Napi::Value QListWidgetItemWrap::setHidden(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool hide = info[0].As<Napi::Boolean>().Value();
this->instance->setHidden(hide);
return env.Null();
}
Napi::Value QListWidgetItemWrap::isHidden(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return Napi::Value::From(env, this->instance->isHidden());
}
Napi::Value QListWidgetItemWrap::setSelected(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool select = info[0].As<Napi::Boolean>().Value();
this->instance->setSelected(select);
return env.Null();
}
Napi::Value QListWidgetItemWrap::isSelected(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
return Napi::Value::From(env, this->instance->isSelected());
}
Napi::Value QListWidgetItemWrap::setSizeHint(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object sizeObject = info[0].As<Napi::Object>();
QSizeWrap* sizeWrap = Napi::ObjectWrap<QSizeWrap>::Unwrap(sizeObject);
this->instance->setSizeHint(*sizeWrap->getInternalInstance());
return env.Null();
}
Napi::Value QListWidgetItemWrap::sizeHint(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QSize size = this->instance->sizeHint();
auto instance = QSizeWrap::constructor.New({Napi::External<QSize>::New(
env, new QSize(size.width(), size.height()))});
return instance;
}
Napi::Value QListWidgetItemWrap::setStatusTip(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string statusTip = info[0].As<Napi::String>().Utf8Value();
this->instance->setStatusTip(QString::fromUtf8(statusTip.c_str()));
return env.Null();
}
Napi::Value QListWidgetItemWrap::statusTip(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string statusTip = this->instance->text().toStdString();
return Napi::String::New(env, statusTip);
}
Napi::Value QListWidgetItemWrap::setText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string text = info[0].As<Napi::String>().Utf8Value();
this->instance->setText(QString::fromUtf8(text.c_str()));
return env.Null();
}
Napi::Value QListWidgetItemWrap::text(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string text = this->instance->text().toStdString();
return Napi::String::New(env, text);
}
Napi::Value QListWidgetItemWrap::setTextAlignment(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int alignment = info[0].As<Napi::Number>().Int32Value();
this->instance->setTextAlignment(alignment);
return env.Null();
}
Napi::Value QListWidgetItemWrap::textAlignment(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int alignment = this->instance->textAlignment();
return Napi::Number::New(env, alignment);
}
Napi::Value QListWidgetItemWrap::setToolTip(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string toolTip = info[0].As<Napi::String>().Utf8Value();
this->instance->setToolTip(QString::fromUtf8(toolTip.c_str()));
return env.Null();
}
Napi::Value QListWidgetItemWrap::toolTip(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string toolTip = this->instance->toolTip().toStdString();
return Napi::String::New(env, toolTip);
}
Napi::Value QListWidgetItemWrap::setWhatsThis(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string whatsThis = info[0].As<Napi::String>().Utf8Value();
this->instance->setWhatsThis(QString::fromUtf8(whatsThis.c_str()));
return env.Null();
}
Napi::Value QListWidgetItemWrap::whatsThis(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string whatsThis = this->instance->whatsThis().toStdString();
return Napi::String::New(env, whatsThis);
}

View File

@ -24,9 +24,7 @@ Napi::Object QPlainTextEditWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("setLineWrapMode", &QPlainTextEditWrap::setLineWrapMode),
InstanceMethod("lineWrapMode", &QPlainTextEditWrap::lineWrapMode),
InstanceMethod("insertPlainText", &QPlainTextEditWrap::insertPlainText),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPlainTextEditWrap)
QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(
QPlainTextEditWrap)});
QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(QPlainTextEditWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;

View File

@ -1,5 +1,6 @@
#include <napi.h>
#include "QtCore/QModelIndex/qmodelindex_wrap.h"
#include "QtCore/QObject/qobject_wrap.h"
#include "QtCore/QPoint/qpoint_wrap.h"
#include "QtCore/QRect/qrect_wrap.h"
@ -30,6 +31,8 @@
#include "QtWidgets/QLabel/qlabel_wrap.h"
#include "QtWidgets/QLayout/qlayout_wrap.h"
#include "QtWidgets/QLineEdit/qlineedit_wrap.h"
#include "QtWidgets/QListWidget/qlistwidget_wrap.h"
#include "QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.h"
#include "QtWidgets/QMainWindow/qmainwindow_wrap.h"
#include "QtWidgets/QMenu/qmenu_wrap.h"
#include "QtWidgets/QMenuBar/qmenubar_wrap.h"
@ -60,6 +63,7 @@ void InitPrivateHelpers(Napi::Env env) {
Napi::Object Main(Napi::Env env, Napi::Object exports) {
InitPrivateHelpers(env);
QApplicationWrap::init(env, exports);
QModelIndexWrap::init(env, exports);
QObjectWrap::init(env, exports);
QVariantWrap::init(env, exports);
QSizeWrap::init(env, exports);
@ -80,6 +84,8 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
QComboBoxWrap::init(env, exports);
QBoxLayoutWrap::init(env, exports);
QFileDialogWrap::init(env, exports);
QListWidgetWrap::init(env, exports);
QListWidgetItemWrap::init(env, exports);
QTableWidgetWrap::init(env, exports);
QTableWidgetItemWrap::init(env, exports);
QPainterWrap::init(env, exports);

View File

@ -24,6 +24,7 @@ export { NodeLayout, QLayoutSignals } from './lib/QtWidgets/QLayout';
export { QAbstractScrollArea } from './lib/QtWidgets/QAbstractScrollArea';
export { QAbstractSlider, QAbstractSliderSignals } from './lib/QtWidgets/QAbstractSlider';
export { QAbstractButton, QAbstractButtonSignals } from './lib/QtWidgets/QAbstractButton';
export { QAbstractItemView, QAbstractItemViewSignals } from './lib/QtWidgets/QAbstractItemView';
// Widgets:
export { QCheckBox, QCheckBoxSignals } from './lib/QtWidgets/QCheckBox';
export { QLabel, QLabelSignals } from './lib/QtWidgets/QLabel';
@ -38,6 +39,8 @@ export { QToolButton, QToolButtonSignals, ToolButtonPopupMode } from './lib/QtWi
export { QSpinBox, QSpinBoxSignals } from './lib/QtWidgets/QSpinBox';
export { QRadioButton, QRadioButtonSignals } from './lib/QtWidgets/QRadioButton';
export { QStackedWidget, QStackedWidgetSignals } from './lib/QtWidgets/QStackedWidget';
export { QListWidget, QListWidgetSignals } from './lib/QtWidgets/QListWidget';
export { QListWidgetItem } from './lib/QtWidgets/QListWidgetItem';
export { QTabWidget, QTabWidgetSignals } from './lib/QtWidgets/QTabWidget';
export { QTableWidget, QTableWidgetSignals } from './lib/QtWidgets/QTableWidget';
export { QTableWidgetItem } from './lib/QtWidgets/QTableWidgetItem';
@ -58,6 +61,7 @@ export { QAction, QActionSignals } from './lib/QtWidgets/QAction';
export { QShortcut, QShortcutSignals } from './lib/QtWidgets/QShortcut';
export { QGroupBox, QGroupBoxSignals } from './lib/QtWidgets/QGroupBox';
// Core
export { QModelIndex } from './lib/QtCore/QModelIndex';
export { QObject, QObjectSignals, NodeObject } from './lib/QtCore/QObject';
export { QVariant } from './lib/QtCore/QVariant';
export { QSize } from './lib/QtCore/QSize';

View File

@ -0,0 +1,52 @@
import addon from '../utils/addon';
import { NativeElement, Component } from '../core/Component';
import { QVariant } from './QVariant';
import { checkIfNativeElement } from '../utils/helpers';
import { ItemDataRole } from '../QtEnums/ItemDataRole';
import { ItemFlag } from '../QtEnums/ItemFlag';
export class QModelIndex extends Component {
native: NativeElement;
constructor();
constructor(nativeElement: NativeElement);
constructor(arg?: NativeElement) {
super();
if (!arg) {
this.native = new addon.QModelIndex();
} else if (checkIfNativeElement(arg)) {
this.native = arg as NativeElement;
} else {
throw new Error('QModelIndex cannot be initialised this way.');
}
}
column(): number {
return this.native.column();
}
data(role: ItemDataRole = ItemDataRole.DisplayRole): QVariant {
return new QVariant(this.native.data(role));
}
flags(): ItemFlag {
return this.native.flags();
}
isValid(): boolean {
return this.native.isValid();
}
parent(): QModelIndex {
return new QModelIndex(this.native.parent());
}
row(): number {
return this.native.row();
}
sibling(row: number, column: number): QModelIndex {
return new QModelIndex(this.native.sibling(row, column));
}
siblingAtColumn(column: number): QModelIndex {
return new QModelIndex(this.native.siblingAtColumn(column));
}
siblingAtRow(row: number): QModelIndex {
return new QModelIndex(this.native.siblingAtRow(row));
}
static fromQVariant(variant: QVariant): QModelIndex {
return new QModelIndex(addon.QModelIndex.fromQVariant(variant.native));
}
}

View File

@ -0,0 +1,171 @@
import { QAbstractScrollArea, QAbstractScrollAreaSignals } from './QAbstractScrollArea';
import { QWidget } from './QWidget';
import { QModelIndex } from '../QtCore/QModelIndex';
import { QSize } from '../QtCore/QSize';
import { DropAction } from '../QtEnums/DropAction';
import { TextElideMode } from '../QtEnums/TextElideMode';
export enum DragDropMode {
NoDragDrop,
DragOnly,
DropOnly,
DragDrop,
InternalMove,
}
export enum EditTrigger {
NoEditTriggers = 0,
CurrentChanged = 1,
DoubleClicked = 2,
SelectedClicked = 4,
EditKeyPressed = 8,
AnyKeyPressed = 16,
AllEditTriggers = 31,
}
export enum ScrollMode {
ScrollPerItem,
ScrollPerPixel,
}
export enum SelectionBehavior {
SelectItems,
SelectRows,
SelectColumns,
}
export enum SelectionMode {
NoSelection,
SingleSelection,
MultiSelection,
ExtendedSelection,
ContiguousSelection,
}
export interface QAbstractItemViewSignals extends QAbstractScrollAreaSignals {
viewportEntered: () => void;
}
export abstract class QAbstractItemView<Signals extends QAbstractItemViewSignals> extends QAbstractScrollArea<Signals> {
setCurrentIndex(index: QModelIndex): void {
this.native.setCurrentIndex(index.native);
}
currentIndex(): QModelIndex {
return new QModelIndex(this.native.currentIndex());
}
setIndexWidget(index: QModelIndex, widget: QWidget): void {
this.native.setIndexWidget(index.native, widget.native);
}
indexWidget(index: QModelIndex): QWidget {
return new QWidget(this.native.indexWidget(index));
}
scrollToBottom(): void {
this.native.scrollToBottom();
}
scrollToTop(): void {
this.native.scrollToTop();
}
setAlternatingRowColors(enable: boolean): void {
this.setProperty('alternatingRowColors', enable);
}
alternatingRowColors(): boolean {
return this.property('alternatingRowColors').toBool();
}
setAutoScroll(enable: boolean): void {
this.setProperty('autoScroll', enable);
}
hasAutoScroll(): boolean {
return this.property('autoScroll').toBool();
}
setAutoScrollMargin(margin: number): void {
this.setProperty('autoScrollMargin', margin);
}
autoScrollMargin(): number {
return this.property('autoScrollMargin').toInt();
}
setDefaultDropAction(dropAction: DropAction): void {
this.setProperty('defaultDropAction', dropAction);
}
defaultDropAction(): DropAction {
return this.property('defaultDropAction').toInt();
}
setDragDropMode(behavior: DragDropMode): void {
this.setProperty('dragDropMode', behavior);
}
dragDropMode(): DragDropMode {
return this.property('dragDropMode').toInt();
}
setDragDropOverwriteMode(overwrite: boolean): void {
this.setProperty('dragDropOverwriteMode', overwrite);
}
dragDropOverwriteMode(): boolean {
return this.property('dragDropOverwriteMode').toBool();
}
setDragEnabled(enable: boolean): void {
this.setProperty('dragEnabled', enable);
}
dragEnabled(): boolean {
return this.property('dragEnabled').toBool();
}
setEditTriggers(triggers: number): void {
this.setProperty('editTriggers', triggers);
}
editTriggers(): number {
return this.property('editTriggers').toInt();
}
setHorizontalScrollMode(mode: boolean): void {
this.setProperty('horizontalScrollMode', mode);
}
horizontalScrollMode(): ScrollMode {
return this.property('horizontalScrollMode').toInt();
}
resetHorizontalScrollMode(): void {
this.native.resetHorizontalScrollMode();
}
setIconSize(iconSize: QSize): void {
this.setProperty('iconSize', iconSize.native);
}
iconSize(): QSize {
const iconSize = this.property('iconSize');
return QSize.fromQVariant(iconSize);
}
setSelectionBehavior(behavior: SelectionBehavior): void {
this.setProperty('selectionBehavior', behavior);
}
selectionBehavior(): SelectionBehavior {
return this.property('selectionBehavior').toInt();
}
setSelectionMode(mode: SelectionMode): void {
this.setProperty('selectionMode', mode);
}
selectionMode(): SelectionMode {
return this.property('selectionMode').toInt();
}
setDropIndicatorShown(enable: boolean): void {
this.setProperty('showDropIndicator', enable);
}
showDropIndicator(): boolean {
return this.property('showDropIndicator').toBool();
}
setTabKeyNavigation(enable: boolean): void {
this.setProperty('tabKeyNavigation', enable);
}
tabKeyNavigation(): boolean {
return this.property('tabKeyNavigation').toBool();
}
setTextElideMode(mode: TextElideMode): void {
this.setProperty('textElideMode', mode);
}
textElideMode(): TextElideMode {
return this.property('textElideMode').toInt();
}
setVerticalScrollMode(mode: ScrollMode): void {
this.setProperty('verticalScrollMode', mode);
}
verticalScrollMode(): ScrollMode {
return this.property('verticalScrollMode').toInt();
}
resetVerticalScrollMode(): void {
this.native.resetVerticalScrollMode();
}
}

View File

@ -0,0 +1,233 @@
import addon from '../utils/addon';
import { NodeWidget, QWidget } from './QWidget';
import { NativeElement, Component } from '../core/Component';
import { QListWidgetItem } from './QListWidgetItem';
import { QAbstractItemView, QAbstractItemViewSignals } from './QAbstractItemView';
import { QSize } from '../QtCore/QSize';
import { QRect } from '../QtCore/QRect';
import { SortOrder, ScrollHint, AlignmentFlag } from '../QtEnums';
export enum Flow {
LeftToRight,
TopToBottom,
}
export enum LayoutMode {
SinglePass,
Batched,
}
export enum Movement {
Static,
Free,
Snap,
}
export enum ResizeMode {
Fixed,
Adjust,
}
export enum ViewMode {
ListMode,
IconMode,
}
export interface QListWidgetSignals extends QAbstractItemViewSignals {
currentRowChanged: (currentRow: number) => void;
currentTextChanged: (currentText: string) => void;
itemSelectionChanged: () => void;
}
export class QListWidget extends QAbstractItemView<QListWidgetSignals> {
native: NativeElement;
items: Set<NativeElement | Component>;
constructor();
constructor(parent: NodeWidget<any>);
constructor(parent?: NodeWidget<any>) {
let native;
if (parent) {
native = new addon.QListWidget(parent.native);
} else {
native = new addon.QListWidget();
}
super(native);
this.native = native;
this.setNodeParent(parent);
this.items = new Set();
}
addItem(item: QListWidgetItem): void {
this.native.addItem(item.native);
this.items.add(item);
}
addItems(labels: string[]): void {
this.native.addItems(labels);
}
closePersistentEditor(item: QListWidgetItem): void {
this.native.closePersistentEditor(item.native);
}
currentItem(): QListWidgetItem {
return new QListWidgetItem(this.native.currentItem());
}
editItem(item: Component): void {
this.native.editItem(item.native);
}
insertItem(row: number, item: QListWidgetItem): void {
this.native.insertItem(row, item.native);
this.items.add(item);
}
insertItems(row: number, labels: string[]): void {
this.native.insertItems(row, labels);
}
isPersistentEditorOpen(item: QListWidgetItem): boolean {
return this.native.isPersistentEditorOpen(item.native);
}
item(row: number): QListWidgetItem {
return new QListWidgetItem(this.native.item(row));
}
itemAt(x: number, y: number): QListWidgetItem {
return new QListWidgetItem(this.native.itemAt(x, y));
}
itemWidget(item: QListWidgetItem): QWidget {
return new QWidget(this.native.itemWidget(item.native));
}
openPersistentEditor(item: QListWidgetItem): void {
this.native.openPersistentEditor(item.native);
}
removeItemWidget(item: QListWidgetItem): void {
this.native.removeItemWidget(item.native);
}
row(item: QListWidgetItem): number {
return this.native.row(item.native);
}
setCurrentItem(item: QListWidgetItem): void {
this.native.setCurrentItem(item.native);
}
setItemWidget(item: QListWidgetItem, widget: QWidget): void {
this.native.setItemWidget(item.native, widget.native);
}
sortItems(order: SortOrder): void {
this.native.sortItems(order);
}
takeItem(row: number): void {
this.native.takeItem(row);
}
visualItemRect(item: QListWidgetItem): QRect {
return new QRect(this.native.visualItemRect(item.native));
}
clear(): void {
this.native.clear();
}
scrollToItem(item: QListWidgetItem, hint: ScrollHint): void {
this.native.scrollToItem(item.native, hint);
}
clearPropertyFlags(): void {
this.native.clearPropertyFlags();
}
setRowHidden(row: number, hide: boolean): void {
this.native.setRowHidden(row, hide);
}
isRowHidden(row: number): boolean {
return this.native.isRowHidden(row);
}
count(): number {
return this.property('count').toInt();
}
setCurrentRow(row: number): void {
this.setProperty('currentRow', row);
}
currentRow(): number {
return this.property('currentRow').toInt();
}
setSortingEnabled(enable: boolean): void {
this.setProperty('sortingEnabled', enable);
}
isSortingEnabled(): boolean {
return this.property('sortingEnabled').toBool();
}
setBatchSize(batchSize: number): void {
this.setProperty('batchSize', batchSize);
}
batchSize(): number {
return this.property('batchSize').toInt();
}
setFlow(flow: Flow): void {
this.setProperty('flow', flow);
}
flow(): Flow {
return this.property('flow').toInt();
}
setGridSize(size: QSize): void {
this.setProperty('gridSize', size.native);
}
gridSize(): QSize {
const gridSize = this.property('gridSize');
return QSize.fromQVariant(gridSize);
}
setWrapping(enable: boolean): void {
this.setProperty('isWrapping', enable);
}
isWrapping(): boolean {
return this.property('isWrapping').toBool();
}
setItemAlignment(alignment: AlignmentFlag): void {
this.setProperty('itemAlignment', alignment);
}
itemAlignment(): AlignmentFlag {
return this.property('itemAlignment').toInt();
}
setLayoutMode(mode: LayoutMode): void {
this.setProperty('layoutMode', mode);
}
layoutMode(): LayoutMode {
return this.property('layoutMode').toInt();
}
setModelColumn(column: number): void {
this.setProperty('modelColumn', column);
}
modelColumn(): number {
return this.property('modelColumn').toInt();
}
setMovement(movement: Movement): void {
this.setProperty('movement', movement);
}
movement(): Movement {
return this.property('movement').toInt();
}
setResizeMode(mode: ResizeMode): void {
this.setProperty('resizeMode', mode);
}
resizeMode(): ResizeMode {
return this.property('resizeMode').toInt();
}
setSelectionRectVisible(show: boolean): void {
this.setProperty('selectionRectVisible', show);
}
isSelectionRectVisible(): boolean {
return this.property('selectionRectVisible').toBool();
}
setSpacing(space: number): void {
this.setProperty('spacing', space);
}
spacing(): number {
return this.property('spacing').toInt();
}
setUniformItemSizes(enable: boolean): void {
this.setProperty('uniformItemSizes', enable);
}
uniformItemSizes(): boolean {
return this.property('uniformItemSizes').toBool();
}
setViewMode(mode: ViewMode): void {
this.setProperty('viewMode', mode);
}
viewMode(): ViewMode {
return this.property('viewMode').toInt();
}
setWordWrap(on: boolean): void {
this.setProperty('wordWrap', on);
}
wordWrap(): boolean {
return this.property('wordWrap').toBool();
}
}

View File

@ -0,0 +1,94 @@
import addon from '../utils/addon';
import { NativeElement, Component } from '../core/Component';
import { QIcon } from '../QtGui/QIcon';
import { QSize } from '../QtCore/QSize';
import { QVariant } from '../QtCore/QVariant';
import { checkIfNativeElement } from '../utils/helpers';
import { CheckState } from '../QtEnums';
import { ItemFlag } from '../QtEnums/ItemFlag';
type arg = string | NativeElement;
export class QListWidgetItem extends Component {
native: NativeElement;
constructor(arg?: arg) {
let native;
if (typeof arg === 'string') {
native = new addon.QListWidgetItem(arg);
} else if (checkIfNativeElement(arg)) {
native = arg as NativeElement;
} else {
native = new addon.QListWidgetItem();
}
super();
this.native = native;
}
setCheckState(state: CheckState): void {
this.native.setCheckState(state);
}
checkState(): CheckState {
return this.native.checkState();
}
data(role: number): QVariant {
return new QVariant(this.native.data(role));
}
setFlags(flags: ItemFlag): void {
this.native.setFlags(flags);
}
flags(): ItemFlag {
return this.native.flags();
}
setIcon(icon: QIcon): void {
this.native.setIcon(icon.native);
}
icon(): QIcon {
return new QIcon(this.native.icon());
}
setHidden(hide: boolean): void {
this.native.setHidden(hide);
}
isHidden(): boolean {
return this.native.isHidden();
}
setSelected(select: boolean): void {
this.native.setSelected(select);
}
isSelected(): boolean {
return this.native.isSelected();
}
setSizeHint(size: QSize): void {
this.native.setSizeHint(size.native);
}
sizeHint(): QSize {
return new QSize(this.native.sizeHint());
}
setStatusTip(statusTip: string): void {
this.native.setStatusTip(statusTip);
}
statusTip(): string {
return this.native.statusTip();
}
setText(text: string): void {
this.native.setText(text);
}
text(): string {
return this.native.text();
}
setTextAlignment(alignment: number): void {
return this.native.setTextAlignment(alignment);
}
textAlignment(): number {
return this.native.textAlignment();
}
setToolTip(toolTip: string): void {
this.native.setToolTip(toolTip);
}
toolTip(): string {
return this.native.toolTip();
}
setWhatsThis(whatsThis: string): void {
this.native.setWhatsThis(whatsThis);
}
whatsThis(): string {
return this.native.whatsThis();
}
}

View File

@ -28,7 +28,7 @@ export class QTableWidget extends QAbstractScrollArea<QTableWidgetSignals> {
constructor(rows: number, columns: number, parent?: NodeWidget<any>) {
let native;
if (parent) {
native = new addon.QTableWidget(rows, columns, parent);
native = new addon.QTableWidget(rows, columns, parent.native);
} else {
native = new addon.QTableWidget(rows, columns);
}