From 035c392e3e890ce0c0e76163f9ce329b881d9df5 Mon Sep 17 00:00:00 2001 From: Filippo Cucchetto Date: Sun, 5 Mar 2017 19:30:57 +0100 Subject: [PATCH] Fixed test and renaming --- lib/include/DOtherSide/DosQAbstractItemModel.h | 4 ++-- .../DOtherSide/DosQAbstractItemModelWrapper.h | 18 +++++++++--------- lib/include/DOtherSide/DosQMetaObject.h | 4 ++-- lib/src/DosQDeclarative.cpp | 12 ++++++------ lib/src/DosQMetaObject.cpp | 2 +- test/MockQAbstractItemModel.cpp | 7 +++++++ test/test_dotherside.cpp | 6 +++--- 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/include/DOtherSide/DosQAbstractItemModel.h b/lib/include/DOtherSide/DosQAbstractItemModel.h index 9f75317..68f67fb 100644 --- a/lib/include/DOtherSide/DosQAbstractItemModel.h +++ b/lib/include/DOtherSide/DosQAbstractItemModel.h @@ -29,10 +29,10 @@ public: /// @see IDynamicQObject::emitSignal bool emitSignal(QObject *emitter, const QString &name, const std::vector &argumentsValues) override; - /// @see QAbstractListModel::metaObject() + /// @see QAbstractItemModel::metaObject() const QMetaObject *metaObject() const override; - /// @see QAbstractListModel::qt_metacall + /// @see QAbstractItemModel::qt_metacall int qt_metacall(QMetaObject::Call, int, void **) override; /// Return the model's row count diff --git a/lib/include/DOtherSide/DosQAbstractItemModelWrapper.h b/lib/include/DOtherSide/DosQAbstractItemModelWrapper.h index 1a84f8e..bc6e5ce 100644 --- a/lib/include/DOtherSide/DosQAbstractItemModelWrapper.h +++ b/lib/include/DOtherSide/DosQAbstractItemModelWrapper.h @@ -37,25 +37,25 @@ public: /// Sets the qmlRegisterType id static void setId(int id); - /// @see QAbstractListModel::rowCount + /// @see QAbstractItemModel::rowCount int rowCount(const QModelIndex &parent = QModelIndex()) const override; - /// @see QAbstractListModel::columnCount + /// @see QAbstractItemModel::columnCount int columnCount(const QModelIndex &parent = QModelIndex()) const override; - /// @see QAbstractListModel::data + /// @see QAbstractItemModel::data QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - /// @see QAbstractListModel::setData + /// @see QAbstractItemModel::setData bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - /// @see QAbstractListModel::flags + /// @see QAbstractItemModel::flags Qt::ItemFlags flags(const QModelIndex &index) const override; - /// @see QAbstractListModel::headerData + /// @see QAbstractItemModel::headerData QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; - /// @see QAbstractListModel::roleNames + /// @see QAbstractItemModel::roleNames QHash roleNames() const override; /// @see QAbstractItemModel::index @@ -110,7 +110,7 @@ private: }; template -const QMetaObject DosQAbstractItemModelWrapper::staticMetaObject = QAbstractListModel::staticMetaObject; +const QMetaObject DosQAbstractItemModelWrapper::staticMetaObject = QAbstractItemModel::staticMetaObject; template QmlRegisterType DosQAbstractItemModelWrapper::m_data; @@ -339,7 +339,7 @@ const QmlRegisterType &DosQAbstractItemModelWrapper::qmlRegisterType() return m_data; } -namespace DQALMW { +namespace DQAIMW { template using RegisterTypeQObject = DosQAbstractItemModelWrapper; diff --git a/lib/include/DOtherSide/DosQMetaObject.h b/lib/include/DOtherSide/DosQMetaObject.h index 66410f6..5c290ba 100644 --- a/lib/include/DOtherSide/DosQMetaObject.h +++ b/lib/include/DOtherSide/DosQMetaObject.h @@ -49,14 +49,14 @@ public: DosQObjectMetaObject(); }; -/// This is the DosQMetaObject for a QAbstractListModel +/// This is the DosQMetaObject for a QAbstractItemModel class DosQAbstractItemModelMetaObject : public BaseDosQMetaObject { public: DosQAbstractItemModelMetaObject(); }; -/// This the generic version used by subclasses of QObject or QAbstractListModels +/// This the generic version used by subclasses of QObject or QAbstractItemModels class DosQMetaObject : public BaseDosQMetaObject { public: diff --git a/lib/src/DosQDeclarative.cpp b/lib/src/DosQDeclarative.cpp index aa1900f..e9ba9c9 100644 --- a/lib/src/DosQDeclarative.cpp +++ b/lib/src/DosQDeclarative.cpp @@ -4,11 +4,11 @@ namespace DOS { -bool isQAbstractListModel(const QMetaObject *metaObject) +bool isQAbstractItemModel(const QMetaObject *metaObject) { const QMetaObject *current = metaObject; while (current) { - if (&QAbstractListModel::staticMetaObject == current) + if (&QAbstractItemModel::staticMetaObject == current) return true; current = current->superClass(); } @@ -19,8 +19,8 @@ int dosQmlRegisterType(QmlRegisterType args) { static int i = 0; static int j = 0; - if (isQAbstractListModel(args.staticMetaObject->metaObject())) - return DQALMW::DosQmlRegisterHelper<35>::Register(j++, std::move(args)); + if (isQAbstractItemModel(args.staticMetaObject->metaObject())) + return DQAIMW::DosQmlRegisterHelper<35>::Register(j++, std::move(args)); else return DQOW::DosQmlRegisterHelper<35>::Register(i++, std::move(args)); } @@ -29,8 +29,8 @@ int dosQmlRegisterSingletonType(QmlRegisterType args) { static int i = 0; static int j = 0; - if (isQAbstractListModel(args.staticMetaObject->metaObject())) - return DQALMW::DosQmlRegisterSingletonHelper<35>::Register(j++, std::move(args)); + if (isQAbstractItemModel(args.staticMetaObject->metaObject())) + return DQAIMW::DosQmlRegisterSingletonHelper<35>::Register(j++, std::move(args)); else return DQOW::DosQmlRegisterSingletonHelper<35>::Register(i++, std::move(args)); } diff --git a/lib/src/DosQMetaObject.cpp b/lib/src/DosQMetaObject.cpp index d97f278..34b3815 100644 --- a/lib/src/DosQMetaObject.cpp +++ b/lib/src/DosQMetaObject.cpp @@ -3,7 +3,7 @@ #include "private/qmetaobjectbuilder_p.h" #include "private/qmetaobject_p.h" #include "private/qobject_p.h" -#include +#include namespace { diff --git a/test/MockQAbstractItemModel.cpp b/test/MockQAbstractItemModel.cpp index 085371e..8977af1 100644 --- a/test/MockQAbstractItemModel.cpp +++ b/test/MockQAbstractItemModel.cpp @@ -200,8 +200,15 @@ void MockQAbstractItemModel::onHeaderDataCalled(void *selfVPtr, int section, int void MockQAbstractItemModel::onIndexCalled(void *selfVPtr, int row, int column, const DosQModelIndex *parent, DosQModelIndex *result) { + auto self = static_cast(selfVPtr); + auto index = dos_qabstractitemmodel_createIndex(self->data(), row, column, 0); + dos_qmodelindex_assign(result, index); + dos_qmodelindex_delete(index); } void MockQAbstractItemModel::onParentCalled(void *selfVPtr, const DosQModelIndex *child, DosQModelIndex *result) { + auto index = dos_qmodelindex_create(); + dos_qmodelindex_assign(result, index); + dos_qmodelindex_delete(index); } diff --git a/test/test_dotherside.cpp b/test/test_dotherside.cpp index 9ea85d8..5752b67 100644 --- a/test/test_dotherside.cpp +++ b/test/test_dotherside.cpp @@ -424,9 +424,9 @@ private: }; /* - * Test QAbstractListModel + * Test QAbstractItemModel */ -class TestQAbstractListModel : public QObject +class TestQAbstractItemModel : public QObject { Q_OBJECT @@ -697,7 +697,7 @@ int main(int argc, char *argv[]) success &= ExecuteGuiTest(argc, argv); success &= ExecuteGuiTest(argc, argv); success &= ExecuteGuiTest(argc, argv); - success &= ExecuteGuiTest(argc, argv); + success &= ExecuteGuiTest(argc, argv); success &= ExecuteGuiTest(argc, argv); success &= ExecuteGuiTest(argc, argv); return success ? 0 : 1;