ui: use enum PrimeType for prime_type (#29491)
old-commit-hash: 99279b8eef43586aa09d001668355fa41e01b98f
This commit is contained in:
@@ -158,8 +158,8 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) {
|
||||
left_widget->setStyleSheet("border-radius: 10px;");
|
||||
|
||||
left_widget->setCurrentIndex(uiState()->primeType() ? 0 : 1);
|
||||
connect(uiState(), &UIState::primeTypeChanged, [=](int prime_type) {
|
||||
left_widget->setCurrentIndex(prime_type ? 0 : 1);
|
||||
connect(uiState(), &UIState::primeTypeChanged, [=](PrimeType prime_type) {
|
||||
left_widget->setCurrentIndex((prime_type != PrimeType::NONE) ? 0 : 1);
|
||||
});
|
||||
|
||||
home_layout->addWidget(left_widget, 1);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "selfdrive/ui/qt/qt_window.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/qt/widgets/controls.h"
|
||||
#include "selfdrive/ui/qt/widgets/prime.h"
|
||||
#include "selfdrive/ui/qt/widgets/scrollview.h"
|
||||
|
||||
|
||||
@@ -184,7 +183,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
|
||||
// Set initial config
|
||||
wifi->updateGsmSettings(roamingEnabled, QString::fromStdString(params.get("GsmApn")), metered);
|
||||
|
||||
connect(uiState(), &UIState::primeTypeChanged, this, [=](int prime_type) {
|
||||
connect(uiState(), &UIState::primeTypeChanged, this, [=](PrimeType prime_type) {
|
||||
bool gsmVisible = prime_type == PrimeType::NONE || prime_type == PrimeType::LITE;
|
||||
roamingToggle->setVisible(gsmVisible);
|
||||
editApnButton->setVisible(gsmVisible);
|
||||
|
||||
@@ -269,7 +269,7 @@ void SetupWidget::replyFinished(const QString &response, bool success) {
|
||||
}
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
int prime_type = json["prime_type"].toInt();
|
||||
PrimeType prime_type = static_cast<PrimeType>(json["prime_type"].toInt());
|
||||
uiState()->setPrimeType(prime_type);
|
||||
|
||||
if (!json["is_paired"].toBool()) {
|
||||
|
||||
@@ -7,15 +7,6 @@
|
||||
|
||||
#include "selfdrive/ui/qt/widgets/input.h"
|
||||
|
||||
enum PrimeType {
|
||||
NONE = 0,
|
||||
MAGENTA = 1,
|
||||
LITE = 2,
|
||||
BLUE = 3,
|
||||
MAGENTA_NEW = 4,
|
||||
};
|
||||
|
||||
|
||||
// pairing QR code
|
||||
class PairingQRWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -245,8 +245,11 @@ UIState::UIState(QObject *parent) : QObject(parent) {
|
||||
});
|
||||
|
||||
Params params;
|
||||
prime_type = std::atoi(params.get("PrimeType").c_str());
|
||||
language = QString::fromStdString(params.get("LanguageSetting"));
|
||||
auto prime_value = params.get("PrimeType");
|
||||
if (!prime_value.empty()) {
|
||||
prime_type = static_cast<PrimeType>(std::atoi(prime_value.c_str()));
|
||||
}
|
||||
|
||||
// update timer
|
||||
timer = new QTimer(this);
|
||||
@@ -265,7 +268,7 @@ void UIState::update() {
|
||||
emit uiUpdate(*this);
|
||||
}
|
||||
|
||||
void UIState::setPrimeType(int type) {
|
||||
void UIState::setPrimeType(PrimeType type) {
|
||||
if (type != prime_type) {
|
||||
prime_type = type;
|
||||
Params().put("PrimeType", std::to_string(prime_type));
|
||||
|
||||
@@ -96,6 +96,15 @@ typedef enum UIStatus {
|
||||
STATUS_ENGAGED,
|
||||
} UIStatus;
|
||||
|
||||
enum PrimeType {
|
||||
UNKNOWN = -1,
|
||||
NONE = 0,
|
||||
MAGENTA = 1,
|
||||
LITE = 2,
|
||||
BLUE = 3,
|
||||
MAGENTA_NEW = 4,
|
||||
};
|
||||
|
||||
const QColor bg_colors [] = {
|
||||
[STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8),
|
||||
[STATUS_OVERRIDE] = QColor(0x91, 0x9b, 0x95, 0xf1),
|
||||
@@ -153,8 +162,8 @@ public:
|
||||
return scene.started && (*sm)["controlsState"].getControlsState().getEnabled();
|
||||
}
|
||||
|
||||
void setPrimeType(int type);
|
||||
inline int primeType() const { return prime_type; }
|
||||
void setPrimeType(PrimeType type);
|
||||
inline PrimeType primeType() const { return prime_type; }
|
||||
|
||||
int fb_w = 0, fb_h = 0;
|
||||
|
||||
@@ -170,7 +179,7 @@ public:
|
||||
signals:
|
||||
void uiUpdate(const UIState &s);
|
||||
void offroadTransition(bool offroad);
|
||||
void primeTypeChanged(int prime_type);
|
||||
void primeTypeChanged(PrimeType prime_type);
|
||||
|
||||
private slots:
|
||||
void update();
|
||||
@@ -178,7 +187,7 @@ private slots:
|
||||
private:
|
||||
QTimer *timer;
|
||||
bool started_prev = false;
|
||||
int prime_type = -1;
|
||||
PrimeType prime_type = PrimeType::UNKNOWN;
|
||||
};
|
||||
|
||||
UIState *uiState();
|
||||
|
||||
Reference in New Issue
Block a user