Compare commits

...

1 Commits

  1. 2
      CMakeLists.txt
  2. 6
      resources/qml/TimelineView.qml
  3. 4
      src/timeline/TimelineModel.cpp
  4. 2
      src/timeline/TimelineModel.h
  5. 37
      src/timeline/TimelineModelFilterProxy.cpp
  6. 48
      src/timeline/TimelineModelFilterProxy.h

@ -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

@ -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

@ -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) {

@ -9,6 +9,7 @@
#include <mtxclient/http/errors.hpp>
#include "CacheCryptoStructs.h"
#include "TimelineModelFilterProxy.h"
namespace mtx::http {
using RequestErr = const std::optional<mtx::http::ClientError> &;
@ -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;

@ -0,0 +1,37 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2020 thurloat <thurloat@protonmail.ch>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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;
}

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef TIMELINEMODELFILTERPROXY_H
#define TIMELINEMODELFILTERPROXY_H
#include <qsortfilterproxymodel.h>
#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
Loading…
Cancel
Save