Skip to content

Commit 3fb2527

Browse files
pd0wmtwilsonco
authored andcommitted
cabana: replace space by underscore when editing signal name (commaai#27130)
cabana: replace space by _ whene editing signal name
1 parent af6006b commit 3fb2527

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

tools/cabana/detailwidget.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ EditMessageDialog::EditMessageDialog(const QString &msg_id, const QString &title
288288
form_layout->addRow("ID", new QLabel(msg_id));
289289

290290
name_edit = new QLineEdit(title, this);
291-
name_edit->setValidator(new QRegExpValidator(QRegExp("^(\\w+)"), name_edit));
291+
name_edit->setValidator(new NameValidator(name_edit));
292292
form_layout->addRow(tr("Name"), name_edit);
293293

294294
size_spin = new QSpinBox(this);

tools/cabana/signaledit.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SignalForm::SignalForm(QWidget *parent) : QWidget(parent) {
1919
main_layout->addLayout(form_layout);
2020

2121
name = new QLineEdit();
22-
name->setValidator(new QRegExpValidator(QRegExp("^(\\w+)"), name));
22+
name->setValidator(new NameValidator(name));
2323
form_layout->addRow(tr("Name"), name);
2424

2525
QHBoxLayout *hl = new QHBoxLayout(this);

tools/cabana/util.cc

+7
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,10 @@ void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
9797
i++;
9898
}
9999
}
100+
101+
NameValidator::NameValidator(QObject *parent) : QRegExpValidator(QRegExp("^(\\w+)"), parent) { }
102+
103+
QValidator::State NameValidator::validate(QString &input, int &pos) const {
104+
input.replace(' ', '_');
105+
return QRegExpValidator::validate(input, pos);
106+
}

tools/cabana/util.h

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QByteArray>
44
#include <QColor>
55
#include <QFont>
6+
#include <QRegExpValidator>
67
#include <QStyledItemDelegate>
78
#include <QVector>
89

@@ -36,3 +37,11 @@ inline const QString &getColor(int i) {
3637
static const QString SIGNAL_COLORS[] = {"#9FE2BF", "#40E0D0", "#6495ED", "#CCCCFF", "#FF7F50", "#FFBF00"};
3738
return SIGNAL_COLORS[i % std::size(SIGNAL_COLORS)];
3839
}
40+
41+
class NameValidator : public QRegExpValidator {
42+
Q_OBJECT
43+
44+
public:
45+
NameValidator(QObject *parent=nullptr);
46+
QValidator::State validate(QString &input, int &pos) const override;
47+
};

0 commit comments

Comments
 (0)