Add some documentation for how the background filtering works

This commit is contained in:
Nicolas Werner 2022-12-19 03:30:54 +01:00
parent 561085ef9d
commit 51cbe0f6d8
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,16 @@
#include "Logging.h" #include "Logging.h"
/// Searching currently can be done incrementally. For that we define a specific role to filter on
/// and then process that role in chunk. This is the `FilterRole`. Of course we need to then also
/// send proper update signals. Filtering then works as follows:
///
/// - At first no range is filtered (incrementalSearchIndex == 0).
/// - Then, when filtering is requested, we start posting events to the
/// event loop with lower than low priority (low prio - 1). The only thing those events do is
/// increment the incrementalSearchIndex and emit a dataChanged for that range of events.
/// - This then causes those events to be reevaluated if they should be visible.
static int FilterRole = Qt::UserRole * 3; static int FilterRole = Qt::UserRole * 3;
static QEvent::Type static QEvent::Type
@ -37,6 +47,7 @@ TimelineFilter::continueFiltering()
{ {
if (auto s = source(); s && s->rowCount() > incrementalSearchIndex) { if (auto s = source(); s && s->rowCount() > incrementalSearchIndex) {
auto ev = new QEvent(getFilterEventType()); auto ev = new QEvent(getFilterEventType());
// request filtering a new chunk with lower than low priority.
QCoreApplication::postEvent(this, ev, Qt::LowEventPriority - 1); QCoreApplication::postEvent(this, ev, Qt::LowEventPriority - 1);
} }
} }
@ -45,6 +56,7 @@ bool
TimelineFilter::event(QEvent *ev) TimelineFilter::event(QEvent *ev)
{ {
if (ev->type() == getFilterEventType()) { if (ev->type() == getFilterEventType()) {
// process the next 30 events by claiming their "filterrole" data has changed.
int orgIndex = incrementalSearchIndex; int orgIndex = incrementalSearchIndex;
incrementalSearchIndex += 30; incrementalSearchIndex += 30;
@ -139,6 +151,7 @@ TimelineFilter::setSource(TimelineModel *s)
&TimelineFilter::sourceDataChanged, &TimelineFilter::sourceDataChanged,
Qt::QueuedConnection); Qt::QueuedConnection);
// reset the search index a second time just to be safe.
incrementalSearchIndex = 0; incrementalSearchIndex = 0;
emit sourceChanged(); emit sourceChanged();
invalidateFilter(); invalidateFilter();
@ -172,6 +185,7 @@ TimelineFilter::currentIndex() const
bool bool
TimelineFilter::filterAcceptsRow(int source_row, const QModelIndex &) const TimelineFilter::filterAcceptsRow(int source_row, const QModelIndex &) const
{ {
// this chunk is still unfiltered.
if (source_row > incrementalSearchIndex) if (source_row > incrementalSearchIndex)
return true; return true;