cabana: small improvements to MessageListModel::setFilterString (#27153)

old-commit-hash: 3815afbde7
beeps
Dean Lee 2 years ago committed by GitHub
parent 8f812acb0d
commit 6741c99afc
  1. 29
      tools/cabana/messageswidget.cc

@ -84,27 +84,22 @@ QVariant MessageListModel::data(const QModelIndex &index, int role) const {
} }
void MessageListModel::setFilterString(const QString &string) { void MessageListModel::setFilterString(const QString &string) {
filter_str = string; auto contains = [](const QString &id, const QString &txt) {
msgs.clear(); auto cs = Qt::CaseInsensitive;
for (auto it = can->can_msgs.begin(); it != can->can_msgs.end(); ++it) { if (id.contains(txt, cs) || msgName(id).contains(txt, cs)) return true;
bool found = false;
// Search by message id or name
if (it.key().contains(filter_str, Qt::CaseInsensitive) || msgName(it.key()).contains(filter_str, Qt::CaseInsensitive)) {
found = true;
}
// Search by signal name // Search by signal name
const DBCMsg *msg = dbc()->msg(it.key()); if (const auto msg = dbc()->msg(id)) {
if (msg != nullptr) { for (auto &signal : msg->getSignals()) {
for (auto &signal: msg->getSignals()) { if (QString::fromStdString(signal->name).contains(txt, cs)) return true;
if (QString::fromStdString(signal->name).contains(filter_str, Qt::CaseInsensitive)) {
found = true;
}
} }
} }
return false;
};
if (found) { filter_str = string;
msgs.clear();
for (auto it = can->can_msgs.begin(); it != can->can_msgs.end(); ++it) {
if (filter_str.isEmpty() || contains(it.key(), filter_str)) {
msgs.push_back(it.key()); msgs.push_back(it.key());
} }
} }

Loading…
Cancel
Save