From c6d30f8f9f5ec22fbdbdf640abeccd62d7ae7136 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Fri, 29 Apr 2022 13:30:39 +0200 Subject: [PATCH] Combine `NodeObject`+`QObject`; put `native` field in `Component` --- src/index.ts | 10 ++++- src/lib/QtCore/QAbstractItemModel.ts | 10 ++--- src/lib/QtCore/QDate.ts | 12 +++--- src/lib/QtCore/QDateTime.ts | 10 ++--- src/lib/QtCore/QItemSelectionModel.ts | 6 +-- src/lib/QtCore/QMimeData.ts | 8 ++-- src/lib/QtCore/QModelIndex.ts | 10 ++--- src/lib/QtCore/QObject.ts | 41 ++++++++----------- src/lib/QtCore/QPoint.ts | 16 ++++---- src/lib/QtCore/QPointF.ts | 24 +++++------ src/lib/QtCore/QRect.ts | 17 ++++---- src/lib/QtCore/QRectF.ts | 17 ++++---- src/lib/QtCore/QSettings.ts | 6 +-- src/lib/QtCore/QSize.ts | 17 ++++---- src/lib/QtCore/QSizeF.ts | 19 ++++----- src/lib/QtCore/QTime.ts | 14 +++---- src/lib/QtCore/QUrl.ts | 30 +++++--------- src/lib/QtCore/QVariant.ts | 10 ++--- src/lib/QtGui/QApplication.ts | 6 +-- src/lib/QtGui/QBrush.ts | 20 ++++----- src/lib/QtGui/QClipboard.ts | 11 ++--- src/lib/QtGui/QColor.ts | 14 +++---- src/lib/QtGui/QCursor.ts | 8 ++-- src/lib/QtGui/QDrag.ts | 19 ++++----- src/lib/QtGui/QFont.ts | 12 +++--- src/lib/QtGui/QFontDatabase.ts | 6 +-- src/lib/QtGui/QFontMetrics.ts | 10 ++--- src/lib/QtGui/QFontMetricsF.ts | 10 ++--- src/lib/QtGui/QIcon.ts | 10 ++--- src/lib/QtGui/QImage.ts | 20 ++++----- src/lib/QtGui/QKeySequence.ts | 10 ++--- src/lib/QtGui/QMovie.ts | 10 ++--- src/lib/QtGui/QPalette.ts | 8 +--- src/lib/QtGui/QPen.ts | 6 +-- src/lib/QtGui/QPicture.ts | 10 ++--- src/lib/QtGui/QPixmap.ts | 10 ++--- src/lib/QtGui/QScreen.ts | 11 ++--- src/lib/QtGui/QStyle.ts | 7 +--- src/lib/QtGui/QWindow.ts | 12 ++---- src/lib/QtWidgets/QAction.ts | 8 ++-- src/lib/QtWidgets/QBoxLayout.ts | 2 - src/lib/QtWidgets/QButtonGroup.ts | 8 ++-- src/lib/QtWidgets/QCalendarWidget.ts | 6 +-- src/lib/QtWidgets/QCheckBox.ts | 2 - src/lib/QtWidgets/QColorDialog.ts | 6 +-- src/lib/QtWidgets/QComboBox.ts | 4 +- src/lib/QtWidgets/QDateEdit.ts | 4 +- src/lib/QtWidgets/QDateTimeEdit.ts | 3 -- src/lib/QtWidgets/QDial.ts | 4 +- src/lib/QtWidgets/QDialog.ts | 2 - src/lib/QtWidgets/QDoubleSpinBox.ts | 4 +- src/lib/QtWidgets/QErrorMessage.ts | 4 +- src/lib/QtWidgets/QFileDialog.ts | 6 +-- src/lib/QtWidgets/QFontDialog.ts | 4 +- src/lib/QtWidgets/QFrame.ts | 4 +- src/lib/QtWidgets/QGraphicsBlurEffect.ts | 8 ++-- .../QtWidgets/QGraphicsDropShadowEffect.ts | 8 ++-- src/lib/QtWidgets/QGraphicsEffect.ts | 6 +-- src/lib/QtWidgets/QGridLayout.ts | 2 - src/lib/QtWidgets/QGroupBox.ts | 4 +- src/lib/QtWidgets/QHeaderView.ts | 4 +- src/lib/QtWidgets/QInputDialog.ts | 7 +--- src/lib/QtWidgets/QLCDNumber.ts | 7 +--- src/lib/QtWidgets/QLabel.ts | 8 +--- src/lib/QtWidgets/QLayout.ts | 6 +-- src/lib/QtWidgets/QLineEdit.ts | 5 --- src/lib/QtWidgets/QListView.ts | 4 +- src/lib/QtWidgets/QListWidget.ts | 5 +-- src/lib/QtWidgets/QListWidgetItem.ts | 10 +---- src/lib/QtWidgets/QMainWindow.ts | 11 +++-- src/lib/QtWidgets/QMenu.ts | 4 -- src/lib/QtWidgets/QMenuBar.ts | 8 +--- src/lib/QtWidgets/QMessageBox.ts | 8 +--- src/lib/QtWidgets/QPainter.ts | 8 +--- src/lib/QtWidgets/QPainterPath.ts | 7 +--- src/lib/QtWidgets/QPlainTextEdit.ts | 6 +-- src/lib/QtWidgets/QProgressBar.ts | 6 +-- src/lib/QtWidgets/QProgressDialog.ts | 7 +--- src/lib/QtWidgets/QPushButton.ts | 9 +--- src/lib/QtWidgets/QRadioButton.ts | 7 +--- src/lib/QtWidgets/QScrollArea.ts | 6 +-- src/lib/QtWidgets/QScrollBar.ts | 8 +--- src/lib/QtWidgets/QShortcut.ts | 10 ++--- src/lib/QtWidgets/QSlider.ts | 12 ++---- src/lib/QtWidgets/QSpinBox.ts | 7 +--- src/lib/QtWidgets/QSplitter.ts | 6 +-- src/lib/QtWidgets/QStackedWidget.ts | 5 --- src/lib/QtWidgets/QStandardItem.ts | 10 ++--- src/lib/QtWidgets/QStandardItemModel.ts | 9 +--- src/lib/QtWidgets/QStatusBar.ts | 7 +--- src/lib/QtWidgets/QSvgWidget.ts | 4 +- src/lib/QtWidgets/QSystemTrayIcon.ts | 12 ++---- src/lib/QtWidgets/QTabBar.ts | 5 --- src/lib/QtWidgets/QTabWidget.ts | 11 ++--- src/lib/QtWidgets/QTableView.ts | 5 --- src/lib/QtWidgets/QTableWidget.ts | 2 - src/lib/QtWidgets/QTableWidgetItem.ts | 6 +-- src/lib/QtWidgets/QTextBrowser.ts | 4 +- src/lib/QtWidgets/QTextEdit.ts | 7 +--- src/lib/QtWidgets/QTimeEdit.ts | 7 +--- src/lib/QtWidgets/QToolButton.ts | 8 +--- src/lib/QtWidgets/QTreeWidget.ts | 9 ++-- src/lib/QtWidgets/QTreeWidgetItem.ts | 22 ++++++---- src/lib/QtWidgets/QWidget.ts | 2 - src/lib/core/Component.ts | 11 +++-- src/lib/core/EventWidget.ts | 3 +- src/lib/core/FlexLayout.ts | 7 +--- src/lib/core/YogaWidget.ts | 6 +-- src/lib/core/__test__/CacheTestQObject.ts | 5 +-- tsconfig.json | 1 + .../development/signal_and_event_handling.md | 4 +- 111 files changed, 349 insertions(+), 615 deletions(-) diff --git a/src/index.ts b/src/index.ts index d059c8c60..135722327 100644 --- a/src/index.ts +++ b/src/index.ts @@ -153,7 +153,7 @@ export { QDateTime } from './lib/QtCore/QDateTime'; export { QItemSelectionModel, SelectionFlag } from './lib/QtCore/QItemSelectionModel'; export { QModelIndex } from './lib/QtCore/QModelIndex'; export { QMimeData } from './lib/QtCore/QMimeData'; -export { QObject, QObjectSignals, NodeObject } from './lib/QtCore/QObject'; +export { QObject, QObjectSignals } from './lib/QtCore/QObject'; export { QVariant } from './lib/QtCore/QVariant'; export { QSize } from './lib/QtCore/QSize'; export { QSizeF } from './lib/QtCore/QSizeF'; @@ -163,7 +163,13 @@ export { QPoint } from './lib/QtCore/QPoint'; export { QPointF } from './lib/QtCore/QPointF'; export { QColor } from './lib/QtGui/QColor'; export { QTime } from './lib/QtCore/QTime'; -export { QUrl, ParsingMode } from './lib/QtCore/QUrl'; +export { + QUrl, + ParsingMode, + UserInputResolutionOption, + UrlFormattingOption, + ComponentFormattingOption, +} from './lib/QtCore/QUrl'; export { QSettings, QSettingsFormat, QSettingsScope } from './lib/QtCore/QSettings'; // Layouts: export { QBoxLayout, QBoxLayoutSignals } from './lib/QtWidgets/QBoxLayout'; diff --git a/src/lib/QtCore/QAbstractItemModel.ts b/src/lib/QtCore/QAbstractItemModel.ts index 7a5834b78..9825fa207 100644 --- a/src/lib/QtCore/QAbstractItemModel.ts +++ b/src/lib/QtCore/QAbstractItemModel.ts @@ -1,18 +1,14 @@ import addon from '../utils/addon'; -import { NativeElement } from '../core/Component'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QModelIndex } from './QModelIndex'; import { QVariant } from './QVariant'; import { ItemDataRole, ItemFlag, Orientation } from '../QtEnums'; export type QAbstractItemSignals = QObjectSignals; -export class QAbstractItemModel extends NodeObject { - native: NativeElement; +export class QAbstractItemModel extends QObject { constructor() { - const native = new addon.QAbstractItemModel(); - super(native); - this.native = native; + super(new addon.QAbstractItemModel()); const dispatcher = (methodName: string, ...args: any[]): any => { switch (methodName) { case 'index': diff --git a/src/lib/QtCore/QDate.ts b/src/lib/QtCore/QDate.ts index 71aa8f391..edc0f69b6 100644 --- a/src/lib/QtCore/QDate.ts +++ b/src/lib/QtCore/QDate.ts @@ -5,17 +5,17 @@ import { QVariant } from './QVariant'; import { DateFormat } from '../QtEnums'; export class QDate extends Component { - native: NativeElement; constructor(arg?: NativeElement | number, month?: number, day?: number) { - super(); const count = arguments.length; + let native: NativeElement; if (count == 3) { - this.native = new addon.QDate(arg, month, day); - } else if (count == 1 && checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = new addon.QDate(arg, month, day); + } else if (checkIfNativeElement(arg)) { + native = arg as NativeElement; } else { - this.native = new addon.QDate(); + native = new addon.QDate(); } + super(native); } addDays(ndays: number): QDate { return new QDate(this.native.addDays(ndays)); diff --git a/src/lib/QtCore/QDateTime.ts b/src/lib/QtCore/QDateTime.ts index a4eecb57d..1653f6b6f 100644 --- a/src/lib/QtCore/QDateTime.ts +++ b/src/lib/QtCore/QDateTime.ts @@ -7,17 +7,17 @@ import { QTime } from './QTime'; import { TimeSpec, DateFormat } from '../QtEnums'; export class QDateTime extends Component { - native: NativeElement; constructor(arg?: NativeElement, time?: NativeElement) { - super(); const count = arguments.length; + let native: NativeElement; if (arg && time) { - this.native = new addon.QDateTime(arg.native, time.native); + native = new addon.QDateTime(arg.native, time.native); } else if (count == 1 && checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QDateTime(); + native = new addon.QDateTime(); } + super(native); } addDays(ndays: number): QDateTime { return new QDateTime(this.native.addDays(ndays)); diff --git a/src/lib/QtCore/QItemSelectionModel.ts b/src/lib/QtCore/QItemSelectionModel.ts index d468a156c..665c4c47f 100644 --- a/src/lib/QtCore/QItemSelectionModel.ts +++ b/src/lib/QtCore/QItemSelectionModel.ts @@ -1,13 +1,12 @@ import addon from '../utils/addon'; import { NativeElement } from '../core/Component'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QModelIndex } from './QModelIndex'; import { checkIfNativeElement } from '../utils/helpers'; export type QItemSelectionModelSignals = QObjectSignals; -export class QItemSelectionModel extends NodeObject { - native: NativeElement; +export class QItemSelectionModel extends QObject { constructor(arg?: NativeElement) { let native = null; if (arg == null) { @@ -18,7 +17,6 @@ export class QItemSelectionModel extends NodeObject throw new Error('QItemSelectionModel cannot be initialised this way.'); } super(native); - this.native = native; } // *** Public Functions *** diff --git a/src/lib/QtCore/QMimeData.ts b/src/lib/QtCore/QMimeData.ts index f824839f5..a97457ac4 100644 --- a/src/lib/QtCore/QMimeData.ts +++ b/src/lib/QtCore/QMimeData.ts @@ -6,14 +6,14 @@ import { QUrl } from './QUrl'; * description */ export class QMimeData extends Component { - native: NativeElement; constructor(arg?: NativeElement) { - super(); + let native: NativeElement; if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QMimeData(); + native = new addon.QMimeData(); } + super(native); } /** diff --git a/src/lib/QtCore/QModelIndex.ts b/src/lib/QtCore/QModelIndex.ts index f210baf13..92f7e90be 100644 --- a/src/lib/QtCore/QModelIndex.ts +++ b/src/lib/QtCore/QModelIndex.ts @@ -6,18 +6,16 @@ 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(); + let native: NativeElement; if (!arg) { - this.native = new addon.QModelIndex(); + native = new addon.QModelIndex(); } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { throw new Error('QModelIndex cannot be initialised this way.'); } + super(native); } column(): number { return this.native.column(); diff --git a/src/lib/QtCore/QObject.ts b/src/lib/QtCore/QObject.ts index e87c9a4b2..fcd53452b 100644 --- a/src/lib/QtCore/QObject.ts +++ b/src/lib/QtCore/QObject.ts @@ -5,7 +5,22 @@ import addon from '../utils/addon'; import { QVariant, QVariantType } from './QVariant'; import { TimerType } from '../QtEnums/TimerType'; -export abstract class NodeObject extends EventWidget { +export class QObject extends EventWidget { + constructor(nativeElementOrParent?: NativeElement | QObject) { + let native; + let parent; + if (checkIfNativeElement(nativeElementOrParent)) { + native = nativeElementOrParent as NativeElement; + } else if (nativeElementOrParent) { + parent = nativeElementOrParent as QObject; + native = new addon.QObject(parent.native); + } else { + native = new addon.QObject(); + } + super(native); + this.setNodeParent(parent); + } + inherits(className: string): boolean { return this.native.inherits(className); } @@ -28,7 +43,7 @@ export abstract class NodeObject extends EventWi dumpObjectInfo(): void { this.native.dumpObjectInfo(); } - setParent(parent: NodeObject): void { + setParent(parent: QObject): void { if (parent != null) { const extern = parent.native.__external_qobject__(); this.native.setParent(extern); @@ -47,25 +62,3 @@ export abstract class NodeObject extends EventWi export interface QObjectSignals { objectNameChanged: (objectName: string) => void; } - -export class QObject extends NodeObject { - native: NativeElement; - constructor(); - constructor(nativeElement: NativeElement); - constructor(parent: NodeObject); - constructor(arg?: NodeObject | NativeElement) { - let native; - let parent; - if (checkIfNativeElement(arg)) { - native = arg as NativeElement; - } else if (arg) { - parent = arg as NodeObject; - native = new addon.QObject(parent.native); - } else { - native = new addon.QObject(); - } - super(native); - this.setNodeParent(parent); - this.native = native; - } -} diff --git a/src/lib/QtCore/QPoint.ts b/src/lib/QtCore/QPoint.ts index cc4d4d4d0..f8cadfbcb 100644 --- a/src/lib/QtCore/QPoint.ts +++ b/src/lib/QtCore/QPoint.ts @@ -7,19 +7,19 @@ import { QVariant } from './QVariant'; * The QPoint class defines a point in the plane using integer precision. */ export class QPoint extends Component { - native: NativeElement; constructor(); constructor(nativeElement: NativeElement); constructor(x?: number, y?: number); - constructor(arg?: NativeElement | number, y = 0) { - super(); - if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; - } else if (typeof arg === 'number') { - this.native = new addon.QPoint(arg, y); + constructor(nativeOrX?: NativeElement | number, y = 0) { + let native: NativeElement; + if (checkIfNativeElement(nativeOrX)) { + native = nativeOrX as NativeElement; + } else if (typeof nativeOrX === 'number') { + native = new addon.QPoint(nativeOrX, y); } else { - this.native = new addon.QPoint(); + native = new addon.QPoint(); } + super(native); } setX(value: number): void { this.native.setX(value); diff --git a/src/lib/QtCore/QPointF.ts b/src/lib/QtCore/QPointF.ts index 36680e4f7..436b31bbb 100644 --- a/src/lib/QtCore/QPointF.ts +++ b/src/lib/QtCore/QPointF.ts @@ -11,22 +11,18 @@ import { QPoint } from './QPoint'; * In addition, the QPointF class provides a constructor converting a QPoint object into a QPointF object, and a corresponding toPoint() function which returns a QPoint copy of this point. */ export class QPointF extends Component { - native: NativeElement; - constructor(); - constructor(nativeElement: NativeElement); - constructor(x?: number, y?: number); - constructor(point: QPoint); - constructor(arg?: NativeElement | number | QPoint, y = 0) { - super(); - if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; - } else if (typeof arg === 'number') { - this.native = new addon.QPointF(arg, y); - } else if (arg instanceof QPoint) { - this.native = new addon.QPointF(arg.x(), arg.y()); + constructor(nativeOrXOrQPoint?: NativeElement | number | QPoint, y = 0) { + let native: NativeElement; + if (checkIfNativeElement(nativeOrXOrQPoint)) { + native = nativeOrXOrQPoint as NativeElement; + } else if (typeof nativeOrXOrQPoint === 'number') { + native = new addon.QPointF(nativeOrXOrQPoint, y); + } else if (nativeOrXOrQPoint instanceof QPoint) { + native = new addon.QPointF(nativeOrXOrQPoint.x(), nativeOrXOrQPoint.y()); } else { - this.native = new addon.QPointF(); + native = new addon.QPointF(); } + super(native); } /** * Sets the x coordinate of this point to the given x coordinate. diff --git a/src/lib/QtCore/QRect.ts b/src/lib/QtCore/QRect.ts index 49de66ca1..7714ba0dd 100644 --- a/src/lib/QtCore/QRect.ts +++ b/src/lib/QtCore/QRect.ts @@ -4,20 +4,17 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; export class QRect extends Component { - native: NativeElement; - constructor(); - constructor(nativeElement: NativeElement); - constructor(x?: number, y?: number, width?: number, height?: number); - constructor(arg?: NativeElement | number, y = 0, width = 0, height = 0) { - super(); + constructor(nativeOrX?: NativeElement | number, y = 0, width = 0, height = 0) { const count = arguments.length; + let native: NativeElement; if (count > 1) { - this.native = new addon.QRect(arg, y, width, height); - } else if (count == 1 && checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = new addon.QRect(nativeOrX, y, width, height); + } else if (checkIfNativeElement(nativeOrX)) { + native = nativeOrX as NativeElement; } else { - this.native = new addon.QRect(); + native = new addon.QRect(); } + super(native); } setWidth(width: number): void { return this.native.setWidth(width); diff --git a/src/lib/QtCore/QRectF.ts b/src/lib/QtCore/QRectF.ts index b5d3fec51..8e58135f3 100644 --- a/src/lib/QtCore/QRectF.ts +++ b/src/lib/QtCore/QRectF.ts @@ -8,20 +8,17 @@ import { QRect } from './QRect'; * description */ export class QRectF extends Component { - native: NativeElement; - constructor(); - constructor(nativeElement: NativeElement); - constructor(x?: number, y?: number, width?: number, height?: number); - constructor(arg?: NativeElement | number, y = 0, width = 0, height = 0) { - super(); + constructor(nativeOrX?: NativeElement | number, y = 0, width = 0, height = 0) { const count = arguments.length; + let native: NativeElement; if (count > 1) { - this.native = new addon.QRectF(arg, y, width, height); - } else if (count == 1 && checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = new addon.QRectF(nativeOrX, y, width, height); + } else if (count == 1 && checkIfNativeElement(nativeOrX)) { + native = nativeOrX as NativeElement; } else { - this.native = new addon.QRectF(); + native = new addon.QRectF(); } + super(native); } /** diff --git a/src/lib/QtCore/QSettings.ts b/src/lib/QtCore/QSettings.ts index 4e4056f8a..e117d7aa4 100644 --- a/src/lib/QtCore/QSettings.ts +++ b/src/lib/QtCore/QSettings.ts @@ -1,4 +1,4 @@ -import { NativeElement, Component } from '../core/Component'; +import { Component } from '../core/Component'; import addon from '../utils/addon'; import { QVariant } from './QVariant'; @@ -16,10 +16,8 @@ export enum QSettingsScope { } export class QSettings extends Component { - native: NativeElement; constructor(organization: string, application: string) { - super(); - this.native = new addon.QSettings(organization, application); + super(new addon.QSettings(organization, application)); } sync(): void { this.native.sync(); diff --git a/src/lib/QtCore/QSize.ts b/src/lib/QtCore/QSize.ts index bcbf36b6a..bfac0905c 100644 --- a/src/lib/QtCore/QSize.ts +++ b/src/lib/QtCore/QSize.ts @@ -4,19 +4,18 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; export class QSize extends Component { - native: NativeElement; - constructor(); constructor(nativeElement: NativeElement); constructor(width?: number, height?: number); - constructor(arg?: number | NativeElement, height?: number) { - super(); - if (!arg) { - this.native = new addon.QSize(); - } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + constructor(nativeOrWidth?: number | NativeElement, height?: number) { + let native: NativeElement; + if (!nativeOrWidth) { + native = new addon.QSize(); + } else if (checkIfNativeElement(nativeOrWidth)) { + native = nativeOrWidth as NativeElement; } else { - this.native = new addon.QSize(arg, height); + native = new addon.QSize(nativeOrWidth, height); } + super(native); } setWidth(width: number): void { return this.native.setWidth(width); diff --git a/src/lib/QtCore/QSizeF.ts b/src/lib/QtCore/QSizeF.ts index bb5acd124..aee07943a 100644 --- a/src/lib/QtCore/QSizeF.ts +++ b/src/lib/QtCore/QSizeF.ts @@ -4,19 +4,16 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; export class QSizeF extends Component { - native: NativeElement; - constructor(); - constructor(nativeElement: NativeElement); - constructor(width?: number, height?: number); - constructor(arg?: number | NativeElement, height?: number) { - super(); - if (!arg) { - this.native = new addon.QSizeF(); - } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + constructor(nativeOrWidth?: number | NativeElement, height?: number) { + let native: NativeElement; + if (!nativeOrWidth) { + native = new addon.QSizeF(); + } else if (checkIfNativeElement(nativeOrWidth)) { + native = nativeOrWidth as NativeElement; } else { - this.native = new addon.QSizeF(arg, height); + native = new addon.QSizeF(nativeOrWidth, height); } + super(native); } setWidth(width: number): void { return this.native.setWidth(width); diff --git a/src/lib/QtCore/QTime.ts b/src/lib/QtCore/QTime.ts index b67616b9e..2a190f651 100644 --- a/src/lib/QtCore/QTime.ts +++ b/src/lib/QtCore/QTime.ts @@ -5,17 +5,17 @@ import { QVariant } from './QVariant'; import { DateFormat } from '../QtEnums'; export class QTime extends Component { - native: NativeElement; - constructor(arg?: NativeElement | number, m?: number, s = 0, ms = 0) { - super(); + constructor(nativeOrHours?: NativeElement | number, m?: number, s = 0, ms = 0) { const count = arguments.length; + let native: NativeElement; if (count > 1) { - this.native = new addon.QTime(arg, m, s, ms); - } else if (count == 1 && checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = new addon.QTime(nativeOrHours, m, s, ms); + } else if (checkIfNativeElement(nativeOrHours)) { + native = nativeOrHours as NativeElement; } else { - this.native = new addon.QTime(); + native = new addon.QTime(); } + super(native); } addMSecs(ms: number): QTime { return new QTime(this.native.addMSecs(ms)); diff --git a/src/lib/QtCore/QUrl.ts b/src/lib/QtCore/QUrl.ts index 7cfbd2f3a..8e5d922da 100644 --- a/src/lib/QtCore/QUrl.ts +++ b/src/lib/QtCore/QUrl.ts @@ -3,7 +3,7 @@ import addon from '../utils/addon'; import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from './QVariant'; -enum ComponentFormattingOption { +export enum ComponentFormattingOption { /** The component is returned in a "pretty form", with most percent-encoded characters decoded. The exact behavior of PrettyDecoded varies from component to component and may also change from Qt release to Qt release. This is the default. */ PrettyDecoded = 0x000000, /** Leave space characters in their encoded form ("%20"). */ @@ -29,7 +29,7 @@ export enum ParsingMode { /** QUrl will interpret the URL component in the fully-decoded form, where percent characters stand for themselves, not as the beginning of a percent-encoded sequence. This mode is only valid for the setters setting components of a URL; it is not permitted in the QUrl constructor, in fromEncoded() or in setUrl(). For more information on this mode, see the documentation for QUrl::FullyDecoded.*/ DecodedMode = 2, } -enum UrlFormattingOption { +export enum UrlFormattingOption { None = 0x0, RemoveScheme = 0x1, RemovePassword = 0x2, @@ -44,7 +44,7 @@ enum UrlFormattingOption { StripTrailingSlash = 0x400, NormalizePathSegments = 0x1000, } -enum UserInputResolutionOption { +export enum UserInputResolutionOption { /** The default resolution mechanism is to check whether a local file exists, in the working directory given to fromUserInput, and only return a local path in that case. Otherwise a URL is assumed. */ DefaultResolution = 0, /** This option makes fromUserInput() always return a local path unless the input contains a scheme, such as http://file.pl. This is useful for applications such as text editors, which are able to create the file if it doesn't exist. */ @@ -52,27 +52,19 @@ enum UserInputResolutionOption { } export class QUrl extends Component { - static readonly ComponentFormattingOption = ComponentFormattingOption; - static readonly ParsingMode = ParsingMode; - static readonly UrlFormattingOption = UrlFormattingOption; - static readonly UserInputResolutionOption = UserInputResolutionOption; - readonly ComponentFormattingOption = ComponentFormattingOption; - readonly ParsingMode = ParsingMode; - readonly UrlFormattingOption = UrlFormattingOption; - readonly UserInputResolutionOption = UserInputResolutionOption; - native: NativeElement; constructor(); constructor(nativeElement: NativeElement); constructor(url: string, parsingMode?: ParsingMode); - constructor(arg?: string | NativeElement, parsingMode: ParsingMode = ParsingMode.TolerantMode) { - super(); - if (!arg) { - this.native = new addon.QUrl(); - } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + constructor(nativeOrString?: string | NativeElement, parsingMode: ParsingMode = ParsingMode.TolerantMode) { + let native: NativeElement; + if (!nativeOrString) { + native = new addon.QUrl(); + } else if (checkIfNativeElement(nativeOrString)) { + native = nativeOrString as NativeElement; } else { - this.native = new addon.QUrl(arg, parsingMode); + native = new addon.QUrl(nativeOrString, parsingMode); } + super(native); } static fromQVariant(variant: QVariant): QUrl { diff --git a/src/lib/QtCore/QVariant.ts b/src/lib/QtCore/QVariant.ts index d1f7d6345..1708bffa8 100644 --- a/src/lib/QtCore/QVariant.ts +++ b/src/lib/QtCore/QVariant.ts @@ -5,19 +5,19 @@ import { checkIfNativeElement } from '../utils/helpers'; export type QVariantType = NativeElement | string | string[] | number | boolean; export class QVariant extends Component { - native: NativeElement; constructor(); constructor(nativeElement: NativeElement); constructor(variant: QVariantType); constructor(arg?: QVariantType | NativeElement) { - super(); + let native: NativeElement; if (checkIfNativeElement(arg) && arg instanceof addon.QVariant) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else if (arg) { - this.native = new addon.QVariant.convertToQVariant(arg); + native = new addon.QVariant.convertToQVariant(arg); } else { - this.native = new addon.QVariant(); + native = new addon.QVariant(); } + super(native); } toString(): string { return this.native.toString(); diff --git a/src/lib/QtGui/QApplication.ts b/src/lib/QtGui/QApplication.ts index c4200db03..eedf26587 100644 --- a/src/lib/QtGui/QApplication.ts +++ b/src/lib/QtGui/QApplication.ts @@ -3,7 +3,7 @@ import { NativeElement } from '../core/Component'; import { checkIfNativeElement } from '../utils/helpers'; import { QClipboard } from './QClipboard'; import { QStyle } from './QStyle'; -import { QObjectSignals, NodeObject } from '../QtCore/QObject'; +import { QObjectSignals, QObject } from '../QtCore/QObject'; import { QPalette } from './QPalette'; import { StyleSheet } from '../core/Style/StyleSheet'; import memoizeOne from 'memoize-one'; @@ -27,8 +27,7 @@ const qApp = QApplication.instance(); qApp.quit(); ``` */ -export class QApplication extends NodeObject { - native: NativeElement; +export class QApplication extends QObject { constructor(); constructor(native: NativeElement); constructor(arg?: NativeElement) { @@ -39,7 +38,6 @@ export class QApplication extends NodeObject { native = new addon.QApplication(); } super(native); - this.native = native; this.setStyleSheet = memoizeOne(this.setStyleSheet); } diff --git a/src/lib/QtGui/QBrush.ts b/src/lib/QtGui/QBrush.ts index b13ba953a..4c484015f 100644 --- a/src/lib/QtGui/QBrush.ts +++ b/src/lib/QtGui/QBrush.ts @@ -21,18 +21,18 @@ const brush = new QBrush(); ``` */ export class QBrush extends Component { - native: NativeElement; - constructor(arg?: NativeElement | GlobalColor | QColor, style = BrushStyle.SolidPattern) { - super(); - if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; - } else if (typeof arg === 'number') { - this.native = new addon.QBrush(arg, style); - } else if (arg == null) { - this.native = new addon.QBrush(); + constructor(nativeOrGlobalColor?: NativeElement | GlobalColor | QColor, style = BrushStyle.SolidPattern) { + let native: NativeElement; + if (checkIfNativeElement(nativeOrGlobalColor)) { + native = nativeOrGlobalColor as NativeElement; + } else if (typeof nativeOrGlobalColor === 'number') { + native = new addon.QBrush(nativeOrGlobalColor, style); + } else if (nativeOrGlobalColor == null) { + native = new addon.QBrush(); } else { - this.native = new addon.QBrush(arg?.native, style); + native = new addon.QBrush(nativeOrGlobalColor?.native, style); } + super(native); } isOpaque(): boolean { return this.native.isOpaque(); diff --git a/src/lib/QtGui/QClipboard.ts b/src/lib/QtGui/QClipboard.ts index e7df4e94c..5799a741b 100644 --- a/src/lib/QtGui/QClipboard.ts +++ b/src/lib/QtGui/QClipboard.ts @@ -1,6 +1,6 @@ import { NativeElement } from '../core/Component'; import { checkIfNativeElement, registerNativeWrapFunction } from '../utils/helpers'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QPixmap } from './QPixmap'; import { wrapperCache } from '../core/WrapperCache'; @@ -23,15 +23,12 @@ const clipboard = QApplication.clipboard(); const text = clipboard.text(QClipboardMode.Clipboard); ``` */ -export class QClipboard extends NodeObject { - native: NativeElement; +export class QClipboard extends QObject { constructor(native: NativeElement) { - super(native); - if (checkIfNativeElement(native)) { - this.native = native; - } else { + if (!checkIfNativeElement(native)) { throw new Error('QClipboard cannot be initialised this way. Use QApplication::clipboard()'); } + super(native); } clear(mode = QClipboardMode.Clipboard): void { this.native.clear(mode); diff --git a/src/lib/QtGui/QColor.ts b/src/lib/QtGui/QColor.ts index 898bd23fc..f2d026779 100644 --- a/src/lib/QtGui/QColor.ts +++ b/src/lib/QtGui/QColor.ts @@ -5,28 +5,28 @@ import { QVariant } from '../QtCore/QVariant'; import { GlobalColor } from '../QtEnums'; export class QColor extends Component { - native: NativeElement; constructor(); constructor(nativeElement: NativeElement); constructor(colorString: string); constructor(color: GlobalColor); constructor(r?: number, g?: number, b?: number, a?: number); constructor(arg?: NativeElement | number | string, g = 0, b = 0, a = 255) { - super(); + let native: NativeElement; if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else if (typeof arg === 'number') { if (arguments.length === 1) { // This is for QGlobalColor enum - this.native = new addon.QColor(arg); + native = new addon.QColor(arg); } else { - this.native = new addon.QColor(arg, g, b, a); + native = new addon.QColor(arg, g, b, a); } } else if (typeof arg === 'string') { - this.native = new addon.QColor(arg); + native = new addon.QColor(arg); } else { - this.native = new addon.QColor(); + native = new addon.QColor(); } + super(native); } setRed(value: number): void { this.native.setRed(value); diff --git a/src/lib/QtGui/QCursor.ts b/src/lib/QtGui/QCursor.ts index 331b2f6b2..a5884c1b6 100644 --- a/src/lib/QtGui/QCursor.ts +++ b/src/lib/QtGui/QCursor.ts @@ -17,17 +17,17 @@ const cursor = new QCursor(); ``` */ export class QCursor extends Component { - native: NativeElement; constructor(); constructor(native: NativeElement); constructor(shape: CursorShape); constructor(arg?: NativeElement | CursorShape) { - super(); + let native: NativeElement; if (arg) { - this.native = new addon.QCursor(arg); + native = new addon.QCursor(arg); } else { - this.native = new addon.QCursor(); + native = new addon.QCursor(); } + super(native); } pos(): { x: number; y: number } { return this.native.pos(); diff --git a/src/lib/QtGui/QDrag.ts b/src/lib/QtGui/QDrag.ts index 869ac640e..3ab6d142a 100644 --- a/src/lib/QtGui/QDrag.ts +++ b/src/lib/QtGui/QDrag.ts @@ -11,21 +11,18 @@ import { QMimeData } from '../QtCore/QMimeData'; * description */ export class QDrag extends Component { - native: NativeElement; constructor(arg?: NativeElement | QObject) { - super(); + let native: NativeElement; if (!arg) { - this.native = new addon.QDrag(); + native = new addon.QDrag(); + } else if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else if (arg.native) { + native = new addon.QDrag(arg.native); } else { - const isNative = checkIfNativeElement(arg); - if (isNative) { - this.native = arg as NativeElement; - } else if (arg.native) { - this.native = new addon.QDrag(arg.native); - } else { - this.native = new addon.QDrag(); - } + native = new addon.QDrag(); } + super(native); } /** diff --git a/src/lib/QtGui/QFont.ts b/src/lib/QtGui/QFont.ts index 645ea0057..eeb00c4cc 100644 --- a/src/lib/QtGui/QFont.ts +++ b/src/lib/QtGui/QFont.ts @@ -4,22 +4,22 @@ import { QVariant } from '../QtCore/QVariant'; import { checkIfNativeElement } from '../utils/helpers'; export class QFont extends Component { - native: NativeElement; constructor(); constructor(font: QFont); constructor(native: NativeElement); constructor(family: string, pointSize?: number, weight?: QFontWeight, italic?: boolean); constructor(arg?: QFont | string | NativeElement, pointSize = -1, weight = -1, italic = false) { - super(); + let native: NativeElement; if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else if (arg instanceof QFont) { - this.native = arg.native; + native = arg.native; } else if (typeof arg === 'string') { - this.native = new addon.QFont(arg, pointSize, weight, italic); + native = new addon.QFont(arg, pointSize, weight, italic); } else { - this.native = new addon.QFont(); + native = new addon.QFont(); } + super(native); } bold(): boolean { return this.native.bold(); diff --git a/src/lib/QtGui/QFontDatabase.ts b/src/lib/QtGui/QFontDatabase.ts index d38218aac..8e5414fbd 100644 --- a/src/lib/QtGui/QFontDatabase.ts +++ b/src/lib/QtGui/QFontDatabase.ts @@ -1,5 +1,5 @@ import addon from '../utils/addon'; -import { Component, NativeElement } from '../core/Component'; +import { Component } from '../core/Component'; export enum WritingSystem { Any = 0, @@ -40,10 +40,8 @@ export enum WritingSystem { } export class QFontDatabase extends Component { - native: NativeElement; constructor() { - super(); - this.native = new addon.QFontDatabase(); + super(new addon.QFontDatabase()); } families(ws: WritingSystem = WritingSystem.Any): string[] { return this.native.families(ws); diff --git a/src/lib/QtGui/QFontMetrics.ts b/src/lib/QtGui/QFontMetrics.ts index 84dde5468..128f9b089 100644 --- a/src/lib/QtGui/QFontMetrics.ts +++ b/src/lib/QtGui/QFontMetrics.ts @@ -7,19 +7,19 @@ import { TextElideMode, TextFlag } from '../QtEnums'; import { QRect } from '../..'; export class QFontMetrics extends Component { - native: NativeElement; constructor(native: NativeElement); constructor(qfont: QFont); constructor(qfontmetrics: QFontMetrics); constructor(arg: QFont | QFontMetrics | NativeElement) { - super(); + let native: NativeElement; if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else if (arg instanceof QFontMetrics) { - this.native = arg.native; + native = arg.native; } else { - this.native = new addon.QFontMetrics(arg.native); + native = new addon.QFontMetrics(arg.native); } + super(native); } // *** Public Functions *** diff --git a/src/lib/QtGui/QFontMetricsF.ts b/src/lib/QtGui/QFontMetricsF.ts index f5c840d8c..2b8d594dc 100644 --- a/src/lib/QtGui/QFontMetricsF.ts +++ b/src/lib/QtGui/QFontMetricsF.ts @@ -7,19 +7,19 @@ import { TextElideMode, TextFlag } from '../QtEnums'; import { QRect } from '../..'; export class QFontMetricsF extends Component { - native: NativeElement; constructor(native: NativeElement); constructor(qfont: QFont); constructor(qfontmetricsf: QFontMetricsF); constructor(arg: QFont | QFontMetricsF | NativeElement) { - super(); + let native: NativeElement; if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else if (arg instanceof QFontMetricsF) { - this.native = arg.native; + native = arg.native; } else { - this.native = new addon.QFontMetricsF(arg.native); + native = new addon.QFontMetricsF(arg.native); } + super(native); } // *** Public Functions *** diff --git a/src/lib/QtGui/QIcon.ts b/src/lib/QtGui/QIcon.ts index 66e699c7d..bc074f0bb 100644 --- a/src/lib/QtGui/QIcon.ts +++ b/src/lib/QtGui/QIcon.ts @@ -20,20 +20,20 @@ const icon = new QIcon(imageUrl); ``` */ export class QIcon extends Component { - native: NativeElement; constructor(); constructor(native: NativeElement); constructor(filePath: string); constructor(arg?: string | NativeElement) { - super(); + let native: NativeElement; if (typeof arg === 'string') { const imagePath = arg; - this.native = new addon.QIcon(imagePath); + native = new addon.QIcon(imagePath); } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QIcon(); + native = new addon.QIcon(); } + super(native); } pixmap(width: number, height: number, mode?: QIconMode, state?: QIconState): QPixmap { let nativePixmap; diff --git a/src/lib/QtGui/QImage.ts b/src/lib/QtGui/QImage.ts index 615cb70a8..8fed74577 100644 --- a/src/lib/QtGui/QImage.ts +++ b/src/lib/QtGui/QImage.ts @@ -24,19 +24,13 @@ const image = new QImage(); ``` */ export class QImage extends Component { - native!: NativeElement; - /** Constructs a null image */ constructor(); - constructor(native: NativeElement); - /** Constructs an image and tries to load the image from the file with the given fileName */ constructor(filename: string); - /** Constructs an image with the given width, height and format */ constructor(width: number, height: number, format: QImageFormat); - /** Constructs an image with the given size and format */ constructor(size: QSize, format: QImageFormat); constructor( @@ -44,19 +38,19 @@ export class QImage extends Component { formatOrHeight?: QImageFormat | string | number, format?: QImageFormat, ) { - super(); - + let native: NativeElement; if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else if (typeof arg === 'string') { - this.native = new addon.QImage(arg); + native = new addon.QImage(arg); } else if (typeof arg === 'number') { - this.native = new addon.QImage(arg, formatOrHeight, format); + native = new addon.QImage(arg, formatOrHeight, format); } else if (arg instanceof QSize) { - this.native = new addon.QImage(arg.native, formatOrHeight); + native = new addon.QImage(arg.native, formatOrHeight); } else { - this.native = new addon.QImage(); + native = new addon.QImage(); } + super(native); } /** diff --git a/src/lib/QtGui/QKeySequence.ts b/src/lib/QtGui/QKeySequence.ts index 158ad191f..efcef2775 100644 --- a/src/lib/QtGui/QKeySequence.ts +++ b/src/lib/QtGui/QKeySequence.ts @@ -18,20 +18,20 @@ const keySequence = new QKeySequence(`Ctrl+L`); ``` */ export class QKeySequence extends Component { - native: NativeElement; constructor(); constructor(native: NativeElement); constructor(keySequence: string); constructor(arg?: string | NativeElement) { - super(); + let native: NativeElement; if (typeof arg === 'string') { const keySequence = arg; - this.native = new addon.QKeySequence(keySequence); + native = new addon.QKeySequence(keySequence); } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QKeySequence(); + native = new addon.QKeySequence(); } + super(native); } count(): number { return this.native.count(); diff --git a/src/lib/QtGui/QMovie.ts b/src/lib/QtGui/QMovie.ts index f9c25871b..14639dd0e 100644 --- a/src/lib/QtGui/QMovie.ts +++ b/src/lib/QtGui/QMovie.ts @@ -1,16 +1,15 @@ import addon from '../utils/addon'; import { NativeElement } from '../core/Component'; import { checkIfNativeElement } from '../utils/helpers'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QSize } from '../QtCore/QSize'; import { QPixmap } from './QPixmap'; -export class QMovie extends NodeObject { - native: NativeElement; +export class QMovie extends QObject { constructor(); constructor(native: NativeElement); - constructor(parent: NodeObject); - constructor(arg?: NodeObject | NativeElement) { + constructor(parent: QObject); + constructor(arg?: QObject | NativeElement) { let native: NativeElement; if (arg) { if (checkIfNativeElement(arg)) { @@ -22,7 +21,6 @@ export class QMovie extends NodeObject { native = new addon.QMovie(); } super(native); - this.native = native; } //Methods setFileName(fileName: string): void { diff --git a/src/lib/QtGui/QPalette.ts b/src/lib/QtGui/QPalette.ts index d8365ec31..377ac911a 100644 --- a/src/lib/QtGui/QPalette.ts +++ b/src/lib/QtGui/QPalette.ts @@ -1,4 +1,4 @@ -import { Component, NativeElement } from '../core/Component'; +import { Component } from '../core/Component'; import { QColor } from './QColor'; export enum ColorGroup { @@ -33,12 +33,6 @@ export enum ColorRole { } export class QPalette extends Component { - native: NativeElement; - constructor(native: NativeElement) { - super(); - this.native = native; - } - color(group: ColorGroup, role: ColorRole): QColor { return new QColor(this.native.color(group, role)); } diff --git a/src/lib/QtGui/QPen.ts b/src/lib/QtGui/QPen.ts index 69f0f33de..119db3d56 100644 --- a/src/lib/QtGui/QPen.ts +++ b/src/lib/QtGui/QPen.ts @@ -1,4 +1,4 @@ -import { Component, NativeElement } from '../core/Component'; +import { Component } from '../core/Component'; import addon from '../utils/addon'; import { GlobalColor, PenStyle, PenCapStyle } from '../QtEnums'; import { QColor } from './QColor'; @@ -18,10 +18,8 @@ const pen = new QPen(); ``` */ export class QPen extends Component { - native: NativeElement; constructor() { - super(); - this.native = new addon.QPen(); + super(new addon.QPen()); } setColor(color: QColor | GlobalColor): void { if (typeof color === 'number') { diff --git a/src/lib/QtGui/QPicture.ts b/src/lib/QtGui/QPicture.ts index 11e1e8a89..a420416a0 100644 --- a/src/lib/QtGui/QPicture.ts +++ b/src/lib/QtGui/QPicture.ts @@ -18,20 +18,20 @@ const picture = new QPicture(); ``` */ export class QPicture extends Component { - native: NativeElement; constructor(); constructor(native: NativeElement); constructor(formatVersion: number); constructor(arg?: number | NativeElement) { - super(); + let native: NativeElement; if (typeof arg === 'number') { const formatVersion = arg; - this.native = new addon.QPicture(formatVersion); + native = new addon.QPicture(formatVersion); } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QPicture(); + native = new addon.QPicture(); } + super(native); } setBoundingRect(r: QRect): void { this.native.setBoundingRect(r.native); diff --git a/src/lib/QtGui/QPixmap.ts b/src/lib/QtGui/QPixmap.ts index 3cabe183e..8999810cc 100644 --- a/src/lib/QtGui/QPixmap.ts +++ b/src/lib/QtGui/QPixmap.ts @@ -23,20 +23,20 @@ const pixMap = new QPixmap(imageUrl); ``` */ export class QPixmap extends Component { - native: NativeElement; constructor(); constructor(native: NativeElement); constructor(filePath: string); constructor(arg?: string | NativeElement) { - super(); + let native: NativeElement; if (typeof arg === 'string') { const imagePath = arg; - this.native = new addon.QPixmap(imagePath); + native = new addon.QPixmap(imagePath); } else if (checkIfNativeElement(arg)) { - this.native = arg as NativeElement; + native = arg as NativeElement; } else { - this.native = new addon.QPixmap(); + native = new addon.QPixmap(); } + super(native); } load(imagePath: string): boolean { return this.native.load(imagePath); diff --git a/src/lib/QtGui/QScreen.ts b/src/lib/QtGui/QScreen.ts index 39f3611ba..68debebcb 100644 --- a/src/lib/QtGui/QScreen.ts +++ b/src/lib/QtGui/QScreen.ts @@ -1,21 +1,18 @@ import { NativeElement } from '../core/Component'; import { checkIfNativeElement, registerNativeWrapFunction } from '../utils/helpers'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QRect } from '../QtCore/QRect'; import { QSizeF } from '../QtCore/QSizeF'; import { QSize } from '../QtCore/QSize'; import { wrapperCache } from '../core/WrapperCache'; import { QPixmap } from './QPixmap'; -export class QScreen extends NodeObject { - native: NativeElement; +export class QScreen extends QObject { constructor(native: NativeElement) { - super(native); - if (checkIfNativeElement(native)) { - this.native = native; - } else { + if (!checkIfNativeElement(native)) { throw new Error('QScreen cannot be initialised this way.'); } + super(native); } availableGeometry(): QRect { diff --git a/src/lib/QtGui/QStyle.ts b/src/lib/QtGui/QStyle.ts index 2db30408c..363d94940 100644 --- a/src/lib/QtGui/QStyle.ts +++ b/src/lib/QtGui/QStyle.ts @@ -3,14 +3,11 @@ import { Component, NativeElement } from '../core/Component'; import { checkIfNativeElement } from '../utils/helpers'; export class QStyle extends Component { - native: NativeElement; constructor(native: NativeElement) { - super(); - if (checkIfNativeElement(native)) { - this.native = native; - } else { + if (!checkIfNativeElement(native)) { throw new Error('QStyle cannot be initialised this way. Use QApplication::style()'); } + super(native); } pixelMetric(metric: QStylePixelMetric): number { diff --git a/src/lib/QtGui/QWindow.ts b/src/lib/QtGui/QWindow.ts index 7adcc620e..c8f98b8e4 100644 --- a/src/lib/QtGui/QWindow.ts +++ b/src/lib/QtGui/QWindow.ts @@ -1,20 +1,16 @@ import { NativeElement } from '../core/Component'; import { checkIfNativeElement, registerNativeWrapFunction } from '../utils/helpers'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QScreen } from './QScreen'; import { wrapperCache } from '../core/WrapperCache'; import { Edge, Visibility, WindowState } from '../QtEnums'; -export class QWindow extends NodeObject { - native: NativeElement; +export class QWindow extends QObject { constructor(native: NativeElement) { - super(native); - - if (checkIfNativeElement(native)) { - this.native = native; - } else { + if (!checkIfNativeElement(native)) { throw new Error('QWindow cannot be initialised this way.'); } + super(native); } screen(): QScreen { diff --git a/src/lib/QtWidgets/QAction.ts b/src/lib/QtWidgets/QAction.ts index 28772a8e7..9c19f36d9 100644 --- a/src/lib/QtWidgets/QAction.ts +++ b/src/lib/QtWidgets/QAction.ts @@ -6,7 +6,7 @@ import { QIcon } from '../QtGui/QIcon'; import { QFont } from '../QtGui/QFont'; import { QKeySequence } from '../QtGui/QKeySequence'; import { ShortcutContext } from '../QtEnums'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { checkIfNativeElement } from '../utils/helpers'; import { QVariant } from '../QtCore/QVariant'; @@ -30,13 +30,12 @@ menuAction.addEventListener("triggered", () => { menu.addAction(menuAction); ``` */ -export class QAction extends NodeObject { - native: NativeElement; +export class QAction extends QObject { constructor(); constructor(native: NativeElement); constructor(parent: NodeWidget); constructor(parent?: NativeElement | NodeWidget) { - let native; + let native: NativeElement; if (checkIfNativeElement(parent)) { native = parent as NativeElement; } else if (parent) { @@ -45,7 +44,6 @@ export class QAction extends NodeObject { native = new addon.QAction(); } super(native); - this.native = native; } setText(text: string): void { this.native.setText(text); diff --git a/src/lib/QtWidgets/QBoxLayout.ts b/src/lib/QtWidgets/QBoxLayout.ts index 39df53f36..03621edc4 100644 --- a/src/lib/QtWidgets/QBoxLayout.ts +++ b/src/lib/QtWidgets/QBoxLayout.ts @@ -26,7 +26,6 @@ centralWidget.setLayout(boxLayout); ``` */ export class QBoxLayout extends NodeLayout { - native: NativeElement; childLayouts: Set>; constructor(dir: Direction); constructor(dir: Direction, parent: NodeWidget); @@ -39,7 +38,6 @@ export class QBoxLayout extends NodeLayout { } super(native); this.setNodeParent(parent); - this.native = native; this.childLayouts = new Set(); } addLayout(layout: NodeLayout, stretch = 0): void { diff --git a/src/lib/QtWidgets/QButtonGroup.ts b/src/lib/QtWidgets/QButtonGroup.ts index 817aaaed9..da7a16c68 100644 --- a/src/lib/QtWidgets/QButtonGroup.ts +++ b/src/lib/QtWidgets/QButtonGroup.ts @@ -1,15 +1,14 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement, NativeRawPointer } from '../core/Component'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { NativeRawPointer } from '../core/Component'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; export interface QButtonGroupSignals extends QObjectSignals { buttonClicked: (id?: number) => void; } -export class QButtonGroup extends NodeObject { - native: NativeElement; +export class QButtonGroup extends QObject { constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { @@ -20,7 +19,6 @@ export class QButtonGroup extends NodeObject { native = new addon.QButtonGroup(); } super(native); - this.native = native; parent && parent.nodeChildren.add(this); } addButton(button: QAbstractButton, id = -1): void { diff --git a/src/lib/QtWidgets/QCalendarWidget.ts b/src/lib/QtWidgets/QCalendarWidget.ts index b8ef50dcf..76b857096 100644 --- a/src/lib/QtWidgets/QCalendarWidget.ts +++ b/src/lib/QtWidgets/QCalendarWidget.ts @@ -5,7 +5,7 @@ import { QDate } from '../QtCore/QDate'; import { DayOfWeek } from '../QtEnums'; /** - + > Create and control a selectable monthly calendar. * **This class is a JS wrapper around Qt's [QCalendarWidget class](https://doc.qt.io/qt-5/qcalendarwidget.html)** @@ -22,18 +22,16 @@ const calendarWidget = new QCalendarWidget(); ``` */ export class QCalendarWidget extends NodeWidget { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QCalendarWidget(parent.native); } else { native = new addon.QCalendarWidget(); } super(native); - this.native = native; this.setNodeParent(parent); } setDateEditAcceptDelay(delay: number): void { diff --git a/src/lib/QtWidgets/QCheckBox.ts b/src/lib/QtWidgets/QCheckBox.ts index 73d8b5c0d..66e6a33be 100644 --- a/src/lib/QtWidgets/QCheckBox.ts +++ b/src/lib/QtWidgets/QCheckBox.ts @@ -23,7 +23,6 @@ checkbox.setText("Hello"); ``` */ export class QCheckBox extends QAbstractButton { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(rawPointer: NativeRawPointer, disableNativeDeletion?: boolean); @@ -42,7 +41,6 @@ export class QCheckBox extends QAbstractButton { native = new addon.QCheckBox(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setTristate(y = true): void { diff --git a/src/lib/QtWidgets/QColorDialog.ts b/src/lib/QtWidgets/QColorDialog.ts index a4784d3e5..aa7c1637f 100644 --- a/src/lib/QtWidgets/QColorDialog.ts +++ b/src/lib/QtWidgets/QColorDialog.ts @@ -5,7 +5,7 @@ import { NodeDialog, QDialogSignals } from './QDialog'; import { QColor } from '../QtGui/QColor'; /** - + > Create and control color dialogs. * **This class is a JS wrapper around Qt's [QColorDialog class](https://doc.qt.io/qt-5/qcolordialog.html)** @@ -27,18 +27,16 @@ console.log(color.red(), color.green(), color.blue()); ``` */ export class QColorDialog extends NodeDialog { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QColorDialog(parent.native); } else { native = new addon.QColorDialog(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setCurrentColor(color: QColor): void { diff --git a/src/lib/QtWidgets/QComboBox.ts b/src/lib/QtWidgets/QComboBox.ts index 77149bd9a..2b7788993 100644 --- a/src/lib/QtWidgets/QComboBox.ts +++ b/src/lib/QtWidgets/QComboBox.ts @@ -37,18 +37,16 @@ comboBox.addEventListener('currentIndexChanged', (index) => { ``` */ export class QComboBox extends NodeWidget { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QComboBox(parent.native); } else { native = new addon.QComboBox(); } super(native); - this.native = native; this.setNodeParent(parent); } // *** Public Functions *** diff --git a/src/lib/QtWidgets/QDateEdit.ts b/src/lib/QtWidgets/QDateEdit.ts index 1aa329f50..1b67f0d63 100644 --- a/src/lib/QtWidgets/QDateEdit.ts +++ b/src/lib/QtWidgets/QDateEdit.ts @@ -21,18 +21,16 @@ const dateEdit = new QDateEdit(); ``` */ export class QDateEdit extends NodeDateTimeEdit { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QDateEdit(parent.native); } else { native = new addon.QDateEdit(); } super(native); - this.native = native; this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QDateTimeEdit.ts b/src/lib/QtWidgets/QDateTimeEdit.ts index 951a1a677..2183cec62 100644 --- a/src/lib/QtWidgets/QDateTimeEdit.ts +++ b/src/lib/QtWidgets/QDateTimeEdit.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { QAbstractSpinBox, QAbstractSpinBoxSignals } from './QAbstractSpinBox'; import { QCalendarWidget } from './QCalendarWidget'; import { QDate } from '../QtCore/QDate'; @@ -86,7 +85,6 @@ dateTimeEdit.setTime(time); ``` */ export class QDateTimeEdit extends NodeDateTimeEdit { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { @@ -97,7 +95,6 @@ export class QDateTimeEdit extends NodeDateTimeEdit { native = new addon.QDateTimeEdit(); } super(native); - this.native = native; this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QDial.ts b/src/lib/QtWidgets/QDial.ts index 928e72923..6ba0112a0 100644 --- a/src/lib/QtWidgets/QDial.ts +++ b/src/lib/QtWidgets/QDial.ts @@ -20,18 +20,16 @@ const dial = new QDial(); ``` */ export class QDial extends QAbstractSlider { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QDial(parent.native); } else { native = new addon.QDial(); } super(native); - this.native = native; this.setNodeParent(parent); } notchSize(): number { diff --git a/src/lib/QtWidgets/QDialog.ts b/src/lib/QtWidgets/QDialog.ts index a5958ac3d..dc6f41bf8 100644 --- a/src/lib/QtWidgets/QDialog.ts +++ b/src/lib/QtWidgets/QDialog.ts @@ -43,7 +43,6 @@ export abstract class NodeDialog extends NodeWid It is inherited by QFileDialog and QMessageBox (n/a QColorDialog, QErrorMessage, QFontDialog, QInputDialog, QMessageBox, QProgressDialog, and QWizard) */ export class QDialog extends NodeDialog { - native: NativeElement; constructor(arg?: NodeDialog | NativeElement) { let native; let parent; @@ -57,7 +56,6 @@ export class QDialog extends NodeDialog { } super(native); this.setNodeParent(parent); - this.native = native; } } diff --git a/src/lib/QtWidgets/QDoubleSpinBox.ts b/src/lib/QtWidgets/QDoubleSpinBox.ts index 38d08e5a2..d3d194724 100644 --- a/src/lib/QtWidgets/QDoubleSpinBox.ts +++ b/src/lib/QtWidgets/QDoubleSpinBox.ts @@ -20,18 +20,16 @@ const doublespinBox = new QDoubleSpinBox(); ``` */ export class QDoubleSpinBox extends QAbstractSpinBox { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QDoubleSpinBox(parent.native); } else { native = new addon.QDoubleSpinBox(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } cleanText(): string { diff --git a/src/lib/QtWidgets/QErrorMessage.ts b/src/lib/QtWidgets/QErrorMessage.ts index adef87987..073df1e1d 100644 --- a/src/lib/QtWidgets/QErrorMessage.ts +++ b/src/lib/QtWidgets/QErrorMessage.ts @@ -21,18 +21,16 @@ const errorMessage = new QErrorMessage(); ``` */ export class QErrorMessage extends NodeDialog { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QErrorMessage(parent.native); } else { native = new addon.QErrorMessage(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } showMessage(message: string): void { diff --git a/src/lib/QtWidgets/QFileDialog.ts b/src/lib/QtWidgets/QFileDialog.ts index 4f5b94f62..7954a9b76 100644 --- a/src/lib/QtWidgets/QFileDialog.ts +++ b/src/lib/QtWidgets/QFileDialog.ts @@ -5,7 +5,7 @@ import { AcceptMode, DialogLabel, FileMode, Option, ViewMode } from '../QtEnums' import { NodeDialog, QDialogSignals } from './QDialog'; /** - + > Create and control file dialogs. * **This class is a JS wrapper around Qt's [QFileDialog class](https://doc.qt.io/qt-5/qfiledialog.html)** @@ -28,18 +28,16 @@ console.log(selectedFiles); ``` */ export class QFileDialog extends NodeDialog { - native: NativeElement; constructor(); constructor(parent: NodeWidget, caption?: string, directory?: string, filter?: string); constructor(parent?: NodeWidget, caption = 'Select File', directory = '', filter = '') { - let native; + let native: NativeElement; if (parent) { native = new addon.QFileDialog(parent.native, caption, directory, filter); } else { native = new addon.QFileDialog(); } super(native); - this.native = native; this.setNodeParent(parent); } supportedSchemes(): string[] { diff --git a/src/lib/QtWidgets/QFontDialog.ts b/src/lib/QtWidgets/QFontDialog.ts index cb553a276..ad6ec76cd 100644 --- a/src/lib/QtWidgets/QFontDialog.ts +++ b/src/lib/QtWidgets/QFontDialog.ts @@ -25,18 +25,16 @@ console.log(font); ``` */ export class QFontDialog extends NodeDialog { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QFontDialog(parent.native); } else { native = new addon.QFontDialog(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setCurrentFont(font: QFont): void { diff --git a/src/lib/QtWidgets/QFrame.ts b/src/lib/QtWidgets/QFrame.ts index c1cce1c8d..69a69dcbb 100644 --- a/src/lib/QtWidgets/QFrame.ts +++ b/src/lib/QtWidgets/QFrame.ts @@ -80,9 +80,8 @@ const frame = new QFrame(); ``` */ export class QFrame extends NodeFrame { - native: NativeElement; constructor(arg?: NodeWidget | NativeElement) { - let native; + let native: NativeElement; let parent; if (checkIfNativeElement(arg)) { native = arg as NativeElement; @@ -94,6 +93,5 @@ export class QFrame extends NodeFrame { } super(native); this.setNodeParent(parent); - this.native = native; } } diff --git a/src/lib/QtWidgets/QGraphicsBlurEffect.ts b/src/lib/QtWidgets/QGraphicsBlurEffect.ts index 2a5c18a24..ce2bacf7e 100644 --- a/src/lib/QtWidgets/QGraphicsBlurEffect.ts +++ b/src/lib/QtWidgets/QGraphicsBlurEffect.ts @@ -1,7 +1,7 @@ import addon from '../utils/addon'; import { NativeElement } from '../core/Component'; import { checkIfNativeElement } from '../utils/helpers'; -import { NodeObject } from '../QtCore/QObject'; +import { QObject } from '../QtCore/QObject'; import { QGraphicsEffect, QGraphicsEffectSignals } from './QGraphicsEffect'; /** @@ -22,11 +22,10 @@ blur.setBlurRadius(8); ``` */ export class QGraphicsBlurEffect extends QGraphicsEffect { - native: NativeElement; constructor(); constructor(native: NativeElement); - constructor(parent: NodeObject); - constructor(arg?: NodeObject | NativeElement) { + constructor(parent: QObject); + constructor(arg?: QObject | NativeElement) { let native: NativeElement; if (arg) { if (checkIfNativeElement(arg)) { @@ -38,7 +37,6 @@ export class QGraphicsBlurEffect extends QGraphicsEffect { - native: NativeElement; constructor(); constructor(native: NativeElement); - constructor(parent: NodeObject); - constructor(arg?: NodeObject | NativeElement) { + constructor(parent: QObject); + constructor(arg?: QObject | NativeElement) { let native: NativeElement; if (arg) { if (checkIfNativeElement(arg)) { @@ -39,7 +38,6 @@ export class QGraphicsDropShadowEffect extends QGraphicsEffect This is the abstract base class of graphicseffect, providing their functionality. * **This class is a JS wrapper around Qt's [QGraphicsEffect class](https://doc.qt.io/qt-5/qgraphicseffect.html)** @@ -10,7 +10,7 @@ The QGraphicsEffect class is an abstract class and therefore, technically, no fu It is inherited by QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, and QGraphicsOpacityEffect. */ -export abstract class QGraphicsEffect extends NodeObject { +export abstract class QGraphicsEffect extends QObject { setEnabled(enable: boolean): void { this.setProperty('enabled', enable); } diff --git a/src/lib/QtWidgets/QGridLayout.ts b/src/lib/QtWidgets/QGridLayout.ts index 8f477b738..c5a6ca729 100644 --- a/src/lib/QtWidgets/QGridLayout.ts +++ b/src/lib/QtWidgets/QGridLayout.ts @@ -30,7 +30,6 @@ layout.addWidget(label2); */ export class QGridLayout extends NodeLayout { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { @@ -42,7 +41,6 @@ export class QGridLayout extends NodeLayout { } super(native); this.setNodeParent(parent); - this.native = native; } addLayout( diff --git a/src/lib/QtWidgets/QGroupBox.ts b/src/lib/QtWidgets/QGroupBox.ts index 0db6a035e..50f91e966 100644 --- a/src/lib/QtWidgets/QGroupBox.ts +++ b/src/lib/QtWidgets/QGroupBox.ts @@ -40,18 +40,16 @@ win.show(); ``` */ export class QGroupBox extends NodeWidget { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QGroupBox(parent.native); } else { native = new addon.QGroupBox(); } super(native); - this.native = native; this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { diff --git a/src/lib/QtWidgets/QHeaderView.ts b/src/lib/QtWidgets/QHeaderView.ts index 48a6c99d3..3f8131688 100644 --- a/src/lib/QtWidgets/QHeaderView.ts +++ b/src/lib/QtWidgets/QHeaderView.ts @@ -205,9 +205,8 @@ export abstract class NodeHeaderView extends } export class QHeaderView extends NodeHeaderView { - native: NativeElement; constructor(orientationOrNative: Orientation | NativeElement, parent: NodeWidget | null = null) { - let native; + let native: NativeElement; if (checkIfNativeElement(orientationOrNative)) { native = orientationOrNative as NativeElement; } else { @@ -218,7 +217,6 @@ export class QHeaderView extends NodeHeaderView { } } super(native); - this.native = native; parent && this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QInputDialog.ts b/src/lib/QtWidgets/QInputDialog.ts index 43e623818..dc8207d30 100644 --- a/src/lib/QtWidgets/QInputDialog.ts +++ b/src/lib/QtWidgets/QInputDialog.ts @@ -1,11 +1,10 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { NodeDialog, QDialogSignals } from './QDialog'; import { EchoMode } from './QLineEdit'; /** - + > Create and control input modal dialogs. * **This class is a JS wrapper around Qt's [QInputDialog class](https://doc.qt.io/qt-5/qinputdialog.html)** @@ -23,9 +22,6 @@ dialog.exec(); ``` */ export class QInputDialog extends NodeDialog { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -34,7 +30,6 @@ export class QInputDialog extends NodeDialog { native = new addon.QInputDialog(); } super(native); - this.native = native; this.setNodeParent(parent); } setCancelButtonText(text: string): void { diff --git a/src/lib/QtWidgets/QLCDNumber.ts b/src/lib/QtWidgets/QLCDNumber.ts index 9e875dbb1..8e9d08a59 100644 --- a/src/lib/QtWidgets/QLCDNumber.ts +++ b/src/lib/QtWidgets/QLCDNumber.ts @@ -1,9 +1,8 @@ import addon from '../utils/addon'; import { NodeWidget, QWidgetSignals } from './QWidget'; -import { NativeElement } from '../core/Component'; /** - + > Create and control number. * **This class is a JS wrapper around Qt's [QLCDNumber class](https://doc.qt.io/qt-5/qlcdnumber.html)** @@ -21,9 +20,6 @@ const lcd = new QLCDNumber(); */ export class QLCDNumber extends NodeWidget { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -32,7 +28,6 @@ export class QLCDNumber extends NodeWidget { native = new addon.QLCDNumber(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setDigitCount(numDigits: number): void { diff --git a/src/lib/QtWidgets/QLabel.ts b/src/lib/QtWidgets/QLabel.ts index ed65bea94..c15337288 100644 --- a/src/lib/QtWidgets/QLabel.ts +++ b/src/lib/QtWidgets/QLabel.ts @@ -1,7 +1,6 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; import { NodeFrame, QFrameSignals } from './QFrame'; -import { NativeElement } from '../core/Component'; import { QPixmap } from '../QtGui/QPixmap'; import { QMovie } from '../QtGui/QMovie'; import { AlignmentFlag } from '../QtEnums/AlignmentFlag'; @@ -10,7 +9,7 @@ import { TextInteractionFlag } from '../QtEnums'; import { QPicture } from '../QtGui/QPicture'; /** - + > Create and control text. * **This class is a JS wrapper around Qt's [QLabel class](https://doc.qt.io/qt-5/qlabel.html)** @@ -28,13 +27,11 @@ label.setText("Hello"); */ export class QLabel extends NodeFrame { - native: NativeElement; private _picture?: QPicture; private _pixmap?: QPixmap; private _movie?: QMovie; private _buddy?: NodeWidget | null; - constructor(); - constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { @@ -43,7 +40,6 @@ export class QLabel extends NodeFrame { native = new addon.QLabel(); } super(native); - this.native = native; this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { diff --git a/src/lib/QtWidgets/QLayout.ts b/src/lib/QtWidgets/QLayout.ts index 018accb2e..734ffe13e 100644 --- a/src/lib/QtWidgets/QLayout.ts +++ b/src/lib/QtWidgets/QLayout.ts @@ -1,10 +1,10 @@ import { NodeWidget } from './QWidget'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; // All Layouts should extend this abstract class. /** - + > Abstract class to add functionalities common to all Layout. **This class implements all methods, properties of Qt's [QLayout class](https://doc.qt.io/qt-5/qlayout.html) so that it can be inherited by all layouts** @@ -32,7 +32,7 @@ addChildToLayout(new FlexLayout(), new QPushButton()); addChildToLayout(new GridLayout(), new QWidget()); ``` */ -export abstract class NodeLayout extends NodeObject { +export abstract class NodeLayout extends QObject { type = 'layout'; abstract addWidget(childWidget: NodeWidget, ...args: any[]): void; abstract removeWidget(childWidget: NodeWidget): void; diff --git a/src/lib/QtWidgets/QLineEdit.ts b/src/lib/QtWidgets/QLineEdit.ts index 00e89d3c8..ec49056f6 100644 --- a/src/lib/QtWidgets/QLineEdit.ts +++ b/src/lib/QtWidgets/QLineEdit.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeWidget, QWidgetSignals } from './QWidget'; -import { NativeElement } from '../core/Component'; import { AlignmentFlag } from '../QtEnums/AlignmentFlag'; import { CursorMoveStyle } from '../QtEnums/CursorMoveStyle'; import { QPoint } from '../QtCore/QPoint'; @@ -23,9 +22,6 @@ const lineEdit = new QLineEdit(); */ export class QLineEdit extends NodeWidget { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -34,7 +30,6 @@ export class QLineEdit extends NodeWidget { native = new addon.QLineEdit(); } super(native); - this.native = native; this.setNodeParent(parent); } // TODO: void addAction(QAction *action, QLineEdit::ActionPosition position) diff --git a/src/lib/QtWidgets/QListView.ts b/src/lib/QtWidgets/QListView.ts index c1a1bcb70..d0649d919 100644 --- a/src/lib/QtWidgets/QListView.ts +++ b/src/lib/QtWidgets/QListView.ts @@ -144,18 +144,16 @@ export enum ListViewMode { } export class QListView extends NodeListView { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QListView(parent.native); } else { native = new addon.QListView(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QListWidget.ts b/src/lib/QtWidgets/QListWidget.ts index d4fb1ca36..ed67a3015 100644 --- a/src/lib/QtWidgets/QListWidget.ts +++ b/src/lib/QtWidgets/QListWidget.ts @@ -33,10 +33,8 @@ for (let i = 0; i < 30; i++) { ``` */ export class QListWidget extends NodeListView { - native: NativeElement; items: Set; - constructor(); - constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { @@ -45,7 +43,6 @@ export class QListWidget extends NodeListView { native = new addon.QListWidget(); } super(native); - this.native = native; parent && this.setNodeParent(parent); this.items = new Set(); } diff --git a/src/lib/QtWidgets/QListWidgetItem.ts b/src/lib/QtWidgets/QListWidgetItem.ts index b4be0fc2c..b9997b86d 100644 --- a/src/lib/QtWidgets/QListWidgetItem.ts +++ b/src/lib/QtWidgets/QListWidgetItem.ts @@ -10,7 +10,7 @@ import { CheckState } from '../QtEnums'; import { ItemFlag } from '../QtEnums/ItemFlag'; /** - + > Creates an item for QListWidget. * **This class is a JS wrapper around Qt's [QListWidgetItem class](https://doc.qt.io/qt-5/qlistwidgetitem.html)** @@ -35,11 +35,6 @@ for (let i = 0; i < 30; i++) { ``` */ export class QListWidgetItem extends Component { - native: NativeElement; - constructor(); - constructor(other: QListWidgetItem); - constructor(native: NativeElement); - constructor(text: string); constructor(arg?: QListWidgetItem | NativeElement | string) { let native; if (typeof arg === 'string') { @@ -49,8 +44,7 @@ export class QListWidgetItem extends Component { } else { native = new addon.QListWidgetItem(); } - super(); - this.native = native; + super(native); } setBackground(brush: QBrush): void { this.native.setBackground(brush.native); diff --git a/src/lib/QtWidgets/QMainWindow.ts b/src/lib/QtWidgets/QMainWindow.ts index fbbd974eb..c5e1734ff 100644 --- a/src/lib/QtWidgets/QMainWindow.ts +++ b/src/lib/QtWidgets/QMainWindow.ts @@ -1,12 +1,12 @@ import addon from '../utils/addon'; import { NodeWidget, QWidgetSignals } from './QWidget'; -import { NativeElement } from '../core/Component'; import { NodeLayout } from './QLayout'; import { QMenuBar } from './QMenuBar'; import { QStatusBar } from './QStatusBar'; +import { NativeElement } from '../core/Component'; /** - + > Create and control windows. * **This class is a JS wrapper around Qt's [QMainWindow class](https://doc.qt.io/qt-5/qmainwindow.html)** @@ -32,21 +32,20 @@ QMainWindow needs to have a central widget set before other widgets can be added Once a central widget is set you can add children/layout to the central widget. */ export class QMainWindow extends NodeWidget { - native: NativeElement; public centralWidget?: NodeWidget | null; private _menuBar?: QMenuBar; private _statusBar?: QStatusBar | null; + constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QMainWindow(parent.native); } else { native = new addon.QMainWindow(); } super(native); - this.native = native; this.setNodeParent(parent); this.setLayout = (parentLayout: NodeLayout): void => { @@ -115,7 +114,7 @@ export class QMainWindow extends NodeWidget { * Returns the status bar for the main window. */ statusBar(): QStatusBar { - return this.native.statusBar(); + return new QStatusBar(this.native.statusBar()); } } diff --git a/src/lib/QtWidgets/QMenu.ts b/src/lib/QtWidgets/QMenu.ts index 14346496b..9211708eb 100644 --- a/src/lib/QtWidgets/QMenu.ts +++ b/src/lib/QtWidgets/QMenu.ts @@ -19,9 +19,6 @@ const menu = new QMenu(); ``` */ export class QMenu extends NodeWidget { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -30,7 +27,6 @@ export class QMenu extends NodeWidget { native = new addon.QMenu(); } super(native); - this.native = native; this.setNodeParent(parent); } clear(): void { diff --git a/src/lib/QtWidgets/QMenuBar.ts b/src/lib/QtWidgets/QMenuBar.ts index 15f065865..b82305c57 100644 --- a/src/lib/QtWidgets/QMenuBar.ts +++ b/src/lib/QtWidgets/QMenuBar.ts @@ -6,7 +6,7 @@ import { checkIfNativeElement } from '../utils/helpers'; import { QAction } from './QAction'; /** - + > The QMenuBar class provides a menu widget for use in menu bars, context menus, and other popup menus. * **This class is a JS wrapper around Qt's [QMenuBar class](https://doc.qt.io/qt-5/qmenu.html)** @@ -24,11 +24,8 @@ global.win = win; ``` */ export class QMenuBar extends NodeWidget { - native: NativeElement; _menus: Set; - constructor(); - constructor(parent: NodeWidget); - constructor(native: NativeElement); + constructor(arg?: NodeWidget | NativeElement) { let native; let parent; @@ -41,7 +38,6 @@ export class QMenuBar extends NodeWidget { native = new addon.QMenuBar(); } super(native); - this.native = native; this._menus = new Set(); this.setNodeParent(parent); } diff --git a/src/lib/QtWidgets/QMessageBox.ts b/src/lib/QtWidgets/QMessageBox.ts index 3a2817c94..4fb4cc5ee 100644 --- a/src/lib/QtWidgets/QMessageBox.ts +++ b/src/lib/QtWidgets/QMessageBox.ts @@ -1,6 +1,6 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement, NativeRawPointer } from '../core/Component'; +import { NativeRawPointer } from '../core/Component'; import { NodeDialog, QDialogSignals } from './QDialog'; import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; import { QPushButton } from './QPushButton'; @@ -19,7 +19,7 @@ export enum ButtonRole { } /** - + > Create and control classic modal dialogs. * **This class is a JS wrapper around Qt's [QMessageBox class](https://doc.qt.io/qt-5/qmessagebox.html)** @@ -40,9 +40,6 @@ messageBox.exec(); ``` */ export class QMessageBox extends NodeDialog { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -51,7 +48,6 @@ export class QMessageBox extends NodeDialog { native = new addon.QMessageBox(); } super(native); - this.native = native; this.setNodeParent(parent); } accept(): void { diff --git a/src/lib/QtWidgets/QPainter.ts b/src/lib/QtWidgets/QPainter.ts index 481d250ac..97673b2f6 100644 --- a/src/lib/QtWidgets/QPainter.ts +++ b/src/lib/QtWidgets/QPainter.ts @@ -46,18 +46,14 @@ win.show(); https://github.com/nodegui/examples/blob/master/nodegui/custom-native-widget-qpainter */ export class QPainter extends Component { - native: NativeElement; - constructor(); - constructor(device: Component); constructor(device?: Component) { - let native; + let native: NativeElement; if (device) { native = new addon.QPainter(device.native); } else { native = new addon.QPainter(); } - super(); - this.native = native; + super(native); } // *** Public Functions *** diff --git a/src/lib/QtWidgets/QPainterPath.ts b/src/lib/QtWidgets/QPainterPath.ts index 358bd22cc..8b13bbd93 100644 --- a/src/lib/QtWidgets/QPainterPath.ts +++ b/src/lib/QtWidgets/QPainterPath.ts @@ -1,5 +1,5 @@ import addon from '../utils/addon'; -import { Component, NativeElement } from '../core/Component'; +import { Component } from '../core/Component'; import { SizeMode, FillRule } from '../QtEnums'; import { QFont } from '../QtGui/QFont'; @@ -12,11 +12,8 @@ import { QFont } from '../QtGui/QFont'; */ export class QPainterPath extends Component { - native: NativeElement; constructor() { - super(); - const native = new addon.QPainterPath(); - this.native = native; + super(new addon.QPainterPath()); } moveTo(x: number, y: number): void { diff --git a/src/lib/QtWidgets/QPlainTextEdit.ts b/src/lib/QtWidgets/QPlainTextEdit.ts index 2db011c96..dd024c846 100644 --- a/src/lib/QtWidgets/QPlainTextEdit.ts +++ b/src/lib/QtWidgets/QPlainTextEdit.ts @@ -32,19 +32,15 @@ const plainTextEdit = new QPlainTextEdit(); ``` */ export class QPlainTextEdit extends QAbstractScrollArea { - native: NativeElement; placeholderText?: string; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QPlainTextEdit(parent.native); } else { native = new addon.QPlainTextEdit(); } super(native); - this.native = native; this.setNodeParent(parent); } setPlainText(text: string | number): void { diff --git a/src/lib/QtWidgets/QProgressBar.ts b/src/lib/QtWidgets/QProgressBar.ts index bc82fc840..0f60d9b14 100644 --- a/src/lib/QtWidgets/QProgressBar.ts +++ b/src/lib/QtWidgets/QProgressBar.ts @@ -20,18 +20,14 @@ const progressBar = new QProgressBar(); ``` */ export class QProgressBar extends NodeWidget { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QProgressBar(parent.native); } else { native = new addon.QProgressBar(); } super(native); - this.native = native; this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { diff --git a/src/lib/QtWidgets/QProgressDialog.ts b/src/lib/QtWidgets/QProgressDialog.ts index fbd86fc6c..9fd608f49 100644 --- a/src/lib/QtWidgets/QProgressDialog.ts +++ b/src/lib/QtWidgets/QProgressDialog.ts @@ -1,10 +1,9 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { NodeDialog, QDialogSignals } from './QDialog'; /** - + > Create and control progress dialogs. * **This class is a JS wrapper around Qt's [QProgressDialog class](https://doc.qt.io/qt-5/qprogressdialog.html)** @@ -21,9 +20,6 @@ const progressDialog = new QProgressDialog(); ``` */ export class QProgressDialog extends NodeDialog { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -32,7 +28,6 @@ export class QProgressDialog extends NodeDialog { native = new addon.QProgressDialog(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setAutoClose(close: boolean): void { diff --git a/src/lib/QtWidgets/QPushButton.ts b/src/lib/QtWidgets/QPushButton.ts index 67131110f..8c591e030 100644 --- a/src/lib/QtWidgets/QPushButton.ts +++ b/src/lib/QtWidgets/QPushButton.ts @@ -6,7 +6,7 @@ import { checkIfNativeElement, checkIfNapiExternal } from '../utils/helpers'; import { QMenu } from './QMenu'; /** - + > Create and control buttons. * **This class is a JS wrapper around Qt's [QPushButton class](https://doc.qt.io/qt-5/qpushbutton.html)** @@ -23,12 +23,8 @@ button.setText("Hello"); ``` */ export class QPushButton extends QAbstractButton { - native: NativeElement; private _menu?: QMenu | null; - constructor(); - constructor(parent: NodeWidget); - constructor(native: NativeElement); - constructor(rawPointer: NativeRawPointer, disableNativeDeletion?: boolean); + constructor(arg?: NodeWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { let native; let parent: Component | undefined; @@ -44,7 +40,6 @@ export class QPushButton extends QAbstractButton { native = new addon.QPushButton(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setAutoDefault(auto: boolean): void { diff --git a/src/lib/QtWidgets/QRadioButton.ts b/src/lib/QtWidgets/QRadioButton.ts index 1f7f332c0..6813c63ad 100644 --- a/src/lib/QtWidgets/QRadioButton.ts +++ b/src/lib/QtWidgets/QRadioButton.ts @@ -5,7 +5,7 @@ import { QAbstractButton, QAbstractButtonSignals } from './QAbstractButton'; import { checkIfNativeElement, checkIfNapiExternal } from '../utils/helpers'; /** - + > Create and control radio button. * **This class is a JS wrapper around Qt's [QRadioButton class](https://doc.qt.io/qt-5/qradiobutton.html)** @@ -23,10 +23,6 @@ radioButton.setText("Hello"); */ export class QRadioButton extends QAbstractButton { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); - constructor(rawPointer: NativeRawPointer, disableNativeDeletion?: boolean); constructor(arg?: NodeWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { let native; let parent: Component | undefined; @@ -42,7 +38,6 @@ export class QRadioButton extends QAbstractButton { native = new addon.QRadioButton(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QScrollArea.ts b/src/lib/QtWidgets/QScrollArea.ts index bdd4fbb5c..e91d2fdf7 100644 --- a/src/lib/QtWidgets/QScrollArea.ts +++ b/src/lib/QtWidgets/QScrollArea.ts @@ -29,19 +29,15 @@ scrollArea.setWidget(imageLabel); ``` */ export class QScrollArea extends QAbstractScrollArea { - native: NativeElement; contentWidget?: NodeWidget | null; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QScrollArea(parent.native); } else { native = new addon.QScrollArea(); } super(native); - this.native = native; this.setNodeParent(parent); } setAlignment(alignment: AlignmentFlag): void { diff --git a/src/lib/QtWidgets/QScrollBar.ts b/src/lib/QtWidgets/QScrollBar.ts index b06fa38e9..d8b150503 100644 --- a/src/lib/QtWidgets/QScrollBar.ts +++ b/src/lib/QtWidgets/QScrollBar.ts @@ -4,7 +4,7 @@ import { NativeElement } from '../core/Component'; import { QAbstractSlider, QAbstractSliderSignals } from './QAbstractSlider'; /** - + > Create and control scollbar widgets. * **This class is a JS wrapper around Qt's [QScrollBar class](https://doc.qt.io/qt-5/qscrollbar.html)** @@ -20,18 +20,14 @@ const scrollbar = new QScrollBar(); ``` */ export class QScrollBar extends QAbstractSlider { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QScrollBar(parent.native); } else { native = new addon.QScrollBar(); } super(native); - this.native = native; this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QShortcut.ts b/src/lib/QtWidgets/QShortcut.ts index 6e2ddbc4b..32e306ab0 100644 --- a/src/lib/QtWidgets/QShortcut.ts +++ b/src/lib/QtWidgets/QShortcut.ts @@ -1,9 +1,8 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { QKeySequence } from '../QtGui/QKeySequence'; import { ShortcutContext } from '../QtEnums'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; /** @@ -29,12 +28,9 @@ global.win = win; global.shortcut = shortcut; ``` */ -export class QShortcut extends NodeObject { - native: NativeElement; +export class QShortcut extends QObject { constructor(parent: NodeWidget) { - const native = new addon.QShortcut(parent.native); - super(native); - this.native = native; + super(new addon.QShortcut(parent.native)); } setEnabled(enabled: boolean): void { this.native.setEnabled(enabled); diff --git a/src/lib/QtWidgets/QSlider.ts b/src/lib/QtWidgets/QSlider.ts index f3fde92db..9b2667c62 100644 --- a/src/lib/QtWidgets/QSlider.ts +++ b/src/lib/QtWidgets/QSlider.ts @@ -1,10 +1,10 @@ import addon from '../utils/addon'; -import { NodeWidget } from './QWidget'; +import { QWidget } from './QWidget'; import { NativeElement } from '../core/Component'; import { QAbstractSlider, QAbstractSliderSignals } from './QAbstractSlider'; /** - + > Create and control slider widgets. * **This class is a JS wrapper around Qt's [QSlider class](https://doc.qt.io/qt-5/qslider.html)** @@ -20,18 +20,14 @@ const slider = new QSlider(); ``` */ export class QSlider extends QAbstractSlider { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); - constructor(parent?: NodeWidget) { - let native; + constructor(parent?: QWidget) { + let native: NativeElement; if (parent) { native = new addon.QSlider(parent.native); } else { native = new addon.QSlider(); } super(native); - this.native = native; this.setNodeParent(parent); } setTickInterval(ti: number): void { diff --git a/src/lib/QtWidgets/QSpinBox.ts b/src/lib/QtWidgets/QSpinBox.ts index 7cbaee719..87bb300ca 100644 --- a/src/lib/QtWidgets/QSpinBox.ts +++ b/src/lib/QtWidgets/QSpinBox.ts @@ -1,10 +1,9 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { QAbstractSpinBox, QAbstractSpinBoxSignals, StepType } from './QAbstractSpinBox'; /** - + > Create and control spin box widgets. * **This class is a JS wrapper around Qt's [QSpinBox class](https://doc.qt.io/qt-5/qspinbox.html)** @@ -20,9 +19,6 @@ const spinBox = new QSpinBox(); ``` */ export class QSpinBox extends QAbstractSpinBox { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -32,7 +28,6 @@ export class QSpinBox extends QAbstractSpinBox { } super(native); this.setNodeParent(parent); - this.native = native; } cleanText(): string { return this.property('cleanText').toString(); diff --git a/src/lib/QtWidgets/QSplitter.ts b/src/lib/QtWidgets/QSplitter.ts index 177706c6a..82dad87c2 100644 --- a/src/lib/QtWidgets/QSplitter.ts +++ b/src/lib/QtWidgets/QSplitter.ts @@ -35,18 +35,14 @@ splitterHorizontal.addWidget(right); */ export class QSplitter extends NodeFrame { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QSplitter(parent.native); } else { native = new addon.QSplitter(); } super(native); - this.native = native; this.setNodeParent(parent); } addWidget(widget: NodeWidget): void { diff --git a/src/lib/QtWidgets/QStackedWidget.ts b/src/lib/QtWidgets/QStackedWidget.ts index 13e1d2f45..46da1a545 100644 --- a/src/lib/QtWidgets/QStackedWidget.ts +++ b/src/lib/QtWidgets/QStackedWidget.ts @@ -1,7 +1,6 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; import { NodeFrame, QFrameSignals } from './QFrame'; -import { NativeElement } from '../core/Component'; /** @@ -45,9 +44,6 @@ win.show(); ``` */ export class QStackedWidget extends NodeFrame { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -57,7 +53,6 @@ export class QStackedWidget extends NodeFrame { } super(native); this.setNodeParent(parent); - this.native = native; } // *** Public Function *** diff --git a/src/lib/QtWidgets/QStandardItem.ts b/src/lib/QtWidgets/QStandardItem.ts index bb9be5d81..c43fcf2be 100644 --- a/src/lib/QtWidgets/QStandardItem.ts +++ b/src/lib/QtWidgets/QStandardItem.ts @@ -5,21 +5,21 @@ import { ItemFlag } from '../QtEnums/ItemFlag'; import { CheckState } from '../QtEnums'; export class QStandardItem extends Component { - native: NativeElement; constructor(); constructor(parent: QStandardItem, text?: string); constructor(native: NativeElement); constructor(parent?: NativeElement | QStandardItem, text?: string) { - super(); + let native: NativeElement; if (checkIfNativeElement(parent)) { - this.native = parent as NativeElement; + native = parent as NativeElement; } else { if (text) { - this.native = new addon.QStandardItem(text); + native = new addon.QStandardItem(text); } else { - this.native = new addon.QStandardItem(); + native = new addon.QStandardItem(); } } + super(native); } setCheckState(state: CheckState): void { this.native.setCheckState(state); diff --git a/src/lib/QtWidgets/QStandardItemModel.ts b/src/lib/QtWidgets/QStandardItemModel.ts index b09db9406..27b000d80 100644 --- a/src/lib/QtWidgets/QStandardItemModel.ts +++ b/src/lib/QtWidgets/QStandardItemModel.ts @@ -1,17 +1,13 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { QStandardItem } from './QStandardItem'; export interface QStandardItemModelSignals extends QObjectSignals { itemChanged: (item: QStandardItem) => void; } -export class QStandardItemModel extends NodeObject { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); +export class QStandardItemModel extends QObject { constructor(parent?: NodeWidget) { let native; if (parent) { @@ -20,7 +16,6 @@ export class QStandardItemModel extends NodeObject { native = new addon.QStandardItemModel(); } super(native); - this.native = native; parent && parent.nodeChildren.add(this); } item(row: number, column = 0): QStandardItem | void { diff --git a/src/lib/QtWidgets/QStatusBar.ts b/src/lib/QtWidgets/QStatusBar.ts index d3571b45a..be36eb713 100644 --- a/src/lib/QtWidgets/QStatusBar.ts +++ b/src/lib/QtWidgets/QStatusBar.ts @@ -7,7 +7,7 @@ export interface QStatusBarSignals extends QWidgetSignals { } /** - + > Create and control progress bar widgets. * **This class is a JS wrapper around Qt's [QStatusBar class](https://doc.qt.io/qt-5/qstatusbar.html)** @@ -23,11 +23,9 @@ const progressBar = new QStatusBar(); ``` */ export class QStatusBar extends NodeWidget { - native: NativeElement; permanentWidgets: Set; widgets: Set; - constructor(); - constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { @@ -37,7 +35,6 @@ export class QStatusBar extends NodeWidget { } super(native); - this.native = native; this.setNodeParent(parent); this.permanentWidgets = new Set(); diff --git a/src/lib/QtWidgets/QSvgWidget.ts b/src/lib/QtWidgets/QSvgWidget.ts index 6ed0af1f3..acf5f258a 100644 --- a/src/lib/QtWidgets/QSvgWidget.ts +++ b/src/lib/QtWidgets/QSvgWidget.ts @@ -27,18 +27,16 @@ fs.readFile("icon.svg", (err, buffer) => { */ export class QSvgWidget extends NodeWidget { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QSvgWidget(parent.native); } else { native = new addon.QSvgWidget(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } load(file: string | Buffer): void { diff --git a/src/lib/QtWidgets/QSystemTrayIcon.ts b/src/lib/QtWidgets/QSystemTrayIcon.ts index 220027257..f9c5cf2ae 100644 --- a/src/lib/QtWidgets/QSystemTrayIcon.ts +++ b/src/lib/QtWidgets/QSystemTrayIcon.ts @@ -1,12 +1,11 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { QIcon } from '../QtGui/QIcon'; import { QMenu } from './QMenu'; -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; /** - + > Create and control system tray icon. * **This class is a JS wrapper around Qt's [QSystemTrayIcon class](https://doc.qt.io/qt-5/qsystemtrayicon.html)** @@ -28,11 +27,9 @@ tray.show(); global.tray = tray; // prevents garbage collection of tray ``` */ -export class QSystemTrayIcon extends NodeObject { - native: NativeElement; +export class QSystemTrayIcon extends QObject { contextMenu?: QMenu; - constructor(); - constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { @@ -41,7 +38,6 @@ export class QSystemTrayIcon extends NodeObject { native = new addon.QSystemTrayIcon(); } super(native); - this.native = native; } show(): void { this.native.show(); diff --git a/src/lib/QtWidgets/QTabBar.ts b/src/lib/QtWidgets/QTabBar.ts index d6862175e..797e68c38 100644 --- a/src/lib/QtWidgets/QTabBar.ts +++ b/src/lib/QtWidgets/QTabBar.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeWidget, QWidgetSignals } from './QWidget'; -import { NativeElement } from '../core/Component'; import { QIcon } from '../QtGui/QIcon'; import { TextElideMode } from '../QtEnums'; import { QSize } from '../QtCore/QSize'; @@ -27,9 +26,6 @@ const tabBar = new QTabBar(); ``` */ export class QTabBar extends NodeWidget { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -38,7 +34,6 @@ export class QTabBar extends NodeWidget { native = new addon.QTabBar(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setAutoHide(hide: boolean): void { diff --git a/src/lib/QtWidgets/QTabWidget.ts b/src/lib/QtWidgets/QTabWidget.ts index 2ddffe107..44ef10d1d 100644 --- a/src/lib/QtWidgets/QTabWidget.ts +++ b/src/lib/QtWidgets/QTabWidget.ts @@ -5,12 +5,12 @@ import { QIcon } from '../QtGui/QIcon'; import { TabPosition } from '../QtEnums'; /** - + > Create and control a stack of tabbed widgets. * **This class is a JS wrapper around Qt's [QTabWidget class](https://doc.qt.io/qt-5/qtabwidget.html)** -A 'QTabWidget' provides a tab bar and a "page area" that is used to display pages related to each tab. +A 'QTabWidget' provides a tab bar and a "page area" that is used to display pages related to each tab. ### Example @@ -25,12 +25,10 @@ tabWidget.addTab(new QCalendarWidget(), new QIcon(), 'Tab 2'); ``` */ export class QTabWidget extends NodeWidget { - native: NativeElement; tabs: NodeWidget[]; - constructor(); - constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QTabWidget(parent.native); } else { @@ -39,7 +37,6 @@ export class QTabWidget extends NodeWidget { super(native); this.setNodeParent(parent); this.tabs = []; - this.native = native; } addTab(page: NodeWidget, icon: QIcon, label: string): number { diff --git a/src/lib/QtWidgets/QTableView.ts b/src/lib/QtWidgets/QTableView.ts index d629903c1..8f80d4da4 100644 --- a/src/lib/QtWidgets/QTableView.ts +++ b/src/lib/QtWidgets/QTableView.ts @@ -1,6 +1,5 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { SortOrder, PenStyle } from '../QtEnums'; import { QAbstractItemView, QAbstractItemViewSignals } from './QAbstractItemView'; import { QHeaderView } from './QHeaderView'; @@ -179,9 +178,6 @@ export abstract class NodeTableView extends Q } export class QTableView extends NodeTableView { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -190,7 +186,6 @@ export class QTableView extends NodeTableView { native = new addon.QTableView(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QTableWidget.ts b/src/lib/QtWidgets/QTableWidget.ts index b6ff25d0f..546cbac9f 100644 --- a/src/lib/QtWidgets/QTableWidget.ts +++ b/src/lib/QtWidgets/QTableWidget.ts @@ -38,7 +38,6 @@ win.show(); ``` */ export class QTableWidget extends QAbstractScrollArea { - native: NativeElement; items: Set; constructor(rows: number, columns: number, parent?: NodeWidget) { let native; @@ -48,7 +47,6 @@ export class QTableWidget extends QAbstractScrollArea { native = new addon.QTableWidget(rows, columns); } super(native); - this.native = native; this.setNodeParent(parent); this.items = new Set(); } diff --git a/src/lib/QtWidgets/QTableWidgetItem.ts b/src/lib/QtWidgets/QTableWidgetItem.ts index 910a4b31a..79137ae49 100644 --- a/src/lib/QtWidgets/QTableWidgetItem.ts +++ b/src/lib/QtWidgets/QTableWidgetItem.ts @@ -41,13 +41,12 @@ win.show(); */ export class QTableWidgetItem extends Component { - native: NativeElement; constructor(); constructor(other: QTableWidgetItem); constructor(native: NativeElement); constructor(text: string); constructor(arg?: QTableWidgetItem | NativeElement | string) { - let native; + let native: NativeElement; if (typeof arg === 'string') { native = new addon.QTableWidgetItem(arg); } else if (checkIfNativeElement(arg)) { @@ -55,8 +54,7 @@ export class QTableWidgetItem extends Component { } else { native = new addon.QTableWidgetItem(); } - super(); - this.native = native; + super(native); } setBackground(brush: QBrush): void { this.native.setBackground(brush.native); diff --git a/src/lib/QtWidgets/QTextBrowser.ts b/src/lib/QtWidgets/QTextBrowser.ts index 35a10ae3e..906156c24 100644 --- a/src/lib/QtWidgets/QTextBrowser.ts +++ b/src/lib/QtWidgets/QTextBrowser.ts @@ -22,18 +22,16 @@ const textBrowser = new QTextBrowser(); */ export class QTextBrowser extends NodeTextEdit { - native: NativeElement; constructor(); constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QTextBrowser(parent.native); } else { native = new addon.QTextBrowser(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setOpenExternalLinks(open: boolean): void { diff --git a/src/lib/QtWidgets/QTextEdit.ts b/src/lib/QtWidgets/QTextEdit.ts index e014bdb51..f7e9d2a20 100644 --- a/src/lib/QtWidgets/QTextEdit.ts +++ b/src/lib/QtWidgets/QTextEdit.ts @@ -1,13 +1,12 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { QAbstractScrollArea, QAbstractScrollAreaSignals } from './QAbstractScrollArea'; import { AlignmentFlag, TextInteractionFlag } from '../QtEnums'; import { QFont } from '../QtGui/QFont'; import { QColor } from '../QtGui/QColor'; /** - + > Create and control editable text field. * **This class is a JS wrapper around Qt's [QTextEdit class](https://doc.qt.io/qt-5/qtextedit.html)** @@ -240,9 +239,6 @@ export enum WrapMode { } export class QTextEdit extends NodeTextEdit { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -251,7 +247,6 @@ export class QTextEdit extends NodeTextEdit { native = new addon.QTextEdit(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QTimeEdit.ts b/src/lib/QtWidgets/QTimeEdit.ts index 18d3c97a9..7b38d39d3 100644 --- a/src/lib/QtWidgets/QTimeEdit.ts +++ b/src/lib/QtWidgets/QTimeEdit.ts @@ -1,10 +1,9 @@ import addon from '../utils/addon'; import { NodeWidget } from './QWidget'; -import { NativeElement } from '../core/Component'; import { NodeDateTimeEdit } from './QDateTimeEdit'; /** - + > Creates a widget to edit dates with spin box layout. WIP! * **This class is a JS wrapper around Qt's [QTimeEdit class](https://doc.qt.io/qt-5/qtimeedit.html)** @@ -21,9 +20,6 @@ const timeEdit = new QTimeEdit(); ``` */ export class QTimeEdit extends NodeDateTimeEdit { - native: NativeElement; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -32,7 +28,6 @@ export class QTimeEdit extends NodeDateTimeEdit { native = new addon.QTimeEdit(); } super(native); - this.native = native; this.setNodeParent(parent); } } diff --git a/src/lib/QtWidgets/QToolButton.ts b/src/lib/QtWidgets/QToolButton.ts index 629f76fcd..3a8cf9729 100644 --- a/src/lib/QtWidgets/QToolButton.ts +++ b/src/lib/QtWidgets/QToolButton.ts @@ -9,7 +9,7 @@ import { QMenu } from './QMenu'; import { checkIfNativeElement, checkIfNapiExternal } from '../utils/helpers'; /** - + > Create and control buttons to use inside a QToolBar. * **This class is a JS wrapper around Qt's [QToolButton class](https://doc.qt.io/qt-5/qtoolbutton.html)** @@ -26,12 +26,9 @@ tool.setText('Help'); ``` */ export class QToolButton extends QAbstractButton { - native: NativeElement; private _defaultAction?: QAction | null; private _menu?: QMenu | null; - constructor(); - constructor(parent: NodeWidget); - constructor(rawPointer: NativeRawPointer, disableNativeDeletion?: boolean); + constructor(arg?: NodeWidget | NativeRawPointer | NativeElement, disableNativeDeletion = true) { let native; let parent: Component | undefined; @@ -47,7 +44,6 @@ export class QToolButton extends QAbstractButton { native = new addon.QToolButton(); } super(native); - this.native = native; parent && this.setNodeParent(parent); } setArrowType(type: ArrowType): void { diff --git a/src/lib/QtWidgets/QTreeWidget.ts b/src/lib/QtWidgets/QTreeWidget.ts index 4eb5e5d5a..1e60d70eb 100644 --- a/src/lib/QtWidgets/QTreeWidget.ts +++ b/src/lib/QtWidgets/QTreeWidget.ts @@ -6,8 +6,8 @@ import { QTreeWidgetItem } from './QTreeWidgetItem'; import { MatchFlag } from '../..'; /** - -> Creates a tree view that uses a predefined tree model. + +> Creates a tree view that uses a predefined tree model. * **This class is a JS wrapper around Qt's [QTreeWidget class](https://doc.qt.io/qt-5/qtreewidget.html)** @@ -49,11 +49,9 @@ win.show(); (global as any).win = win;``` */ export class QTreeWidget extends QAbstractScrollArea { - native: NativeElement; topLevelItems: Set; itemWidgets: Map; - constructor(); - constructor(parent: NodeWidget); + constructor(parent?: NodeWidget) { let native; if (parent) { @@ -62,7 +60,6 @@ export class QTreeWidget extends QAbstractScrollArea { native = new addon.QTreeWidget(); } super(native); - this.native = native; this.setNodeParent(parent); this.topLevelItems = new Set(); this.itemWidgets = new Map(); diff --git a/src/lib/QtWidgets/QTreeWidgetItem.ts b/src/lib/QtWidgets/QTreeWidgetItem.ts index a654951bd..c8e931c28 100644 --- a/src/lib/QtWidgets/QTreeWidgetItem.ts +++ b/src/lib/QtWidgets/QTreeWidgetItem.ts @@ -46,7 +46,6 @@ win.show(); ``` */ export class QTreeWidgetItem extends Component { - native: NativeElement; items: Set; constructor(); constructor(parent: QTreeWidgetItem, strings?: string[]); @@ -54,26 +53,31 @@ export class QTreeWidgetItem extends Component { constructor(native: NativeElement); constructor(strings: string[]); constructor(parent?: NativeElement | QTreeWidgetItem | QTreeWidget | string[], strings?: string[]) { - super(); - this.items = new Set(); + let native: NativeElement; + let parentTreeWidgetItem: QTreeWidgetItem | QTreeWidget = null; if (checkIfNativeElement(parent)) { - this.native = parent as NativeElement; + native = parent as NativeElement; } else { if (parent instanceof QTreeWidgetItem || parent instanceof QTreeWidget) { - this.setNodeParent(parent); const type = parent instanceof QTreeWidgetItem ? 'item' : 'tree'; + parentTreeWidgetItem = parent; if (strings) { - this.native = new addon.QTreeWidgetItem(parent.native, strings, type); + native = new addon.QTreeWidgetItem(parent.native, strings, type); } else { - this.native = new addon.QTreeWidgetItem(parent.native, type); + native = new addon.QTreeWidgetItem(parent.native, type); } } else if (Array.isArray(parent)) { const strings = parent; - this.native = new addon.QTreeWidgetItem(strings); + native = new addon.QTreeWidgetItem(strings); } else { - this.native = new addon.QTreeWidgetItem(); + native = new addon.QTreeWidgetItem(); } } + super(native); + this.items = new Set(); + if (parentTreeWidgetItem != null) { + this.setNodeParent(parentTreeWidgetItem); + } } setText(column: number, text: string): void { this.native.setText(column, text); diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index dc8126459..99f776552 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -679,7 +679,6 @@ view.setLayout(new FlexLayout()); ``` */ export class QWidget extends NodeWidget { - native: NativeElement; constructor(arg?: NodeWidget | NativeElement) { let native; let parent; @@ -693,6 +692,5 @@ export class QWidget extends NodeWidget { } super(native); this.setNodeParent(parent); - this.native = native; } } diff --git a/src/lib/core/Component.ts b/src/lib/core/Component.ts index d1ed5e52a..d5dbe5407 100644 --- a/src/lib/core/Component.ts +++ b/src/lib/core/Component.ts @@ -7,10 +7,10 @@ export type NativeRawPointer = Record; > Abstract class that is root most base class for all widgets and layouts in the NodeGui World. **This class is used to add core properties to all widgets, layouts etc in NodeGui world. - Currently it helps us maintain references to the native C++ instance of the widget or layout. + Currently it helps us maintain references to the native C++ instance of the widget or layout. It also helps in preventing gc of child elements of a layout or widget** -`Component` is an abstract class and hence no instances of the same should be created. +`Component` is an abstract class and hence no instances of the same should be created. It exists so that we can add core functionalities to all widgets and layouts easily. This is an internal class. Its the root base class in NodeGui world. @@ -20,12 +20,15 @@ Its the root base class in NodeGui world. export abstract class Component { nodeChildren: Set; nodeParent?: Component; - constructor() { + + native: NativeElement | null; + + constructor(native: NativeElement) { + this.native = native; this.nodeChildren = new Set(); } setNodeParent(parent?: Component): void { this.nodeParent = parent; parent?.nodeChildren.add(this); } - abstract native: NativeElement; } diff --git a/src/lib/core/EventWidget.ts b/src/lib/core/EventWidget.ts index b41950104..583a5e5aa 100644 --- a/src/lib/core/EventWidget.ts +++ b/src/lib/core/EventWidget.ts @@ -36,8 +36,9 @@ view.addEventListener(WidgetEventTypes.MouseMove, () => { export abstract class EventWidget extends Component { private emitter: EventEmitter; private _isEventProcessed = false; + constructor(native: NativeElement) { - super(); + super(native); if (native.initNodeEventEmitter == null) { throw new Error('initNodeEventEmitter not implemented on native side'); } diff --git a/src/lib/core/FlexLayout.ts b/src/lib/core/FlexLayout.ts index 6ed19989b..580221a99 100644 --- a/src/lib/core/FlexLayout.ts +++ b/src/lib/core/FlexLayout.ts @@ -2,12 +2,11 @@ import addon from '../utils/addon'; import { NodeWidget } from '../QtWidgets/QWidget'; import { NodeLayout, QLayoutSignals } from '../QtWidgets/QLayout'; import { FlexNode } from './YogaWidget'; -import { NativeElement } from './Component'; export type FlexLayoutSignals = QLayoutSignals; /** - + > Custom layout to help layout child widgets using flex layout. * **This class is a JS wrapper around custom Qt layout implemented using [Yoga](https://github.com/facebook/yoga)** @@ -33,11 +32,8 @@ layout.addWidget(label2); ``` */ export class FlexLayout extends NodeLayout { - native: NativeElement; protected flexNode?: FlexNode; - constructor(); - constructor(parent: NodeWidget); constructor(parent?: NodeWidget) { let native; if (parent) { @@ -46,7 +42,6 @@ export class FlexLayout extends NodeLayout { native = new addon.FlexLayout(); } super(native); - this.native = native; if (parent) { this.setFlexNode(parent.getFlexNode()); } diff --git a/src/lib/core/YogaWidget.ts b/src/lib/core/YogaWidget.ts index c3cb0fad2..f3123c160 100644 --- a/src/lib/core/YogaWidget.ts +++ b/src/lib/core/YogaWidget.ts @@ -1,10 +1,10 @@ -import { NodeObject, QObjectSignals } from '../QtCore/QObject'; +import { QObject, QObjectSignals } from '../QtCore/QObject'; import { NativeRawPointer } from './Component'; export type FlexNode = NativeRawPointer<'YGNodeRef'>; /** - + > Abstract class to add common functionality related to Flex layout to all Widgets. **This class implements methods related to flex layout required to be present in all widgets** @@ -22,7 +22,7 @@ const flexNode = view.getFlexNode(); YogaWidget helps in storing all flex properties of a widget. */ -export abstract class YogaWidget extends NodeObject { +export abstract class YogaWidget extends QObject { getFlexNode(): FlexNode { return this.native.getFlexNode(); } diff --git a/src/lib/core/__test__/CacheTestQObject.ts b/src/lib/core/__test__/CacheTestQObject.ts index 79e42305a..b3235bfa8 100644 --- a/src/lib/core/__test__/CacheTestQObject.ts +++ b/src/lib/core/__test__/CacheTestQObject.ts @@ -1,10 +1,9 @@ import addon from '../../utils/addon'; import { NativeElement } from '../Component'; -import { NodeObject, QObjectSignals } from '../../QtCore/QObject'; +import { QObject, QObjectSignals } from '../../QtCore/QObject'; import { wrapperCache } from '../../core/WrapperCache'; -export class CacheTestQObject extends NodeObject { - native: NativeElement; +export class CacheTestQObject extends QObject { constructor(arg?: NativeElement) { let native; if (native == null) { diff --git a/tsconfig.json b/tsconfig.json index 5d65b5e7a..dd79bd9a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "sourceMap": false, "outDir": "./dist", "strict": true, + "strictNullChecks": false, "moduleResolution": "node", "esModuleInterop": true, "resolveJsonModule": true diff --git a/website/docs/development/signal_and_event_handling.md b/website/docs/development/signal_and_event_handling.md index 93fe8e4ba..2cca815a9 100644 --- a/website/docs/development/signal_and_event_handling.md +++ b/website/docs/development/signal_and_event_handling.md @@ -64,9 +64,8 @@ export const QPushButtonEvents = Object.freeze({ }); export class QPushButton extends NodeWidget { - native: NativeElement; constructor(parent?: NodeWidget) { - let native; + let native: NativeElement; if (parent) { native = new addon.QPushButton(parent.native); } else { @@ -74,7 +73,6 @@ export class QPushButton extends NodeWidget { } super(native); this.parent = parent; - this.native = native; } setText(text: string | number) {