ui/map: delete map after unsubscribing from prime (#29136)

Co-authored-by: Cameron Clough <cameronjclough@gmail.com>
pull/29595/head
Dean Lee 2 years ago committed by GitHub
parent 20e8170399
commit 792ad7d816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      selfdrive/ui/qt/onroad.cc
  2. 1
      selfdrive/ui/qt/onroad.h

@ -63,6 +63,7 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
QObject::connect(uiState(), &UIState::uiUpdate, this, &OnroadWindow::updateState); QObject::connect(uiState(), &UIState::uiUpdate, this, &OnroadWindow::updateState);
QObject::connect(uiState(), &UIState::offroadTransition, this, &OnroadWindow::offroadTransition); QObject::connect(uiState(), &UIState::offroadTransition, this, &OnroadWindow::offroadTransition);
QObject::connect(uiState(), &UIState::primeChanged, this, &OnroadWindow::primeChanged);
} }
void OnroadWindow::updateState(const UIState &s) { void OnroadWindow::updateState(const UIState &s) {
@ -105,7 +106,7 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) {
void OnroadWindow::offroadTransition(bool offroad) { void OnroadWindow::offroadTransition(bool offroad) {
#ifdef ENABLE_MAPS #ifdef ENABLE_MAPS
if (!offroad) { if (!offroad) {
if (map == nullptr && (uiState()->primeType() || !MAPBOX_TOKEN.isEmpty())) { if (map == nullptr && (uiState()->hasPrime() || !MAPBOX_TOKEN.isEmpty())) {
auto m = new MapPanel(get_mapbox_settings()); auto m = new MapPanel(get_mapbox_settings());
map = m; map = m;
@ -125,6 +126,17 @@ void OnroadWindow::offroadTransition(bool offroad) {
alerts->updateAlert({}); alerts->updateAlert({});
} }
void OnroadWindow::primeChanged(bool prime) {
#ifdef ENABLE_MAPS
if (map && (!prime && MAPBOX_TOKEN.isEmpty())) {
nvg->map_settings_btn->setEnabled(false);
nvg->map_settings_btn->setVisible(false);
map->deleteLater();
map = nullptr;
}
#endif
}
void OnroadWindow::paintEvent(QPaintEvent *event) { void OnroadWindow::paintEvent(QPaintEvent *event) {
QPainter p(this); QPainter p(this);
p.fillRect(rect(), QColor(bg.red(), bg.green(), bg.blue(), 255)); p.fillRect(rect(), QColor(bg.red(), bg.green(), bg.blue(), 255));

@ -150,5 +150,6 @@ private:
private slots: private slots:
void offroadTransition(bool offroad); void offroadTransition(bool offroad);
void primeChanged(bool prime);
void updateState(const UIState &s); void updateState(const UIState &s);
}; };

Loading…
Cancel
Save