diff --git a/CMakeLists.txt b/CMakeLists.txt index 146f2bb..51ac3da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,6 +251,7 @@ set(SRC_FILES # Timeline src/timeline/TimelineViewManager.cpp src/timeline/TimelineModel.cpp + src/timeline/TimelineModelFilterProxy.cpp src/timeline/DelegateChooser.cpp # UI components @@ -450,6 +451,7 @@ qt5_wrap_cpp(MOC_HEADERS # Timeline src/timeline/TimelineViewManager.h + src/timeline/TimelineModelFilterProxy.h src/timeline/TimelineModel.h src/timeline/DelegateChooser.h diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 46cf484..fd112c8 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -75,7 +75,7 @@ Item { ListView { id: chat - visible: timelineManager.timeline != null + // visible: timelineManager.timeline != null anchors.left: parent.left anchors.right: parent.right @@ -85,7 +85,7 @@ Item { anchors.leftMargin: 4 anchors.rightMargin: scrollbar.width - model: timelineManager.timeline + model: timelineManager.timeline.modelFilter; boundsBehavior: Flickable.StopAtBounds pixelAligned: true @@ -179,7 +179,7 @@ Item { bottomPadding: 4 spacing: 8 - visible: !!modelData + // visible: !!modelData width: parent.width height: (section.includes(" ") ? dateBubble.height + 8 + userName.height : userName.height) + 8 diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 2c03937..d33b258 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -19,6 +19,7 @@ #include "TimelineViewManager.h" #include "Utils.h" #include "dialogs/RawMessage.h" +#include "TimelineModelFilterProxy.h" Q_DECLARE_METATYPE(QModelIndex) @@ -132,6 +133,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj , room_id_(room_id) , manager_(manager) { + modelFilter = new TimelineModelFilterProxy(); + modelFilter->setSourceModel(this); + connect( this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents); connect(this, &TimelineModel::messageFailed, this, [this](QString txn_id) { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 15111f0..04580e6 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -9,6 +9,7 @@ #include #include "CacheCryptoStructs.h" +#include "TimelineModelFilterProxy.h" namespace mtx::http { using RequestErr = const std::optional &; @@ -162,6 +163,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QString &id, int role) const; + TimelineModelFilterProxy *modelFilter; bool canFetchMore(const QModelIndex &) const override; void fetchMore(const QModelIndex &) override; diff --git a/src/timeline/TimelineModelFilterProxy.cpp b/src/timeline/TimelineModelFilterProxy.cpp new file mode 100644 index 0000000..b7ee63a --- /dev/null +++ b/src/timeline/TimelineModelFilterProxy.cpp @@ -0,0 +1,37 @@ +/* + * + * Copyright (C) 2020 thurloat + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "TimelineModelFilterProxy.h" + +bool +TimelineModelFilterProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + bool ret(true); + + if (this->sourceModel() != nullptr) { + auto index = this->sourceModel()->index(source_row, 0, source_parent); + if (index.isValid()) { + auto value = index.data(); + if (value.isValid()) { + ret = true; + } + } + } + + return ret; +} diff --git a/src/timeline/TimelineModelFilterProxy.h b/src/timeline/TimelineModelFilterProxy.h new file mode 100644 index 0000000..da937a0 --- /dev/null +++ b/src/timeline/TimelineModelFilterProxy.h @@ -0,0 +1,48 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TIMELINEMODELFILTERPROXY_H +#define TIMELINEMODELFILTERPROXY_H + +#include + +#define UNUSED(...) (void)(__VA_ARGS__) + +/** + * @todo write docs + */ +class TimelineModelFilterProxy : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + /** + * @todo write docs + */ + TimelineModelFilterProxy(){}; + virtual ~TimelineModelFilterProxy(){}; + + /** + * @todo write docs + * + * @param source_row TODO + * @param source_parent TODO + * @return TODO + */ + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; + +}; + +#endif // TIMELINEMODELFILTERPROXY_H