mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-03-03 11:53:58 +08:00
cabana: replace space by underscore when editing signal name (#27130)
cabana: replace space by _ whene editing signal name
This commit is contained in:
@@ -288,7 +288,7 @@ EditMessageDialog::EditMessageDialog(const QString &msg_id, const QString &title
|
||||
form_layout->addRow("ID", new QLabel(msg_id));
|
||||
|
||||
name_edit = new QLineEdit(title, this);
|
||||
name_edit->setValidator(new QRegExpValidator(QRegExp("^(\\w+)"), name_edit));
|
||||
name_edit->setValidator(new NameValidator(name_edit));
|
||||
form_layout->addRow(tr("Name"), name_edit);
|
||||
|
||||
size_spin = new QSpinBox(this);
|
||||
|
||||
@@ -19,7 +19,7 @@ SignalForm::SignalForm(QWidget *parent) : QWidget(parent) {
|
||||
main_layout->addLayout(form_layout);
|
||||
|
||||
name = new QLineEdit();
|
||||
name->setValidator(new QRegExpValidator(QRegExp("^(\\w+)"), name));
|
||||
name->setValidator(new NameValidator(name));
|
||||
form_layout->addRow(tr("Name"), name);
|
||||
|
||||
QHBoxLayout *hl = new QHBoxLayout(this);
|
||||
|
||||
@@ -97,3 +97,10 @@ void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
NameValidator::NameValidator(QObject *parent) : QRegExpValidator(QRegExp("^(\\w+)"), parent) { }
|
||||
|
||||
QValidator::State NameValidator::validate(QString &input, int &pos) const {
|
||||
input.replace(' ', '_');
|
||||
return QRegExpValidator::validate(input, pos);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QByteArray>
|
||||
#include <QColor>
|
||||
#include <QFont>
|
||||
#include <QRegExpValidator>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QVector>
|
||||
|
||||
@@ -36,3 +37,11 @@ inline const QString &getColor(int i) {
|
||||
static const QString SIGNAL_COLORS[] = {"#9FE2BF", "#40E0D0", "#6495ED", "#CCCCFF", "#FF7F50", "#FFBF00"};
|
||||
return SIGNAL_COLORS[i % std::size(SIGNAL_COLORS)];
|
||||
}
|
||||
|
||||
class NameValidator : public QRegExpValidator {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NameValidator(QObject *parent=nullptr);
|
||||
QValidator::State validate(QString &input, int &pos) const override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user