2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2022-10-06 02:39:30 +03:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-06-19 02:38:40 +03:00
|
|
|
#include <QQmlEngine>
|
2022-10-06 02:39:30 +03:00
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <mtx/events/power_levels.hpp>
|
|
|
|
|
|
|
|
#include "TimelineModel.h"
|
|
|
|
|
|
|
|
class TimelineFilter : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2023-06-19 02:38:40 +03:00
|
|
|
QML_ELEMENT
|
2022-10-06 02:39:30 +03:00
|
|
|
|
|
|
|
Q_PROPERTY(QString filterByThread READ filterByThread WRITE setThreadId NOTIFY threadIdChanged)
|
2022-10-06 22:59:59 +03:00
|
|
|
Q_PROPERTY(QString filterByContent READ filterByContent WRITE setContentFilter NOTIFY
|
|
|
|
contentFilterChanged)
|
2022-10-06 02:39:30 +03:00
|
|
|
Q_PROPERTY(TimelineModel *source READ source WRITE setSource NOTIFY sourceChanged)
|
|
|
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
2022-12-21 00:34:55 +03:00
|
|
|
Q_PROPERTY(bool filteringInProgress READ isFiltering NOTIFY isFilteringChanged)
|
2022-10-06 02:39:30 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TimelineFilter(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
QString filterByThread() const { return threadId; }
|
2022-10-06 22:59:59 +03:00
|
|
|
QString filterByContent() const { return contentFilter; }
|
2022-10-06 02:39:30 +03:00
|
|
|
TimelineModel *source() const;
|
|
|
|
int currentIndex() const;
|
2022-12-21 00:34:55 +03:00
|
|
|
bool isFiltering() const;
|
2022-10-06 02:39:30 +03:00
|
|
|
|
|
|
|
void setThreadId(const QString &t);
|
2022-10-06 22:59:59 +03:00
|
|
|
void setContentFilter(const QString &t);
|
2022-10-06 02:39:30 +03:00
|
|
|
void setSource(TimelineModel *t);
|
|
|
|
void setCurrentIndex(int idx);
|
|
|
|
|
2022-10-06 22:59:59 +03:00
|
|
|
Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const
|
|
|
|
{
|
|
|
|
return data(index(i, 0), role);
|
|
|
|
}
|
|
|
|
|
2022-12-19 05:24:22 +03:00
|
|
|
bool event(QEvent *ev) override;
|
|
|
|
|
2022-10-06 02:39:30 +03:00
|
|
|
signals:
|
|
|
|
void threadIdChanged();
|
2022-10-06 22:59:59 +03:00
|
|
|
void contentFilterChanged();
|
2022-10-06 02:39:30 +03:00
|
|
|
void sourceChanged();
|
|
|
|
void currentIndexChanged();
|
2022-12-21 00:34:55 +03:00
|
|
|
void isFilteringChanged();
|
2022-10-06 02:39:30 +03:00
|
|
|
|
2022-11-04 01:26:59 +03:00
|
|
|
private slots:
|
|
|
|
void fetchAgain();
|
2022-12-19 05:24:22 +03:00
|
|
|
void sourceDataChanged(const QModelIndex &topLeft,
|
|
|
|
const QModelIndex &bottomRight,
|
|
|
|
const QVector<int> &roles);
|
2022-11-04 01:26:59 +03:00
|
|
|
|
2022-10-06 02:39:30 +03:00
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
|
|
|
|
|
|
|
private:
|
2022-12-19 05:24:22 +03:00
|
|
|
void startFiltering();
|
|
|
|
void continueFiltering();
|
|
|
|
|
2022-10-06 22:59:59 +03:00
|
|
|
QString threadId, contentFilter;
|
2022-12-19 05:24:22 +03:00
|
|
|
int cachedCount = 0, incrementalSearchIndex = 0;
|
2022-10-06 02:39:30 +03:00
|
|
|
};
|