Add many methods to QSize and QSizeF

This commit is contained in:
Simon Edwards 2022-07-17 09:51:16 +02:00
parent f7c4d5dfae
commit abc1d2cf64
6 changed files with 265 additions and 19 deletions

View File

@ -19,9 +19,18 @@ class DLL_EXPORT QSizeWrap : public Napi::ObjectWrap<QSizeWrap> {
~QSizeWrap();
QSize* getInternalInstance();
// Wrapped methods
Napi::Value boundedTo(const Napi::CallbackInfo& info);
Napi::Value expandedTo(const Napi::CallbackInfo& info);
Napi::Value height(const Napi::CallbackInfo& info);
Napi::Value isEmpty(const Napi::CallbackInfo& info);
Napi::Value isNull(const Napi::CallbackInfo& info);
Napi::Value isValid(const Napi::CallbackInfo& info);
Napi::Value scale(const Napi::CallbackInfo& info);
Napi::Value scaled(const Napi::CallbackInfo& info);
Napi::Value setHeight(const Napi::CallbackInfo& info);
Napi::Value setWidth(const Napi::CallbackInfo& info);
Napi::Value height(const Napi::CallbackInfo& info);
Napi::Value transpose(const Napi::CallbackInfo& info);
Napi::Value transposed(const Napi::CallbackInfo& info);
Napi::Value width(const Napi::CallbackInfo& info);
};

View File

@ -19,9 +19,19 @@ class DLL_EXPORT QSizeFWrap : public Napi::ObjectWrap<QSizeFWrap> {
~QSizeFWrap();
QSizeF* getInternalInstance();
// Wrapped methods
Napi::Value boundedTo(const Napi::CallbackInfo& info);
Napi::Value expandedTo(const Napi::CallbackInfo& info);
Napi::Value height(const Napi::CallbackInfo& info);
Napi::Value isEmpty(const Napi::CallbackInfo& info);
Napi::Value isNull(const Napi::CallbackInfo& info);
Napi::Value isValid(const Napi::CallbackInfo& info);
Napi::Value scale(const Napi::CallbackInfo& info);
Napi::Value scaled(const Napi::CallbackInfo& info);
Napi::Value setHeight(const Napi::CallbackInfo& info);
Napi::Value setWidth(const Napi::CallbackInfo& info);
Napi::Value height(const Napi::CallbackInfo& info);
Napi::Value toSize(const Napi::CallbackInfo& info);
Napi::Value transpose(const Napi::CallbackInfo& info);
Napi::Value transposed(const Napi::CallbackInfo& info);
Napi::Value width(const Napi::CallbackInfo& info);
};

View File

@ -10,9 +10,18 @@ Napi::Object QSizeWrap::init(Napi::Env env, Napi::Object exports) {
char CLASSNAME[] = "QSize";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("setHeight", &QSizeWrap::setHeight),
InstanceMethod("setWidth", &QSizeWrap::setWidth),
{InstanceMethod("boundedTo", &QSizeWrap::boundedTo),
InstanceMethod("expandedTo", &QSizeWrap::expandedTo),
InstanceMethod("isEmpty", &QSizeWrap::isEmpty),
InstanceMethod("isNull", &QSizeWrap::isNull),
InstanceMethod("isValid", &QSizeWrap::isValid),
InstanceMethod("height", &QSizeWrap::height),
InstanceMethod("scale", &QSizeWrap::scale),
InstanceMethod("scaled", &QSizeWrap::scaled),
InstanceMethod("setHeight", &QSizeWrap::setHeight),
InstanceMethod("setWidth", &QSizeWrap::setWidth),
InstanceMethod("transpose", &QSizeWrap::transpose),
InstanceMethod("transposed", &QSizeWrap::transposed),
InstanceMethod("width", &QSizeWrap::width),
StaticMethod("fromQVariant", &StaticQSizeWrapMethods::fromQVariant),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QSizeWrap)});
@ -64,7 +73,6 @@ Napi::Value QSizeWrap::width(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::Value::From(env, this->instance->width());
}
Napi::Value StaticQSizeWrapMethods::fromQVariant(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
@ -77,3 +85,70 @@ Napi::Value StaticQSizeWrapMethods::fromQVariant(
env, new QSize(size.width(), size.height()))});
return instance;
}
Napi::Value QSizeWrap::boundedTo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeWrap* otherSizeWrap =
Napi::ObjectWrap<QSizeWrap>::Unwrap(info[0].As<Napi::Object>());
QSize* otherSize = otherSizeWrap->getInternalInstance();
QSize result = this->instance->boundedTo(*otherSize);
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeWrap::expandedTo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeWrap* otherSizeWrap =
Napi::ObjectWrap<QSizeWrap>::Unwrap(info[0].As<Napi::Object>());
QSize* otherSize = otherSizeWrap->getInternalInstance();
QSize result = this->instance->expandedTo(*otherSize);
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeWrap::isEmpty(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isEmpty();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeWrap::isNull(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isNull();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeWrap::isValid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isValid();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeWrap::scale(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int width = info[0].As<Napi::Number>().Int32Value();
int height = info[1].As<Napi::Number>().Int32Value();
Qt::AspectRatioMode mode =
static_cast<Qt::AspectRatioMode>(info[2].As<Napi::Number>().Int32Value());
this->instance->scale(width, height, mode);
return env.Null();
}
Napi::Value QSizeWrap::scaled(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int width = info[0].As<Napi::Number>().Int32Value();
int height = info[1].As<Napi::Number>().Int32Value();
Qt::AspectRatioMode mode =
static_cast<Qt::AspectRatioMode>(info[2].As<Napi::Number>().Int32Value());
QSize result = this->instance->scaled(width, height, mode);
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeWrap::transpose(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
this->instance->transpose();
return env.Null();
}
Napi::Value QSizeWrap::transposed(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSize result = this->instance->transposed();
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}

View File

@ -1,6 +1,7 @@
#include "QtCore/QSizeF/qsizef_wrap.h"
#include "Extras/Utils/nutils.h"
#include "QtCore/QSize/qsize_wrap.h"
#include "QtCore/QVariant/qvariant_wrap.h"
Napi::FunctionReference QSizeFWrap::constructor;
@ -10,9 +11,19 @@ Napi::Object QSizeFWrap::init(Napi::Env env, Napi::Object exports) {
char CLASSNAME[] = "QSizeF";
Napi::Function func = DefineClass(
env, CLASSNAME,
{InstanceMethod("setHeight", &QSizeFWrap::setHeight),
InstanceMethod("setWidth", &QSizeFWrap::setWidth),
{InstanceMethod("boundedTo", &QSizeFWrap::boundedTo),
InstanceMethod("expandedTo", &QSizeFWrap::expandedTo),
InstanceMethod("height", &QSizeFWrap::height),
InstanceMethod("isEmpty", &QSizeFWrap::isEmpty),
InstanceMethod("isNull", &QSizeFWrap::isNull),
InstanceMethod("isValid", &QSizeFWrap::isValid),
InstanceMethod("scale", &QSizeFWrap::scale),
InstanceMethod("scaled", &QSizeFWrap::scaled),
InstanceMethod("setHeight", &QSizeFWrap::setHeight),
InstanceMethod("setWidth", &QSizeFWrap::setWidth),
InstanceMethod("toSize", &QSizeFWrap::toSize),
InstanceMethod("transpose", &QSizeFWrap::transpose),
InstanceMethod("transposed", &QSizeFWrap::transposed),
InstanceMethod("width", &QSizeFWrap::width),
StaticMethod("fromQVariant", &StaticQSizeFWrapMethods::fromQVariant),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QSizeFWrap)});
@ -77,3 +88,84 @@ Napi::Value StaticQSizeFWrapMethods::fromQVariant(
env, new QSizeF(size.width(), size.height()))});
return instance;
}
Napi::Value QSizeFWrap::boundedTo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeFWrap* otherSizeWrap =
Napi::ObjectWrap<QSizeFWrap>::Unwrap(info[0].As<Napi::Object>());
QSizeF* otherSize = otherSizeWrap->getInternalInstance();
QSizeF result = this->instance->boundedTo(*otherSize);
auto resultInstance = QSizeFWrap::constructor.New(
{Napi::External<QSizeF>::New(env, new QSizeF(result))});
return resultInstance;
}
Napi::Value QSizeFWrap::expandedTo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeFWrap* otherSizeWrap =
Napi::ObjectWrap<QSizeFWrap>::Unwrap(info[0].As<Napi::Object>());
QSizeF* otherSize = otherSizeWrap->getInternalInstance();
QSizeF result = this->instance->expandedTo(*otherSize);
auto resultInstance = QSizeFWrap::constructor.New(
{Napi::External<QSizeF>::New(env, new QSizeF(result))});
return resultInstance;
}
Napi::Value QSizeFWrap::isEmpty(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isEmpty();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeFWrap::isNull(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isNull();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeFWrap::isValid(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
bool result = this->instance->isValid();
return Napi::Boolean::New(env, result);
}
Napi::Value QSizeFWrap::scale(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
qreal width = info[0].As<Napi::Number>().FloatValue();
qreal height = info[1].As<Napi::Number>().FloatValue();
Qt::AspectRatioMode mode =
static_cast<Qt::AspectRatioMode>(info[2].As<Napi::Number>().Int32Value());
this->instance->scale(width, height, mode);
return env.Null();
}
Napi::Value QSizeFWrap::scaled(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
qreal width = info[0].As<Napi::Number>().FloatValue();
qreal height = info[1].As<Napi::Number>().FloatValue();
Qt::AspectRatioMode mode =
static_cast<Qt::AspectRatioMode>(info[2].As<Napi::Number>().Int32Value());
QSizeF result = this->instance->scaled(width, height, mode);
auto resultInstance = QSizeFWrap::constructor.New(
{Napi::External<QSizeF>::New(env, new QSizeF(result))});
return resultInstance;
}
Napi::Value QSizeFWrap::toSize(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSize result = this->instance->toSize();
auto resultInstance = QSizeWrap::constructor.New(
{Napi::External<QSize>::New(env, new QSize(result))});
return resultInstance;
}
Napi::Value QSizeFWrap::transpose(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
this->instance->transpose();
return env.Null();
}
Napi::Value QSizeFWrap::transposed(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
QSizeF result = this->instance->transposed();
auto resultInstance = QSizeFWrap::constructor.New(
{Napi::External<QSizeF>::New(env, new QSizeF(result))});
return resultInstance;
}

View File

@ -1,4 +1,5 @@
import { NativeElement, Component } from '../core/Component';
import { AspectRatioMode } from '../QtEnums';
import addon from '../utils/addon';
import { checkIfNativeElement } from '../utils/helpers';
import { QVariant } from './QVariant';
@ -17,17 +18,44 @@ export class QSize extends Component {
}
super(native);
}
setWidth(width: number): void {
return this.native.setWidth(width);
boundedTo(otherSize: QSize): QSize {
return new QSize(this.native.boundedTo(otherSize));
}
width(): number {
return this.native.width();
expandedTo(otherSize: QSize): QSize {
return new QSize(this.native.expandedTo(otherSize));
}
height(): number {
return this.native.height();
}
isEmpty(): boolean {
return this.native.isEmpty();
}
isNull(): boolean {
return this.native.isNull();
}
isValid(): boolean {
return this.native.isValid();
}
scale(width: number, height: number, mode: AspectRatioMode): void {
this.native.scale(width, height, mode);
}
scaled(width: number, height: number, mode: AspectRatioMode): QSize {
return new QSize(this.native.scaled(width, height, mode));
}
setHeight(height: number): void {
return this.native.setHeight(height);
}
height(): number {
return this.native.height();
setWidth(width: number): void {
return this.native.setWidth(width);
}
transpose(): void {
this.native.transpose();
}
transposed(): QSize {
return new QSize(this.native.transposed());
}
width(): number {
return this.native.width();
}
static fromQVariant(variant: QVariant): QSize {
return new QSize(addon.QSize.fromQVariant(variant.native));

View File

@ -1,6 +1,8 @@
import { NativeElement, Component } from '../core/Component';
import { AspectRatioMode } from '../QtEnums';
import addon from '../utils/addon';
import { checkIfNativeElement } from '../utils/helpers';
import { QSize } from './QSize';
import { QVariant } from './QVariant';
export class QSizeF extends Component {
@ -15,17 +17,47 @@ export class QSizeF extends Component {
}
super(native);
}
setWidth(width: number): void {
return this.native.setWidth(width);
boundedTo(otherSize: QSizeF): QSizeF {
return new QSizeF(this.native.boundedTo(otherSize));
}
width(): number {
return this.native.width();
expandedTo(otherSize: QSizeF): QSizeF {
return new QSizeF(this.native.expandedTo(otherSize));
}
height(): number {
return this.native.height();
}
isEmpty(): boolean {
return this.native.isEmpty();
}
isNull(): boolean {
return this.native.isNull();
}
isValid(): boolean {
return this.native.isValid();
}
scale(width: number, height: number, mode: AspectRatioMode): void {
this.native.scale(width, height, mode);
}
scaled(width: number, height: number, mode: AspectRatioMode): QSizeF {
return new QSizeF(this.native.scaled(width, height, mode));
}
setHeight(height: number): void {
return this.native.setHeight(height);
}
height(): number {
return this.native.height();
setWidth(width: number): void {
return this.native.setWidth(width);
}
toSize(): QSize {
return new QSize(this.native.toSize());
}
transpose(): void {
this.native.transpose();
}
transposed(): QSizeF {
return new QSizeF(this.native.transposed());
}
width(): number {
return this.native.width();
}
static fromQVariant(variant: QVariant): QSizeF {
return new QSizeF(addon.QSizeF.fromQVariant(variant.native));