From 30f358eb59c191cb6ca98b4ee79e17e5b9b82b63 Mon Sep 17 00:00:00 2001 From: Trey Moen <50057480+greatgitsby@users.noreply.github.com> Date: Fri, 28 Aug 2026 07:25:34 -0700 Subject: [PATCH] cabana: use std::string in RoutesDialog API results (#38717) --- openpilot/tools/cabana/routesdialog.cc | 24 ++++++++++--------- openpilot/tools/cabana/routesdialog.h | 6 ++--- .../tools/cabana/streams/replaystream.cc | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/openpilot/tools/cabana/routesdialog.cc b/openpilot/tools/cabana/routesdialog.cc index 35e23a6eee..9891104c9f 100644 --- a/openpilot/tools/cabana/routesdialog.cc +++ b/openpilot/tools/cabana/routesdialog.cc @@ -58,13 +58,13 @@ int64_t parseIsoToUnixMs(const std::string &s) { return static_cast(secs) * 1000 + millis; } -QString formatUnixMs(int64_t ms) { +std::string formatUnixMs(int64_t ms) { time_t secs = static_cast(ms / 1000); std::tm tm{}; localtime_r(&secs, &tm); char buf[64]; std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); - return QString::fromUtf8(buf); + return buf; } } // namespace @@ -113,17 +113,18 @@ RoutesDialog::RoutesDialog(QWidget *parent) : QDialog(parent) { // Fetch devices std::thread([this, alive = std::weak_ptr(alive_)]() { std::string result = PyDownloader::getDevices(); - utils::runOnMainThread([this, alive, r = QString::fromStdString(result), response = checkApiResponse(result)]() { + auto response = checkApiResponse(result); + utils::runOnMainThread([this, alive, r = std::move(result), response]() { if (!alive.expired()) parseDeviceList(r, response.first, response.second); }); }).detach(); } -void RoutesDialog::parseDeviceList(const QString &json, bool success, int error_code) { +void RoutesDialog::parseDeviceList(const std::string &json, bool success, int error_code) { if (success) { device_list_->clear(); std::string err; - auto doc = json11::Json::parse(json.toStdString(), err); + auto doc = json11::Json::parse(json, err); if (err.empty() && doc.is_array()) { for (const auto &device : doc.array_items()) { QString dongle_id = QString::fromStdString(device["dongle_id"].string_value()); @@ -156,16 +157,17 @@ void RoutesDialog::fetchRoutes() { int request_id = ++fetch_id_; std::thread([this, alive = std::weak_ptr(alive_), did, start_ms, end_ms, preserved, request_id]() { std::string result = PyDownloader::getDeviceRoutes(did, start_ms, end_ms, preserved); - utils::runOnMainThread([this, alive, r = QString::fromStdString(result), response = checkApiResponse(result), request_id]() { + auto response = checkApiResponse(result); + utils::runOnMainThread([this, alive, r = std::move(result), response, request_id]() { if (!alive.expired() && fetch_id_ == request_id) parseRouteList(r, response.first, response.second); }); }).detach(); } -void RoutesDialog::parseRouteList(const QString &json, bool success, int error_code) { +void RoutesDialog::parseRouteList(const std::string &json, bool success, int error_code) { if (success) { std::string err; - auto doc = json11::Json::parse(json.toStdString(), err); + auto doc = json11::Json::parse(json, err); if (err.empty() && doc.is_array()) { for (const auto &route : doc.array_items()) { int64_t from_ms = 0, to_ms = 0; @@ -177,7 +179,7 @@ void RoutesDialog::parseRouteList(const QString &json, bool success, int error_c to_ms = static_cast(route["end_time_utc_millis"].number_value()); } const int mins = static_cast((to_ms - from_ms) / 60000); - auto item = new QListWidgetItem(QString("%1 %2min").arg(formatUnixMs(from_ms)).arg(mins)); + auto item = new QListWidgetItem(QString::fromStdString(formatUnixMs(from_ms) + " " + std::to_string(mins) + "min")); item->setData(Qt::UserRole, QString::fromStdString(route["fullname"].string_value())); route_list_->addItem(item); } @@ -190,7 +192,7 @@ void RoutesDialog::parseRouteList(const QString &json, bool success, int error_c route_list_->setEmptyText(tr("No items")); } -QString RoutesDialog::route() { +std::string RoutesDialog::route() { auto current_item = route_list_->currentItem(); - return current_item ? current_item->data(Qt::UserRole).toString() : ""; + return current_item ? current_item->data(Qt::UserRole).toString().toStdString() : ""; } diff --git a/openpilot/tools/cabana/routesdialog.h b/openpilot/tools/cabana/routesdialog.h index 6ed145603f..44d7f068f9 100644 --- a/openpilot/tools/cabana/routesdialog.h +++ b/openpilot/tools/cabana/routesdialog.h @@ -12,11 +12,11 @@ class RoutesDialog : public QDialog { Q_OBJECT public: RoutesDialog(QWidget *parent); - QString route(); + std::string route(); protected: - void parseDeviceList(const QString &json, bool success, int error_code); - void parseRouteList(const QString &json, bool success, int error_code); + void parseDeviceList(const std::string &json, bool success, int error_code); + void parseRouteList(const std::string &json, bool success, int error_code); void fetchRoutes(); QComboBox *device_list_; diff --git a/openpilot/tools/cabana/streams/replaystream.cc b/openpilot/tools/cabana/streams/replaystream.cc index 56e4bfa084..3524c9e600 100644 --- a/openpilot/tools/cabana/streams/replaystream.cc +++ b/openpilot/tools/cabana/streams/replaystream.cc @@ -148,7 +148,7 @@ OpenReplayWidget::OpenReplayWidget(QWidget *parent) : AbstractOpenStreamWidget(p QObject::connect(browse_remote_btn, &QPushButton::clicked, [this]() { RoutesDialog route_dlg(this); if (route_dlg.exec()) { - route_edit->setText(route_dlg.route()); + route_edit->setText(QString::fromStdString(route_dlg.route())); } }); }