/* Copyright (C) 2019 Filippo Cucchetto. Contact: https://github.com/filcuc/dotherside This file is part of the DOtherSide library. The DOtherSide library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your opinion) any later version. The DOtherSide library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the DOtherSide library. If not, see . */ #include "DOtherSide/DosQAbstractItemModel.h" #include "DOtherSide/DosQObjectImpl.h" namespace { template DOS::DosQObjectImpl::ParentMetaCall createParentMetaCall(DOS::DosQAbstractGenericModel *parent) { return [parent](QMetaObject::Call callType, int index, void **args)->int { return parent->T::qt_metacall(callType, index, args); }; } } namespace DOS { template DosQAbstractGenericModel::DosQAbstractGenericModel(void *modelObject, DosIQMetaObjectPtr metaObject, DObjectCallback dObjectCallback, DosQAbstractItemModelCallbacks callbacks) : m_impl(new DosQObjectImpl(::createParentMetaCall(this), std::move(metaObject), modelObject, dObjectCallback)) , m_modelObject(modelObject) , m_callbacks(callbacks) {} template bool DosQAbstractGenericModel::emitSignal(QObject *emitter, const QString &name, const std::vector &argumentsValues) { Q_ASSERT(m_impl); return m_impl->emitSignal(emitter, name, argumentsValues); } template const QMetaObject *DosQAbstractGenericModel::metaObject() const { Q_ASSERT(m_impl); return m_impl->metaObject(); } template int DosQAbstractGenericModel::qt_metacall(QMetaObject::Call call, int index, void **args) { Q_ASSERT(m_impl); return m_impl->qt_metacall(call, index, args); } template int DosQAbstractGenericModel::rowCount(const QModelIndex &parent) const { int result; m_callbacks.rowCount(m_modelObject, &parent, &result); return result; } template int DosQAbstractGenericModel::columnCount(const QModelIndex &parent) const { int result; m_callbacks.columnCount(m_modelObject, &parent, &result); return result; } template QVariant DosQAbstractGenericModel::data(const QModelIndex &index, int role) const { QVariant result; m_callbacks.data(m_modelObject, &index, role, &result); return result; } template bool DosQAbstractGenericModel::setData(const QModelIndex &index, const QVariant &value, int role) { bool result = false; m_callbacks.setData(m_modelObject, &index, &value, role, &result); return result; } template Qt::ItemFlags DosQAbstractGenericModel::flags(const QModelIndex &index) const { int result; m_callbacks.flags(m_modelObject, &index, &result); return Qt::ItemFlags(result); } template QVariant DosQAbstractGenericModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant result; m_callbacks.headerData(m_modelObject, section, orientation, role, &result); return result; } template QModelIndex DosQAbstractGenericModel::index(int row, int column, const QModelIndex &parent) const { QModelIndex result; m_callbacks.index(m_modelObject, row, column, &parent, &result); return result; } template QModelIndex DosQAbstractGenericModel::parent(const QModelIndex &child) const { QModelIndex result; m_callbacks.parent(m_modelObject, &child, &result); return result; } template void *DosQAbstractGenericModel::modelObject() { return m_modelObject; } template QHash DosQAbstractGenericModel::roleNames() const { QHash result; m_callbacks.roleNames(m_modelObject, &result); return result; } template void DosQAbstractGenericModel::publicBeginInsertColumns(const QModelIndex &index, int first, int last) { T::beginInsertColumns(index, first, last); } template void DosQAbstractGenericModel::publicEndInsertColumns() { T::endInsertColumns(); } template void DosQAbstractGenericModel::publicBeginRemoveColumns(const QModelIndex &index, int first, int last) { T::beginRemoveColumns(index, first, last); } template void DosQAbstractGenericModel::publicEndRemoveColumns() { T::endRemoveColumns(); } template void DosQAbstractGenericModel::publicBeginInsertRows(const QModelIndex &index, int first, int last) { T::beginInsertRows(index, first, last); } template void DosQAbstractGenericModel::publicEndInsertRows() { T::endInsertRows(); } template void DosQAbstractGenericModel::publicBeginRemoveRows(const QModelIndex &index, int first, int last) { T::beginRemoveRows(index, first, last); } template void DosQAbstractGenericModel::publicEndRemoveRows() { T::endRemoveRows(); } template void DosQAbstractGenericModel::publicBeginMoveRows(const QModelIndex& sourceParent, int sourceFirst, int sourceLast, const QModelIndex& destinationParent, int destinationChild) { T::beginMoveRows(sourceParent, sourceFirst, sourceLast, destinationParent, destinationChild); } template void DosQAbstractGenericModel::publicEndMoveRows() { T::endMoveRows(); } template void DosQAbstractGenericModel::publicBeginResetModel() { T::beginResetModel(); } template void DosQAbstractGenericModel::publicEndResetModel() { T::endResetModel(); } template void DosQAbstractGenericModel::publicDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { emit T::dataChanged(topLeft, bottomRight, roles); } template QModelIndex DosQAbstractGenericModel::publicCreateIndex(int row, int column, void *data) const { return T::createIndex(row, column, data); } template Qt::ItemFlags DosQAbstractGenericModel::defaultFlags(const QModelIndex &index) const { return T::flags(index); } template QVariant DosQAbstractGenericModel::defaultHeaderData(int section, Qt::Orientation orientation, int role) const { return T::headerData(section, orientation, role); } template QHash DosQAbstractGenericModel::defaultRoleNames() const { return T::roleNames(); } template bool DosQAbstractGenericModel::defaultSetData(const QModelIndex &index, const QVariant &value, int role) { return T::setData(index, value, role); } template bool DosQAbstractGenericModel::hasChildren(const QModelIndex &parent) const { bool result = false; m_callbacks.hasChildren(m_modelObject, &parent, &result); return result; } template bool DosQAbstractGenericModel::hasIndex(int row, int column, const QModelIndex &parent) const { return T::hasIndex(row, column, parent); } template bool DosQAbstractGenericModel::canFetchMore(const QModelIndex &parent) const { bool result = false; m_callbacks.canFetchMore(m_modelObject, &parent, &result); return result; } template bool DosQAbstractGenericModel::defaultCanFetchMore(const QModelIndex &parent) const { return this->T::canFetchMore(parent); } template void DosQAbstractGenericModel::fetchMore(const QModelIndex &parent) { m_callbacks.fetchMore(m_modelObject, &parent); } template void DosQAbstractGenericModel::defaultFetchMore(const QModelIndex &parent) { this->T::fetchMore(parent); } QModelIndex DosQAbstractListModel::defaultIndex(int row, int column, const QModelIndex &parent) const { return QAbstractListModel::index(row, column, parent); } int DosQAbstractListModel::defaultColumnCount(const QModelIndex &parent) const { return parent.isValid() ? 0 : 1; } bool DosQAbstractListModel::defaultHasChildren(const QModelIndex &parent) const { return parent.isValid() ? false : (rowCount() > 0); } QModelIndex DosQAbstractListModel::defaultParent(const QModelIndex & /*child*/) const { return QModelIndex(); } QModelIndex DosQAbstractTableModel::defaultIndex(int row, int column, const QModelIndex &parent) const { return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex(); } bool DosQAbstractTableModel::defaultHasChildren(const QModelIndex &parent) const { if (parent.model() == this || !parent.isValid()) return rowCount(parent) > 0 && columnCount(parent) > 0; return false; } QModelIndex DosQAbstractTableModel::defaultParent(const QModelIndex & /*child*/) const { return QModelIndex(); } bool DosQAbstractItemModel::defaultHasChildren(const QModelIndex &parent) const { return QAbstractItemModel::hasChildren(parent); } } // namespace DOS // Force instantiation template class DOS::DosQAbstractGenericModel; template class DOS::DosQAbstractGenericModel; template class DOS::DosQAbstractGenericModel;