From 6371eda194379388017423c09da9856218be006b Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 18 Dec 2020 19:26:59 -0800 Subject: [PATCH] build Qt UI with clazy (#19537) * clazy, level0 * level1 old-commit-hash: 069189fd7fd9dc677b29725f92fd3b4b80911d8a --- SConstruct | 4 ++++ selfdrive/ui/SConscript | 11 +++++++++++ selfdrive/ui/qt/offroad/wifiManager.cc | 15 +++++++-------- selfdrive/ui/qt/widgets/offroad_alerts.cc | 4 ++-- selfdrive/ui/qt/widgets/toggle.cc | 6 +++--- selfdrive/ui/qt/widgets/toggle.hpp | 2 +- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/SConstruct b/SConstruct index d2397a471c..e518d9fa9a 100644 --- a/SConstruct +++ b/SConstruct @@ -17,6 +17,10 @@ AddOption('--asan', action='store_true', help='turn on ASAN') +AddOption('--clazy', + action='store_true', + help='build with clazy') + real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() if platform.system() == "Darwin": arch = "Darwin" diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index 28b2c2bfee..9ff1ea6f04 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -44,6 +44,17 @@ if arch in ["x86_64", "Darwin", "larch64"]: qt_env['CXXFLAGS'] += qt_flags qt_env['LIBPATH'] += ['#selfdrive/ui'] + if GetOption("clazy"): + checks = [ + "level0", + "level1", + "no-range-loop", + "no-non-pod-global-static", + ] + qt_env['CXX'] = 'clazy' + qt_env['ENV']['CLAZY_IGNORE_DIRS'] = qt_dirs[0] + qt_env['ENV']['CLAZY_CHECKS'] = ','.join(checks) + src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c'] libs = [common, 'zmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc] diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index ff8977c9a7..296e93c422 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -103,7 +103,7 @@ QString WifiManager::get_ipv4_address(){ return ""; } QVector conns = get_active_connections(); - for (auto p : conns){ + for (auto &p : conns){ QString active_connection = p.path(); QDBusInterface nm(nm_service, active_connection, props_iface, bus); QDBusObjectPath pth = get_response(nm.call("Get", connection_iface, "Ip4Config")); @@ -261,14 +261,13 @@ void WifiManager::clear_connections(QString ssid) { const QDBusArgument &dbusArg = response.arguments().at(0).value(); - QMap > map; + QMap> map; dbusArg >> map; - for (QString outer_key : map.keys()) { - QMap innerMap = map.value(outer_key); - for (QString inner_key : innerMap.keys()) { - if (inner_key == "ssid") { - QString value = innerMap.value(inner_key).value(); - if (value == ssid) { + for (auto &inner : map) { + for (auto &val : inner) { + QString key = inner.key(val); + if (key == "ssid") { + if (val == ssid) { nm2.call("Delete"); } } diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.cc b/selfdrive/ui/qt/widgets/offroad_alerts.cc index 08c8bcde62..4fb0b9fdbc 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.cc +++ b/selfdrive/ui/qt/widgets/offroad_alerts.cc @@ -91,7 +91,7 @@ void OffroadAlert::refresh() { } else { vlayout->addSpacing(60); - for (auto alert : alerts) { + for (const auto &alert : alerts) { QLabel *l = new QLabel(alert.text); l->setWordWrap(true); l->setMargin(60); @@ -136,7 +136,7 @@ void OffroadAlert::parse_alerts() { } QJsonObject json = doc.object(); - for (const QString& key : json.keys()) { + for (const QString &key : json.keys()) { std::vector bytes = Params().read_db_bytes(key.toStdString().c_str()); if (bytes.size()) { diff --git a/selfdrive/ui/qt/widgets/toggle.cc b/selfdrive/ui/qt/widgets/toggle.cc index bf30309153..4d6fda9325 100644 --- a/selfdrive/ui/qt/widgets/toggle.cc +++ b/selfdrive/ui/qt/widgets/toggle.cc @@ -19,14 +19,14 @@ void Toggle::paintEvent(QPaintEvent *e) { p.setRenderHint(QPainter::Antialiasing, true); // Draw toggle background left - p.setBrush(QColor("#33ab4c")); + p.setBrush(QColor(0x33ab4c)); p.drawRoundedRect(QRect(0, _y_rect, _x_circle + _radius, _height_rect), _height_rect/2, _height_rect/2); // Draw toggle background right - p.setBrush(QColor("#0a1a26")); + p.setBrush(QColor(0x0a1a26)); p.drawRoundedRect(QRect(_x_circle - _radius, _y_rect, width() -(_x_circle - _radius), _height_rect), _height_rect/2, _height_rect/2); // Draw toggle circle - p.setBrush(QColor("#fafafa")); + p.setBrush(QColor(0xfafafa)); p.drawEllipse(QRectF(_x_circle - _radius, _y_circle - _radius, 2 * _radius, 2 * _radius)); } diff --git a/selfdrive/ui/qt/widgets/toggle.hpp b/selfdrive/ui/qt/widgets/toggle.hpp index 98215c25d2..ca73f47e17 100644 --- a/selfdrive/ui/qt/widgets/toggle.hpp +++ b/selfdrive/ui/qt/widgets/toggle.hpp @@ -3,7 +3,7 @@ class Toggle : public QAbstractButton { Q_OBJECT - Q_PROPERTY(int offset_circle READ offset_circle WRITE set_offset_circle) + Q_PROPERTY(int offset_circle READ offset_circle WRITE set_offset_circle CONSTANT) public: Toggle(QWidget* parent = nullptr);