Handle double-clicks in the tree.

svn path=/trunk/; revision=44592
This commit is contained in:
Gerald Combs 2012-08-19 23:52:08 +00:00
parent 7e924beee9
commit 44cb77d8de
5 changed files with 69 additions and 26 deletions

View File

@ -23,12 +23,16 @@
*/
#ifndef FTYPES_H
#define FTYPES_H
#ifndef __FTYPES_H__
#define __FTYPES_H__
#include <glib.h>
#include "../emem.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* field types */
enum ftenum {
FT_NONE, /* used for text labels with no value */
@ -369,4 +373,8 @@ fvalue_length(fvalue_t *fv);
fvalue_t*
fvalue_slice(fvalue_t *fv, drange *dr);
#endif /* ftypes.h */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __FTYPES_H__ */

View File

@ -250,26 +250,28 @@ PacketList::PacketList(QWidget *parent) :
setUniformRowHeights(TRUE);
setAccessibleName("Packet list");
m_packet_list_model = new PacketListModel(this, &cfile);
setModel(m_packet_list_model);
packet_list_model_ = new PacketListModel(this, &cfile);
setModel(packet_list_model_);
g_assert(cur_packet_list == NULL);
cur_packet_list = this;
m_protoTree = NULL;
m_byteViewTab = NULL;
proto_tree_ = NULL;
byte_view_tab_ = NULL;
}
void PacketList::setProtoTree (ProtoTree *protoTree) {
m_protoTree = protoTree;
proto_tree_ = protoTree;
connect(proto_tree_, SIGNAL(goToFrame(int)), this, SLOT(goToPacket(int)));
}
void PacketList::setByteViewTab (ByteViewTab *byteViewTab) {
m_byteViewTab = byteViewTab;
byte_view_tab_ = byteViewTab;
}
PacketListModel *PacketList::packetListModel() const {
return m_packet_list_model;
return packet_list_model_;
}
void PacketList::showEvent (QShowEvent *event) {
@ -293,7 +295,7 @@ void PacketList::showEvent (QShowEvent *event) {
void PacketList::selectionChanged (const QItemSelection & selected, const QItemSelection & deselected) {
QTreeView::selectionChanged(selected, deselected);
if (m_protoTree) {
if (proto_tree_) {
int row = selected.first().top();
cf_select_packet(&cfile, row);
@ -301,39 +303,39 @@ void PacketList::selectionChanged (const QItemSelection & selected, const QItemS
return;
}
m_protoTree->fillProtocolTree(cfile.edt->tree);
proto_tree_->fillProtocolTree(cfile.edt->tree);
}
if (m_byteViewTab && cfile.edt) {
if (byte_view_tab_ && cfile.edt) {
GSList *src_le;
data_source *source;
// Clear out existing tabs
while (m_byteViewTab->currentWidget()) {
delete m_byteViewTab->currentWidget();
while (byte_view_tab_->currentWidget()) {
delete byte_view_tab_->currentWidget();
}
for (src_le = cfile.edt->pi.data_src; src_le != NULL; src_le = src_le->next) {
source = (data_source *)src_le->data;
m_byteViewTab->addTab(get_data_source_name(source), source->tvb, cfile.edt->tree, m_protoTree, cfile.current_frame->flags.encoding);
byte_view_tab_->addTab(get_data_source_name(source), source->tvb, cfile.edt->tree, proto_tree_, cfile.current_frame->flags.encoding);
}
}
if (m_protoTree && m_byteViewTab) {
if (proto_tree_ && byte_view_tab_) {
// Connect signals between the proto tree and byte views.
connect(m_protoTree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
m_byteViewTab, SLOT(protoTreeItemChanged(QTreeWidgetItem*)));
connect(proto_tree_, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
byte_view_tab_, SLOT(protoTreeItemChanged(QTreeWidgetItem*)));
}
}
void PacketList::clear() {
// packet_history_clear();
packetListModel()->clear();
m_protoTree->clear();
proto_tree_->clear();
// Clear out existing tabs
while (m_byteViewTab->currentWidget()) {
delete m_byteViewTab->currentWidget();
while (byte_view_tab_->currentWidget()) {
delete byte_view_tab_->currentWidget();
}
// /* XXX is this correct in all cases?
@ -396,3 +398,7 @@ void PacketList::goFirstPacket(void) {
void PacketList::goLastPacket(void) {
setCurrentIndex(moveCursor(MoveEnd, Qt::NoModifier));
}
void PacketList::goToPacket(int packet) {
setCurrentIndex(packet_list_model_->index(packet, 0));
}

View File

@ -48,9 +48,9 @@ protected:
void selectionChanged (const QItemSelection & selected, const QItemSelection & deselected);
private:
PacketListModel *m_packet_list_model;
ProtoTree *m_protoTree;
ByteViewTab *m_byteViewTab;
PacketListModel *packet_list_model_;
ProtoTree *proto_tree_;
ByteViewTab *byte_view_tab_;
signals:
@ -59,7 +59,7 @@ public slots:
void goPreviousPacket();
void goFirstPacket();
void goLastPacket();
void goToPacket(int packet);
};
#endif // PACKET_LIST_H

View File

@ -26,11 +26,14 @@
#include "proto_tree.h"
#include "monospace_font.h"
#include <epan/ftypes/ftypes.h>
#include <epan/prefs.h>
#include <QApplication>
#include <QHeaderView>
#include <QTreeWidgetItemIterator>
#include <QDesktopServices>
#include <QUrl>
QColor expert_color_chat ( 0x80, 0xb7, 0xf7 ); /* light blue */
QColor expert_color_note ( 0xa0, 0xff, 0xff ); /* bright turquoise */
@ -152,6 +155,8 @@ ProtoTree::ProtoTree(QWidget *parent) :
this, SLOT(updateSelectionStatus(QTreeWidgetItem*)));
connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expand(QModelIndex)));
connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(collapse(QModelIndex)));
connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
this, SLOT(itemDoubleClick(QTreeWidgetItem*, int)));
}
void ProtoTree::clear() {
@ -313,3 +318,25 @@ void ProtoTree::collapseAll()
}
QTreeWidget::collapseAll();
}
void ProtoTree::itemDoubleClick(QTreeWidgetItem *item, int column) {
Q_UNUSED(column);
gchar *url;
field_info *fi;
fi = item->data(0, Qt::UserRole).value<field_info *>();
if(fi->hfinfo->type == FT_FRAMENUM) {
emit goToFrame(fi->value.value.uinteger - 1);
}
if(FI_GET_FLAG(fi, FI_URL) && IS_FT_STRING(fi->hfinfo->type)) {
url = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, NULL);
if(url){
// browser_open_url(url);
QDesktopServices::openUrl(QUrl(url));
g_free(url);
}
}
}

View File

@ -45,6 +45,7 @@ private:
signals:
void protoItemSelected(QString &);
void protoItemSelected(bool);
void goToFrame(int);
public slots:
void updateSelectionStatus(QTreeWidgetItem*);
@ -53,6 +54,7 @@ public slots:
void expandSubtrees();
void expandAll();
void collapseAll();
void itemDoubleClick(QTreeWidgetItem *item, int column);
};
#endif // PROTO_TREE_H