MapPanel: refresh only when visible and destination changes (#25739)

rebuild widgets only when mappanel is visible
old-commit-hash: ef767f6332
taco
Dean Lee 3 years ago committed by GitHub
parent 7451db46cf
commit df1668b35f
  1. 16
      selfdrive/ui/qt/maps/map_settings.cc
  2. 2
      selfdrive/ui/qt/maps/map_settings.h

@ -156,6 +156,7 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
void MapPanel::showEvent(QShowEvent *event) { void MapPanel::showEvent(QShowEvent *event) {
updateCurrentRoute(); updateCurrentRoute();
refresh();
} }
void MapPanel::clear() { void MapPanel::clear() {
@ -184,18 +185,25 @@ void MapPanel::updateCurrentRoute() {
} }
void MapPanel::parseResponse(const QString &response, bool success) { void MapPanel::parseResponse(const QString &response, bool success) {
stack->setCurrentIndex((uiState()->prime_type || success) ? 0 : 1); if (!success) return;
if (!success) { cur_destinations = response;
return; if (isVisible()) {
refresh();
}
} }
QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8()); void MapPanel::refresh() {
stack->setCurrentIndex(uiState()->prime_type ? 0 : 1);
if (cur_destinations == prev_destinations) return;
QJsonDocument doc = QJsonDocument::fromJson(cur_destinations.trimmed().toUtf8());
if (doc.isNull()) { if (doc.isNull()) {
qDebug() << "JSON Parse failed on navigation locations"; qDebug() << "JSON Parse failed on navigation locations";
return; return;
} }
prev_destinations = cur_destinations;
clear(); clear();
bool has_recents = false; bool has_recents = false;

@ -23,8 +23,10 @@ public:
private: private:
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;
void refresh();
Params params; Params params;
QString prev_destinations, cur_destinations;
QStackedWidget *stack; QStackedWidget *stack;
QPushButton *home_button, *work_button; QPushButton *home_button, *work_button;
QLabel *home_address, *work_address; QLabel *home_address, *work_address;

Loading…
Cancel
Save