ui/map: handle & display error in MapWindow (#28854)

old-commit-hash: ae4a375dd6
vw-mqb-aeb
Dean Lee 2 years ago committed by GitHub
parent ad4031dc3e
commit 387f6b6bf6
  1. 102
      selfdrive/ui/qt/maps/map.cc
  2. 7
      selfdrive/ui/qt/maps/map.h

@ -6,7 +6,6 @@
#include "common/transformations/coordinates.hpp" #include "common/transformations/coordinates.hpp"
#include "selfdrive/ui/qt/maps/map_helpers.h" #include "selfdrive/ui/qt/maps/map_helpers.h"
#include "selfdrive/ui/qt/request_repeater.h"
#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/util.h"
#include "selfdrive/ui/ui.h" #include "selfdrive/ui/ui.h"
@ -61,6 +60,11 @@ MapWindow::MapWindow(const QMapboxGLSettings &settings) : m_settings(settings),
emit requestSettings(true); emit requestSettings(true);
}); });
error = new QLabel(this);
error->setStyleSheet(R"(color:white;padding:50px 11px;font-size: 90px; background-color:rgb(0, 0, 0, 150);)");
error->setAlignment(Qt::AlignCenter);
overlay_layout->addWidget(error);
overlay_layout->addWidget(map_instructions); overlay_layout->addWidget(map_instructions);
overlay_layout->addStretch(1); overlay_layout->addStretch(1);
overlay_layout->addWidget(settings_btn, Qt::AlignLeft); overlay_layout->addWidget(settings_btn, Qt::AlignLeft);
@ -169,21 +173,15 @@ void MapWindow::updateState(const UIState &s) {
emit requestSettings(false); emit requestSettings(false);
} }
if (m_map.isNull()) { loaded_once = loaded_once || (m_map && m_map->isFullyLoaded());
return;
}
loaded_once = loaded_once || m_map->isFullyLoaded();
if (!loaded_once) { if (!loaded_once) {
map_instructions->showError(tr("Map Loading")); setError(tr("Map Loading"));
return; return;
} }
initLayers(); initLayers();
setError(locationd_valid ? "" : tr("Waiting for GPS"));
if (locationd_valid) { if (locationd_valid) {
map_instructions->noError();
// Update current location marker // Update current location marker
auto point = coordinate_to_collection(*last_position); auto point = coordinate_to_collection(*last_position);
QMapbox::Feature feature1(QMapbox::Feature::PointType, point, {}, {}); QMapbox::Feature feature1(QMapbox::Feature::PointType, point, {}, {});
@ -191,8 +189,6 @@ void MapWindow::updateState(const UIState &s) {
carPosSource["type"] = "geojson"; carPosSource["type"] = "geojson";
carPosSource["data"] = QVariant::fromValue<QMapbox::Feature>(feature1); carPosSource["data"] = QVariant::fromValue<QMapbox::Feature>(feature1);
m_map->updateSource("carPosSource", carPosSource); m_map->updateSource("carPosSource", carPosSource);
} else {
map_instructions->showError(tr("Waiting for GPS"));
} }
if (pan_counter == 0) { if (pan_counter == 0) {
@ -242,6 +238,14 @@ void MapWindow::updateState(const UIState &s) {
} }
} }
void MapWindow::setError(const QString &err_str) {
if (err_str != error->text()) {
error->setText(err_str);
error->setVisible(!err_str.isEmpty());
if (!err_str.isEmpty()) map_instructions->setVisible(false);
}
}
void MapWindow::resizeGL(int w, int h) { void MapWindow::resizeGL(int w, int h) {
m_map->resize(size() / MAP_SCALE); m_map->resize(size() / MAP_SCALE);
map_overlay->setFixedSize(width(), height()); map_overlay->setFixedSize(width(), height());
@ -279,7 +283,7 @@ void MapWindow::clearRoute() {
updateDestinationMarker(); updateDestinationMarker();
} }
map_instructions->hideIfNoError(); map_instructions->setVisible(false);
map_eta->setVisible(false); map_eta->setVisible(false);
allow_open = true; allow_open = true;
} }
@ -378,46 +382,31 @@ void MapWindow::updateDestinationMarker() {
} }
} }
MapInstructions::MapInstructions(QWidget * parent) : QWidget(parent) { MapInstructions::MapInstructions(QWidget *parent) : QWidget(parent) {
is_rhd = Params().getBool("IsRhdDetected"); is_rhd = Params().getBool("IsRhdDetected");
QHBoxLayout *main_layout = new QHBoxLayout(this); QHBoxLayout *main_layout = new QHBoxLayout(this);
main_layout->setContentsMargins(11, 50, 11, 11); main_layout->setContentsMargins(11, 50, 11, 11);
{ main_layout->addWidget(icon_01 = new QLabel, 0, Qt::AlignTop);
QVBoxLayout *layout = new QVBoxLayout;
icon_01 = new QLabel;
layout->addWidget(icon_01);
layout->addStretch();
main_layout->addLayout(layout);
}
{
QVBoxLayout *layout = new QVBoxLayout;
distance = new QLabel;
distance->setStyleSheet(R"(font-size: 90px;)");
layout->addWidget(distance);
primary = new QLabel; QWidget *right_container = new QWidget(this);
primary->setStyleSheet(R"(font-size: 60px;)"); right_container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
primary->setWordWrap(true); QVBoxLayout *layout = new QVBoxLayout(right_container);
layout->addWidget(primary);
secondary = new QLabel; layout->addWidget(distance = new QLabel);
secondary->setStyleSheet(R"(font-size: 50px;)"); distance->setStyleSheet(R"(font-size: 90px;)");
secondary->setWordWrap(true);
layout->addWidget(secondary);
lane_widget = new QWidget; layout->addWidget(primary = new QLabel);
lane_widget->setFixedHeight(125); primary->setStyleSheet(R"(font-size: 60px;)");
primary->setWordWrap(true);
lane_layout = new QHBoxLayout(lane_widget); layout->addWidget(secondary = new QLabel);
layout->addWidget(lane_widget); secondary->setStyleSheet(R"(font-size: 50px;)");
secondary->setWordWrap(true);
main_layout->addLayout(layout); layout->addLayout(lane_layout = new QHBoxLayout);
} main_layout->addWidget(right_container);
setStyleSheet("color:white"); setStyleSheet("color:white");
QPalette pal = palette(); QPalette pal = palette();
pal.setColor(QPalette::Background, QColor(0, 0, 0, 150)); pal.setColor(QPalette::Background, QColor(0, 0, 0, 150));
setAutoFillBackground(true); setAutoFillBackground(true);
@ -436,24 +425,6 @@ QString MapInstructions::getDistance(float d) {
} }
} }
void MapInstructions::showError(QString error_text) {
primary->setText("");
distance->setText(error_text);
distance->setAlignment(Qt::AlignCenter);
secondary->setVisible(false);
icon_01->setVisible(false);
this->error = true;
lane_widget->setVisible(false);
setVisible(true);
}
void MapInstructions::noError() {
error = false;
}
void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruction) { void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruction) {
setUpdatesEnabled(false); setUpdatesEnabled(false);
@ -464,7 +435,6 @@ void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruct
primary->setText(primary_str); primary->setText(primary_str);
secondary->setVisible(secondary_str.length() > 0); secondary->setVisible(secondary_str.length() > 0);
secondary->setText(secondary_str); secondary->setText(secondary_str);
distance->setAlignment(Qt::AlignLeft);
distance->setText(getDistance(instruction.getManeuverDistance())); distance->setText(getDistance(instruction.getManeuverDistance()));
// Show arrow with direction // Show arrow with direction
@ -534,19 +504,11 @@ void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruct
for (int i = lanes.size(); i < lane_labels.size(); ++i) { for (int i = lanes.size(); i < lane_labels.size(); ++i) {
lane_labels[i]->setVisible(false); lane_labels[i]->setVisible(false);
} }
lane_widget->setVisible(lanes.size() > 0);
setUpdatesEnabled(true); setUpdatesEnabled(true);
setVisible(true); setVisible(true);
} }
void MapInstructions::hideIfNoError() {
if (!error) {
hide();
}
}
MapETA::MapETA(QWidget *parent) : QWidget(parent) { MapETA::MapETA(QWidget *parent) : QWidget(parent) {
setVisible(false); setVisible(false);
setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_TranslucentBackground);

@ -31,17 +31,12 @@ private:
QLabel *primary; QLabel *primary;
QLabel *secondary; QLabel *secondary;
QLabel *icon_01; QLabel *icon_01;
QWidget *lane_widget;
QHBoxLayout *lane_layout; QHBoxLayout *lane_layout;
bool error = false;
bool is_rhd = false; bool is_rhd = false;
std::vector<QLabel *> lane_labels; std::vector<QLabel *> lane_labels;
public: public:
MapInstructions(QWidget * parent=nullptr); MapInstructions(QWidget * parent=nullptr);
void showError(QString error);
void noError();
void hideIfNoError();
QString getDistance(float d); QString getDistance(float d);
void updateInstructions(cereal::NavInstruction::Reader instruction); void updateInstructions(cereal::NavInstruction::Reader instruction);
}; };
@ -87,6 +82,7 @@ private:
bool event(QEvent *event) final; bool event(QEvent *event) final;
bool gestureEvent(QGestureEvent *event); bool gestureEvent(QGestureEvent *event);
void pinchTriggered(QPinchGesture *gesture); void pinchTriggered(QPinchGesture *gesture);
void setError(const QString &err_str);
bool m_sourceAdded = false; bool m_sourceAdded = false;
@ -105,6 +101,7 @@ private:
bool locationd_valid = false; bool locationd_valid = false;
QWidget *map_overlay; QWidget *map_overlay;
QLabel *error;
MapInstructions* map_instructions; MapInstructions* map_instructions;
MapETA* map_eta; MapETA* map_eta;
QPushButton *settings_btn; QPushButton *settings_btn;

Loading…
Cancel
Save