Fixed wrong signal emittion in QAbstractListModelWrapper
This commit is contained in:
parent
e7dfc7c8b0
commit
bcbe9e5315
|
@ -19,6 +19,7 @@ set(HEADERS_LIST
|
|||
include/DOtherSide/DOtherSide.h
|
||||
include/DOtherSide/DosQDeclarative.h
|
||||
include/DOtherSide/DosQObjectWrapper.h
|
||||
include/DOtherSide/DosQAbstractListModelWrapper.h
|
||||
include/DOtherSide/DosQObject.h
|
||||
include/DOtherSide/DosQObjectImpl.h
|
||||
include/DOtherSide/DosIQObjectImpl.h
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
// Qt
|
||||
#include <QtCore/QModelIndex>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QVector>
|
||||
// DOtherSide
|
||||
#include "DOtherSide/DosIQObjectImpl.h"
|
||||
|
||||
namespace DOS {
|
||||
|
||||
class DosIQAbstractListModelImpl : public DosIQObjectImpl
|
||||
{
|
||||
public:
|
||||
/// Destructor
|
||||
virtual ~DosIQAbstractListModelImpl() = default;
|
||||
|
||||
/// @see QAbstractListModel::rowCount
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
|
||||
|
||||
/// @see QAbstractListModel::columnCount
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
|
||||
|
||||
/// @see QAbstractListModel::data
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
|
||||
|
||||
/// @see QAbstractListModel::setData
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) = 0;
|
||||
|
||||
/// @see QAbstractListModel::flags
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const = 0;
|
||||
|
||||
/// @see QAbstractListModel::headerData
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const = 0;
|
||||
|
||||
/// @see QAbstractListModel::roleNames
|
||||
virtual QHash<int, QByteArray> roleNames() const = 0;
|
||||
|
||||
/// @see QAbstractListModel::beginInsertRows
|
||||
virtual void publicBeginInsertRows(const QModelIndex &index, int first, int last) = 0;
|
||||
|
||||
/// @see QAbstractListModel::endInsertRows
|
||||
virtual void publicEndInsertRows() = 0;
|
||||
|
||||
/// @see QAbstractListModel::beginRemoveRows
|
||||
virtual void publicBeginRemoveRows(const QModelIndex &index, int first, int last) = 0;
|
||||
|
||||
/// @see QAbstractListModel::endRemoveRows
|
||||
virtual void publicEndRemoveRows() = 0;
|
||||
|
||||
/// @see QAbstractListModel::beginResetModel
|
||||
virtual void publicBeginResetModel() = 0;
|
||||
|
||||
/// @see QAbstractListModel::endResetModel
|
||||
virtual void publicEndResetModel() = 0;
|
||||
|
||||
/// @see QAbstractListModel::dataChanged
|
||||
virtual void publicDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) = 0;
|
||||
|
||||
};
|
||||
} // namespace dos
|
|
@ -1,6 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "private/qobject_p.h"
|
||||
// std
|
||||
#include <vector>
|
||||
// Qt
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QMetaObject>
|
||||
|
||||
namespace DOS {
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
#include <QAbstractListModel>
|
||||
// DOtherSide
|
||||
#include "DOtherSide/DOtherSideTypes.h"
|
||||
#include "DOtherSide/DosIQObjectImpl.h"
|
||||
#include "DOtherSide/DosIQAbstractListModelImpl.h"
|
||||
#include "DOtherSide/OnSlotExecutedHandler.h"
|
||||
|
||||
namespace DOS {
|
||||
|
||||
class DosQAbstractListModel : public QAbstractListModel, public DosIQObjectImpl
|
||||
class DosQAbstractListModel : public QAbstractListModel, public DosIQAbstractListModelImpl
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
|
@ -58,28 +58,27 @@ public:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
/// Expose beginInsertRows
|
||||
void publicBeginInsertRows(const QModelIndex &index, int first, int last);
|
||||
void publicBeginInsertRows(const QModelIndex &index, int first, int last) override;
|
||||
|
||||
/// Expose endInsertRows
|
||||
void publicEndInsertRows();
|
||||
void publicEndInsertRows() override;
|
||||
|
||||
/// Expose beginRemoveRows
|
||||
void publicBeginRemoveRows(const QModelIndex &index, int first, int last);
|
||||
void publicBeginRemoveRows(const QModelIndex &index, int first, int last) override;
|
||||
|
||||
/// Expose endInsertRows
|
||||
void publicEndRemoveRows();
|
||||
void publicEndRemoveRows() override;
|
||||
|
||||
/// Expose beginResetModel
|
||||
void publicBeginResetModel();
|
||||
void publicBeginResetModel() override;
|
||||
|
||||
/// Expose endResetModel
|
||||
void publicEndResetModel();
|
||||
void publicEndResetModel() override;
|
||||
|
||||
/// Expose dataChanged
|
||||
void publicDataChanged(const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles = QVector<int>());
|
||||
|
||||
const QVector<int> &roles = QVector<int>()) override;
|
||||
private:
|
||||
std::unique_ptr<DosIQObjectImpl> m_impl;
|
||||
void *m_modelObject;
|
||||
|
|
|
@ -0,0 +1,371 @@
|
|||
#pragma once
|
||||
|
||||
#include "DOtherSide/DosQAbstractListModel.h"
|
||||
#include "DOtherSide/DosQMetaObject.h"
|
||||
|
||||
namespace DOS {
|
||||
template <int, int>
|
||||
class DosQAbstractListModelWrapper : public QAbstractListModel, public DosIQAbstractListModelImpl
|
||||
{
|
||||
public:
|
||||
static const QMetaObject staticMetaObject;
|
||||
|
||||
/// Constructor
|
||||
DosQAbstractListModelWrapper(QObject *parent = nullptr);
|
||||
|
||||
/// Destructor
|
||||
~DosQAbstractListModelWrapper();
|
||||
|
||||
/// @see DosIQObjectImpl::metaObject
|
||||
const QMetaObject *metaObject() const override;
|
||||
|
||||
/// @see DosIQObjectImpl::qt_metacall
|
||||
int qt_metacall(QMetaObject::Call, int, void **) override;
|
||||
|
||||
/// @see DosIQObjectImpl::emitSignal
|
||||
bool emitSignal(QObject* emitter, const QString &name, const std::vector<QVariant> &argumentsValues);
|
||||
|
||||
/// Return the qml registration type
|
||||
static const QmlRegisterType &qmlRegisterType();
|
||||
|
||||
/// Sets the qml registration type
|
||||
static void setQmlRegisterType(QmlRegisterType data);
|
||||
|
||||
/// Sets the static metaobject
|
||||
static void setStaticMetaObject(const QMetaObject &metaObject);
|
||||
|
||||
/// Sets the qmlRegisterType id
|
||||
static void setId(int id);
|
||||
|
||||
/// @see QAbstractListModel::rowCount
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
/// @see QAbstractListModel::columnCount
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
/// @see QAbstractListModel::data
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
/// @see QAbstractListModel::setData
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
/// @see QAbstractListModel::flags
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
/// @see QAbstractListModel::headerData
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
/// @see QAbstractListModel::roleNames
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicBeginInsertRows
|
||||
void publicBeginInsertRows(const QModelIndex &index, int first, int last) override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicEndInsertRows
|
||||
void publicEndInsertRows() override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicBeginRemoveRows
|
||||
void publicBeginRemoveRows(const QModelIndex &index, int first, int last) override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicEndRemoveRows
|
||||
void publicEndRemoveRows() override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicBeginResetModel
|
||||
void publicBeginResetModel() override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicEndResetModel
|
||||
void publicEndResetModel() override;
|
||||
|
||||
/// @see DosIQAbstractListModelImpl::publicDataChanged
|
||||
void publicDataChanged(const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QVector<int> &roles = QVector<int>()) override;
|
||||
|
||||
private:
|
||||
void *m_dObject;
|
||||
DosQAbstractListModel *m_impl;
|
||||
static int m_id;
|
||||
static QmlRegisterType m_data;
|
||||
};
|
||||
|
||||
template<int N, int M>
|
||||
const QMetaObject DosQAbstractListModelWrapper<N, M>::staticMetaObject = QAbstractListModel::staticMetaObject;
|
||||
|
||||
template<int N, int M>
|
||||
QmlRegisterType DosQAbstractListModelWrapper<N, M>::m_data;
|
||||
|
||||
template<int N, int M>
|
||||
int DosQAbstractListModelWrapper<N, M>::m_id = -1;
|
||||
|
||||
template<int N, int M>
|
||||
DosQAbstractListModelWrapper<N, M>::DosQAbstractListModelWrapper(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
, m_dObject(nullptr)
|
||||
, m_impl(nullptr)
|
||||
{
|
||||
void *impl = nullptr;
|
||||
m_data.createDObject(m_id, static_cast<QObject*>(this), &m_dObject, &impl);
|
||||
beginResetModel();
|
||||
m_impl = dynamic_cast<DosQAbstractListModel *>(static_cast<QObject*>(impl));
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::rowsAboutToBeInserted, this, &DosQAbstractListModelWrapper::beginInsertRows);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::rowsInserted, this, &DosQAbstractListModelWrapper::endInsertRows);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::rowsAboutToBeRemoved, this, &DosQAbstractListModelWrapper::beginRemoveRows);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::rowsRemoved, this, &DosQAbstractListModelWrapper::endRemoveRows);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::rowsAboutToBeMoved, this, &DosQAbstractListModelWrapper::beginMoveRows);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::rowsMoved, this, &DosQAbstractListModelWrapper::endMoveRows);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::columnsAboutToBeInserted, this, &DosQAbstractListModelWrapper::beginInsertColumns);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::columnsInserted, this, &DosQAbstractListModelWrapper::endInsertColumns);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::columnsAboutToBeRemoved, this, &DosQAbstractListModelWrapper::beginRemoveColumns);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::columnsRemoved, this, &DosQAbstractListModelWrapper::endRemoveColumns);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::columnsAboutToBeMoved, this, &DosQAbstractListModelWrapper::beginMoveColumns);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::columnsMoved, this, &DosQAbstractListModelWrapper::endMoveColumns);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::modelAboutToBeReset, this, &DosQAbstractListModelWrapper::beginResetModel);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::modelReset, this, &DosQAbstractListModelWrapper::endResetModel);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::dataChanged, this, &DosQAbstractListModelWrapper::dataChanged);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::layoutAboutToBeChanged, this, &DosQAbstractListModelWrapper::layoutAboutToBeChanged);
|
||||
QObject::connect(m_impl, &DosQAbstractListModel::layoutChanged, this, &DosQAbstractListModelWrapper::layoutChanged);
|
||||
endResetModel();
|
||||
Q_ASSERT(m_dObject);
|
||||
Q_ASSERT(m_impl);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
DosQAbstractListModelWrapper<N, M>::~DosQAbstractListModelWrapper()
|
||||
{
|
||||
m_data.deleteDObject(m_id, m_dObject);
|
||||
m_dObject = nullptr;
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
const QMetaObject *DosQAbstractListModelWrapper<N, M>::metaObject() const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->metaObject();
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
int DosQAbstractListModelWrapper<N, M>::qt_metacall(QMetaObject::Call call, int index, void **args)
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->qt_metacall(call, index, args);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
bool DosQAbstractListModelWrapper<N, M>::emitSignal(QObject* emitter, const QString &name, const std::vector<QVariant> &argumentsValues)
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->emitSignal(this, name, argumentsValues);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::setQmlRegisterType(QmlRegisterType data)
|
||||
{
|
||||
m_data = std::move(data);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::setStaticMetaObject(const QMetaObject &metaObject)
|
||||
{
|
||||
*(const_cast<QMetaObject *>(&staticMetaObject)) = metaObject;
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::setId(int id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
int DosQAbstractListModelWrapper<N, M>::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->rowCount(parent);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
int DosQAbstractListModelWrapper<N, M>::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->columnCount(parent);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
QVariant DosQAbstractListModelWrapper<N, M>::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->data(index, role);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
bool DosQAbstractListModelWrapper<N, M>::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->setData(index, value, role);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
Qt::ItemFlags DosQAbstractListModelWrapper<N, M>::flags(const QModelIndex &index) const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->flags(index);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
QVariant DosQAbstractListModelWrapper<N, M>::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
QHash<int, QByteArray> DosQAbstractListModelWrapper<N, M>::roleNames() const
|
||||
{
|
||||
Q_ASSERT(m_impl);
|
||||
return m_impl->roleNames();
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicBeginInsertRows(const QModelIndex &index, int first, int last)
|
||||
{
|
||||
m_impl->publicBeginInsertRows(index, first, last);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicEndInsertRows()
|
||||
{
|
||||
m_impl->publicEndInsertRows();
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicBeginRemoveRows(const QModelIndex &index, int first, int last)
|
||||
{
|
||||
m_impl->publicBeginRemoveRows(index, first, last);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicEndRemoveRows()
|
||||
{
|
||||
m_impl->publicEndRemoveRows();
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicBeginResetModel()
|
||||
{
|
||||
m_impl->publicBeginResetModel();
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicEndResetModel()
|
||||
{
|
||||
m_impl->publicEndResetModel();
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
void DosQAbstractListModelWrapper<N, M>::publicDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
{
|
||||
m_impl->publicDataChanged(topLeft, bottomRight, roles);
|
||||
}
|
||||
|
||||
template<int N, int M>
|
||||
const QmlRegisterType &DosQAbstractListModelWrapper<N, M>::qmlRegisterType()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
namespace DQALMW {
|
||||
|
||||
template<int N>
|
||||
using RegisterTypeQObject = DosQAbstractListModelWrapper<N, 0>;
|
||||
|
||||
template<int N>
|
||||
int dosQmlRegisterType(QmlRegisterType args)
|
||||
{
|
||||
RegisterTypeQObject<N>::setQmlRegisterType(std::move(args));
|
||||
const QmlRegisterType &type = RegisterTypeQObject<N>::qmlRegisterType();
|
||||
RegisterTypeQObject<N>::setStaticMetaObject(*(type.staticMetaObject->metaObject()));
|
||||
int result = qmlRegisterType<RegisterTypeQObject<N>>(type.uri.c_str(), type.major, type.minor, type.qml.c_str());
|
||||
RegisterTypeQObject<N>::setId(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
struct DosQmlRegisterHelper {
|
||||
static int Register(int i, QmlRegisterType args)
|
||||
{
|
||||
if (i > N)
|
||||
return -1;
|
||||
else if (i == N)
|
||||
return dosQmlRegisterType<N>(std::move(args));
|
||||
else
|
||||
return DosQmlRegisterHelper < N - 1 >::Register(i, std::move(args));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct DosQmlRegisterHelper<0> {
|
||||
static int Register(int i, QmlRegisterType args)
|
||||
{
|
||||
return i == 0 ? dosQmlRegisterType<0>(std::move(args)) : -1;
|
||||
}
|
||||
};
|
||||
|
||||
int dosQmlRegisterType(QmlRegisterType args)
|
||||
{
|
||||
static int i = 0;
|
||||
return DosQmlRegisterHelper<35>::Register(i++, std::move(args));
|
||||
}
|
||||
|
||||
template<int N>
|
||||
using RegisterSingletonTypeQObject = DosQAbstractListModelWrapper<N, 1>;
|
||||
|
||||
template<int N>
|
||||
QObject *singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
return new RegisterSingletonTypeQObject<N>();
|
||||
}
|
||||
|
||||
template<int N>
|
||||
int dosQmlRegisterSingletonType(QmlRegisterType args)
|
||||
{
|
||||
using Func = QObject * (*)(QQmlEngine *, QJSEngine *);
|
||||
Func f = singletontype_provider<N>;
|
||||
|
||||
RegisterSingletonTypeQObject<N>::setQmlRegisterType(std::move(args));
|
||||
const QmlRegisterType &type = RegisterSingletonTypeQObject<N>::qmlRegisterType();
|
||||
RegisterSingletonTypeQObject<N>::setStaticMetaObject(*(type.staticMetaObject->metaObject()));
|
||||
int result = qmlRegisterSingletonType<RegisterSingletonTypeQObject<N>>(type.uri.c_str(), type.major, type.minor, type.qml.c_str(), f);
|
||||
RegisterSingletonTypeQObject<N>::setId(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
struct DosQmlRegisterSingletonHelper {
|
||||
static int Register(int i, QmlRegisterType args)
|
||||
{
|
||||
if (i > N)
|
||||
return -1;
|
||||
else if (i == N)
|
||||
return dosQmlRegisterSingletonType<N>(std::move(args));
|
||||
else
|
||||
return DosQmlRegisterSingletonHelper < N - 1 >::Register(i, std::move(args));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct DosQmlRegisterSingletonHelper<0> {
|
||||
static int Register(int i, QmlRegisterType args)
|
||||
{
|
||||
return i == 0 ? dosQmlRegisterSingletonType<0>(std::move(args)) : -1;
|
||||
}
|
||||
};
|
||||
|
||||
int dosQmlRegisterSingletonType(QmlRegisterType args)
|
||||
{
|
||||
static int i = 0;
|
||||
return DosQmlRegisterSingletonHelper<35>::Register(i++, std::move(args));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "DOtherSide/DosIQObjectImpl.h"
|
||||
#include "DOtherSide/DosQMetaObject.h"
|
||||
#include "DOtherSide/DosQObject.h"
|
||||
#include "DOtherSide/DosQMetaObject.h"
|
||||
#include <QtQml/qqml.h>
|
||||
|
||||
namespace DOS {
|
||||
|
@ -35,7 +34,7 @@ public:
|
|||
|
||||
private:
|
||||
void *m_dObject;
|
||||
DosIQObjectImpl *m_impl;
|
||||
DosQObject *m_impl;
|
||||
static int m_id;
|
||||
static QmlRegisterType m_data;
|
||||
};
|
||||
|
@ -57,7 +56,7 @@ DosQObjectWrapper<N, M>::DosQObjectWrapper(QObject *parent)
|
|||
{
|
||||
void *impl = nullptr;
|
||||
m_data.createDObject(m_id, static_cast<QObject*>(this), &m_dObject, &impl);
|
||||
m_impl = dynamic_cast<DosIQObjectImpl *>(static_cast<QObject*>(impl));
|
||||
m_impl = dynamic_cast<DosQObject *>(static_cast<QObject*>(impl));
|
||||
Q_ASSERT(m_dObject);
|
||||
Q_ASSERT(m_impl);
|
||||
}
|
||||
|
@ -116,6 +115,8 @@ const QmlRegisterType &DosQObjectWrapper<N, M>::qmlRegisterType()
|
|||
return m_data;
|
||||
}
|
||||
|
||||
namespace DQOW {
|
||||
|
||||
template<int N>
|
||||
using RegisterTypeQObject = DosQObjectWrapper<N, 0>;
|
||||
|
||||
|
@ -196,3 +197,4 @@ struct DosQmlRegisterSingletonHelper<0> {
|
|||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -578,7 +578,7 @@ void dos_qabstractlistmodel_create(void **vptr,
|
|||
void dos_qabstractlistmodel_beginInsertRows(void *vptr, QModelIndexVoidPtr parentIndex, int first, int last)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
auto index = static_cast<QModelIndex *>(parentIndex);
|
||||
model->publicBeginInsertRows(*index, first, last);
|
||||
}
|
||||
|
@ -586,14 +586,14 @@ void dos_qabstractlistmodel_beginInsertRows(void *vptr, QModelIndexVoidPtr paren
|
|||
void dos_qabstractlistmodel_endInsertRows(void *vptr)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
model->publicEndInsertRows();
|
||||
}
|
||||
|
||||
void dos_qabstractlistmodel_beginRemoveRows(void *vptr, QModelIndexVoidPtr parentIndex, int first, int last)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
auto index = static_cast<QModelIndex *>(parentIndex);
|
||||
model->publicBeginRemoveRows(*index, first, last);
|
||||
}
|
||||
|
@ -601,21 +601,21 @@ void dos_qabstractlistmodel_beginRemoveRows(void *vptr, QModelIndexVoidPtr paren
|
|||
void dos_qabstractlistmodel_endRemoveRows(void *vptr)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
model->publicEndRemoveRows();
|
||||
}
|
||||
|
||||
void dos_qabstractlistmodel_beginResetModel(void *vptr)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
model->publicBeginResetModel();
|
||||
}
|
||||
|
||||
void dos_qabstractlistmodel_endResetModel(void *vptr)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
model->publicEndResetModel();
|
||||
}
|
||||
|
||||
|
@ -626,7 +626,7 @@ void dos_qabstractlistmodel_dataChanged(void *vptr,
|
|||
int rolesArrayLength)
|
||||
{
|
||||
auto object = static_cast<QObject *>(vptr);
|
||||
auto model = dynamic_cast<DosQAbstractListModel *>(object);
|
||||
auto model = dynamic_cast<DosIQAbstractListModelImpl *>(object);
|
||||
auto topLeft = static_cast<QModelIndex *>(topLeftIndex);
|
||||
auto bottomRight = static_cast<QModelIndex *>(bottomRightIndex);
|
||||
auto roles = QVector<int>::fromStdVector(std::vector<int>(rolesArrayPtr, rolesArrayPtr + rolesArrayLength));
|
||||
|
|
|
@ -31,8 +31,7 @@ DosQAbstractListModel::DosQAbstractListModel(void *modelObject,
|
|||
, m_roleNamesCallback(std::move(roleNamesCallback))
|
||||
, m_flagsCallback(std::move(flagsCallback))
|
||||
, m_headerDataCallback(std::move(headerDataCallback))
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bool DosQAbstractListModel::emitSignal(QObject *emitter, const QString &name, const std::vector<QVariant> &argumentsValues)
|
||||
{
|
||||
|
@ -106,37 +105,37 @@ QHash<int, QByteArray> DosQAbstractListModel::roleNames() const
|
|||
return result;
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicBeginInsertRows(const QModelIndex &index, int first, int last)
|
||||
void DOS::DosQAbstractListModel::publicBeginInsertRows(const QModelIndex &index, int first, int last)
|
||||
{
|
||||
beginInsertRows(index, first, last);
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicEndInsertRows()
|
||||
void DOS::DosQAbstractListModel::publicEndInsertRows()
|
||||
{
|
||||
return endInsertRows();
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicBeginRemoveRows(const QModelIndex &index, int first, int last)
|
||||
void DOS::DosQAbstractListModel::publicBeginRemoveRows(const QModelIndex &index, int first, int last)
|
||||
{
|
||||
beginRemoveRows(index, first, last);
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicEndRemoveRows()
|
||||
void DOS::DosQAbstractListModel::publicEndRemoveRows()
|
||||
{
|
||||
return endRemoveRows();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicBeginResetModel()
|
||||
void DOS::DosQAbstractListModel::publicBeginResetModel()
|
||||
{
|
||||
beginResetModel();
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicEndResetModel()
|
||||
void DOS::DosQAbstractListModel::publicEndResetModel()
|
||||
{
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void DosQAbstractListModel::publicDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
void DOS::DosQAbstractListModel::publicDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
{
|
||||
emit dataChanged(topLeft, bottomRight, roles);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,38 @@
|
|||
#include "DOtherSide/DosQDeclarative.h"
|
||||
#include "DOtherSide/DosQObjectWrapper.h"
|
||||
#include "DOtherSide/DosQAbstractListModelWrapper.h"
|
||||
|
||||
namespace DOS {
|
||||
|
||||
bool isQAbstractListModel(const QMetaObject* metaObject)
|
||||
{
|
||||
const QMetaObject* current = metaObject;
|
||||
while(current) {
|
||||
if (&QAbstractListModel::staticMetaObject == current)
|
||||
return true;
|
||||
current = current->superClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int dosQmlRegisterType(QmlRegisterType args)
|
||||
{
|
||||
static int i = 0;
|
||||
return DosQmlRegisterHelper<35>::Register(i++, std::move(args));
|
||||
static int j = 0;
|
||||
if (isQAbstractListModel(args.staticMetaObject->metaObject()))
|
||||
return DQALMW::DosQmlRegisterHelper<35>::Register(j++, std::move(args));
|
||||
else
|
||||
return DQOW::DosQmlRegisterHelper<35>::Register(i++, std::move(args));
|
||||
}
|
||||
|
||||
int dosQmlRegisterSingletonType(QmlRegisterType args)
|
||||
{
|
||||
static int i = 0;
|
||||
return DosQmlRegisterSingletonHelper<35>::Register(i++, std::move(args));
|
||||
static int j = 0;
|
||||
if (isQAbstractListModel(args.staticMetaObject->metaObject()))
|
||||
return DQALMW::DosQmlRegisterSingletonHelper<35>::Register(j++, std::move(args));
|
||||
else
|
||||
return DQOW::DosQmlRegisterSingletonHelper<35>::Register(i++, std::move(args));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue