Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114893
D116.1732590895.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D116.1732590895.diff
View Options
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,6 +20,7 @@
matrix-event-reader.cpp
matrix-event-reader-list-model.cpp
matrix-event.cpp
+ matrix-event-list.cpp
matrix-link.cpp
meta-types.cpp
l10n-provider.cpp
diff --git a/src/matrix-event-list.hpp b/src/matrix-event-list.hpp
new file mode 100644
--- /dev/null
+++ b/src/matrix-event-list.hpp
@@ -0,0 +1,33 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <kazv-defs.hpp>
+#include <QObject>
+#include <QQmlEngine>
+#include <QAbstractListModel>
+#include <lager/extra/qt.hpp>
+#include <base/types.hpp>
+#include "qt-json.hpp"
+#include "kazv-abstract-list-model.hpp"
+Q_MOC_INCLUDE("matrix-event.hpp")
+
+class MatrixEvent;
+
+class MatrixEventList : public KazvAbstractListModel
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("")
+
+ lager::reader<Kazv::EventList> m_eventList;
+
+public:
+ explicit MatrixEventList(lager::reader<Kazv::EventList> eventList, QObject *parent = 0);
+ ~MatrixEventList() override;
+
+ Q_INVOKABLE MatrixEvent *at(int index) const;
+};
diff --git a/src/matrix-event-list.cpp b/src/matrix-event-list.cpp
new file mode 100644
--- /dev/null
+++ b/src/matrix-event-list.cpp
@@ -0,0 +1,25 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <kazv-defs.hpp>
+#include "matrix-event.hpp"
+#include "helper.hpp"
+#include "matrix-event-list.hpp"
+
+using namespace Kazv;
+
+MatrixEventList::MatrixEventList(lager::reader<EventList> eventList, QObject *parent)
+ : KazvAbstractListModel(eventList.xform(containerSize), InitNow, parent)
+ , m_eventList(eventList)
+{
+}
+
+MatrixEventList::~MatrixEventList() = default;
+
+MatrixEvent *MatrixEventList::at(int index) const
+{
+ return new MatrixEvent(m_eventList[index][lager::lenses::or_default]);
+}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -21,6 +21,7 @@
matrix-link-test.cpp
matrix-user-given-attrs-map-test.cpp
kazv-abstract-list-model-test.cpp
+ matrix-event-list-test.cpp
LINK_LIBRARIES Qt${QT_MAJOR_VERSION}::Test kazvtestlib
)
diff --git a/src/tests/matrix-event-list-test.cpp b/src/tests/matrix-event-list-test.cpp
new file mode 100644
--- /dev/null
+++ b/src/tests/matrix-event-list-test.cpp
@@ -0,0 +1,47 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <kazv-defs.hpp>
+#include <QtTest>
+#include <QSignalSpy>
+#include <lager/state.hpp>
+#include <testfixtures/factory.hpp>
+#include "matrix-event-list.hpp"
+#include "matrix-event.hpp"
+#include "test-utils.hpp"
+
+using namespace Kazv;
+using namespace Kazv::Factory;
+
+class MatrixEventListTest : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testEventList();
+};
+
+void MatrixEventListTest::testEventList()
+{
+ auto eventList = EventList{
+ makeEvent(),
+ makeEvent(),
+ };
+
+ auto state = lager::make_state(eventList, lager::automatic_tag{});
+
+ MatrixEventList list(state);
+
+ QCOMPARE(list.count(), 2);
+ auto e1 = toUniquePtr(list.at(0));
+ QCOMPARE(e1->eventId().toStdString(), eventList[0].id());
+ auto e2 = toUniquePtr(list.at(1));
+ QCOMPARE(e2->eventId().toStdString(), eventList[1].id());
+}
+
+QTEST_MAIN(MatrixEventListTest)
+
+#include "matrix-event-list-test.moc"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 7:14 PM (9 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39898
Default Alt Text
D116.1732590895.diff (3 KB)
Attached To
Mode
D116: Add MatrixEventList class
Attached
Detach File
Event Timeline
Log In to Comment