From 489d9164f8c8aba20b898c55e29e1c98f4598d09 Mon Sep 17 00:00:00 2001 From: Nayan Date: Fri, 6 Jun 2025 16:50:10 -0400 Subject: [PATCH] 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 --- .../qt/offroad/settings/models_panel.cc | 33 ++++++++++++++++--- .../qt/offroad/settings/models_panel.h | 3 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.cc index 3c8d034c5..1ce1b1b99 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.cc @@ -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 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; diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.h index 4ba526651..ee6a74a66 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/models_panel.h @@ -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;