mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
cabana: display signal details in tooltip (#28471)
* show details in tooltip * display tooltip in signalView * cleanup * setHeader before sortByColumn * more compact tooltip * move to util old-commit-hash: 9632451d1d6a726d389a91bd47261c0acda1a6ae
This commit is contained in:
@@ -127,15 +127,6 @@ void BinaryView::highlight(const cabana::Signal *sig) {
|
||||
}
|
||||
}
|
||||
|
||||
if (sig && underMouse()) {
|
||||
QString tooltip = tr(R"(%1<br /><span style="color:gray;font-size:small">
|
||||
Size:%2 LE:%3 SGD:%4</span>
|
||||
)").arg(sig->name).arg(sig->size).arg(sig->is_little_endian ? "Y" : "N").arg(sig->is_signed ? "Y" : "N");
|
||||
QToolTip::showText(QCursor::pos(), tooltip, this, rect());
|
||||
} else {
|
||||
QToolTip::showText(QCursor::pos(), "", this, rect());
|
||||
}
|
||||
|
||||
hovered_sig = sig;
|
||||
emit signalHovered(hovered_sig);
|
||||
}
|
||||
@@ -349,6 +340,16 @@ QVariant BinaryViewModel::headerData(int section, Qt::Orientation orientation, i
|
||||
return {};
|
||||
}
|
||||
|
||||
QVariant BinaryViewModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::ToolTipRole) {
|
||||
auto item = (const BinaryViewModel::Item *)index.internalPointer();
|
||||
if (item && !item->sigs.empty()) {
|
||||
return signalToolTip(item->sigs.back());
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// BinaryItemDelegate
|
||||
|
||||
BinaryItemDelegate::BinaryItemDelegate(QObject *parent) : QStyledItemDelegate(parent) {
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
void updateState();
|
||||
void updateItem(int row, int col, const QString &val, const QColor &color);
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { return {}; }
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override { return row_count; }
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return column_count; }
|
||||
inline QModelIndex bitIndex(int bit, bool is_lb) const { return index(bit / 8, is_lb ? (7 - bit % 8) : bit % 8); }
|
||||
|
||||
@@ -33,6 +33,7 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
view->setItemDelegate(delegate);
|
||||
view->setModel(model);
|
||||
view->setHeader(header);
|
||||
view->setSortingEnabled(true);
|
||||
view->sortByColumn(MessageListModel::Column::NAME, Qt::AscendingOrder);
|
||||
view->setAllColumnsShowFocus(true);
|
||||
@@ -40,7 +41,6 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
view->setItemsExpandable(false);
|
||||
view->setIndentation(0);
|
||||
view->setRootIsDecorated(false);
|
||||
view->setHeader(header);
|
||||
|
||||
// Must be called before setting any header parameters to avoid overriding
|
||||
restoreHeaderState(settings.message_header_state);
|
||||
|
||||
@@ -146,7 +146,7 @@ QVariant SignalModel::data(const QModelIndex &index, int role) const {
|
||||
} else if (role == Qt::DecorationRole && index.column() == 0 && item->type == Item::ExtraInfo) {
|
||||
return utils::icon(item->parent->extra_expanded ? "chevron-compact-down" : "chevron-compact-up");
|
||||
} else if (role == Qt::ToolTipRole && item->type == Item::Sig) {
|
||||
return (index.column() == 0) ? item->sig->name : item->sig_val;
|
||||
return (index.column() == 0) ? signalToolTip(item->sig) : QString();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
@@ -300,20 +300,6 @@ QSize SignalItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
|
||||
return {width, QApplication::fontMetrics().height()};
|
||||
}
|
||||
|
||||
bool SignalItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) {
|
||||
if (event && event->type() == QEvent::ToolTip && index.isValid()) {
|
||||
auto item = (SignalModel::Item *)index.internalPointer();
|
||||
if (item->type == SignalModel::Item::Sig && index.column() == 1) {
|
||||
QRect rc = option.rect.adjusted(0, 0, -option.rect.width() * 0.4, 0);
|
||||
if (rc.contains(event->pos())) {
|
||||
event->setAccepted(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QStyledItemDelegate::helpEvent(event, view, option, index);
|
||||
}
|
||||
|
||||
void SignalItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
auto item = (SignalModel::Item *)index.internalPointer();
|
||||
if (editor && item->type == SignalModel::Item::Sig && index.column() == 1) {
|
||||
|
||||
@@ -85,7 +85,6 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) override;
|
||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
QValidator *name_validator, *double_validator;
|
||||
|
||||
@@ -230,3 +230,13 @@ int num_decimals(double num) {
|
||||
auto dot_pos = string.indexOf('.');
|
||||
return dot_pos == -1 ? 0 : string.size() - dot_pos - 1;
|
||||
}
|
||||
|
||||
QString signalToolTip(const cabana::Signal *sig) {
|
||||
return QObject::tr(R"(
|
||||
%1<br /><span font-size:small">
|
||||
Start Bit: %2 Size: %3<br />
|
||||
MSB: %4 LSB: %5<br />
|
||||
Little Endian: %6 Signed: %7</span>
|
||||
)").arg(sig->name).arg(sig->start_bit).arg(sig->size).arg(sig->msb).arg(sig->lsb)
|
||||
.arg(sig->is_little_endian ? "Y" : "N").arg(sig->is_signed ? "Y" : "N");
|
||||
}
|
||||
|
||||
@@ -136,3 +136,4 @@ private:
|
||||
};
|
||||
|
||||
int num_decimals(double num);
|
||||
QString signalToolTip(const cabana::Signal *sig);
|
||||
|
||||
Reference in New Issue
Block a user