Use multidata in timeline model

This commit is contained in:
Nicolas Werner 2023-06-02 02:58:36 +02:00
parent e09188c4d0
commit 24f370d6c0
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 25 additions and 3 deletions

View file

@ -852,8 +852,8 @@ UserSettings::setOpenVideoExternal(bool state)
void void
UserSettings::applyTheme() UserSettings::applyTheme()
{ {
QGuiApplication::setPalette(Theme::paletteFromTheme(this->theme())); QGuiApplication::setPalette(Theme::paletteFromTheme(this->theme()));
QApplication::setPalette(Theme::paletteFromTheme(this->theme())); QApplication::setPalette(Theme::paletteFromTheme(this->theme()));
} }
void void

View file

@ -875,7 +875,6 @@ QVariant
TimelineModel::data(const QModelIndex &index, int role) const TimelineModel::data(const QModelIndex &index, int role) const
{ {
using namespace mtx::accessors; using namespace mtx::accessors;
namespace acc = mtx::accessors;
if (index.row() < 0 && index.row() >= rowCount()) if (index.row() < 0 && index.row() >= rowCount())
return {}; return {};
@ -891,6 +890,28 @@ TimelineModel::data(const QModelIndex &index, int role) const
return data(*event, role); 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 QVariant
TimelineModel::dataById(const QString &id, int role, const QString &relatedTo) TimelineModel::dataById(const QString &id, int role, const QString &relatedTo)
{ {

View file

@ -277,6 +277,7 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) 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; 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 dataById(const QString &id, int role, const QString &relatedTo);
Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const