Something went wrong. Try again.
The agentic engineering control plane for the posthuman future
Something went wrong. Try again.
2.0 kB · 76 lines
C++
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677#include "JumpRowProvider.h"
#include <QVariantMap>
#include <algorithm>#include <utility>#include <vector>
#include "AppModel.h"#include "FuzzyMatch.h"
namespace {
// One scored snapshot row: the original map plus the score and the title taken// once, so the sort comparator never re-walks the variant.struct Hit { QVariant row; int score = 0; QString title;};
} // namespace
JumpRowProvider::JumpRowProvider(QObject* parent) : FuzzyRowProvider(parent) {}
void JumpRowProvider::setModel(AppModel* model){ if (m_model == model) { return; } // A QObject pointer, not shared data: the lock is for the snapshot, not for // the pointer itself. m_model = model; emit modelChanged(); invalidate();}
void JumpRowProvider::captureInputs(){ // jumpCandidates() already returns plain maps; copy them so the worker never // dereferences the model or its live panes. m_snapshot = m_model != nullptr ? m_model->jumpCandidates() : QVariantList();}
QVariantList JumpRowProvider::rowsForQuery(const QString& query){ if (query.isEmpty()) { return m_snapshot; } std::vector<Hit> hits; hits.reserve(static_cast<std::size_t>(m_snapshot.size())); for (const QVariant& candidate : m_snapshot) { const QVariantMap map = candidate.toMap(); const QString title = map.value(QStringLiteral("title")).toString(); const int score = std::max(fuzzyScore(title, query), fuzzyScore(map.value(QStringLiteral("subtitle")).toString(), query)); if (score < 0) { continue; } hits.push_back(Hit{.row = candidate, .score = score, .title = title}); } std::ranges::sort(hits, [](const Hit& a, const Hit& b) { if (a.score != b.score) { return a.score > b.score; } return a.title < b.title; }); QVariantList out; out.reserve(static_cast<qsizetype>(hits.size())); for (Hit& hit : hits) { out.append(std::move(hit.row)); } return out;}