Co-authored-by: wuxiaofeng <wuxiaofeng@erayt.com>
This commit is contained in:
parent
8e574ba33d
commit
2359ca8838
@ -10,6 +10,7 @@
|
||||
#include "QtWidgets/QListWidget/nlistwidget.hpp"
|
||||
|
||||
class DLL_EXPORT QListWidgetWrap : public Napi::ObjectWrap<QListWidgetWrap> {
|
||||
QListView_WRAPPED_METHODS_DECLARATION
|
||||
private:
|
||||
QPointer<NListWidget> instance;
|
||||
|
||||
@ -42,6 +43,4 @@ class DLL_EXPORT QListWidgetWrap : public Napi::ObjectWrap<QListWidgetWrap> {
|
||||
Napi::Value visualItemRect(const Napi::CallbackInfo& info);
|
||||
Napi::Value clear(const Napi::CallbackInfo& info);
|
||||
Napi::Value scrollToItem(const Napi::CallbackInfo& info);
|
||||
|
||||
QListView_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
@ -10,6 +10,7 @@ class DLL_EXPORT QListWidgetItemWrap
|
||||
: public Napi::ObjectWrap<QListWidgetItemWrap> {
|
||||
private:
|
||||
QListWidgetItem* instance;
|
||||
bool disableDeletion;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
|
||||
@ -33,11 +33,17 @@ QModelIndexWrap::QModelIndexWrap(const Napi::CallbackInfo& info)
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<QModelIndex>();
|
||||
if (info.Length() > 0 && info[0].IsExternal()) {
|
||||
// --- if external ---
|
||||
this->instance = std::unique_ptr<QModelIndex>(
|
||||
info[0].As<Napi::External<QModelIndex>>().Data());
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<QModelIndex>();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
this->rawData = extrautils::configureComponent(this->getInternalInstance());
|
||||
}
|
||||
|
||||
@ -46,22 +46,36 @@ Napi::Object QListWidgetItemWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
QListWidgetItem* QListWidgetItemWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
QListWidgetItemWrap::~QListWidgetItemWrap() { delete this->instance; }
|
||||
|
||||
QListWidgetItemWrap::~QListWidgetItemWrap() {
|
||||
if (!this->disableDeletion) {
|
||||
delete this->instance;
|
||||
}
|
||||
}
|
||||
|
||||
QListWidgetItemWrap::QListWidgetItemWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QListWidgetItemWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 1) {
|
||||
QString text =
|
||||
QString::fromUtf8(info[0].As<Napi::String>().Utf8Value().c_str());
|
||||
this->instance = new QListWidgetItem(text);
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new QListWidgetItem();
|
||||
if (info.Length() > 0 && info[0].IsExternal()) {
|
||||
// --- if external ---
|
||||
this->instance = info[0].As<Napi::External<QListWidgetItem>>().Data();
|
||||
if (info.Length() == 2) {
|
||||
this->disableDeletion = info[1].As<Napi::Boolean>().Value();
|
||||
}
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
// --- regular cases ---
|
||||
if (info.Length() == 1) {
|
||||
QString text =
|
||||
QString::fromUtf8(info[0].As<Napi::String>().Utf8Value().c_str());
|
||||
this->instance = new QListWidgetItem(text);
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new QListWidgetItem();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
this->rawData = extrautils::configureComponent(this->getInternalInstance());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user