| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QQmlEngine> |
| 8 |
#include <QSortFilterProxyModel> |
| 9 |
#include <QString> |
| 10 |
|
| 11 |
#include <mtx/events/power_levels.hpp> |
| 12 |
|
| 13 |
class TimelineModel; |
| 14 |
|
| 15 |
class TimelineFilter : public QSortFilterProxyModel |
| 16 |
{ |
| 17 |
Q_OBJECT |
| 18 |
QML_ELEMENT |
| 19 |
|
| 20 |
Q_PROPERTY(QString filterByThread READ filterByThread WRITE setThreadId NOTIFY threadIdChanged) |
| 21 |
Q_PROPERTY(QString filterByContent READ filterByContent WRITE setContentFilter NOTIFY |
| 22 |
contentFilterChanged) |
| 23 |
Q_PROPERTY(TimelineModel *source READ source WRITE setSource NOTIFY sourceChanged) |
| 24 |
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) |
| 25 |
Q_PROPERTY(bool filteringInProgress READ isFiltering NOTIFY isFilteringChanged) |
| 26 |
|
| 27 |
public: |
| 28 |
explicit TimelineFilter(QObject *parent = nullptr); |
| 29 |
|
| 30 |
QString filterByThread() const { return threadId; } |
| 31 |
QString filterByContent() const { return contentFilter; } |
| 32 |
TimelineModel *source() const; |
| 33 |
int currentIndex() const; |
| 34 |
bool isFiltering() const; |
| 35 |
|
| 36 |
void setThreadId(const QString &t); |
| 37 |
void setContentFilter(const QString &t); |
| 38 |
void setSource(TimelineModel *t); |
| 39 |
void setCurrentIndex(int idx); |
| 40 |
|
| 41 |
Q_INVOKABLE QVariant dataByIndex(int i, int role = Qt::DisplayRole) const |
| 42 |
{ |
| 43 |
return data(index(i, 0), role); |
| 44 |
} |
| 45 |
|
| 46 |
bool event(QEvent *ev) override; |
| 47 |
|
| 48 |
signals: |
| 49 |
void threadIdChanged(); |
| 50 |
void contentFilterChanged(); |
| 51 |
void sourceChanged(); |
| 52 |
void currentIndexChanged(); |
| 53 |
void isFilteringChanged(); |
| 54 |
|
| 55 |
private slots: |
| 56 |
void fetchAgain(); |
| 57 |
void sourceDataChanged(const QModelIndex &topLeft, |
| 58 |
const QModelIndex &bottomRight, |
| 59 |
const QVector<int> &roles); |
| 60 |
|
| 61 |
protected: |
| 62 |
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; |
| 63 |
|
| 64 |
private: |
| 65 |
void startFiltering(); |
| 66 |
void continueFiltering(); |
| 67 |
|
| 68 |
QString threadId, contentFilter; |
| 69 |
int cachedCount = 0, incrementalSearchIndex = 0; |
| 70 |
}; |