mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-05 08:16:06 +08:00
cabana: some improvements to messages view (#27935)
* improve messageswidget * remove double semicolon
This commit is contained in:
@@ -132,12 +132,20 @@ QVariant MessageListModel::data(const QModelIndex &index, int role) const {
|
||||
const auto &id = msgs[index.row()];
|
||||
auto &can_data = can->lastMessage(id);
|
||||
|
||||
auto getFreq = [](const CanData &d) -> QString {
|
||||
if (d.freq > 0 && (can->currentSec() - d.ts) < (5.0 / d.freq)) {
|
||||
return d.freq >= 1 ? QString::number(std::nearbyint(d.freq)) : QString::number(d.freq, 'f', 2);
|
||||
} else {
|
||||
return "--";
|
||||
}
|
||||
};
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (index.column()) {
|
||||
case 0: return msgName(id);
|
||||
case 1: return id.source;
|
||||
case 2: return QString::number(id.address, 16);;
|
||||
case 3: return can_data.freq;
|
||||
case 2: return QString::number(id.address, 16);
|
||||
case 3: return getFreq(can_data);
|
||||
case 4: return can_data.count;
|
||||
case 5: return toHex(can_data.dat);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ struct CanData {
|
||||
|
||||
double ts = 0.;
|
||||
uint32_t count = 0;
|
||||
uint32_t freq = 0;
|
||||
double freq = 0;
|
||||
QByteArray dat;
|
||||
QVector<QColor> colors;
|
||||
QVector<double> last_change_t;
|
||||
|
||||
+20
-3
@@ -3,6 +3,7 @@
|
||||
#include <QFontDatabase>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
@@ -76,6 +77,17 @@ QSize MessageBytesDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
|
||||
return size;
|
||||
}
|
||||
|
||||
bool MessageBytesDelegate::helpEvent(QHelpEvent *e, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) {
|
||||
if (e->type() == QEvent::ToolTip && index.column() == 0) {
|
||||
if (view->visualRect(index).width() < QStyledItemDelegate::sizeHint(option, index).width()) {
|
||||
QToolTip::showText(e->globalPos(), index.data(Qt::DisplayRole).toString(), view);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
QToolTip::hideText();
|
||||
return false;
|
||||
}
|
||||
|
||||
void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
auto data = index.data(BytesRole);
|
||||
if (!data.isValid()) {
|
||||
@@ -89,24 +101,29 @@ void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||
int h_margin = option.widget->style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
painter->setPen(option.palette.color(QPalette::HighlightedText));
|
||||
} else {
|
||||
painter->setPen(option.palette.color(QPalette::Text));
|
||||
}
|
||||
|
||||
const QPoint pt{option.rect.left() + h_margin, option.rect.top() + v_margin};
|
||||
QFont old_font = painter->font();
|
||||
QPen old_pen = painter->pen();
|
||||
painter->setFont(fixed_font);
|
||||
for (int i = 0; i < byte_list.size(); ++i) {
|
||||
int row = !multiple_lines ? 0 : i / 8;
|
||||
int column = !multiple_lines ? i : i % 8;
|
||||
QRect r = QRect({pt.x() + column * byte_size.width(), pt.y() + row * byte_size.height()}, byte_size);
|
||||
if (i < colors.size() && colors[i].alpha() > 0) {
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->setPen(option.palette.color(QPalette::Text));
|
||||
painter->fillRect(r, option.palette.color(QPalette::Window));
|
||||
}
|
||||
painter->fillRect(r, colors[i]);
|
||||
} else if (option.state & QStyle::State_Selected) {
|
||||
painter->setPen(option.palette.color(QPalette::HighlightedText));
|
||||
}
|
||||
painter->drawText(r, Qt::AlignCenter, toHex(byte_list[i]));
|
||||
}
|
||||
painter->setFont(old_font);
|
||||
painter->setPen(old_pen);
|
||||
}
|
||||
|
||||
QColor getColor(const cabana::Signal *sig) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QApplication>
|
||||
#include <QByteArray>
|
||||
#include <QDateTime>
|
||||
@@ -66,6 +67,7 @@ public:
|
||||
MessageBytesDelegate(QObject *parent, bool multiple_lines = false);
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override;
|
||||
void setMultipleLines(bool v);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user