From 053fc9dc6522b25b13fcc29f4c0406dbeee21884 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Mon, 16 Aug 2021 22:10:33 +0200 Subject: [PATCH] Add (basic) `QHeaderView`; Support wrappers on plain Qt widgets --- CMakeLists.txt | 2 + .../QtWidgets/QHeaderView/nheaderview.hpp | 16 +++ .../QtWidgets/QHeaderView/qheaderview_wrap.h | 25 ++++ .../QtWidgets/QTableView/qtableview_macro.h | 93 ++++++++----- .../nodegui/core/Events/eventwidget_macro.h | 29 ++-- .../core/YogaWidget/yogawidget_macro.h | 39 +++--- .../QHeaderView/qheaderview_wrap.cpp | 61 +++++++++ src/cpp/main.cpp | 2 + src/index.ts | 1 + src/lib/QtWidgets/QHeaderView.ts | 110 +++++++++++++++ src/lib/QtWidgets/QTableView.ts | 127 ++++++++++++------ 11 files changed, 404 insertions(+), 101 deletions(-) create mode 100644 src/cpp/include/nodegui/QtWidgets/QHeaderView/nheaderview.hpp create mode 100644 src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h create mode 100644 src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp create mode 100644 src/lib/QtWidgets/QHeaderView.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index f717554c0..7ad3b4ff1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QFrame/qframe_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListView/qlistview_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp" @@ -208,6 +209,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTextEdit/ntextedit.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QSvgWidget/nsvgwidget.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QDesktopWidget/nqdesktopwidget.hpp" + "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QHeaderView/nheaderview.hpp" ) AddCommonConfig(${CORE_WIDGETS_ADDON}) diff --git a/src/cpp/include/nodegui/QtWidgets/QHeaderView/nheaderview.hpp b/src/cpp/include/nodegui/QtWidgets/QHeaderView/nheaderview.hpp new file mode 100644 index 000000000..fac500ab2 --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QHeaderView/nheaderview.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include + +#include "Extras/Utils/nutils.h" +#include "QtWidgets/QAbstractItemView/qabstractitemview_macro.h" +#include "core/NodeWidget/nodewidget.h" + +class DLL_EXPORT NHeaderView : public QHeaderView, public NodeWidget { + Q_OBJECT + NODEWIDGET_IMPLEMENTATIONS(QHeaderView) + public: + using QHeaderView::QHeaderView; + + void connectSignalsToEventEmitter() { QABSTRACTITEMVIEW_SIGNALS } +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h b/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h new file mode 100644 index 000000000..8874a6c4e --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QHeaderView/qheaderview_wrap.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include + +#include "Extras/Utils/nutils.h" +#include "QtWidgets/QAbstractItemView/qabstractitemview_macro.h" +#include "QtWidgets/QHeaderView/nheaderview.hpp" + +class DLL_EXPORT QHeaderViewWrap : public Napi::ObjectWrap { + QABSTRACTITEMVIEW_WRAPPED_METHODS_DECLARATION + private: + QPointer instance; + bool disableDeletion; + + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QHeaderViewWrap(const Napi::CallbackInfo& info); + ~QHeaderViewWrap(); + QHeaderView* getInternalInstance(); + // class constructor + static Napi::FunctionReference constructor; + // wrapped methods +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h b/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h index 537658c00..b3e6be365 100644 --- a/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QTableView/qtableview_macro.h @@ -3,6 +3,7 @@ #include #include "QtWidgets/QAbstractItemView/qabstractitemview_macro.h" +#include "QtWidgets/QHeaderView/qheaderview_wrap.h" /* @@ -203,48 +204,66 @@ Qt::SortOrder order = static_cast(orderInt); \ this->instance->sortByColumn(column, order); \ return env.Null(); \ + } \ + Napi::Value horizontalHeader(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + auto header = this->instance->horizontalHeader(); \ + auto instance = QHeaderViewWrap::constructor.New( \ + {Napi::External::New(env, header)}); \ + return instance; \ + } \ + Napi::Value verticalHeader(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + auto header = this->instance->verticalHeader(); \ + auto instance = QHeaderViewWrap::constructor.New( \ + {Napi::External::New(env, header)}); \ + return instance; \ } #endif // QTABLEVIEW_WRAPPED_METHODS_DECLARATION #ifndef QTABLEVIEW_WRAPPED_METHODS_EXPORT_DEFINE -#define QTABLEVIEW_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ - \ - QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ - \ - InstanceMethod("clearSpans", &WidgetWrapName::clearSpans), \ - InstanceMethod("columnAt", &WidgetWrapName::columnAt), \ - InstanceMethod("columnSpan", &WidgetWrapName::columnSpan), \ - InstanceMethod("columnViewportPosition", \ - &WidgetWrapName::columnViewportPosition), \ - InstanceMethod("columnWidth", &WidgetWrapName::columnWidth), \ - InstanceMethod("isColumnHidden", &WidgetWrapName::isColumnHidden), \ - InstanceMethod("isRowHidden", &WidgetWrapName::isRowHidden), \ - InstanceMethod("rowAt", &WidgetWrapName::rowAt), \ - InstanceMethod("rowHeight", &WidgetWrapName::rowHeight), \ - InstanceMethod("rowSpan", &WidgetWrapName::rowSpan), \ - InstanceMethod("rowViewportPosition", \ - &WidgetWrapName::rowViewportPosition), \ - InstanceMethod("setColumnHidden", &WidgetWrapName::setColumnHidden), \ - InstanceMethod("setColumnWidth", &WidgetWrapName::setColumnWidth), \ - InstanceMethod("setRowHeight", &WidgetWrapName::setRowHeight), \ - InstanceMethod("setRowHidden", &WidgetWrapName::setRowHidden), \ - InstanceMethod("setSpan", &WidgetWrapName::setSpan), \ - InstanceMethod("hideColumn", &WidgetWrapName::hideColumn), \ - InstanceMethod("hideRow", &WidgetWrapName::hideRow), \ - InstanceMethod("resizeColumnToContents", \ - &WidgetWrapName::resizeColumnToContents), \ - InstanceMethod("resizeColumnsToContents", \ - &WidgetWrapName::resizeColumnsToContents), \ - InstanceMethod("resizeRowToContents", \ - &WidgetWrapName::resizeRowToContents), \ - InstanceMethod("resizeRowsToContents", \ - &WidgetWrapName::resizeRowsToContents), \ - InstanceMethod("selectColumn", &WidgetWrapName::selectColumn), \ - InstanceMethod("selectRow", &WidgetWrapName::selectRow), \ - InstanceMethod("showColumn", &WidgetWrapName::showColumn), \ - InstanceMethod("showRow", &WidgetWrapName::showRow), \ - InstanceMethod("sortByColumn", &WidgetWrapName::sortByColumn), +#define QTABLEVIEW_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ + \ + QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \ + \ + InstanceMethod("clearSpans", &WidgetWrapName::clearSpans), \ + InstanceMethod("columnAt", &WidgetWrapName::columnAt), \ + InstanceMethod("columnSpan", &WidgetWrapName::columnSpan), \ + InstanceMethod("columnViewportPosition", \ + &WidgetWrapName::columnViewportPosition), \ + InstanceMethod("columnWidth", &WidgetWrapName::columnWidth), \ + InstanceMethod("isColumnHidden", &WidgetWrapName::isColumnHidden), \ + InstanceMethod("isRowHidden", &WidgetWrapName::isRowHidden), \ + InstanceMethod("rowAt", &WidgetWrapName::rowAt), \ + InstanceMethod("rowHeight", &WidgetWrapName::rowHeight), \ + InstanceMethod("rowSpan", &WidgetWrapName::rowSpan), \ + InstanceMethod("rowViewportPosition", \ + &WidgetWrapName::rowViewportPosition), \ + InstanceMethod("setColumnHidden", &WidgetWrapName::setColumnHidden), \ + InstanceMethod("setColumnWidth", &WidgetWrapName::setColumnWidth), \ + InstanceMethod("setRowHeight", &WidgetWrapName::setRowHeight), \ + InstanceMethod("setRowHidden", &WidgetWrapName::setRowHidden), \ + InstanceMethod("setSpan", &WidgetWrapName::setSpan), \ + InstanceMethod("hideColumn", &WidgetWrapName::hideColumn), \ + InstanceMethod("hideRow", &WidgetWrapName::hideRow), \ + InstanceMethod("resizeColumnToContents", \ + &WidgetWrapName::resizeColumnToContents), \ + InstanceMethod("resizeColumnsToContents", \ + &WidgetWrapName::resizeColumnsToContents), \ + InstanceMethod("resizeRowToContents", \ + &WidgetWrapName::resizeRowToContents), \ + InstanceMethod("resizeRowsToContents", \ + &WidgetWrapName::resizeRowsToContents), \ + InstanceMethod("selectColumn", &WidgetWrapName::selectColumn), \ + InstanceMethod("selectRow", &WidgetWrapName::selectRow), \ + InstanceMethod("showColumn", &WidgetWrapName::showColumn), \ + InstanceMethod("showRow", &WidgetWrapName::showRow), \ + InstanceMethod("sortByColumn", &WidgetWrapName::sortByColumn), \ + InstanceMethod("horizontalHeader", &WidgetWrapName::horizontalHeader), \ + InstanceMethod("verticalHeader", &WidgetWrapName::horizontalHeader) #endif // QTABLEVIEW_WRAPPED_METHODS_EXPORT_DEFINE diff --git a/src/cpp/include/nodegui/core/Events/eventwidget_macro.h b/src/cpp/include/nodegui/core/Events/eventwidget_macro.h index c6985f1a9..c93bc01c2 100644 --- a/src/cpp/include/nodegui/core/Events/eventwidget_macro.h +++ b/src/cpp/include/nodegui/core/Events/eventwidget_macro.h @@ -16,16 +16,21 @@ COMPONENT_WRAPPED_METHODS_DECLARATION \ Napi::Value initNodeEventEmitter(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ - this->instance->emitOnNode = \ - Napi::Persistent(info[0].As()); \ - this->instance->connectSignalsToEventEmitter(); \ + EventWidget* eventWidget = \ + dynamic_cast(this->instance.data()); \ + if (eventWidget) { \ + eventWidget->emitOnNode = \ + Napi::Persistent(info[0].As()); \ + eventWidget->connectSignalsToEventEmitter(); \ + } \ return env.Null(); \ } \ - \ Napi::Value getNodeEventEmitter(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ - if (this->instance->emitOnNode) { \ - return this->instance->emitOnNode.Value(); \ + EventWidget* eventWidget = \ + dynamic_cast(this->instance.data()); \ + if (eventWidget && eventWidget->emitOnNode) { \ + return eventWidget->emitOnNode.Value(); \ } else { \ return env.Null(); \ } \ @@ -33,13 +38,21 @@ Napi::Value subscribeToQtEvent(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ Napi::String eventString = info[0].As(); \ - this->instance->subscribeToQtEvent(eventString.Utf8Value()); \ + EventWidget* eventWidget = \ + dynamic_cast(this->instance.data()); \ + if (eventWidget) { \ + eventWidget->subscribeToQtEvent(eventString.Utf8Value()); \ + } \ return env.Null(); \ } \ Napi::Value unSubscribeToQtEvent(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ Napi::String eventString = info[0].As(); \ - this->instance->unSubscribeToQtEvent(eventString.Utf8Value()); \ + EventWidget* eventWidget = \ + dynamic_cast(this->instance.data()); \ + if (eventWidget) { \ + eventWidget->unSubscribeToQtEvent(eventString.Utf8Value()); \ + } \ return env.Null(); \ } diff --git a/src/cpp/include/nodegui/core/YogaWidget/yogawidget_macro.h b/src/cpp/include/nodegui/core/YogaWidget/yogawidget_macro.h index a94066f0c..f9f763db0 100644 --- a/src/cpp/include/nodegui/core/YogaWidget/yogawidget_macro.h +++ b/src/cpp/include/nodegui/core/YogaWidget/yogawidget_macro.h @@ -8,21 +8,30 @@ */ #ifndef YOGAWIDGET_WRAPPED_METHODS_DECLARATION -#define YOGAWIDGET_WRAPPED_METHODS_DECLARATION \ - \ - Napi::Value getFlexNode(const Napi::CallbackInfo& info) { \ - YGNodeRef node = this->instance->getFlexNode(); \ - Napi::Value yogaNodeRef = Napi::External::New(info.Env(), node); \ - return yogaNodeRef; \ - } \ - Napi::Value setFlexNodeSizeControlled(const Napi::CallbackInfo& info) { \ - Napi::Env env = info.Env(); \ - Napi::HandleScope scope(env); \ - Napi::Boolean isSizeControlled = info[0].As(); \ - YGNodeRef node = this->instance->getFlexNode(); \ - FlexNodeContext* ctx = flexutils::getFlexNodeContext(node); \ - ctx->isSizeControlled = isSizeControlled.Value(); \ - return env.Null(); \ +#define YOGAWIDGET_WRAPPED_METHODS_DECLARATION \ + \ + Napi::Value getFlexNode(const Napi::CallbackInfo& info) { \ + FlexItem* item = dynamic_cast(this->instance.data()); \ + if (item) { \ + YGNodeRef node = item->getFlexNode(); \ + Napi::Value yogaNodeRef = Napi::External::New(info.Env(), node); \ + return yogaNodeRef; \ + } else { \ + Napi::Env env = info.Env(); \ + return env.Null(); \ + } \ + } \ + Napi::Value setFlexNodeSizeControlled(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + FlexItem* item = dynamic_cast(this->instance.data()); \ + if (item) { \ + Napi::Boolean isSizeControlled = info[0].As(); \ + YGNodeRef node = item->getFlexNode(); \ + FlexNodeContext* ctx = flexutils::getFlexNodeContext(node); \ + ctx->isSizeControlled = isSizeControlled.Value(); \ + } \ + return env.Null(); \ } #endif // YOGAWIDGET_WRAPPED_METHODS_DECLARATION diff --git a/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp b/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp new file mode 100644 index 000000000..097466dcc --- /dev/null +++ b/src/cpp/lib/QtWidgets/QHeaderView/qheaderview_wrap.cpp @@ -0,0 +1,61 @@ +#include "QtWidgets/QHeaderView/qheaderview_wrap.h" + +#include "Extras/Utils/nutils.h" + +Napi::FunctionReference QHeaderViewWrap::constructor; + +Napi::Object QHeaderViewWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QHeaderView"; + Napi::Function func = DefineClass( + env, CLASSNAME, + {QABSTRACTITEMVIEW_WRAPPED_METHODS_EXPORT_DEFINE(QHeaderViewWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +QHeaderView* QHeaderViewWrap::getInternalInstance() { return this->instance; } + +QHeaderViewWrap::~QHeaderViewWrap() { + if (!this->disableDeletion) { + extrautils::safeDelete(this->instance); + } +} + +QHeaderViewWrap::QHeaderViewWrap(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + int len = info.Length(); + + this->disableDeletion = false; + if (len == 1) { + if (info[0].IsExternal()) { + this->instance = info[0].As>().Data(); + this->disableDeletion = true; + } else { + int orientation = info[0].As().Int32Value(); + this->instance = + new NHeaderView(static_cast(orientation)); + } + } else { + // len ==2 + int orientation = info[0].As().Int32Value(); + Napi::Object parentObject = info[1].As(); + NodeWidgetWrap* parentWidgetWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NHeaderView(static_cast(orientation), + parentWidgetWrap->getInternalInstance()); + } + + // this->instance can be either a `QHeaderView` or `NHeaderView`. Only + // `NHeaderView` has the flex support available. + this->rawData = nullptr; + FlexItem* item = dynamic_cast(this->getInternalInstance()); + if (item) { + this->rawData = extrautils::configureQWidget(this->getInternalInstance(), + item->getFlexNode(), false); + } +} diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 36b3b494d..630456585 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -64,6 +64,7 @@ #include "QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h" #include "QtWidgets/QGridLayout/qgridlayout_wrap.h" #include "QtWidgets/QGroupBox/qgroupbox_wrap.h" +#include "QtWidgets/QHeaderView/qheaderview_wrap.h" #include "QtWidgets/QInputDialog/qinputdialog_wrap.h" #include "QtWidgets/QLCDNumber/qlcdnumber_wrap.h" #include "QtWidgets/QLabel/qlabel_wrap.h" @@ -222,6 +223,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QPaintEventWrap::init(env, exports); QPaletteWrap::init(env, exports); QAbstractItemModelWrap::init(env, exports); + QHeaderViewWrap::init(env, exports); return exports; } diff --git a/src/index.ts b/src/index.ts index 7eac6eef3..b77d85f98 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,6 +74,7 @@ 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 { QHeaderView, QHeaderViewSignals } from './lib/QtWidgets/QHeaderView'; export { QListView, QListViewSignals, diff --git a/src/lib/QtWidgets/QHeaderView.ts b/src/lib/QtWidgets/QHeaderView.ts new file mode 100644 index 000000000..0205071dc --- /dev/null +++ b/src/lib/QtWidgets/QHeaderView.ts @@ -0,0 +1,110 @@ +import addon from '../utils/addon'; +import { NodeWidget } from './QWidget'; +import { NativeElement } from '../core/Component'; +import { QAbstractItemView, QAbstractItemViewSignals } from './QAbstractItemView'; +import { checkIfNativeElement, Orientation } from '../..'; + +/** + +> The QHeaderView class provides a header row or header column for item views. + +* **This class is a JS wrapper around Qt's [QHeaderView class](https://doc.qt.io/qt-5/qheaderview.html)** + + */ +export abstract class NodeHeaderView extends QAbstractItemView { + // *** Public Function *** + // TODO: bool cascadingSectionResizes() const + // TODO: int count() const + // TODO: Qt::Alignment defaultAlignment() const + // TODO: int defaultSectionSize() const + // TODO: int hiddenSectionCount() const + // TODO: void hideSection(int logicalIndex) + // TODO: bool highlightSections() const + // TODO: bool isFirstSectionMovable() const + // TODO: bool isSectionHidden(int logicalIndex) const + // TODO: bool isSortIndicatorShown() const + // TODO: int length() const + // TODO: int logicalIndex(int visualIndex) const + // TODO: int logicalIndexAt(int position) const + // TODO: int logicalIndexAt(int x, int y) const + // TODO: int logicalIndexAt(const QPoint &pos) const + // TODO: int maximumSectionSize() const + // TODO: int minimumSectionSize() const + // TODO: void moveSection(int from, int to) + // TODO: int offset() const + // TODO: Qt::Orientation orientation() const + // TODO: void resetDefaultSectionSize() + // TODO: int resizeContentsPrecision() const + // TODO: void resizeSection(int logicalIndex, int size) + // TODO: void resizeSections(QHeaderView::ResizeMode mode) + // TODO: bool restoreState(const QByteArray &state) + // TODO: QByteArray saveState() const + // TODO: int sectionPosition(int logicalIndex) const + // TODO: QHeaderView::ResizeMode sectionResizeMode(int logicalIndex) const + // TODO: int sectionSize(int logicalIndex) const + // TODO: int sectionSizeHint(int logicalIndex) const + // TODO: int sectionViewportPosition(int logicalIndex) const + // TODO: bool sectionsClickable() const + // TODO: bool sectionsHidden() const + // TODO: bool sectionsMovable() const + // TODO: bool sectionsMoved() const + // TODO: void setCascadingSectionResizes(bool enable) + // TODO: void setDefaultAlignment(Qt::Alignment alignment) + // TODO: void setDefaultSectionSize(int size) + // TODO: void setFirstSectionMovable(bool movable) + // TODO: void setHighlightSections(bool highlight) + // TODO: void setMaximumSectionSize(int size) + // TODO: void setMinimumSectionSize(int size) + // TODO: void setResizeContentsPrecision(int precision) + // TODO: void setSectionHidden(int logicalIndex, bool hide) + // TODO: void setSectionResizeMode(QHeaderView::ResizeMode mode) + // TODO: void setSectionResizeMode(int logicalIndex, QHeaderView::ResizeMode mode) + // TODO: void setSectionsClickable(bool clickable) + // TODO: void setSectionsMovable(bool movable) + // TODO: void setSortIndicator(int logicalIndex, Qt::SortOrder order) + // TODO: void setSortIndicatorShown(bool show) + + setStretchLastSection(stretch: boolean): void { + this.setProperty('stretchLastSection', stretch); + } + + // TODO: void showSection(int logicalIndex) + // TODO: Qt::SortOrder sortIndicatorOrder() const + // TODO: int sortIndicatorSection() const + + stretchLastSection(): boolean { + return this.property('stretchLastSection').toBool(); + } + + // TODO: int stretchSectionCount() const + // TODO: void swapSections(int first, int second) + // TODO: int visualIndex(int logicalIndex) const + // TODO: int visualIndexAt(int position) const + + // *** Public Slots *** + // TODO: void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast) + // TODO: void setOffset(int offset) + // TODO: void setOffsetToLastSection() + // TODO: void setOffsetToSectionPosition(int visualSectionNumber) +} + +export class QHeaderView extends NodeHeaderView { + native: NativeElement; + constructor(orientationOrNative: Orientation | NativeElement, parent: NodeWidget | null = null) { + let native; + if (checkIfNativeElement(orientationOrNative)) { + native = orientationOrNative as NativeElement; + } else { + if (parent != null) { + native = new addon.QHeaderView(orientationOrNative, parent.native); + } else { + native = new addon.QHeaderView(orientationOrNative); + } + } + super(native); + this.native = native; + parent && this.setNodeParent(parent); + } +} + +export type QHeaderViewSignals = QAbstractItemViewSignals; diff --git a/src/lib/QtWidgets/QTableView.ts b/src/lib/QtWidgets/QTableView.ts index f7eb5fe04..d629903c1 100644 --- a/src/lib/QtWidgets/QTableView.ts +++ b/src/lib/QtWidgets/QTableView.ts @@ -3,9 +3,10 @@ import { NodeWidget } from './QWidget'; import { NativeElement } from '../core/Component'; import { SortOrder, PenStyle } from '../QtEnums'; import { QAbstractItemView, QAbstractItemViewSignals } from './QAbstractItemView'; +import { QHeaderView } from './QHeaderView'; /** - + > The QTableView class provides a default model/view implementation of a table view. * **This class is a JS wrapper around Qt's [QTableView class](https://doc.qt.io/qt-5/qtableview.html)** @@ -20,84 +21,121 @@ const tableview = new QTableView(); ``` */ export abstract class NodeTableView extends QAbstractItemView { - setCornerButtonEnabled(enable: boolean): void { - this.setProperty('cornerButtonEnabled', enable); - } - isCornerButtonEnabled(): boolean { - return this.property('cornerButtonEnabled').toBool(); - } - setGridStyle(style: PenStyle): void { - this.setProperty('gridStyle', style); - } - gridStyle(): PenStyle { - return this.property('gridStyle').toInt(); - } - setShowGrid(show: boolean): void { - this.setProperty('showGrid', show); - } - showGrid(): boolean { - return this.property('showGrid').toBool(); - } - setSortingEnabled(enable: boolean): void { - this.setProperty('sortingEnabled', enable); - } - isSortingEnabled(): boolean { - return this.property('sortingEnabled').toBool(); - } - setWordWrap(on: boolean): void { - this.setProperty('wordWrap', on); - } - wordWrap(): boolean { - return this.property('wordWrap').toBool(); - } + // *** Public Functions *** clearSpans(): void { this.native.clearSpans(); } + columnAt(x: number): number { return this.native.columnAt(x); } + columnSpan(row: number, column: number): number { return this.native.columnSpan(row, column); } + columnViewportPosition(column: number): number { return this.native.columnViewportPosition(column); } - setColumnWidth(column: number, width: number): void { - this.native.setColumnWidth(column, width); - } + columnWidth(column: number): number { return this.native.columnWidth(column); } - setColumnHidden(column: number, hide: boolean): void { - this.native.setColumnHidden(column, hide); + + gridStyle(): PenStyle { + return this.property('gridStyle').toInt(); } + + horizontalHeader(): QHeaderView { + return new QHeaderView(this.native.horizontalHeader()); + } + isColumnHidden(column: number): boolean { return this.native.isColumnHidden(column); } - setRowHidden(row: number, hide: boolean): void { - this.native.setRowHidden(row, hide); + + isCornerButtonEnabled(): boolean { + return this.property('cornerButtonEnabled').toBool(); } + isRowHidden(row: number): boolean { return this.native.isRowHidden(row); } + + isSortingEnabled(): boolean { + return this.property('sortingEnabled').toBool(); + } + rowAt(y: number): number { return this.native.rowAt(y); } - setRowHeight(row: number, height: number): void { - this.native.setRowHeight(row, height); - } + rowHeight(row: number): number { return this.native.rowHeight(row); } + rowSpan(row: number, column: number): number { return this.native.rowSpan(row, column); } + rowViewportPosition(row: number): number { return this.native.rowViewportPosition(row); } + + setColumnHidden(column: number, hide: boolean): void { + this.native.setColumnHidden(column, hide); + } + + setColumnWidth(column: number, width: number): void { + this.native.setColumnWidth(column, width); + } + + setCornerButtonEnabled(enable: boolean): void { + this.setProperty('cornerButtonEnabled', enable); + } + + setGridStyle(style: PenStyle): void { + this.setProperty('gridStyle', style); + } + + // TODO: void setHorizontalHeader(QHeaderView *header) + + setRowHeight(row: number, height: number): void { + this.native.setRowHeight(row, height); + } + + setRowHidden(row: number, hide: boolean): void { + this.native.setRowHidden(row, hide); + } + + setSortingEnabled(enable: boolean): void { + this.setProperty('sortingEnabled', enable); + } + setSpan(row: number, column: number, rowSpanCount: number, columnSpanCount: number): void { this.native.setSpan(row, column, rowSpanCount, columnSpanCount); } + + // TODO: void setVerticalHeader(QHeaderView *header) + + setWordWrap(on: boolean): void { + this.setProperty('wordWrap', on); + } + + showGrid(): boolean { + return this.property('showGrid').toBool(); + } + + verticalHeader(): QHeaderView { + return new QHeaderView(this.native.verticalHeader()); + } + + wordWrap(): boolean { + return this.property('wordWrap').toBool(); + } + + // *** Public Slots *** + hideColumn(column: number): void { this.native.hideColumn(column); } @@ -122,12 +160,19 @@ export abstract class NodeTableView extends Q selectRow(row: number): void { this.native.selectRow(row); } + + setShowGrid(show: boolean): void { + this.setProperty('showGrid', show); + } + 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); }