More methods for QAbstractItemModel

This commit is contained in:
Simon Edwards 2021-08-21 20:44:04 +02:00
parent 456824c504
commit 55217146ae
4 changed files with 309 additions and 14 deletions

View File

@ -160,4 +160,56 @@ class DLL_EXPORT NAbstractItemModel : public QAbstractItemModel,
QModelIndex* buddyIndex = buddyIndexWrap->getInternalInstance();
return *buddyIndex;
}
void _protected_beginResetModel() { beginResetModel(); }
void _protected_endResetModel() { endResetModel(); }
void _protected_beginInsertColumns(const QModelIndex& parent, int first,
int last) {
beginInsertColumns(parent, first, last);
}
void _protected_beginInsertRows(const QModelIndex& parent, int first,
int last) {
beginInsertRows(parent, first, last);
}
bool _protected_beginMoveColumns(const QModelIndex& sourceParent,
int sourceFirst, int sourceLast,
const QModelIndex& destinationParent,
int destinationChild) {
return beginMoveColumns(sourceParent, sourceFirst, sourceLast,
destinationParent, destinationChild);
}
bool _protected_beginMoveRows(const QModelIndex& sourceParent,
int sourceFirst, int sourceLast,
const QModelIndex& destinationParent,
int destinationChild) {
return beginMoveRows(sourceParent, sourceFirst, sourceLast,
destinationParent, destinationChild);
}
void _protected_beginRemoveColumns(const QModelIndex& parent, int first,
int last) {
beginRemoveColumns(parent, first, last);
}
void _protected_beginRemoveRows(const QModelIndex& parent, int first,
int last) {
beginRemoveRows(parent, first, last);
}
void _protected_endInsertColumns() { endInsertColumns(); }
void _protected_endInsertRows() { endInsertRows(); }
void _protected_endMoveColumns() { endMoveColumns(); }
void _protected_endMoveRows() { endMoveRows(); }
void _protected_endRemoveColumns() { endRemoveColumns(); }
void _protected_endRemoveRows() { endRemoveRows(); }
};

View File

@ -31,4 +31,18 @@ class DLL_EXPORT QAbstractItemModelWrap
Napi::Value emitDataChanged(const Napi::CallbackInfo& info);
Napi::Value checkIndex(const Napi::CallbackInfo& info);
Napi::Value _super_buddy(const Napi::CallbackInfo& info);
Napi::Value beginInsertColumns(const Napi::CallbackInfo& info);
Napi::Value beginInsertRows(const Napi::CallbackInfo& info);
Napi::Value beginMoveColumns(const Napi::CallbackInfo& info);
Napi::Value beginMoveRows(const Napi::CallbackInfo& info);
Napi::Value beginRemoveColumns(const Napi::CallbackInfo& info);
Napi::Value beginRemoveRows(const Napi::CallbackInfo& info);
Napi::Value beginResetModel(const Napi::CallbackInfo& info);
Napi::Value endResetModel(const Napi::CallbackInfo& info);
Napi::Value endInsertColumns(const Napi::CallbackInfo& info);
Napi::Value endInsertRows(const Napi::CallbackInfo& info);
Napi::Value endMoveColumns(const Napi::CallbackInfo& info);
Napi::Value endMoveRows(const Napi::CallbackInfo& info);
Napi::Value endRemoveColumns(const Napi::CallbackInfo& info);
Napi::Value endRemoveRows(const Napi::CallbackInfo& info);
};

View File

@ -19,6 +19,29 @@ Napi::Object QAbstractItemModelWrap::init(Napi::Env env, Napi::Object exports) {
&QAbstractItemModelWrap::emitDataChanged),
InstanceMethod("checkIndex", &QAbstractItemModelWrap::checkIndex),
InstanceMethod("_super_buddy", &QAbstractItemModelWrap::_super_buddy),
InstanceMethod("beginInsertColumns",
&QAbstractItemModelWrap::beginInsertColumns),
InstanceMethod("beginInsertRows",
&QAbstractItemModelWrap::beginInsertRows),
InstanceMethod("beginMoveColumns",
&QAbstractItemModelWrap::beginMoveColumns),
InstanceMethod("beginMoveRows", &QAbstractItemModelWrap::beginMoveRows),
InstanceMethod("beginRemoveColumns",
&QAbstractItemModelWrap::beginRemoveColumns),
InstanceMethod("beginRemoveRows",
&QAbstractItemModelWrap::beginRemoveRows),
InstanceMethod("beginResetModel",
&QAbstractItemModelWrap::beginResetModel),
InstanceMethod("endResetModel", &QAbstractItemModelWrap::endResetModel),
InstanceMethod("endInsertColumns",
&QAbstractItemModelWrap::endInsertColumns),
InstanceMethod("endInsertRows", &QAbstractItemModelWrap::endInsertRows),
InstanceMethod("endMoveColumns",
&QAbstractItemModelWrap::endMoveColumns),
InstanceMethod("endMoveRows", &QAbstractItemModelWrap::endMoveRows),
InstanceMethod("endRemoveColumns",
&QAbstractItemModelWrap::endRemoveColumns),
InstanceMethod("endRemoveRows", &QAbstractItemModelWrap::endRemoveRows),
QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QAbstractItemModelWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -147,3 +170,157 @@ Napi::Value QAbstractItemModelWrap::_super_buddy(
{Napi::External<QModelIndex>::New(env, new QModelIndex(resultIndex))});
return resultModelIndexWrap;
}
Napi::Value QAbstractItemModelWrap::beginInsertColumns(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* parentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* parent = parentWrap->getInternalInstance();
int first = info[1].As<Napi::Number>().Int32Value();
int last = info[2].As<Napi::Number>().Int32Value();
this->instance->_protected_beginInsertColumns(*parent, first, last);
return env.Null();
}
Napi::Value QAbstractItemModelWrap::beginInsertRows(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* parentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* parent = parentWrap->getInternalInstance();
int first = info[1].As<Napi::Number>().Int32Value();
int last = info[2].As<Napi::Number>().Int32Value();
this->instance->_protected_beginInsertRows(*parent, first, last);
return env.Null();
}
Napi::Value QAbstractItemModelWrap::beginMoveColumns(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* sourceParentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* sourceParent = sourceParentWrap->getInternalInstance();
int sourceFirst = info[1].As<Napi::Number>().Int32Value();
int sourceLast = info[2].As<Napi::Number>().Int32Value();
QModelIndexWrap* destinationParentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[3].As<Napi::Object>());
QModelIndex* destinationParent = destinationParentWrap->getInternalInstance();
int destinationChild = info[4].As<Napi::Number>().Int32Value();
bool result = this->instance->_protected_beginMoveColumns(
*sourceParent, sourceFirst, sourceLast, *destinationParent,
destinationChild);
return Napi::Boolean::New(env, result);
}
Napi::Value QAbstractItemModelWrap::beginMoveRows(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* sourceParentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* sourceParent = sourceParentWrap->getInternalInstance();
int sourceFirst = info[1].As<Napi::Number>().Int32Value();
int sourceLast = info[2].As<Napi::Number>().Int32Value();
QModelIndexWrap* destinationParentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[3].As<Napi::Object>());
QModelIndex* destinationParent = destinationParentWrap->getInternalInstance();
int destinationChild = info[4].As<Napi::Number>().Int32Value();
bool result = this->instance->_protected_beginMoveRows(
*sourceParent, sourceFirst, sourceLast, *destinationParent,
destinationChild);
return Napi::Boolean::New(env, result);
}
Napi::Value QAbstractItemModelWrap::beginRemoveColumns(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* parentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* parent = parentWrap->getInternalInstance();
int first = info[1].As<Napi::Number>().Int32Value();
int last = info[2].As<Napi::Number>().Int32Value();
this->instance->_protected_beginRemoveColumns(*parent, first, last);
return env.Null();
}
Napi::Value QAbstractItemModelWrap::beginRemoveRows(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
QModelIndexWrap* parentWrap =
Napi::ObjectWrap<QModelIndexWrap>::Unwrap(info[0].As<Napi::Object>());
QModelIndex* parent = parentWrap->getInternalInstance();
int first = info[1].As<Napi::Number>().Int32Value();
int last = info[2].As<Napi::Number>().Int32Value();
this->instance->_protected_beginRemoveRows(*parent, first, last);
return env.Null();
}
Napi::Value QAbstractItemModelWrap::beginResetModel(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_beginResetModel();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endInsertColumns(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endInsertColumns();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endInsertRows(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endInsertRows();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endMoveColumns(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endMoveColumns();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endMoveRows(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endMoveRows();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endRemoveColumns(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endRemoveColumns();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endRemoveRows(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endRemoveRows();
return env.Null();
}
Napi::Value QAbstractItemModelWrap::endResetModel(
const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->_protected_endResetModel();
return env.Null();
}

View File

@ -202,14 +202,45 @@ export class QAbstractItemModel extends NodeObject<any> {
// TODO: void layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint)
// *** Protected Functions ***
beginInsertColumns(parent: QModelIndex, first: number, last: number): void {
this.native.beginInsertColumns(parent, first, last);
}
// TODO: void beginInsertColumns(const QModelIndex &parent, int first, int last)
// TODO: void beginInsertRows(const QModelIndex &parent, int first, int last)
// TODO: bool beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
// TODO: bool beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
// TODO: void beginRemoveColumns(const QModelIndex &parent, int first, int last)
// TODO: void beginRemoveRows(const QModelIndex &parent, int first, int last)
// TODO: void beginResetModel()
beginInsertRows(parent: QModelIndex, first: number, last: number): void {
this.native.beginInsertRows(parent, first, last);
}
beginMoveColumns(
sourceParent: QModelIndex,
sourceFirst: number,
sourceLast: number,
destinationParent: QModelIndex,
destinationChild: number,
): boolean {
return this.native.beginMoveColumns(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
}
beginMoveRows(
sourceParent: QModelIndex,
sourceFirst: number,
sourceLast: number,
destinationParent: QModelIndex,
destinationChild: number,
): boolean {
return this.native.beginMoveRows(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild);
}
beginRemoveColumns(parent: QModelIndex, first: number, last: number): void {
this.native.beginRemoveColumns(parent, first, last);
}
beginRemoveRows(parent: QModelIndex, first: number, last: number): void {
this.native.beginRemoveRows(parent, first, last);
}
beginResetModel(): void {
this.native.beginResetModel();
}
// TODO: void changePersistentIndex(const QModelIndex &from, const QModelIndex &to)
// TODO: void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
@ -219,12 +250,33 @@ export class QAbstractItemModel extends NodeObject<any> {
}
// TODO: QModelIndex createIndex(int row, int column, quintptr id) const
// TODO: void endInsertColumns()
// TODO: void endInsertRows()
// TODO: void endMoveColumns()
// TODO: void endMoveRows()
// TODO: void endRemoveColumns()
// TODO: void endRemoveRows()
// TODO: void endResetModel()
endInsertColumns(): void {
this.native.endInsertColumns();
}
endInsertRows(): void {
this.native.endInsertRows();
}
endMoveColumns(): void {
this.native.endMoveColumns();
}
endMoveRows(): void {
this.native.endMoveRows();
}
endRemoveColumns(): void {
this.native.endRemoveColumns();
}
endRemoveRows(): void {
this.native.endRemoveRows();
}
endResetModel(): void {
this.native.endResetModel();
}
// TODO: QModelIndexList persistentIndexList() const
}