build Qt UI with clazy (#19537)

* clazy, level0

* level1
old-commit-hash: 069189fd7f
commatwo_master
Adeeb Shihadeh 4 years ago committed by GitHub
parent 99b06dd837
commit 6371eda194
  1. 4
      SConstruct
  2. 11
      selfdrive/ui/SConscript
  3. 15
      selfdrive/ui/qt/offroad/wifiManager.cc
  4. 4
      selfdrive/ui/qt/widgets/offroad_alerts.cc
  5. 6
      selfdrive/ui/qt/widgets/toggle.cc
  6. 2
      selfdrive/ui/qt/widgets/toggle.hpp

@ -17,6 +17,10 @@ AddOption('--asan',
action='store_true', action='store_true',
help='turn on ASAN') help='turn on ASAN')
AddOption('--clazy',
action='store_true',
help='build with clazy')
real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
if platform.system() == "Darwin": if platform.system() == "Darwin":
arch = "Darwin" arch = "Darwin"

@ -44,6 +44,17 @@ if arch in ["x86_64", "Darwin", "larch64"]:
qt_env['CXXFLAGS'] += qt_flags qt_env['CXXFLAGS'] += qt_flags
qt_env['LIBPATH'] += ['#selfdrive/ui'] 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'] src = ['ui.cc', 'paint.cc', 'sidebar.cc', '#phonelibs/nanovg/nanovg.c']
libs = [common, 'zmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc] libs = [common, 'zmq', 'capnp', 'kj', 'm', cereal, messaging, gpucommon, visionipc]

@ -103,7 +103,7 @@ QString WifiManager::get_ipv4_address(){
return ""; return "";
} }
QVector<QDBusObjectPath> conns = get_active_connections(); QVector<QDBusObjectPath> conns = get_active_connections();
for (auto p : conns){ for (auto &p : conns){
QString active_connection = p.path(); QString active_connection = p.path();
QDBusInterface nm(nm_service, active_connection, props_iface, bus); QDBusInterface nm(nm_service, active_connection, props_iface, bus);
QDBusObjectPath pth = get_response<QDBusObjectPath>(nm.call("Get", connection_iface, "Ip4Config")); QDBusObjectPath pth = get_response<QDBusObjectPath>(nm.call("Get", connection_iface, "Ip4Config"));
@ -261,14 +261,13 @@ void WifiManager::clear_connections(QString ssid) {
const QDBusArgument &dbusArg = response.arguments().at(0).value<QDBusArgument>(); const QDBusArgument &dbusArg = response.arguments().at(0).value<QDBusArgument>();
QMap<QString,QMap<QString,QVariant> > map; QMap<QString, QMap<QString,QVariant>> map;
dbusArg >> map; dbusArg >> map;
for (QString outer_key : map.keys()) { for (auto &inner : map) {
QMap<QString,QVariant> innerMap = map.value(outer_key); for (auto &val : inner) {
for (QString inner_key : innerMap.keys()) { QString key = inner.key(val);
if (inner_key == "ssid") { if (key == "ssid") {
QString value = innerMap.value(inner_key).value<QString>(); if (val == ssid) {
if (value == ssid) {
nm2.call("Delete"); nm2.call("Delete");
} }
} }

@ -91,7 +91,7 @@ void OffroadAlert::refresh() {
} else { } else {
vlayout->addSpacing(60); vlayout->addSpacing(60);
for (auto alert : alerts) { for (const auto &alert : alerts) {
QLabel *l = new QLabel(alert.text); QLabel *l = new QLabel(alert.text);
l->setWordWrap(true); l->setWordWrap(true);
l->setMargin(60); l->setMargin(60);
@ -136,7 +136,7 @@ void OffroadAlert::parse_alerts() {
} }
QJsonObject json = doc.object(); QJsonObject json = doc.object();
for (const QString& key : json.keys()) { for (const QString &key : json.keys()) {
std::vector<char> bytes = Params().read_db_bytes(key.toStdString().c_str()); std::vector<char> bytes = Params().read_db_bytes(key.toStdString().c_str());
if (bytes.size()) { if (bytes.size()) {

@ -19,14 +19,14 @@ void Toggle::paintEvent(QPaintEvent *e) {
p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHint(QPainter::Antialiasing, true);
// Draw toggle background left // 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); p.drawRoundedRect(QRect(0, _y_rect, _x_circle + _radius, _height_rect), _height_rect/2, _height_rect/2);
// Draw toggle background right // 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); p.drawRoundedRect(QRect(_x_circle - _radius, _y_rect, width() -(_x_circle - _radius), _height_rect), _height_rect/2, _height_rect/2);
// Draw toggle circle // Draw toggle circle
p.setBrush(QColor("#fafafa")); p.setBrush(QColor(0xfafafa));
p.drawEllipse(QRectF(_x_circle - _radius, _y_circle - _radius, 2 * _radius, 2 * _radius)); p.drawEllipse(QRectF(_x_circle - _radius, _y_circle - _radius, 2 * _radius, 2 * _radius));
} }

@ -3,7 +3,7 @@
class Toggle : public QAbstractButton { class Toggle : public QAbstractButton {
Q_OBJECT 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: public:
Toggle(QWidget* parent = nullptr); Toggle(QWidget* parent = nullptr);

Loading…
Cancel
Save