Qt: Update ByteView recent settings on all tabs

The ByteView recent settings are common for all tabs. Ensure all
tabs are updated when display format or character encoding is changed.

This fixes an issue where the row_width is wrong and the menu action
checkmarks are out of sync after switching ByteView tab.

Change-Id: Ied25ac41467143f37327ccadcb821262eb86ef0a
Reviewed-on: https://code.wireshark.org/review/37655
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
This commit is contained in:
Stig Bjørlykke 2020-07-01 22:35:42 +02:00
parent 0c5b81c641
commit b8a330d2d5
4 changed files with 70 additions and 36 deletions

View File

@ -114,6 +114,8 @@ void ByteViewTab::addTab(const char *name, tvbuff_t *tvb) {
connect(byte_view_text, SIGNAL(byteHovered(int)), this, SLOT(byteViewTextHovered(int)));
connect(byte_view_text, SIGNAL(byteSelected(int)), this, SLOT(byteViewTextMarked(int)));
connect(byte_view_text, SIGNAL(byteViewSettingsChanged()), this, SIGNAL(byteViewSettingsChanged()));
connect(this, SIGNAL(byteViewSettingsChanged()), byte_view_text, SLOT(updateByteViewSettings()));
}
int idx = QTabWidget::addTab(byte_view_text, name);

View File

@ -45,6 +45,7 @@ public slots:
signals:
void fieldSelected(FieldInformation *);
void fieldHighlight(FieldInformation *);
void byteViewSettingsChanged(void);
private:
capture_file *cap_file_;

View File

@ -76,25 +76,18 @@ ByteViewText::~ByteViewText()
void ByteViewText::createContextMenu()
{
QAction *action;
QActionGroup * copy_actions = DataPrinter::copyActions(this);
ctx_menu_.addActions(copy_actions->actions());
ctx_menu_.addSeparator();
QActionGroup * format_actions = new QActionGroup(this);
action = format_actions->addAction(tr("Show bytes as hexadecimal"));
action->setData(QVariant::fromValue(BYTES_HEX));
action->setCheckable(true);
if (recent.gui_bytes_view == BYTES_HEX) {
action->setChecked(true);
}
action = format_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as bits"));
action->setData(QVariant::fromValue(BYTES_BITS));
action->setCheckable(true);
if (recent.gui_bytes_view == BYTES_BITS) {
action->setChecked(true);
}
action_bytes_hex_ = format_actions->addAction(tr("Show bytes as hexadecimal"));
action_bytes_hex_->setData(QVariant::fromValue(BYTES_HEX));
action_bytes_hex_->setCheckable(true);
action_bytes_bits_ = format_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as bits"));
action_bytes_bits_->setData(QVariant::fromValue(BYTES_BITS));
action_bytes_bits_->setCheckable(true);
ctx_menu_.addActions(format_actions->actions());
connect(format_actions, &QActionGroup::triggered, this, &ByteViewText::setHexDisplayFormat);
@ -102,29 +95,48 @@ void ByteViewText::createContextMenu()
ctx_menu_.addSeparator();
QActionGroup * encoding_actions = new QActionGroup(this);
action = encoding_actions->addAction(tr("Show text based on packet"));
action->setData(QVariant::fromValue(BYTES_ENC_FROM_PACKET));
action->setCheckable(true);
if (recent.gui_bytes_encoding == BYTES_ENC_FROM_PACKET) {
action->setChecked(true);
}
action = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as ASCII"));
action->setData(QVariant::fromValue(BYTES_ENC_ASCII));
action->setCheckable(true);
if (recent.gui_bytes_encoding == BYTES_ENC_ASCII) {
action->setChecked(true);
}
action = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as EBCDIC"));
action->setData(QVariant::fromValue(BYTES_ENC_EBCDIC));
action->setCheckable(true);
if (recent.gui_bytes_encoding == BYTES_ENC_EBCDIC) {
action->setChecked(true);
}
action_bytes_enc_from_packet_ = encoding_actions->addAction(tr("Show text based on packet"));
action_bytes_enc_from_packet_->setData(QVariant::fromValue(BYTES_ENC_FROM_PACKET));
action_bytes_enc_from_packet_->setCheckable(true);
action_bytes_enc_ascii_ = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as ASCII"));
action_bytes_enc_ascii_->setData(QVariant::fromValue(BYTES_ENC_ASCII));
action_bytes_enc_ascii_->setCheckable(true);
action_bytes_enc_ebcdic_ = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as EBCDIC"));
action_bytes_enc_ebcdic_->setData(QVariant::fromValue(BYTES_ENC_EBCDIC));
action_bytes_enc_ebcdic_->setCheckable(true);
updateContextMenu();
ctx_menu_.addActions(encoding_actions->actions());
connect(encoding_actions, &QActionGroup::triggered, this, &ByteViewText::setCharacterEncoding);
}
void ByteViewText::updateContextMenu()
{
switch (recent.gui_bytes_view) {
case BYTES_HEX:
action_bytes_hex_->setChecked(true);
break;
case BYTES_BITS:
action_bytes_bits_->setChecked(true);
break;
}
switch (recent.gui_bytes_encoding) {
case BYTES_ENC_FROM_PACKET:
action_bytes_enc_from_packet_->setChecked(true);
break;
case BYTES_ENC_ASCII:
action_bytes_enc_ascii_->setChecked(true);
break;
case BYTES_ENC_EBCDIC:
action_bytes_enc_ebcdic_->setChecked(true);
break;
}
}
bool ByteViewText::isEmpty() const
{
return data_.isEmpty();
@ -182,6 +194,15 @@ void ByteViewText::setMonospaceFont(const QFont &mono_font)
viewport()->update();
}
void ByteViewText::updateByteViewSettings()
{
row_width_ = recent.gui_bytes_view == BYTES_HEX ? 16 : 8;
updateContextMenu();
updateScrollbars();
viewport()->update();
}
void ByteViewText::paintEvent(QPaintEvent *)
{
QPainter painter(viewport());
@ -659,9 +680,8 @@ void ByteViewText::setHexDisplayFormat(QAction *action)
}
recent.gui_bytes_view = action->data().value<bytes_view_type>();
row_width_ = recent.gui_bytes_view == BYTES_HEX ? 16 : 8;
updateScrollbars();
viewport()->update();
emit byteViewSettingsChanged();
}
void ByteViewText::setCharacterEncoding(QAction *action)
@ -671,7 +691,8 @@ void ByteViewText::setCharacterEncoding(QAction *action)
}
recent.gui_bytes_encoding = action->data().value<bytes_encoding_type>();
viewport()->update();
emit byteViewSettingsChanged();
}
/*

View File

@ -45,9 +45,11 @@ public:
signals:
void byteHovered(int pos);
void byteSelected(int pos);
void byteViewSettingsChanged();
public slots:
void setMonospaceFont(const QFont &mono_font);
void updateByteViewSettings();
void markProtocol(int start, int length);
void markField(int start, int length, bool scroll_to = true);
@ -84,6 +86,7 @@ private:
int byteOffsetAtPixel(QPoint pos);
void createContextMenu();
void updateContextMenu();
int offsetChars(bool include_pad = true);
int offsetPixels();
@ -123,6 +126,13 @@ private:
// Data selection
QVector<int> x_pos_to_column_;
// Context menu actions
QAction *action_bytes_hex_;
QAction *action_bytes_bits_;
QAction *action_bytes_enc_from_packet_;
QAction *action_bytes_enc_ascii_;
QAction *action_bytes_enc_ebcdic_;
private slots:
void copyBytes(bool);
void setHexDisplayFormat(QAction *action);