diff options
-rw-r--r-- | ui/qt/byte_view_tab.cpp | 11 | ||||
-rw-r--r-- | ui/qt/byte_view_tab.h | 1 | ||||
-rw-r--r-- | ui/qt/byte_view_text.cpp | 29 | ||||
-rw-r--r-- | ui/qt/byte_view_text.h | 2 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 12 | ||||
-rw-r--r-- | ui/qt/proto_tree.cpp | 30 |
6 files changed, 50 insertions, 35 deletions
diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index 8b60b0d7fa..b152ebea6a 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -33,6 +33,7 @@ ByteViewTab::ByteViewTab(QWidget *parent) : addTab(); } +#include <QDebug> void ByteViewTab::addTab(const char *name, tvbuff_t *tvb, proto_tree *tree, QTreeWidget *protoTree, packet_char_enc encoding) { ByteViewText *byte_view_text = new ByteViewText(this, tvb, tree, protoTree, encoding); @@ -40,6 +41,13 @@ void ByteViewTab::addTab(const char *name, tvbuff_t *tvb, proto_tree *tree, QTre QTabWidget::addTab(byte_view_text, name); } +void ByteViewTab::clear() +{ + while (currentWidget()) { + delete currentWidget(); + } +} + void ByteViewTab::tabInserted(int index) { setTabsVisible(); QTabWidget::tabInserted(index); @@ -75,7 +83,6 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) { int p_start = -1, p_end = -1, p_len = -1; guint len = tvb_length(fi->ds_tvb); -// byte_view_text->setEncoding(cap_file_->current_frame->flags.encoding); // Find and highlight the protocol bytes while (parent && parent->parent()) { parent = parent->parent(); @@ -157,7 +164,7 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) { // Appendix (trailer) bytes byte_view_text->setFieldAppendixHighlight(fa_start, fa_end); - byte_view_text->render(); + byte_view_text->renderBytes(); setCurrentIndex(i); } diff --git a/ui/qt/byte_view_tab.h b/ui/qt/byte_view_tab.h index c06102e5fe..10f3ac378e 100644 --- a/ui/qt/byte_view_tab.h +++ b/ui/qt/byte_view_tab.h @@ -41,6 +41,7 @@ class ByteViewTab : public QTabWidget public: explicit ByteViewTab(QWidget *parent = 0); void addTab(const char *name = "", tvbuff_t *tvb = NULL, proto_tree *tree = NULL, QTreeWidget *protoTree = NULL, packet_char_enc encoding = PACKET_CHAR_ENC_CHAR_ASCII); + void clear(); private: void setTabsVisible(); diff --git a/ui/qt/byte_view_text.cpp b/ui/qt/byte_view_text.cpp index c90a6e6a0a..7f21da3ebb 100644 --- a/ui/qt/byte_view_text.cpp +++ b/ui/qt/byte_view_text.cpp @@ -41,12 +41,20 @@ ByteViewText::ByteViewText(QWidget *parent, tvbuff_t *tvb, proto_tree *tree, QTr bold_highlight_(false), encoding_(encoding), format_(BYTES_HEX), + p_start_(-1), + p_end_(-1), + f_start_(-1), + f_end_(-1), + fa_start_(-1), + fa_end_(-1), per_line_(16), offset_width_(4) { setReadOnly(true); setLineWrapMode(QTextEdit::NoWrap); setState(StateNormal); + + renderBytes(); } void ByteViewText::setEncoding(packet_char_enc encoding) @@ -80,15 +88,18 @@ void ByteViewText::setFieldAppendixHighlight(int start, int end) fa_end_ = end; } -void ByteViewText::render() +void ByteViewText::renderBytes() { int length; + int start_byte = 0; if (!tvb_) { clear(); return; } + setUpdatesEnabled(false); + textCursor().beginEditBlock(); clear(); @@ -96,14 +107,16 @@ void ByteViewText::render() for (int off = 0; off < length; off += per_line_) { lineCommon(off); } + textCursor().endEditBlock(); - if (f_start_ != -1 && f_end_ != -1) { - scrollToByte(f_start_); - } else if (p_start_ != -1 && p_end_ != -1) { - scrollToByte(p_start_); + if (f_start_ > 0 && f_end_ > 0) { + start_byte = f_start_; + } else if (p_start_ > 0 && p_end_ > 0) { + start_byte = p_start_; } + scrollToByte(start_byte); - textCursor().endEditBlock(); + setUpdatesEnabled(true); } // Private @@ -303,9 +316,9 @@ void ByteViewText::scrollToByte(int byte) { QTextCursor cursor(textCursor()); - cursor.movePosition(QTextCursor::Start); - cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, byte / per_line_); + cursor.setPosition(byte * (per_line_ + 1)); // Newline setTextCursor(cursor); + ensureCursorVisible(); } int ByteViewText::byteFromRowCol(int row, int col) diff --git a/ui/qt/byte_view_text.h b/ui/qt/byte_view_text.h index 76d7124e04..dbd13baefe 100644 --- a/ui/qt/byte_view_text.h +++ b/ui/qt/byte_view_text.h @@ -53,7 +53,7 @@ public: void setProtocolHighlight(int start, int end); void setFieldHighlight(int start, int end, guint32 mask = 0, int mask_le = 0); void setFieldAppendixHighlight(int start, int end); - void render(); + void renderBytes(); private: typedef enum { diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 932033da42..4aa064011b 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -287,15 +287,13 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS GSList *src_le; struct data_source *source; - // Clear out existing tabs - while (byte_view_tab_->currentWidget()) { - delete byte_view_tab_->currentWidget(); - } + byte_view_tab_->clear(); for (src_le = cap_file_->edt->pi.data_src; src_le != NULL; src_le = src_le->next) { source = (struct data_source *)src_le->data; byte_view_tab_->addTab(get_data_source_name(source), get_data_source_tvb(source), cap_file_->edt->tree, proto_tree_, cap_file_->current_frame->flags.encoding); } + byte_view_tab_->setCurrentIndex(0); } if (proto_tree_ && byte_view_tab_) { @@ -318,11 +316,7 @@ void PacketList::clear() { // packet_history_clear(); packet_list_model_->clear(); proto_tree_->clear(); - - // Clear out existing tabs - while (byte_view_tab_->currentWidget()) { - delete byte_view_tab_->currentWidget(); - } + byte_view_tab_->clear(); /* XXX is this correct in all cases? * Reset the sort column, use packetlist as model in case the list is frozen. diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index 180c87c8d6..e115ea5fbb 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -178,31 +178,31 @@ void ProtoTree::updateSelectionStatus(QTreeWidgetItem* item) { if (item) { field_info *fi; - QString itemInfo; + QString item_info; fi = item->data(0, Qt::UserRole).value<field_info *>(); if (!fi || !fi->hfinfo) return; if (fi->hfinfo->blurb != NULL && fi->hfinfo->blurb[0] != '\0') { - itemInfo.append(QString().fromUtf8(fi->hfinfo->blurb)); + item_info.append(QString().fromUtf8(fi->hfinfo->blurb)); } else { - itemInfo.append(QString().fromUtf8(fi->hfinfo->name)); + item_info.append(QString().fromUtf8(fi->hfinfo->name)); } - if (!itemInfo.isEmpty()) { + if (!item_info.isEmpty()) { int finfo_length; - itemInfo.append(" (" + QString().fromUtf8(fi->hfinfo->abbrev) + ")"); + item_info.append(" (" + QString().fromUtf8(fi->hfinfo->abbrev) + ")"); finfo_length = fi->length + fi->appendix_length; if (finfo_length == 1) { - itemInfo.append(tr(", 1 byte")); + item_info.append(tr(", 1 byte")); } else if (finfo_length > 1) { - itemInfo.append(QString(tr(", %1 bytes")).arg(finfo_length)); + item_info.append(QString(tr(", %1 bytes")).arg(finfo_length)); } emit protoItemSelected(*new QString()); emit protoItemSelected(NULL); - emit protoItemSelected(itemInfo); + emit protoItemSelected(item_info); emit protoItemSelected(fi); } // else the GTK+ version pushes an empty string as described below. /* @@ -277,25 +277,25 @@ void ProtoTree::collapse(const QModelIndex & index) { void ProtoTree::expandSubtrees() { - QTreeWidgetItem *topSel; + QTreeWidgetItem *top_sel; if (selectedItems().length() < 1) { return; } - topSel = selectedItems()[0]; + top_sel = selectedItems()[0]; - if (!topSel) { + if (!top_sel) { return; } - while (topSel->parent()) { - topSel = topSel->parent(); + while (top_sel->parent()) { + top_sel = top_sel->parent(); } - QTreeWidgetItemIterator iter(topSel); + QTreeWidgetItemIterator iter(top_sel); while (*iter) { - if ((*iter) != topSel && (*iter)->parent() == NULL) { + if ((*iter) != top_sel && (*iter)->parent() == NULL) { // We found the next top-level item break; } |