feat(StatusQ): Test utility for tracking qt model access

This commit is contained in:
Michał Cieślak 2023-12-19 16:24:31 +01:00 committed by Michał
parent 79cca1d5cc
commit 480673d8be
4 changed files with 40 additions and 0 deletions

View File

@ -13,6 +13,8 @@ find_package(Qt5 COMPONENTS QuickTest Qml Quick WebEngine REQUIRED)
add_library(StatusQTestLib
src/TestHelpers/MonitorQtOutput.cpp
src/TestHelpers/MonitorQtOutput.h
src/TestHelpers/modelaccessobserverproxy.cpp
src/TestHelpers/modelaccessobserverproxy.h
)
target_link_libraries(StatusQTestLib PUBLIC Qt5::Core Qt5::Quick)

View File

@ -4,6 +4,7 @@
#include <QtWebEngine>
#include "TestHelpers/MonitorQtOutput.h"
#include "TestHelpers/modelaccessobserverproxy.h"
class RunBeforeQApplicationIsInitialized {
public:
@ -27,6 +28,7 @@ public slots:
// TODO: Alternative to not yet supported QML_ELEMENT
qmlRegisterType<MonitorQtOutput>("StatusQ.TestHelpers", 0, 1, "MonitorQtOutput");
qmlRegisterType<ModelAccessObserverProxy>("StatusQ.TestHelpers", 0, 1, "ModelAccessObserverProxy");
}
};

View File

@ -0,0 +1,20 @@
#include "modelaccessobserverproxy.h"
ModelAccessObserverProxy::ModelAccessObserverProxy(QObject* parent)
: QIdentityProxyModel{parent}
{
}
QVariant ModelAccessObserverProxy::data(const QModelIndex& index, int role) const
{
QVariant result;
if (checkIndex(index))
result = QIdentityProxyModel::data(index, role);
emit const_cast<ModelAccessObserverProxy*>(this)->dataAccessed(
index.row(), role, result);
return result;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <QIdentityProxyModel>
class ModelAccessObserverProxy : public QIdentityProxyModel
{
Q_OBJECT
public:
explicit ModelAccessObserverProxy(QObject* parent = nullptr);
QVariant data(const QModelIndex& index, int role) const override;
signals:
void dataAccessed(int row, int role, const QVariant& value);
};