initial work on the model filter proxy

quiet-time
Adasauce 5 years ago
parent 005ed00d67
commit cb8441b169
Signed by: adasauce
GPG Key ID: B4FD3151235211CB
  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 # Timeline
src/timeline/TimelineViewManager.cpp src/timeline/TimelineViewManager.cpp
src/timeline/TimelineModel.cpp src/timeline/TimelineModel.cpp
src/timeline/TimelineModelFilterProxy.cpp
src/timeline/DelegateChooser.cpp src/timeline/DelegateChooser.cpp
# UI components # UI components
@ -450,6 +451,7 @@ qt5_wrap_cpp(MOC_HEADERS
# Timeline # Timeline
src/timeline/TimelineViewManager.h src/timeline/TimelineViewManager.h
src/timeline/TimelineModelFilterProxy.h
src/timeline/TimelineModel.h src/timeline/TimelineModel.h
src/timeline/DelegateChooser.h src/timeline/DelegateChooser.h

@ -75,7 +75,7 @@ Item {
ListView { ListView {
id: chat id: chat
visible: timelineManager.timeline != null // visible: timelineManager.timeline != null
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
@ -85,7 +85,7 @@ Item {
anchors.leftMargin: 4 anchors.leftMargin: 4
anchors.rightMargin: scrollbar.width anchors.rightMargin: scrollbar.width
model: timelineManager.timeline model: timelineManager.timeline.modelFilter;
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
pixelAligned: true pixelAligned: true
@ -179,7 +179,7 @@ Item {
bottomPadding: 4 bottomPadding: 4
spacing: 8 spacing: 8
visible: !!modelData // visible: !!modelData
width: parent.width width: parent.width
height: (section.includes(" ") ? dateBubble.height + 8 + userName.height : userName.height) + 8 height: (section.includes(" ") ? dateBubble.height + 8 + userName.height : userName.height) + 8

@ -19,6 +19,7 @@
#include "TimelineViewManager.h" #include "TimelineViewManager.h"
#include "Utils.h" #include "Utils.h"
#include "dialogs/RawMessage.h" #include "dialogs/RawMessage.h"
#include "TimelineModelFilterProxy.h"
Q_DECLARE_METATYPE(QModelIndex) Q_DECLARE_METATYPE(QModelIndex)
@ -132,6 +133,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
, room_id_(room_id) , room_id_(room_id)
, manager_(manager) , manager_(manager)
{ {
modelFilter = new TimelineModelFilterProxy();
modelFilter->setSourceModel(this);
connect( connect(
this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents); this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents);
connect(this, &TimelineModel::messageFailed, this, [this](QString txn_id) { connect(this, &TimelineModel::messageFailed, this, [this](QString txn_id) {

@ -9,6 +9,7 @@
#include <mtxclient/http/errors.hpp> #include <mtxclient/http/errors.hpp>
#include "CacheCryptoStructs.h" #include "CacheCryptoStructs.h"
#include "TimelineModelFilterProxy.h"
namespace mtx::http { namespace mtx::http {
using RequestErr = const std::optional<mtx::http::ClientError> &; using RequestErr = const std::optional<mtx::http::ClientError> &;
@ -162,6 +163,7 @@ public:
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;
QVariant data(const QString &id, int role) const; QVariant data(const QString &id, int role) const;
TimelineModelFilterProxy *modelFilter;
bool canFetchMore(const QModelIndex &) const override; bool canFetchMore(const QModelIndex &) const override;
void fetchMore(const QModelIndex &) 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