summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-06-02 02:58:36 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-06-08 22:32:09 +0200
commit24f370d6c0a779373d1484206bb8ff617b1e24f2 (patch)
tree5a508d8e94deb3e7b612cbb0bcb3d3fc4da79e71 /src
parentRemove style sheets (diff)
downloadnheko-24f370d6c0a779373d1484206bb8ff617b1e24f2.tar.xz
Use multidata in timeline model
Diffstat (limited to 'src')
-rw-r--r--src/UserSettingsPage.cpp4
-rw-r--r--src/timeline/TimelineModel.cpp23
-rw-r--r--src/timeline/TimelineModel.h1
3 files changed, 25 insertions, 3 deletions
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp
index 84453962..ea7f22c4 100644
--- a/src/UserSettingsPage.cpp
+++ b/src/UserSettingsPage.cpp
@@ -852,8 +852,8 @@ UserSettings::setOpenVideoExternal(bool state)
 void
 UserSettings::applyTheme()
 {
-  QGuiApplication::setPalette(Theme::paletteFromTheme(this->theme()));
-  QApplication::setPalette(Theme::paletteFromTheme(this->theme()));
+    QGuiApplication::setPalette(Theme::paletteFromTheme(this->theme()));
+    QApplication::setPalette(Theme::paletteFromTheme(this->theme()));
 }
 
 void
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 0e99e7e1..f3b3ce81 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -875,7 +875,6 @@ QVariant
 TimelineModel::data(const QModelIndex &index, int role) const
 {
     using namespace mtx::accessors;
-    namespace acc = mtx::accessors;
     if (index.row() < 0 && index.row() >= rowCount())
         return {};
 
@@ -891,6 +890,28 @@ TimelineModel::data(const QModelIndex &index, int role) const
     return data(*event, role);
 }
 
+void
+TimelineModel::multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const
+{
+    if (index.row() < 0 && index.row() >= rowCount())
+        return;
+
+    // HACK(Nico): fetchMore likes to break with dynamically sized delegates and reuseItems
+    if (index.row() + 1 == rowCount() && !m_paginationInProgress)
+        const_cast<TimelineModel *>(this)->fetchMore(index);
+
+    auto event = events.get(rowCount() - index.row() - 1);
+
+    if (!event)
+        return;
+
+    for (QModelRoleData &roleData : roleDataSpan) {
+        int role = roleData.role();
+
+        roleData.setData(data(*event, role));
+    }
+}
+
 QVariant
 TimelineModel::dataById(const QString &id, int role, const QString &relatedTo)
 {
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 02a5ee80..d1f04e21 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -277,6 +277,7 @@ public:
     QHash<int, QByteArray> roleNames() const override;
     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+    void multiData(const QModelIndex &index, QModelRoleDataSpan roleDataSpan) const override;
     QVariant data(const mtx::events::collections::TimelineEvents &event, int role) const;
     Q_INVOKABLE QVariant dataById(const QString &id, int role, const QString &relatedTo);
     Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const