cabana: fix displaying zero length messages (#27953)

pull/27955/head
Willem Melching 2 years ago committed by GitHub
parent 97aeb83f95
commit 9c88c3fe4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      tools/cabana/util.cc
  2. 2
      tools/cabana/util.h

@ -65,9 +65,9 @@ QSize MessageBytesDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
return {1, byte_size.height() + 2 * v_margin}; return {1, byte_size.height() + 2 * v_margin};
} }
int n = data.toByteArray().size(); int n = data.toByteArray().size();
assert(n > 0 && n <= 64); assert(n >= 0 && n <= 64);
QSize size = size_cache[n - 1]; QSize size = size_cache[n];
if (size.isEmpty()) { if (size.isEmpty()) {
if (!multiple_lines) { if (!multiple_lines) {
size.setWidth(widthForBytes(n)); size.setWidth(widthForBytes(n));
@ -76,7 +76,7 @@ QSize MessageBytesDelegate::sizeHint(const QStyleOptionViewItem &option, const Q
size.setWidth(widthForBytes(8)); size.setWidth(widthForBytes(8));
size.setHeight(byte_size.height() * std::max(1, n / 8) + 2 * v_margin); size.setHeight(byte_size.height() * std::max(1, n / 8) + 2 * v_margin);
} }
size_cache[n - 1] = size; size_cache[n] = size;
} }
return size; return size;
} }

@ -76,7 +76,7 @@ private:
QFont fixed_font; QFont fixed_font;
QSize byte_size = {}; QSize byte_size = {};
bool multiple_lines = false; bool multiple_lines = false;
mutable QSize size_cache[64] = {}; mutable QSize size_cache[65] = {};
}; };
inline QString toHex(const QByteArray &dat) { return dat.toHex(' ').toUpper(); } inline QString toHex(const QByteArray &dat) { return dat.toHex(' ').toUpper(); }

Loading…
Cancel
Save