ui: model fuzzy search (#958)

* models panel

* models panel

* fix ui report

* stupid scroll

* move model selector to models panel

* cleanup whitespaces

* cleanup bad merge

* model search

* support searching with short name

---------

Co-authored-by: DevTekVE <devtekve@gmail.com>
This commit is contained in:
Nayan
2025-06-06 16:50:10 -04:00
committed by GitHub
parent 1979b00cc0
commit 489d9164f8
2 changed files with 31 additions and 5 deletions
@@ -24,7 +24,17 @@ ModelsPanel::ModelsPanel(QWidget *parent) : QWidget(parent) {
currentModelLblBtn = new ButtonControlSP(tr("Current Model"), tr("SELECT"), current_model);
currentModelLblBtn->setValue(current_model);
connect(currentModelLblBtn, &ButtonControlSP::clicked, this, &ModelsPanel::handleCurrentModelLblBtnClicked);
connect(currentModelLblBtn, &ButtonControlSP::clicked, [=]() {
InputDialog d(tr("Search Model"), this, tr("Enter search keywords, or leave blank to list all models."), false);
d.setMinLength(0);
const int ret = d.exec();
if (ret) {
handleCurrentModelLblBtnClicked(d.text());
}
});
connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
is_onroad = !offroad;
updateLabels();
@@ -134,7 +144,7 @@ void ModelsPanel::updateModelManagerState() {
* @brief Handles the model bundle selection button click
* Displays available bundles, allows selection, and initiates download
*/
void ModelsPanel::handleCurrentModelLblBtnClicked() {
void ModelsPanel::handleCurrentModelLblBtnClicked(const QString &query) {
currentModelLblBtn->setEnabled(false);
currentModelLblBtn->setValue(tr("Fetching models..."));
@@ -142,7 +152,8 @@ void ModelsPanel::handleCurrentModelLblBtnClicked() {
QMap<uint32_t, QString> index_to_bundle;
const auto bundles = model_manager.getAvailableBundles();
for (const auto &bundle: bundles) {
index_to_bundle.insert(bundle.getIndex(), QString::fromStdString(bundle.getDisplayName()));
std::string bundleStr = std::string(bundle.getDisplayName()) + " $SNAME$ " + std::string(bundle.getInternalName());
index_to_bundle.insert(bundle.getIndex(), QString::fromStdString(bundleStr));
}
// Sort bundles by index in descending order
@@ -156,10 +167,24 @@ void ModelsPanel::handleCurrentModelLblBtnClicked() {
bundleNames.append(index_to_bundle[index]);
}
QStringList filteredBundleNames = searchFromList(query, bundleNames);
currentModelLblBtn->setValue(GetActiveModelName());
if (filteredBundleNames.isEmpty()) {
ConfirmationDialog::alert(tr("No model found for keywords: %1").arg(query), this);
return;
}
for (const QString &bundleName: filteredBundleNames) {
int index = bundleName.indexOf("$SNAME$");
if (index != -1) {
filteredBundleNames.replace(filteredBundleNames.indexOf(bundleName), bundleName.left(index).trimmed());
}
}
const QString selectedBundleName = MultiOptionDialog::getSelection(
tr("Select a Model"), bundleNames, GetActiveModelName(), this);
tr("Select a Model"), filteredBundleNames, GetActiveModelName(), this);
if (selectedBundleName.isEmpty() || !canContinueOnMeteredDialog()) {
return;
@@ -7,6 +7,7 @@
#pragma once
#include "selfdrive/ui/sunnypilot/qt/util.h"
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/settings.h"
class ModelsPanel : public QWidget {
@@ -30,7 +31,7 @@ private:
// UI update related methods
void updateLabels();
void handleCurrentModelLblBtnClicked();
void handleCurrentModelLblBtnClicked(const QString &query);
void handleBundleDownloadProgress();
void showResetParamsDialog();
cereal::ModelManagerSP::Reader model_manager;