introduce getPlatformBundle

This commit is contained in:
Jason Wen
2025-01-30 22:20:58 -05:00
parent 59afe4df1a
commit 158eaf4dda
2 changed files with 15 additions and 14 deletions
@@ -13,6 +13,17 @@
#include <QJsonValue>
#include <QMap>
QVariant PlatformSelector::getPlatformBundle(const QString &key) {
QString platform_bundle = QString::fromStdString(params.get("CarPlatformBundle"));
if (!platform_bundle.isEmpty()) {
QJsonDocument json = QJsonDocument::fromJson(platform_bundle.toUtf8());
if (!json.isNull() && json.isObject()) {
return json.object().value(key).toVariant();
}
}
return {};
}
PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") {
QObject::connect(this, &ButtonControl::clicked, [=]() {
if (text() == tr("SEARCH")) {
@@ -33,20 +44,9 @@ PlatformSelector::PlatformSelector() : ButtonControl(tr("Vehicle"), "", "") {
}
void PlatformSelector::refresh(bool _offroad) {
QString platform_bundle = QString::fromStdString(params.get("CarPlatformBundle"));
if (!platform_bundle.isEmpty()) {
QJsonDocument json = QJsonDocument::fromJson(platform_bundle.toUtf8());
if (!json.isNull() && json.isObject()) {
setValue(json.object()["name"].toString());
} else {
setValue("");
}
setText("REMOVE");
} else {
setValue("");
setText("SEARCH");
}
QString name = getPlatformBundle("name").toString();
setValue(name);
setText(name.isEmpty() ? tr("SEARCH") : tr("SELECT"));
setEnabled(true);
offroad = _offroad;
@@ -14,6 +14,7 @@ class PlatformSelector : public ButtonControl {
public:
PlatformSelector();
QVariant getPlatformBundle(const QString &key);
public slots:
void refresh(bool _offroad);