Qtablewidget rebase (#264)

* sync upstream

* Initial tablewidget

* methods from tableview and signals

* remove comment in CMakeLists

* inherits from QAbstractScrollArea

* revert demo
This commit is contained in:
slidinghotdog 2019-12-14 00:57:34 -03:00 committed by Atul R
parent 9aa53ea118
commit a59e8b5e2e
14 changed files with 926 additions and 16 deletions

View File

@ -56,6 +56,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/QTableWidget/qtablewidget_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGridLayout/qgridlayout_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QDial/qdial_wrap.cpp"
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QLabel/qlabel_wrap.cpp"
@ -86,6 +88,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/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"
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QProgressBar/nprogressbar.hpp"

View File

@ -20,7 +20,7 @@ class QFontDatabaseWrap : public Napi::ObjectWrap<QFontDatabaseWrap> {
Napi::Value bold(const Napi::CallbackInfo& info);
Napi::Value italic(const Napi::CallbackInfo& info);
Napi::Value weight(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};

View File

@ -0,0 +1,76 @@
#pragma once
#include <QTableWidget>
#include "core/NodeWidget/nodewidget.h"
#include "napi.h"
class NTableWidget : public QTableWidget, public NodeWidget {
public:
Q_OBJECT
NODEWIDGET_IMPLEMENTATIONS(QTableWidget)
using QTableWidget::QTableWidget;
void connectWidgetSignalsToEventEmitter() {
// Qt Connects: Implement all signal connects here
QObject::connect(
this, &QTableWidget::cellActivated, [=](int row, int column) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "cellActivated"),
Napi::Number::New(env, row),
Napi::Number::New(env, column)});
});
QObject::connect(
this, &QTableWidget::cellChanged, [=](int row, int column) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "cellChanged"),
Napi::Number::New(env, row),
Napi::Number::New(env, column)});
});
QObject::connect(
this, &QTableWidget::cellClicked, [=](int row, int column) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "cellClicked"),
Napi::Number::New(env, row),
Napi::Number::New(env, column)});
});
QObject::connect(
this, &QTableWidget::cellDoubleClicked, [=](int row, int column) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "cellDoubleClicked"),
Napi::Number::New(env, row),
Napi::Number::New(env, column)});
});
QObject::connect(
this, &QTableWidget::cellEntered, [=](int row, int column) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "cellEntered"),
Napi::Number::New(env, row),
Napi::Number::New(env, column)});
});
QObject::connect(
this, &QTableWidget::cellPressed, [=](int row, int column) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "cellPressed"),
Napi::Number::New(env, row),
Napi::Number::New(env, column)});
});
QObject::connect(
this, &QTableWidget::currentCellChanged,
[=](int currentRow, int currentColumn, int previousRow,
int previousColumn) {
Napi::Env env = this->emitOnNode.Env();
Napi::HandleScope scope(env);
this->emitOnNode.Call({Napi::String::New(env, "currentCellChanged"),
Napi::Number::New(env, currentRow),
Napi::Number::New(env, currentColumn),
Napi::Number::New(env, previousRow),
Napi::Number::New(env, previousColumn)});
});
}
};

View File

@ -0,0 +1,60 @@
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QPointer>
#include "Extras/Utils/nutils.h"
#include "QtWidgets/QAbstractScrollArea/qabstractscrollarea_macro.h"
#include "QtWidgets/QTableWidget/ntablewidget.hpp"
class QTableWidgetWrap : public Napi::ObjectWrap<QTableWidgetWrap> {
private:
QPointer<NTableWidget> instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QTableWidgetWrap(const Napi::CallbackInfo& info);
~QTableWidgetWrap();
NTableWidget* getInternalInstance();
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value selectedRanges(const Napi::CallbackInfo& info);
Napi::Value closePersistentEditor(const Napi::CallbackInfo& info);
Napi::Value editItem(const Napi::CallbackInfo& info);
Napi::Value setCellWidget(const Napi::CallbackInfo& info);
Napi::Value setItem(const Napi::CallbackInfo& info);
Napi::Value setHorizontalHeaderItem(const Napi::CallbackInfo& info);
Napi::Value setHorizontalHeaderLabels(const Napi::CallbackInfo& info);
Napi::Value setVerticalHeaderItem(const Napi::CallbackInfo& info);
Napi::Value setVerticalHeaderLabels(const Napi::CallbackInfo& info);
Napi::Value clear(const Napi::CallbackInfo& info);
Napi::Value clearContents(const Napi::CallbackInfo& info);
Napi::Value insertColumn(const Napi::CallbackInfo& info);
Napi::Value removeColumn(const Napi::CallbackInfo& info);
Napi::Value insertRow(const Napi::CallbackInfo& info);
Napi::Value removeRow(const Napi::CallbackInfo& info);
Napi::Value scrollToItem(const Napi::CallbackInfo& info);
// FROM TABLEVIEW
Napi::Value hideColumn(const Napi::CallbackInfo& info);
Napi::Value hideRow(const Napi::CallbackInfo& info);
Napi::Value resizeColumnToContents(const Napi::CallbackInfo& info);
Napi::Value resizeColumnsToContents(const Napi::CallbackInfo& info);
Napi::Value resizeRowToContents(const Napi::CallbackInfo& info);
Napi::Value resizeRowsToContents(const Napi::CallbackInfo& info);
Napi::Value selectColumn(const Napi::CallbackInfo& info);
Napi::Value selectRow(const Napi::CallbackInfo& info);
Napi::Value setShowGrid(const Napi::CallbackInfo& info);
Napi::Value showGrid(const Napi::CallbackInfo& info);
Napi::Value showColumn(const Napi::CallbackInfo& info);
Napi::Value showRow(const Napi::CallbackInfo& info);
Napi::Value sortByColumn(const Napi::CallbackInfo& info);
Napi::Value setColumnWidth(const Napi::CallbackInfo& info);
Napi::Value setRowHeight(const Napi::CallbackInfo& info);
Napi::Value setSortingEnabled(const Napi::CallbackInfo& info);
Napi::Value isSortingEnabled(const Napi::CallbackInfo& info);
QABSTRACTSCROLLAREA_WRAPPED_METHODS_DECLARATION
};

View File

@ -0,0 +1,31 @@
#pragma once
#include <napi.h>
#include <stdlib.h>
#include <QTableWidgetItem>
#include "Extras/Utils/nutils.h"
#include "core/Component/component_wrap.h"
class QTableWidgetItemWrap : public Napi::ObjectWrap<QTableWidgetItemWrap> {
private:
QTableWidgetItem* instance;
public:
static Napi::Object init(Napi::Env env, Napi::Object exports);
QTableWidgetItemWrap(const Napi::CallbackInfo& info);
~QTableWidgetItemWrap();
QTableWidgetItem* getInternalInstance();
// class constructor
static Napi::FunctionReference constructor;
// wrapped methods
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value setToolTip(const Napi::CallbackInfo& info);
Napi::Value setTextAlignment(const Napi::CallbackInfo& info);
Napi::Value textAlignment(const Napi::CallbackInfo& info);
Napi::Value text(const Napi::CallbackInfo& info);
Napi::Value toolTip(const Napi::CallbackInfo& info);
COMPONENT_WRAPPED_METHODS_DECLARATION
};

View File

@ -7,17 +7,16 @@ Napi::FunctionReference QFontDatabaseWrap::constructor;
Napi::Object QFontDatabaseWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QFontDatabase";
Napi::Function func =
DefineClass(
env, CLASSNAME,
{InstanceMethod("bold", &QFontDatabaseWrap::bold),
InstanceMethod("italic", &QFontDatabaseWrap::italic),
InstanceMethod("weight", &QFontDatabaseWrap::weight),
StaticMethod("addApplicationFont",
&StaticQFontDatabaseWrapMethods::addApplicationFont),
StaticMethod("removeApplicationFont",
&StaticQFontDatabaseWrapMethods::removeApplicationFont),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("bold", &QFontDatabaseWrap::bold),
InstanceMethod("italic", &QFontDatabaseWrap::italic),
InstanceMethod("weight", &QFontDatabaseWrap::weight),
StaticMethod("addApplicationFont",
&StaticQFontDatabaseWrapMethods::addApplicationFont),
StaticMethod("removeApplicationFont",
&StaticQFontDatabaseWrapMethods::removeApplicationFont),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
@ -31,8 +30,8 @@ QFontDatabaseWrap::QFontDatabaseWrap(const Napi::CallbackInfo& info)
this->rawData = extrautils::configureComponent(this->getInternalInstance());
}
QFontDatabase* QFontDatabaseWrap::getInternalInstance() {
return this->instance.get();
QFontDatabase* QFontDatabaseWrap::getInternalInstance() {
return this->instance.get();
}
Napi::Value QFontDatabaseWrap::bold(const Napi::CallbackInfo& info) {
@ -70,8 +69,8 @@ Napi::Value StaticQFontDatabaseWrapMethods::addApplicationFont(
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
std::string fileName = info[0].As<Napi::String>().Utf8Value();
int id =
QFontDatabase::addApplicationFont(QString::fromUtf8(fileName.c_str()));
int id =
QFontDatabase::addApplicationFont(QString::fromUtf8(fileName.c_str()));
return Napi::Value::From(env, id);
}

View File

@ -0,0 +1,447 @@
#include "QtWidgets/QTableWidget/qtablewidget_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
Napi::FunctionReference QTableWidgetWrap::constructor;
Napi::Object QTableWidgetWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QTableWidget";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("selectedRanges", &QTableWidgetWrap::selectedRanges),
InstanceMethod("closePersistentEditor",
&QTableWidgetWrap::closePersistentEditor),
InstanceMethod("editItem", &QTableWidgetWrap::editItem),
InstanceMethod("setCellWidget", &QTableWidgetWrap::setCellWidget),
InstanceMethod("setItem", &QTableWidgetWrap::setItem),
InstanceMethod("setHorizontalHeaderItem",
&QTableWidgetWrap::setHorizontalHeaderItem),
InstanceMethod("setHorizontalHeaderLabels",
&QTableWidgetWrap::setHorizontalHeaderLabels),
InstanceMethod("setVerticalHeaderItem",
&QTableWidgetWrap::setVerticalHeaderItem),
InstanceMethod("setVerticalHeaderLabels",
&QTableWidgetWrap::setVerticalHeaderLabels),
InstanceMethod("clear", &QTableWidgetWrap::clear),
InstanceMethod("clearContents", &QTableWidgetWrap::clearContents),
InstanceMethod("insertColumn", &QTableWidgetWrap::insertColumn),
InstanceMethod("removeColumn", &QTableWidgetWrap::removeColumn),
InstanceMethod("insertRow", &QTableWidgetWrap::insertRow),
InstanceMethod("removeRow", &QTableWidgetWrap::removeRow),
InstanceMethod("scrollToItem", &QTableWidgetWrap::scrollToItem),
// FROM TABLEVIEW
InstanceMethod("hideColumn", &QTableWidgetWrap::hideColumn),
InstanceMethod("hideRow", &QTableWidgetWrap::hideRow),
InstanceMethod("resizeColumnToContents",
&QTableWidgetWrap::resizeColumnToContents),
InstanceMethod("resizeColumnsToContents",
&QTableWidgetWrap::resizeColumnsToContents),
InstanceMethod("resizeRowToContents",
&QTableWidgetWrap::resizeRowToContents),
InstanceMethod("resizeRowsToContents",
&QTableWidgetWrap::resizeRowsToContents),
InstanceMethod("selectColumn", &QTableWidgetWrap::selectColumn),
InstanceMethod("selectRow", &QTableWidgetWrap::selectRow),
InstanceMethod("setShowGrid", &QTableWidgetWrap::setShowGrid),
InstanceMethod("showGrid", &QTableWidgetWrap::showGrid),
InstanceMethod("showColumn", &QTableWidgetWrap::showColumn),
InstanceMethod("showRow", &QTableWidgetWrap::showRow),
InstanceMethod("sortByColumn", &QTableWidgetWrap::sortByColumn),
InstanceMethod("setColumnWidth", &QTableWidgetWrap::setColumnWidth),
InstanceMethod("setRowHeight", &QTableWidgetWrap::setRowHeight),
InstanceMethod("setSortingEnabled",
&QTableWidgetWrap::setSortingEnabled),
InstanceMethod("isSortingEnabled", &QTableWidgetWrap::isSortingEnabled),
QABSTRACTSCROLLAREA_WRAPPED_METHODS_EXPORT_DEFINE(QTableWidgetWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
NTableWidget* QTableWidgetWrap::getInternalInstance() { return this->instance; }
QTableWidgetWrap::~QTableWidgetWrap() {
extrautils::safeDelete(this->instance);
}
QTableWidgetWrap::QTableWidgetWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QTableWidgetWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if (info.Length() == 2 || info.Length() == 3) {
int rows = info[0].As<Napi::Number>().Int32Value();
int columns = info[1].As<Napi::Number>().Int32Value();
if (info.Length() == 3) {
Napi::Object parentObject = info[2].As<Napi::Object>();
QWidgetWrap* parentWidgetWrap =
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
this->instance = new NTableWidget(
rows, columns, parentWidgetWrap->getInternalInstance());
} else {
this->instance = new NTableWidget(rows, columns);
}
} else if (info.Length() == 1) {
Napi::Object parentObject = info[0].As<Napi::Object>();
QWidgetWrap* parentWidgetWrap =
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
this->instance = new NTableWidget(parentWidgetWrap->getInternalInstance());
} else if (info.Length() == 0) {
this->instance = new NTableWidget();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureQWidget(
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
false);
}
Napi::Value QTableWidgetWrap::selectedRanges(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QList<QTableWidgetSelectionRange> range = this->instance->selectedRanges();
Napi::Array napiRange = Napi::Array::New(env, range.size());
for (int i = 0; i < range.size(); i++) {
int topRow = range[0].topRow();
int leftColumn = range[0].leftColumn();
int bottomRow = range[0].bottomRow();
int rightColumn = range[0].rightColumn();
int columnCount = range[0].columnCount();
int rowCount = range[0].rowCount();
Napi::Object newRange = Napi::Object::New(env);
newRange.Set("topRow", Napi::Number::New(env, topRow));
newRange.Set("leftColumn", Napi::Number::New(env, leftColumn));
newRange.Set("bottomRow", Napi::Number::New(env, bottomRow));
newRange.Set("rightColumn", Napi::Number::New(env, rightColumn));
newRange.Set("columnCount", Napi::Number::New(env, columnCount));
newRange.Set("rowCount", Napi::Number::New(env, rowCount));
napiRange[i] = newRange;
}
return napiRange;
return env.Null();
}
Napi::Value QTableWidgetWrap::closePersistentEditor(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QTableWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QTableWidgetItemWrap>::Unwrap(itemObject);
this->instance->closePersistentEditor(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QTableWidgetWrap::editItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QTableWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QTableWidgetItemWrap>::Unwrap(itemObject);
this->instance->editItem(itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QTableWidgetWrap::setCellWidget(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();
Napi::Object widgetObject = info[2].As<Napi::Object>();
QWidgetWrap* widgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(widgetObject);
this->instance->setCellWidget(row, column, widgetWrap->getInternalInstance());
return env.Null();
}
Napi::Value QTableWidgetWrap::setItem(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();
Napi::Object itemObject = info[2].As<Napi::Object>();
QTableWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QTableWidgetItemWrap>::Unwrap(itemObject);
this->instance->setItem(row, column, itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QTableWidgetWrap::setHorizontalHeaderItem(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
Napi::Object itemObject = info[0].As<Napi::Object>();
QTableWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QTableWidgetItemWrap>::Unwrap(itemObject);
this->instance->setHorizontalHeaderItem(column,
itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QTableWidgetWrap::setHorizontalHeaderLabels(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Array labelsNapi = info[0].As<Napi::Array>();
QList<QString> list;
for (int i = 0; i < labelsNapi.Length(); i++) {
Napi::Value labelNapi = labelsNapi[i];
list.append(labelNapi.As<Napi::String>().Utf8Value().c_str());
}
QStringList labels = QStringList(list);
this->instance->setHorizontalHeaderLabels(labels);
return env.Null();
}
Napi::Value QTableWidgetWrap::setVerticalHeaderItem(
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[0].As<Napi::Object>();
QTableWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QTableWidgetItemWrap>::Unwrap(itemObject);
this->instance->setVerticalHeaderItem(row, itemWrap->getInternalInstance());
return env.Null();
}
Napi::Value QTableWidgetWrap::setVerticalHeaderLabels(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Array labelsNapi = info[0].As<Napi::Array>();
QList<QString> list;
for (int i = 0; i < labelsNapi.Length(); i++) {
Napi::Value labelNapi = labelsNapi[i];
list.append(labelNapi.As<Napi::String>().Utf8Value().c_str());
}
QStringList labels = QStringList(list);
this->instance->setVerticalHeaderLabels(labels);
return env.Null();
}
Napi::Value QTableWidgetWrap::clear(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->clear();
return env.Null();
}
Napi::Value QTableWidgetWrap::clearContents(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->clearContents();
return env.Null();
}
Napi::Value QTableWidgetWrap::insertColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
this->instance->insertColumn(column);
return env.Null();
}
Napi::Value QTableWidgetWrap::removeColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
this->instance->removeColumn(column);
return env.Null();
}
Napi::Value QTableWidgetWrap::insertRow(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->insertRow(row);
return env.Null();
}
Napi::Value QTableWidgetWrap::removeRow(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->removeRow(row);
return env.Null();
}
Napi::Value QTableWidgetWrap::scrollToItem(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object itemObject = info[0].As<Napi::Object>();
QTableWidgetItemWrap* itemWrap =
Napi::ObjectWrap<QTableWidgetItemWrap>::Unwrap(itemObject);
int hintInt = info[1].As<Napi::Number>().Int32Value();
QAbstractItemView::ScrollHint hint =
static_cast<QAbstractItemView::ScrollHint>(hintInt);
this->instance->scrollToItem(itemWrap->getInternalInstance(), hint);
return env.Null();
}
// FROM TABLEVIEW
Napi::Value QTableWidgetWrap::hideColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
this->instance->hideColumn(column);
return env.Null();
}
Napi::Value QTableWidgetWrap::hideRow(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->hideRow(row);
return env.Null();
}
Napi::Value QTableWidgetWrap::resizeColumnToContents(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
this->instance->resizeColumnToContents(column);
return env.Null();
}
Napi::Value QTableWidgetWrap::resizeColumnsToContents(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->resizeColumnsToContents();
return env.Null();
}
Napi::Value QTableWidgetWrap::resizeRowToContents(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->resizeRowToContents(row);
return env.Null();
}
Napi::Value QTableWidgetWrap::resizeRowsToContents(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->resizeRowsToContents();
return env.Null();
}
Napi::Value QTableWidgetWrap::selectColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
this->instance->selectColumn(column);
return env.Null();
}
Napi::Value QTableWidgetWrap::selectRow(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->selectRow(row);
return env.Null();
}
Napi::Value QTableWidgetWrap::setShowGrid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool show = info[0].As<Napi::Boolean>().Value();
this->instance->setShowGrid(show);
return env.Null();
}
Napi::Value QTableWidgetWrap::showGrid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool show = this->instance->showGrid();
return Napi::Boolean::New(env, show);
}
Napi::Value QTableWidgetWrap::showColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
this->instance->showColumn(column);
return env.Null();
}
Napi::Value QTableWidgetWrap::showRow(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
this->instance->showRow(row);
return env.Null();
}
Napi::Value QTableWidgetWrap::sortByColumn(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
int orderInt = info[1].As<Napi::Number>().Int32Value();
Qt::SortOrder order = static_cast<Qt::SortOrder>(orderInt);
this->instance->sortByColumn(column, order);
return env.Null();
}
Napi::Value QTableWidgetWrap::setColumnWidth(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int column = info[0].As<Napi::Number>().Int32Value();
int width = info[1].As<Napi::Number>().Int32Value();
this->instance->setColumnWidth(column, width);
return env.Null();
}
Napi::Value QTableWidgetWrap::setRowHeight(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int row = info[0].As<Napi::Number>().Int32Value();
int height = info[1].As<Napi::Number>().Int32Value();
this->instance->setRowHeight(row, height);
return env.Null();
}
Napi::Value QTableWidgetWrap::setSortingEnabled(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool enable = info[0].As<Napi::Boolean>().Value();
this->instance->setSortingEnabled(enable);
return env.Null();
}
Napi::Value QTableWidgetWrap::isSortingEnabled(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
bool enabled = this->instance->isSortingEnabled();
return Napi::Boolean::New(env, enabled);
}

View File

@ -0,0 +1,96 @@
#include "QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h"
#include "Extras/Utils/nutils.h"
#include "core/Component/component_wrap.h"
Napi::FunctionReference QTableWidgetItemWrap::constructor;
Napi::Object QTableWidgetItemWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QTableWidgetItem";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("setText", &QTableWidgetItemWrap::setText),
InstanceMethod("setToolTip", &QTableWidgetItemWrap::setToolTip),
InstanceMethod("setTextAlignment",
&QTableWidgetItemWrap::setTextAlignment),
InstanceMethod("textAlignment", &QTableWidgetItemWrap::textAlignment),
InstanceMethod("text", &QTableWidgetItemWrap::text),
InstanceMethod("toolTip", &QTableWidgetItemWrap::toolTip),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
QTableWidgetItem* QTableWidgetItemWrap::getInternalInstance() {
return this->instance;
}
QTableWidgetItemWrap::~QTableWidgetItemWrap() { delete this->instance; }
QTableWidgetItemWrap::QTableWidgetItemWrap(const Napi::CallbackInfo& info)
: Napi::ObjectWrap<QTableWidgetItemWrap>(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 QTableWidgetItem(text);
} else if (info.Length() == 0) {
this->instance = new QTableWidgetItem();
} else {
Napi::TypeError::New(env, "Wrong number of arguments")
.ThrowAsJavaScriptException();
}
this->rawData = extrautils::configureComponent(this->getInternalInstance());
}
Napi::Value QTableWidgetItemWrap::setText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String napiText = info[0].As<Napi::String>();
std::string text = napiText.Utf8Value();
this->instance->setText(QString::fromUtf8(text.c_str()));
return env.Null();
}
Napi::Value QTableWidgetItemWrap::setToolTip(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::String napiText = info[0].As<Napi::String>();
std::string tollTip = napiText.Utf8Value();
this->instance->setToolTip(QString::fromUtf8(tollTip.c_str()));
return env.Null();
}
Napi::Value QTableWidgetItemWrap::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 QTableWidgetItemWrap::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);
return env.Null();
}
Napi::Value QTableWidgetItemWrap::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);
return env.Null();
}
Napi::Value QTableWidgetItemWrap::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);
return env.Null();
}

View File

@ -40,6 +40,8 @@
#include "QtWidgets/QStackedWidget/qstackedwidget_wrap.h"
#include "QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h"
#include "QtWidgets/QTabWidget/qtabwidget_wrap.h"
#include "QtWidgets/QTableWidget/qtablewidget_wrap.h"
#include "QtWidgets/QTableWidgetItem/qtablewidgetitem_wrap.h"
#include "QtWidgets/QWidget/qwidget_wrap.h"
#include "core/FlexLayout/flexlayout_wrap.h"
// These cant be instantiated in JS Side
@ -68,6 +70,8 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
QComboBoxWrap::init(env, exports);
QBoxLayoutWrap::init(env, exports);
QFileDialogWrap::init(env, exports);
QTableWidgetWrap::init(env, exports);
QTableWidgetItemWrap::init(env, exports);
QGridLayoutWrap::init(env, exports);
QGroupBoxWrap::init(env, exports);
FlexLayoutWrap::init(env, exports);

View File

@ -38,6 +38,8 @@ export { QSpinBox, QSpinBoxEvents } from './lib/QtWidgets/QSpinBox';
export { QRadioButton, QRadioButtonEvents } from './lib/QtWidgets/QRadioButton';
export { QStackedWidget, QStackedWidgetEvents } from './lib/QtWidgets/QStackedWidget';
export { QTabWidget, QTabWidgetEvents } from './lib/QtWidgets/QTabWidget';
export { QTableWidget, QTableWidgetEvents } from './lib/QtWidgets/QTableWidget';
export { QTableWidgetItem } from './lib/QtWidgets/QTableWidgetItem';
export { QMenu, QMenuEvents } from './lib/QtWidgets/QMenu';
export { QMenuBar, QMenuBarEvents } from './lib/QtWidgets/QMenuBar';
export { QPlainTextEdit, QPlainTextEditEvents, LineWrapMode } from './lib/QtWidgets/QPlainTextEdit';

View File

@ -0,0 +1,6 @@
export enum ScrollHint {
EnsureVisible = 0,
PositionAtTop = 1,
PositionAtBottom = 2,
PositionAtCenter = 3,
}

View File

@ -59,6 +59,7 @@ export { Option } from './Option';
export { Orientation } from './Orientation';
export { ScreenOrientation } from './ScreenOrientation';
export { ScrollBarPolicy } from './ScrollBarPolicy';
export { ScrollHint } from './ScrollHint';
export { ScrollPhase } from './ScrollPhase';
export { ShortcutContext } from './ShortcutContext';
export { SizeAdjustPolicy } from './SizeAdjustPolicy';

View File

@ -0,0 +1,150 @@
import addon from '../utils/addon';
import { NodeWidget } from './QWidget';
import { BaseWidgetEvents } from '../core/EventWidget';
import { NativeElement, Component } from '../core/Component';
import { ScrollHint, SortOrder } from '../QtEnums';
import { QTableWidgetItem } from './QTableWidgetItem';
import { QAbstractScrollArea } from './QAbstractScrollArea';
export const QTableWidgetEvents = Object.freeze({
...BaseWidgetEvents,
cellActivated: 'cellActivated',
cellChanged: 'cellChanged',
cellClicked: 'cellClicked',
cellDoubleClicked: 'cellDoubleClicked',
cellEntered: 'cellEntered',
cellPressed: 'cellPressed',
currentCellChanged: 'currentCellChanged',
});
interface Range {
topRow: number;
rightColumn: number;
bottomRow: number;
leftColumn: number;
columnCount: number;
rowCount: number;
}
export class QTableWidget extends QAbstractScrollArea {
native: NativeElement;
items: Set<NativeElement | Component>;
constructor(rows: number, columns: number, parent?: NodeWidget) {
let native;
if (parent) {
native = new addon.QTableWidget(rows, columns, parent);
} else {
native = new addon.QTableWidget(rows, columns);
}
super(native);
this.native = native;
this.nodeParent = parent;
this.items = new Set();
}
selectedRanges(): Range[] {
return this.native.selectedRanges();
}
closePersistentEditor(item: QTableWidgetItem): void {
this.native.closePersistentEditor(item.native);
}
editItem(item: Component): void {
this.native.editItem(item.native);
}
setCellWidget(row: number, column: number, widget: NodeWidget): void {
this.native.setCellWidget(row, column, widget.native);
this.items.add(widget);
}
setItem(row: number, column: number, item: QTableWidgetItem): void {
this.native.setItem(row, column, item.native);
this.items.add(item);
}
setHorizontalHeaderItem(column: number, item: QTableWidgetItem): void {
this.native.setHorizontalHeaderItem(column, item.native);
this.items.add(item);
}
setHorizontalHeaderLabels(labels: string[]): void {
this.native.setHorizontalHeaderLabels(labels);
}
setVerticalHeaderItem(row: number, item: QTableWidgetItem): void {
this.native.setVerticalHeaderItem(row, item.native);
this.items.add(item);
}
setVerticalHeaderLabels(labels: string[]): void {
this.native.setVerticalHeaderLabels(labels);
}
clear(): void {
this.native.clear();
this.items.clear();
}
clearContents(): void {
this.native.clearContents();
this.items.clear();
}
insertColumn(column: number): void {
this.native.insertColumn(column);
}
removeColumn(column: number): void {
this.native.removeColumn(column);
}
insertRow(row: number): void {
this.native.insertRow(row);
}
removeRow(row: number): void {
this.native.removeRow(row);
}
scrollToItem(item: QTableWidgetItem, hint: ScrollHint = ScrollHint.EnsureVisible): void {
this.native.scrollToItem(item.native, hint);
}
// FROM TABLEVIEW
hideColumn(column: number): void {
this.native.hideColumn(column);
}
hideRow(row: number): void {
this.native.hideRow(row);
}
resizeColumnToContents(column: number): void {
this.native.resizeColumnToContents(column);
}
resizeColumnsToContents(): void {
this.native.resizeColumnsToContents();
}
resizeRowToContents(row: number): void {
this.native.resizeRowToContents(row);
}
resizeRowsToContents(): void {
this.native.resizeRowsToContents();
}
selectColumn(column: number): void {
this.native.selectColumn(column);
}
selectRow(row: number): void {
this.native.selectRow(row);
}
setShowGrid(show: boolean): void {
this.native.setShowGrid(show);
}
showGrid(): boolean {
return this.native.showGrid();
}
showColumn(column: number): void {
this.native.showColumn(column);
}
showRow(row: number): void {
this.native.showRow(row);
}
sortByColumn(column: number, order: SortOrder): void {
this.native.sortByColumn(column, order);
}
setColumnWidth(column: number, width: number): void {
this.native.setColumnWidth(column, width);
}
setRowHeight(row: number, height: number): void {
this.native.setRowHeight(row, height);
}
setSortingEnabled(enable: boolean): void {
this.native.setSortingEnabled(enable);
}
isSortingEnabled(): boolean {
return this.native.isSortingEnabled();
}
}

View File

@ -0,0 +1,35 @@
import addon from '../utils/addon';
import { NativeElement, Component } from '../core/Component';
import { AlignmentFlag } from '../QtEnums';
export class QTableWidgetItem extends Component {
native: NativeElement;
constructor(text?: string) {
let native;
if (text) {
native = new addon.QTableWidgetItem(text);
} else {
native = new addon.QTableWidgetItem();
}
super();
this.native = native;
}
setText(text: string): void {
this.native.setText(text);
}
setToolTip(text: string): void {
this.native.setToolTip(text);
}
setTextAlignment(alignment: AlignmentFlag): void {
this.native.setTextAlignment(alignment);
}
textAlignment(): AlignmentFlag {
return this.native.textAlignment();
}
text(): string {
return this.native.text();
}
toolTip(): string {
return this.native.toolTip();
}
}