summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2017-01-11 13:55:23 +0100
committerRoland Knall <rknall@gmail.com>2017-01-12 16:04:00 +0000
commit3df81a055064e2e2c8c9548f1c6837ddef5e5034 (patch)
tree484d3a1e56679668e657ddb29fe6aa6a9d964cdf /ui
parentd6d516888122a26d477dcaa39a52fc9cd8b24479 (diff)
downloadwireshark-3df81a055064e2e2c8c9548f1c6837ddef5e5034.tar.gz
Qt: Remove unneccessary Q_DECLARE_METATYPE
Remove unnecessary Q_DECLARE_METATYPE macros and replace calls to QVariant conversions with VariantPointer where necessary Change-Id: Ia4690590095f930bf94644197de7fa30b00ee7ec Reviewed-on: https://code.wireshark.org/review/19611 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/bluetooth_device_dialog.cpp23
-rw-r--r--ui/qt/bluetooth_device_dialog.h7
-rw-r--r--ui/qt/bluetooth_devices_dialog.cpp21
-rw-r--r--ui/qt/bluetooth_hci_summary_dialog.cpp44
-rw-r--r--ui/qt/byte_view_tab.cpp6
-rw-r--r--ui/qt/byte_view_text.cpp4
-rw-r--r--ui/qt/conversation_dialog.h2
-rw-r--r--ui/qt/decode_as_dialog.cpp8
-rw-r--r--ui/qt/display_filter_expression_dialog.cpp8
-rw-r--r--ui/qt/endpoint_dialog.h2
-rw-r--r--ui/qt/extcap_argument.h3
-rw-r--r--ui/qt/extcap_options_dialog.cpp9
-rw-r--r--ui/qt/file_set_dialog.cpp8
-rw-r--r--ui/qt/io_graph_dialog.cpp27
-rw-r--r--ui/qt/main_window.cpp4
-rw-r--r--ui/qt/main_window.h3
-rw-r--r--ui/qt/main_window_slots.cpp20
-rw-r--r--ui/qt/module_preferences_scroll_area.cpp58
-rw-r--r--ui/qt/preferences_dialog.cpp29
-rw-r--r--ui/qt/profile_dialog.cpp22
-rw-r--r--ui/qt/proto_tree.cpp24
-rw-r--r--ui/qt/proto_tree.h2
-rw-r--r--ui/qt/protocol_hierarchy_dialog.cpp9
-rw-r--r--ui/qt/rtp_player_dialog.cpp3
-rw-r--r--ui/qt/sparkline_delegate.h2
-rw-r--r--ui/qt/stats_tree_dialog.cpp12
-rw-r--r--ui/qt/variant_pointer.h46
-rw-r--r--ui/qt/voip_calls_dialog.cpp2
-rw-r--r--ui/qt/wireless_frame.cpp1
29 files changed, 223 insertions, 186 deletions
diff --git a/ui/qt/bluetooth_device_dialog.cpp b/ui/qt/bluetooth_device_dialog.cpp
index 5bcf31bfd7..a858520a37 100644
--- a/ui/qt/bluetooth_device_dialog.cpp
+++ b/ui/qt/bluetooth_device_dialog.cpp
@@ -34,6 +34,8 @@
#include "ui/simple_dialog.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QClipboard>
#include <QContextMenuEvent>
#include <QPushButton>
@@ -66,15 +68,6 @@ static const int row_number_page_timeout = 19;
static const int row_number_simple_pairing_mode = 20;
static const int row_number_voice_setting = 21;
-typedef struct _item_data_t {
- guint32 interface_id;
- guint32 adapter_id;
- guint32 frame_number;
- gint changes;
-} item_data_t;
-
-Q_DECLARE_METATYPE(item_data_t *)
-
static gboolean
bluetooth_device_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data)
{
@@ -351,7 +344,7 @@ void BluetoothDeviceDialog::tapReset(void *tapinfo_ptr)
void BluetoothDeviceDialog::updateChanges(QTableWidget *tableWidget, QString value, const int row, guint *changes, packet_info *pinfo)
{
QTableWidgetItem *item = tableWidget->item(row, column_number_value);
- item_data_t *item_data = item->data(Qt::UserRole).value<item_data_t *>();
+ bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(Qt::UserRole));
if (item->text() == value)
return;
@@ -372,12 +365,12 @@ void BluetoothDeviceDialog::saveItemData(QTableWidgetItem *item,
if (item->data(Qt::UserRole).isValid())
return;
- item_data_t *item_data = wmem_new(wmem_file_scope(), item_data_t);
+ bluetooth_item_data_t *item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_device->interface_id;
item_data->adapter_id = tap_device->adapter_id;
item_data->changes = -1;
item_data->frame_number = pinfo->fd->num;
- item->setData(Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ item->setData(Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
}
@@ -455,12 +448,12 @@ gboolean BluetoothDeviceDialog::tapPacket(void *tapinfo_ptr, packet_info *pinfo,
case BLUETOOTH_DEVICE_RESET:
for (int i_row = 0; i_row < dialog->ui->tableWidget->rowCount(); i_row += 1) {
QTableWidgetItem *item;
- item_data_t *item_data;
+ bluetooth_item_data_t *item_data;
item = dialog->ui->tableWidget->item(i_row, column_number_value);
saveItemData(item, tap_device, pinfo);
- item_data = item->data(Qt::UserRole).value<item_data_t *>();
+ item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(Qt::UserRole));
if (item_data->changes > -1) {
item_data->changes += 1;
@@ -661,7 +654,7 @@ void BluetoothDeviceDialog::on_tableWidget_itemActivated(QTableWidgetItem *item)
if (!item->data(Qt::UserRole).isValid())
return;
- item_data_t *item_data = item->data(Qt::UserRole).value<item_data_t *>();
+ bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(Qt::UserRole));
emit goToPacket(item_data->frame_number);
diff --git a/ui/qt/bluetooth_device_dialog.h b/ui/qt/bluetooth_device_dialog.h
index d5e0898608..1993705ccb 100644
--- a/ui/qt/bluetooth_device_dialog.h
+++ b/ui/qt/bluetooth_device_dialog.h
@@ -51,6 +51,13 @@ typedef struct _bluetooth_device_tapinfo_t {
guint *changes;
} bluetooth_device_tapinfo_t;
+typedef struct _bluetooth_item_data_t {
+ guint32 interface_id;
+ guint32 adapter_id;
+ guint32 frame_number;
+ gint changes;
+} bluetooth_item_data_t;
+
namespace Ui {
class BluetoothDeviceDialog;
}
diff --git a/ui/qt/bluetooth_devices_dialog.cpp b/ui/qt/bluetooth_devices_dialog.cpp
index 0940938916..49607867a4 100644
--- a/ui/qt/bluetooth_devices_dialog.cpp
+++ b/ui/qt/bluetooth_devices_dialog.cpp
@@ -34,6 +34,8 @@
#include "epan/dissectors/packet-bluetooth.h"
#include "epan/dissectors/packet-bthci_evt.h"
+#include <ui/qt/variant_pointer.h>
+
#include "ui/simple_dialog.h"
#include <QClipboard>
@@ -52,13 +54,6 @@ static const int column_number_hci_version = 6;
static const int column_number_hci_revision = 7;
static const int column_number_is_local_adapter = 8;
-typedef struct _item_data_t {
- guint32 interface_id;
- guint32 adapter_id;
- guint32 frame_number;
-} item_data_t;
-
-Q_DECLARE_METATYPE(item_data_t *)
static gboolean
bluetooth_device_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data)
@@ -171,10 +166,10 @@ void BluetoothDevicesDialog::tableContextMenu(const QPoint &pos)
void BluetoothDevicesDialog::tableItemDoubleClicked(QTreeWidgetItem *item, int column _U_)
{
- item_data_t *item_data;
+ bluetooth_item_data_t *item_data;
BluetoothDeviceDialog *bluetooth_device_dialog;
- item_data = item->data(0, Qt::UserRole).value<item_data_t *>();
+ item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(0, Qt::UserRole));
bluetooth_device_dialog = new BluetoothDeviceDialog(*this, cap_file_, item->text(column_number_bd_addr), item->text(column_number_name), item_data->interface_id, item_data->adapter_id, !item->text(column_number_is_local_adapter).isEmpty());
connect(bluetooth_device_dialog, SIGNAL(goToPacket(int)),
packet_list_, SLOT(goToPacket(int)));
@@ -324,7 +319,7 @@ gboolean BluetoothDevicesDialog::tapPacket(void *tapinfo_ptr, packet_info *pinfo
while (*i_item) {
QTreeWidgetItem *current_item = static_cast<QTreeWidgetItem*>(*i_item);
- item_data_t *item_data = current_item->data(0, Qt::UserRole).value<item_data_t *>();
+ bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(current_item->data(0, Qt::UserRole));
if ((tap_device->has_bd_addr && current_item->text(column_number_bd_addr) == bd_addr) ||
(tap_device->is_local &&
@@ -346,11 +341,11 @@ gboolean BluetoothDevicesDialog::tapPacket(void *tapinfo_ptr, packet_info *pinfo
item->setText(column_number_is_local_adapter, tr("true"));
}
- item_data_t *item_data = wmem_new(wmem_file_scope(), item_data_t);
+ bluetooth_item_data_t *item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_device->interface_id;
item_data->adapter_id = tap_device->adapter_id;
item_data->frame_number = pinfo->num;
- item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
}
if (tap_device->type == BLUETOOTH_DEVICE_BD_ADDR) {
@@ -402,7 +397,7 @@ void BluetoothDevicesDialog::on_tableTreeWidget_itemActivated(QTreeWidgetItem *i
if (file_closed_)
return;
- item_data_t *item_data = item->data(0, Qt::UserRole).value<item_data_t *>();
+ bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(0, Qt::UserRole));
emit goToPacket(item_data->frame_number);
diff --git a/ui/qt/bluetooth_hci_summary_dialog.cpp b/ui/qt/bluetooth_hci_summary_dialog.cpp
index 886df89d6d..04aa81738d 100644
--- a/ui/qt/bluetooth_hci_summary_dialog.cpp
+++ b/ui/qt/bluetooth_hci_summary_dialog.cpp
@@ -22,6 +22,8 @@
#include "bluetooth_hci_summary_dialog.h"
#include <ui_bluetooth_hci_summary_dialog.h>
+#include "bluetooth_device_dialog.h"
+
#include "color_utils.h"
#include "epan/epan.h"
@@ -33,6 +35,8 @@
#include "epan/dissectors/packet-bthci_cmd.h"
#include "epan/dissectors/packet-bthci_evt.h"
+#include <ui/qt/variant_pointer.h>
+
#include "ui/simple_dialog.h"
#include <QClipboard>
@@ -52,14 +56,6 @@ static const int column_number_reason = 7;
static const int column_number_hardware_error = 8;
static const int column_number_occurrence = 9;
-typedef struct _item_data_t {
- guint32 interface_id;
- guint32 adapter_id;
- guint32 frame_number;
-} item_data_t;
-
-Q_DECLARE_METATYPE(item_data_t *)
-
static gboolean
bluetooth_hci_summary_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data)
{
@@ -355,7 +351,7 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
QTreeWidgetItem *item = NULL;
QTreeWidgetItem *frame_item = NULL;
QTreeWidgetItem *meta_item = NULL;
- item_data_t *item_data = NULL;
+ bluetooth_item_data_t *item_data = NULL;
QString adapter;
QString name;
@@ -476,11 +472,11 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_event, QString("").sprintf("0x%02X", tap_hci->event));
item->addChild(frame_item);
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
break;
case BLUETOOTH_HCI_SUMMARY_EVENT:
@@ -544,11 +540,11 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_event, QString("").sprintf("0x%02X", tap_hci->event));
item->addChild(frame_item);
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
break;
case BLUETOOTH_HCI_SUMMARY_SUBEVENT:
@@ -595,12 +591,12 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_event, QString("").sprintf("0x%02X", tap_hci->event));
frame_item->setText(column_number_subevent, QString("").sprintf("0x%02X", tap_hci->subevent));
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
item->addChild(frame_item);
@@ -657,11 +653,11 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_status, QString("").sprintf("0x%02X", tap_hci->status));
item->addChild(frame_item);
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
break;
case BLUETOOTH_HCI_SUMMARY_STATUS_PENDING:
@@ -691,11 +687,11 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_status, QString("").sprintf("%u", tap_hci->status));
item->addChild(frame_item);
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
break;
case BLUETOOTH_HCI_SUMMARY_REASON:
@@ -728,11 +724,11 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_reason, QString("").sprintf("0x%02X", tap_hci->reason));
item->addChild(frame_item);
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
break;
case BLUETOOTH_HCI_SUMMARY_HARDWARE_ERROR:
@@ -762,11 +758,11 @@ gboolean BluetoothHciSummaryDialog::tapPacket(void *tapinfo_ptr, packet_info *pi
frame_item->setText(column_number_hardware_error, QString("").sprintf("0x%02X", tap_hci->hardware_error));
item->addChild(frame_item);
- item_data = wmem_new(wmem_file_scope(), item_data_t);
+ item_data = wmem_new(wmem_file_scope(), bluetooth_item_data_t);
item_data->interface_id = tap_hci->interface_id;
item_data->adapter_id = tap_hci->adapter_id;
item_data->frame_number = pinfo->num;
- frame_item->setData(0, Qt::UserRole, QVariant::fromValue<item_data_t *>(item_data));
+ frame_item->setData(0, Qt::UserRole, VariantPointer<bluetooth_item_data_t>::asQVariant(item_data));
break;
}
@@ -793,7 +789,7 @@ void BluetoothHciSummaryDialog::on_tableTreeWidget_itemActivated(QTreeWidgetItem
if (file_closed_)
return;
- item_data_t *item_data = item->data(0, Qt::UserRole).value<item_data_t *>();
+ bluetooth_item_data_t *item_data = VariantPointer<bluetooth_item_data_t>::asPtr(item->data(0, Qt::UserRole));
if (item_data)
emit goToPacket(item_data->frame_number);
diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp
index 4ec3d88a43..8dffe1fb62 100644
--- a/ui/qt/byte_view_tab.cpp
+++ b/ui/qt/byte_view_tab.cpp
@@ -28,6 +28,8 @@
#include <QTabBar>
#include <QTreeWidgetItem>
+#include <ui/qt/variant_pointer.h>
+
// To do:
// - We might want to add a callback to free_data_sources in so that we
// don't have to blindly call clear().
@@ -273,7 +275,7 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) {
if (current && cap_file_) {
field_info *fi;
- fi = current->data(0, Qt::UserRole).value<field_info *>();
+ fi = VariantPointer<field_info>::asPtr(current->data(0, Qt::UserRole));
int i = 0;
ByteViewText *byte_view_text = qobject_cast<ByteViewText*>(widget(i));
@@ -291,7 +293,7 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) {
parent = parent->parent();
}
if (parent) {
- parent_fi = parent->data(0, Qt::UserRole).value<field_info *>();
+ parent_fi = VariantPointer<field_info>::asPtr(parent->data(0, Qt::UserRole));
}
if (parent_fi && parent_fi->ds_tvb == fi->ds_tvb) {
p_start = parent_fi->start;
diff --git a/ui/qt/byte_view_text.cpp b/ui/qt/byte_view_text.cpp
index e812a1c046..71aefc4904 100644
--- a/ui/qt/byte_view_text.cpp
+++ b/ui/qt/byte_view_text.cpp
@@ -32,6 +32,8 @@
#include "wireshark_application.h"
#include "ui/recent.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QActionGroup>
#include <QMouseEvent>
#include <QPainter>
@@ -258,7 +260,7 @@ void ByteViewText::mousePressEvent (QMouseEvent *event) {
// XXX - This should probably be a ProtoTree method.
QTreeWidgetItemIterator iter(tree_widget_);
while (*iter) {
- if (fi == (*iter)->data(0, Qt::UserRole).value<field_info *>()) {
+ if (fi == VariantPointer<field_info>::asPtr((*iter)->data(0, Qt::UserRole))) {
tree_widget_->setCurrentItem((*iter));
tree_widget_->scrollToItem((*iter));
}
diff --git a/ui/qt/conversation_dialog.h b/ui/qt/conversation_dialog.h
index 718619ad0f..8ea25f7f3b 100644
--- a/ui/qt/conversation_dialog.h
+++ b/ui/qt/conversation_dialog.h
@@ -24,8 +24,6 @@
#include "traffic_table_dialog.h"
-Q_DECLARE_METATYPE(conv_item_t *)
-
class ConversationTreeWidget : public TrafficTableTreeWidget
{
Q_OBJECT
diff --git a/ui/qt/decode_as_dialog.cpp b/ui/qt/decode_as_dialog.cpp
index f371b97aff..67e9cbb1c2 100644
--- a/ui/qt/decode_as_dialog.cpp
+++ b/ui/qt/decode_as_dialog.cpp
@@ -35,6 +35,8 @@
#include "qt_ui_utils.h"
#include "wireshark_application.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QComboBox>
#include <QFont>
#include <QFontMetrics>
@@ -335,7 +337,7 @@ void DecodeAsDialog::buildChangedList(const gchar *table_name, ftenum_t, gpointe
dissector_info_t *dissector_info = new dissector_info_t();
dissector_info->proto_name = current_proto_name;
dissector_info->dissector_handle = current_dh;
- item->setData(proto_col_, Qt::UserRole, QVariant::fromValue<dissector_info_t *>(dissector_info));
+ item->setData(proto_col_, Qt::UserRole, VariantPointer<dissector_info_t>::asQVariant(dissector_info));
da_dlg->ui->decodeAsTreeWidget->addTopLevelItem(item);
}
@@ -496,7 +498,7 @@ void DecodeAsDialog::tableNamesCurrentIndexChanged(const QString &text)
while (i.hasNext()) {
dissector_info_t *dissector_info = i.next();
- cur_proto_combo_box_->addItem(dissector_info->proto_name, QVariant::fromValue<dissector_info_t *>(dissector_info));
+ cur_proto_combo_box_->addItem(dissector_info->proto_name, VariantPointer<dissector_info_t>::asQVariant(dissector_info));
}
cur_proto_combo_box_->model()->sort(0);
@@ -595,7 +597,7 @@ void DecodeAsDialog::applyChanges()
continue;
}
- dissector_info = variant.value<dissector_info_t *>();
+ dissector_info = VariantPointer<dissector_info_t>::asPtr(variant);
for (GList *cur = decode_as_list; cur; cur = cur->next) {
decode_as_entry = (decode_as_t *) cur->data;
diff --git a/ui/qt/display_filter_expression_dialog.cpp b/ui/qt/display_filter_expression_dialog.cpp
index e6afdbc80a..b7dd784d1b 100644
--- a/ui/qt/display_filter_expression_dialog.cpp
+++ b/ui/qt/display_filter_expression_dialog.cpp
@@ -34,6 +34,8 @@
#include "qt_ui_utils.h"
#include "wireshark_application.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QPushButton>
#include <QDialogButtonBox>
#include <QListWidgetItem>
@@ -60,8 +62,6 @@ enum {
matches_op_
};
-Q_DECLARE_METATYPE(header_field_info *)
-
DisplayFilterExpressionDialog::DisplayFilterExpressionDialog(QWidget *parent) :
GeometryStateDialog(parent),
ui(new Ui::DisplayFilterExpressionDialog),
@@ -148,7 +148,7 @@ void DisplayFilterExpressionDialog::fillTree()
QTreeWidgetItem *field_ti = new QTreeWidgetItem(field_type_);
QString label = QString("%1 " UTF8_MIDDLE_DOT " %3").arg(hfinfo->abbrev).arg(hfinfo->name);
field_ti->setText(0, label);
- field_ti->setData(0, Qt::UserRole, qVariantFromValue(hfinfo));
+ field_ti->setData(0, Qt::UserRole, VariantPointer<header_field_info>::asQVariant(hfinfo));
field_list << field_ti;
field_count++;
@@ -294,7 +294,7 @@ void DisplayFilterExpressionDialog::on_fieldTreeWidget_itemSelectionChanged()
ftype_ = FT_PROTOCOL;
field_ = proto_get_protocol_filter_name(cur_fti->data(0, Qt::UserRole).toInt());
} else if (cur_fti && cur_fti->type() == field_type_) {
- header_field_info *hfinfo = cur_fti->data(0, Qt::UserRole).value<header_field_info*>();
+ header_field_info *hfinfo = VariantPointer<header_field_info>::asPtr(cur_fti->data(0, Qt::UserRole));
if (hfinfo) {
ftype_ = hfinfo->type;
field_ = hfinfo->abbrev;
diff --git a/ui/qt/endpoint_dialog.h b/ui/qt/endpoint_dialog.h
index fdf2f22d74..97c737fb19 100644
--- a/ui/qt/endpoint_dialog.h
+++ b/ui/qt/endpoint_dialog.h
@@ -24,8 +24,6 @@
#include "traffic_table_dialog.h"
-Q_DECLARE_METATYPE(hostlist_talker_t *)
-
class EndpointTreeWidget : public TrafficTableTreeWidget
{
Q_OBJECT
diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h
index 851fcfb009..6a8ad281c2 100644
--- a/ui/qt/extcap_argument.h
+++ b/ui/qt/extcap_argument.h
@@ -131,9 +131,6 @@ private Q_SLOTS:
};
-Q_DECLARE_METATYPE(ExtcapArgument)
-Q_DECLARE_METATYPE(ExtcapArgument *)
-
class ExtArgText : public ExtcapArgument
{
diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp
index 43a82bfc59..56f82fb7ab 100644
--- a/ui/qt/extcap_options_dialog.cpp
+++ b/ui/qt/extcap_options_dialog.cpp
@@ -60,6 +60,7 @@
#include <ui/preference_utils.h>
#include <ui/qt/wireshark_application.h>
+#include <ui/qt/variant_pointer.h>
#include <ui/qt/extcap_argument.h>
#include <ui/qt/extcap_argument_file.h>
@@ -278,7 +279,7 @@ void ExtcapOptionsDialog::updateWidgets()
editWidget = argument->createEditor((QWidget *) this);
if ( editWidget != NULL )
{
- editWidget->setProperty(QString("extcap").toLocal8Bit(), QVariant::fromValue(argument));
+ editWidget->setProperty(QString("extcap").toLocal8Bit(), VariantPointer<ExtcapArgument>::asQVariant(argument));
layout->addWidget(editWidget, counter, 1, Qt::AlignVCenter);
}
@@ -415,9 +416,9 @@ void ExtcapOptionsDialog::resetValues()
ExtcapArgument * arg = 0;
QVariant prop = child->property(QString("extcap").toLocal8Bit());
- if ( prop.isValid() && prop.canConvert<ExtcapArgument *>())
+ if ( prop.isValid() )
{
- arg = prop.value<ExtcapArgument *>();
+ arg = VariantPointer<ExtcapArgument>::asPtr(prop);
/* value<> can fail */
if (arg)
@@ -429,7 +430,7 @@ void ExtcapOptionsDialog::resetValues()
QWidget * editWidget = arg->createEditor((QWidget *) this);
if ( editWidget != NULL )
{
- editWidget->setProperty(QString("extcap").toLocal8Bit(), QVariant::fromValue(arg));
+ editWidget->setProperty(QString("extcap").toLocal8Bit(), VariantPointer<ExtcapArgument>::asQVariant(arg));
layout->addWidget(editWidget, row, 1, Qt::AlignVCenter);
}
}
diff --git a/ui/qt/file_set_dialog.cpp b/ui/qt/file_set_dialog.cpp
index f62f8ce8c9..64c79ceae4 100644
--- a/ui/qt/file_set_dialog.cpp
+++ b/ui/qt/file_set_dialog.cpp
@@ -28,6 +28,8 @@
#include "ui/help_url.h"
+#include <ui/qt/variant_pointer.h>
+
#include <wsutil/str_util.h>
#include "file_set_dialog.h"
@@ -42,8 +44,6 @@
#include <QTreeWidgetItem>
#include <QUrl>
-Q_DECLARE_METATYPE(fileset_entry *)
-
/* this file is a part of the current file set, add it to the dialog */
void
fileset_dlg_add_file(fileset_entry *entry, void *window) {
@@ -124,7 +124,7 @@ void FileSetDialog::addFile(fileset_entry *entry) {
entry_item = new QTreeWidgetItem(fs_ui_->fileSetTree);
entry_item->setToolTip(0, QString(tr("Open this capture file")));
- entry_item->setData(0, Qt::UserRole, qVariantFromValue(entry));
+ entry_item->setData(0, Qt::UserRole, VariantPointer<fileset_entry>::asQVariant(entry));
entry_item->setText(0, entry->name);
entry_item->setText(1, created);
@@ -184,7 +184,7 @@ void FileSetDialog::on_fileSetTree_currentItemChanged(QTreeWidgetItem *current,
if (!current)
return;
- entry = current->data(0, Qt::UserRole).value<fileset_entry *>();
+ entry = VariantPointer<fileset_entry>::asPtr(current->data(0, Qt::UserRole));
if (!entry || entry->current)
return;
diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp
index a70c358f5c..5899eb60f3 100644
--- a/ui/qt/io_graph_dialog.cpp
+++ b/ui/qt/io_graph_dialog.cpp
@@ -32,6 +32,8 @@
#include "qt_ui_utils.h"
+#include <ui/qt/variant_pointer.h>
+
#include "color_utils.h"
#include "qcustomplot.h"
#include "progress_frame.h"
@@ -167,9 +169,6 @@ static void io_graph_free_cb(void* p) {
} // extern "C"
-
-Q_DECLARE_METATYPE(IOGraph *)
-
IOGraphDialog::IOGraphDialog(QWidget &parent, CaptureFile &cf) :
WiresharkDialog(parent, cf),
ui(new Ui::IOGraphDialog),
@@ -326,7 +325,7 @@ IOGraphDialog::~IOGraphDialog()
{
cap_file_.stopLoading();
for (int i = 0; i < ui->graphTreeWidget->topLevelItemCount(); i++) {
- IOGraph *iog = qvariant_cast<IOGraph *>(ui->graphTreeWidget->topLevelItem(i)->data(name_col_, Qt::UserRole));
+ IOGraph *iog = VariantPointer<IOGraph>::asPtr(ui->graphTreeWidget->topLevelItem(i)->data(name_col_, Qt::UserRole));
delete iog;
}
delete ui;
@@ -339,7 +338,7 @@ void IOGraphDialog::addGraph(bool checked, QString name, QString dfilter, int co
ui->graphTreeWidget->addTopLevelItem(ti);
IOGraph *iog = new IOGraph(ui->ioPlot);
- ti->setData(name_col_, Qt::UserRole, qVariantFromValue(iog));
+ ti->setData(name_col_, Qt::UserRole, VariantPointer<IOGraph>::asQVariant(iog));
ti->setCheckState(name_col_, checked ? Qt::Checked : Qt::Unchecked);
ti->setText(name_col_, name);
ti->setText(dfilter_col_, dfilter);
@@ -408,7 +407,7 @@ void IOGraphDialog::addDefaultGraph(bool enabled, int idx)
void IOGraphDialog::syncGraphSettings(QTreeWidgetItem *item)
{
if (!item) return;
- IOGraph *iog = item->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ IOGraph *iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
if (!iog) return;
bool visible = item->checkState(name_col_) == Qt::Checked;
@@ -583,7 +582,7 @@ void IOGraphDialog::reject()
QTreeWidgetItem *item = ui->graphTreeWidget->topLevelItem(i);
IOGraph *iog = NULL;
if (item) {
- iog = item->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
io_graph_settings_t iogs;
QColor color(iog->color());
iogs.enabled = iog->visible() ? 1 : 0;
@@ -721,7 +720,7 @@ void IOGraphDialog::getGraphInfo()
QTreeWidgetItem *item = ui->graphTreeWidget->topLevelItem(i);
IOGraph *iog = NULL;
if (item) {
- iog = item->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
QCPGraph *graph = iog->graph();
QCPBars *bars = iog->bars();
int style = item->data(style_col_, Qt::UserRole).toInt();
@@ -760,7 +759,7 @@ void IOGraphDialog::updateLegend()
QTreeWidgetItem *ti = ui->graphTreeWidget->topLevelItem(i);
IOGraph *iog = NULL;
if (ti && ti->checkState(name_col_) == Qt::Checked) {
- iog = ti->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ iog = VariantPointer<IOGraph>::asPtr(ti->data(name_col_, Qt::UserRole));
vu_label_set.insert(iog->valueUnitLabel());
}
}
@@ -790,7 +789,7 @@ void IOGraphDialog::updateLegend()
QTreeWidgetItem *ti = ui->graphTreeWidget->topLevelItem(i);
IOGraph *iog = NULL;
if (ti) {
- iog = ti->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ iog = VariantPointer<IOGraph>::asPtr(ti->data(name_col_, Qt::UserRole));
if (ti->checkState(name_col_) == Qt::Checked) {
iog->addToLegend();
} else {
@@ -888,7 +887,7 @@ void IOGraphDialog::mouseMoved(QMouseEvent *event)
QTreeWidgetItem *ti = ui->graphTreeWidget->topLevelItem(0);
IOGraph *iog = NULL;
if (ti) {
- iog = ti->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ iog = VariantPointer<IOGraph>::asPtr(ti->data(name_col_, Qt::UserRole));
interval_packet = iog->packetFromTime(ts);
}
}
@@ -1181,7 +1180,7 @@ void IOGraphDialog::on_intervalComboBox_currentIndexChanged(int)
QTreeWidgetItem *item = ui->graphTreeWidget->topLevelItem(i);
IOGraph *iog = NULL;
if (item) {
- iog = item->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
if (iog) {
iog->setInterval(interval);
if (iog->visible()) {
@@ -1399,7 +1398,7 @@ void IOGraphDialog::on_deleteToolButton_clicked()
QTreeWidgetItem *item = ui->graphTreeWidget->currentItem();
if (!item) return;
- IOGraph *iog = qvariant_cast<IOGraph *>(item->data(name_col_, Qt::UserRole));
+ IOGraph *iog = VariantPointer<IOGraph>::asPtr(item->data(name_col_, Qt::UserRole));
delete iog;
delete item;
@@ -1600,7 +1599,7 @@ void IOGraphDialog::makeCsv(QTextStream &stream) const
for (int i = 0; i < ui->graphTreeWidget->topLevelItemCount(); i++) {
QTreeWidgetItem *ti = ui->graphTreeWidget->topLevelItem(i);
if (ti && ti->checkState(name_col_) == Qt::Checked) {
- IOGraph *iog = ti->data(name_col_, Qt::UserRole).value<IOGraph *>();
+ IOGraph *iog = VariantPointer<IOGraph>::asPtr(ti->data(name_col_, Qt::UserRole));
activeGraphs.append(iog);
if (max_interval < iog->maxInterval()) {
max_interval = iog->maxInterval();
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index c2cba0c6f1..4f53d81ada 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -1795,8 +1795,6 @@ void MainWindow::initShowHideMainWidgets()
connect(show_hide_actions_, SIGNAL(triggered(QAction*)), this, SLOT(showHideMainWidgets(QAction*)));
}
-Q_DECLARE_METATYPE(ts_type)
-
void MainWindow::initTimeDisplayFormatMenu()
{
if (time_display_actions_) {
@@ -1824,8 +1822,6 @@ void MainWindow::initTimeDisplayFormatMenu()
connect(time_display_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setTimestampFormat(QAction*)));
}
-Q_DECLARE_METATYPE(ts_precision)
-
void MainWindow::initTimePrecisionFormatMenu()
{
if (time_precision_actions_) {
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index a020befe12..440476a85e 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -75,6 +75,9 @@ namespace Ui {
class MainWindow;
}
+Q_DECLARE_METATYPE(ts_type)
+Q_DECLARE_METATYPE(ts_precision)
+
class MainWindow : public QMainWindow
{
Q_OBJECT
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index b1e6526248..4ae7dbe88c 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -78,6 +78,8 @@
#include "ui/all_files_wildcard.h"
#include "ui/qt/simple_dialog.h"
+#include <ui/qt/variant_pointer.h>
+
#ifdef HAVE_SOFTWARE_UPDATE
#include "ui/software_update.h"
#endif
@@ -2185,8 +2187,6 @@ void MainWindow::showHideMainWidgets(QAction *action)
}
}
-Q_DECLARE_METATYPE(ts_type)
-
void MainWindow::setTimestampFormat(QAction *action)
{
if (!action) {
@@ -2207,8 +2207,6 @@ void MainWindow::setTimestampFormat(QAction *action)
}
}
-Q_DECLARE_METATYPE(ts_precision)
-
void MainWindow::setTimestampPrecision(QAction *action)
{
if (!action) {
@@ -3733,14 +3731,12 @@ void MainWindow::showExtcapOptionsDialog(QString &device_name)
}
#endif
-// Q_DECLARE_METATYPE(field_info *) called in proto_tree.h
-
void MainWindow::on_actionContextCopyBytesHexTextDump_triggered()
{
QAction *ca = qobject_cast<QAction*>(sender());
if (!ca) return;
- field_info *fi = ca->data().value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(ca->data());
byte_view_tab_->copyData(ByteViewTab::copyDataHexTextDump, fi);
}
@@ -3750,7 +3746,7 @@ void MainWindow::on_actionContextCopyBytesHexDump_triggered()
QAction *ca = qobject_cast<QAction*>(sender());
if (!ca) return;
- field_info *fi = ca->data().value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(ca->data());
byte_view_tab_->copyData(ByteViewTab::copyDataHexDump, fi);
}
@@ -3760,7 +3756,7 @@ void MainWindow::on_actionContextCopyBytesPrintableText_triggered()
QAction *ca = qobject_cast<QAction*>(sender());
if (!ca) return;
- field_info *fi = ca->data().value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(ca->data());
byte_view_tab_->copyData(ByteViewTab::copyDataPrintableText, fi);
}
@@ -3770,7 +3766,7 @@ void MainWindow::on_actionContextCopyBytesHexStream_triggered()
QAction *ca = qobject_cast<QAction*>(sender());
if (!ca) return;
- field_info *fi = ca->data().value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(ca->data());
byte_view_tab_->copyData(ByteViewTab::copyDataHexStream, fi);
}
@@ -3780,7 +3776,7 @@ void MainWindow::on_actionContextCopyBytesBinary_triggered()
QAction *ca = qobject_cast<QAction*>(sender());
if (!ca) return;
- field_info *fi = ca->data().value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(ca->data());
byte_view_tab_->copyData(ByteViewTab::copyDataBinary, fi);
}
@@ -3790,7 +3786,7 @@ void MainWindow::on_actionContextCopyBytesEscapedString_triggered()
QAction *ca = qobject_cast<QAction*>(sender());
if (!ca) return;
- field_info *fi = ca->data().value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(ca->data());
byte_view_tab_->copyData(ByteViewTab::copyDataEscapedString, fi);
}
diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp
index d9387ca1d3..06b87334b8 100644
--- a/ui/qt/module_preferences_scroll_area.cpp
+++ b/ui/qt/module_preferences_scroll_area.cpp
@@ -26,6 +26,8 @@
#include "uat_dialog.h"
#include "wireshark_application.h"
+#include <ui/qt/variant_pointer.h>
+
#include <epan/prefs-int.h>
#include <wsutil/utf8_entities.h>
@@ -43,8 +45,6 @@
#include <QScrollBar>
#include <QSpacerItem>
-Q_DECLARE_METATYPE(pref_t *)
-
const char *pref_prop_ = "pref_ptr";
// Escape our ampersands so that Qt won't try to interpret them as
@@ -82,7 +82,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
hb->addWidget(label);
QLineEdit *uint_le = new QLineEdit();
uint_le->setToolTip(tooltip);
- uint_le->setProperty(pref_prop_, qVariantFromValue(pref));
+ uint_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
uint_le->setMinimumWidth(uint_le->fontMetrics().height() * 8);
hb->addWidget(uint_le);
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
@@ -93,7 +93,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
{
QCheckBox *bool_cb = new QCheckBox(title_to_shortcut(pref->title));
bool_cb->setToolTip(tooltip);
- bool_cb->setProperty(pref_prop_, qVariantFromValue(pref));
+ bool_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
vb->addWidget(bool_cb);
break;
}
@@ -111,7 +111,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
QRadioButton *enum_rb = new QRadioButton(title_to_shortcut(ev->description));
enum_rb->setToolTip(tooltip);
QStyleOption style_opt;
- enum_rb->setProperty(pref_prop_, qVariantFromValue(pref));
+ enum_rb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
enum_rb->setStyleSheet(QString(
"QRadioButton {"
" margin-left: %1px;"
@@ -125,7 +125,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
QHBoxLayout *hb = new QHBoxLayout();
QComboBox *enum_cb = new QComboBox();
enum_cb->setToolTip(tooltip);
- enum_cb->setProperty(pref_prop_, qVariantFromValue(pref));
+ enum_cb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
for (ev = pref->info.enum_info.enumvals; ev && ev->description; ev++) {
enum_cb->addItem(ev->description, QVariant(ev->value));
}
@@ -144,7 +144,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
hb->addWidget(label);
QLineEdit *string_le = new QLineEdit();
string_le->setToolTip(tooltip);
- string_le->setProperty(pref_prop_, qVariantFromValue(pref));
+ string_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
string_le->setMinimumWidth(string_le->fontMetrics().height() * 20);
hb->addWidget(string_le);
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
@@ -160,7 +160,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
hb->addWidget(label);
SyntaxLineEdit *range_se = new SyntaxLineEdit();
range_se->setToolTip(tooltip);
- range_se->setProperty(pref_prop_, qVariantFromValue(pref));
+ range_se->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
range_se->setMinimumWidth(range_se->fontMetrics().height() * 20);
hb->addWidget(range_se);
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
@@ -183,7 +183,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
hb->addWidget(label);
QPushButton *uat_pb = new QPushButton(QObject::tr("Edit" UTF8_HORIZONTAL_ELLIPSIS));
uat_pb->setToolTip(tooltip);
- uat_pb->setProperty(pref_prop_, qVariantFromValue(pref));
+ uat_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
hb->addWidget(uat_pb);
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
vb->addLayout(hb);
@@ -199,7 +199,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
QLineEdit *path_le = new QLineEdit();
path_le->setToolTip(tooltip);
QStyleOption style_opt;
- path_le->setProperty(pref_prop_, qVariantFromValue(pref));
+ path_le->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
path_le->setMinimumWidth(path_le->fontMetrics().height() * 20);
path_le->setStyleSheet(QString(
"QLineEdit {"
@@ -209,7 +209,7 @@ pref_show(pref_t *pref, gpointer layout_ptr)
.arg(path_le->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()));
hb->addWidget(path_le);
QPushButton *path_pb = new QPushButton(QObject::tr("Browse" UTF8_HORIZONTAL_ELLIPSIS));
- path_pb->setProperty(pref_prop_, qVariantFromValue(pref));
+ path_pb->setProperty(pref_prop_, VariantPointer<pref_t>::asQVariant(pref));
hb->addWidget(path_pb);
hb->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
vb->addLayout(hb);
@@ -249,7 +249,7 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
prefs_pref_foreach(module, pref_show, (gpointer) ui->verticalLayout);
foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
- pref_t *pref = le->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_));
if (!pref) continue;
switch (pref->type) {
@@ -274,7 +274,7 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
}
foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
- pref_t *pref = cb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(cb->property(pref_prop_));
if (!pref) continue;
if (pref->type == PREF_BOOL) {
@@ -283,7 +283,7 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
}
foreach (QRadioButton *rb, findChildren<QRadioButton *>()) {
- pref_t *pref = rb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(rb->property(pref_prop_));
if (!pref) continue;
if (pref->type == PREF_ENUM && pref->info.enum_info.radio_buttons) {
@@ -292,7 +292,7 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
}
foreach (QComboBox *combo, findChildren<QComboBox *>()) {
- pref_t *pref = combo->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(combo->property(pref_prop_));
if (!pref) continue;
if (pref->type == PREF_ENUM && !pref->info.enum_info.radio_buttons) {
@@ -301,7 +301,7 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
}
foreach (QPushButton *pb, findChildren<QPushButton *>()) {
- pref_t *pref = pb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(pb->property(pref_prop_));
if (!pref) continue;
if (pref->type == PREF_UAT) {
@@ -340,14 +340,14 @@ void ModulePreferencesScrollArea::resizeEvent(QResizeEvent *evt)
void ModulePreferencesScrollArea::updateWidgets()
{
foreach (QLineEdit *le, findChildren<QLineEdit *>()) {
- pref_t *pref = le->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_));
if (!pref) continue;
le->setText(gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)).remove(QRegExp("\n\t")));
}
foreach (QCheckBox *cb, findChildren<QCheckBox *>()) {
- pref_t *pref = cb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(cb->property(pref_prop_));
if (!pref) continue;
if (pref->type == PREF_BOOL) {
@@ -356,7 +356,7 @@ void ModulePreferencesScrollArea::updateWidgets()
}
foreach (QRadioButton *enum_rb, findChildren<QRadioButton *>()) {
- pref_t *pref = enum_rb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(enum_rb->property(pref_prop_));
if (!pref) continue;
QButtonGroup *enum_bg = enum_rb->group();
@@ -370,7 +370,7 @@ void ModulePreferencesScrollArea::updateWidgets()
}
foreach (QComboBox *enum_cb, findChildren<QComboBox *>()) {
- pref_t *pref = enum_cb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
if (!pref) continue;
if (pref->type == PREF_ENUM && !pref->info.enum_info.radio_buttons) {
@@ -388,7 +388,7 @@ void ModulePreferencesScrollArea::uintLineEditTextEdited(const QString &new_str)
QLineEdit *uint_le = qobject_cast<QLineEdit*>(sender());
if (!uint_le) return;
- pref_t *pref = uint_le->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(uint_le->property(pref_prop_));
if (!pref) return;
bool ok;
@@ -403,7 +403,7 @@ void ModulePreferencesScrollArea::boolCheckBoxToggled(bool checked)
QCheckBox *bool_cb = qobject_cast<QCheckBox*>(sender());
if (!bool_cb) return;
- pref_t *pref = bool_cb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(bool_cb->property(pref_prop_));
if (!pref) return;
pref->stashed_val.boolval = checked;
@@ -418,7 +418,7 @@ void ModulePreferencesScrollArea::enumRadioButtonToggled(bool checked)
QButtonGroup *enum_bg = enum_rb->group();
if (!enum_bg) return;
- pref_t *pref = enum_rb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(enum_rb->property(pref_prop_));
if (!pref) return;
if (enum_bg->checkedId() >= 0) {
@@ -431,7 +431,7 @@ void ModulePreferencesScrollArea::enumComboBoxCurrentIndexChanged(int index)
QComboBox *enum_cb = qobject_cast<QComboBox*>(sender());
if (!enum_cb) return;
- pref_t *pref = enum_cb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(enum_cb->property(pref_prop_));
if (!pref) return;
pref->stashed_val.enumval = enum_cb->itemData(index).toInt();
@@ -442,7 +442,7 @@ void ModulePreferencesScrollArea::stringLineEditTextEdited(const QString &new_st
QLineEdit *string_le = qobject_cast<QLineEdit*>(sender());
if (!string_le) return;
- pref_t *pref = string_le->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(string_le->property(pref_prop_));
if (!pref) return;
g_free((void *)pref->stashed_val.string);
@@ -454,7 +454,7 @@ void ModulePreferencesScrollArea::rangeSyntaxLineEditTextEdited(const QString &n
SyntaxLineEdit *range_se = qobject_cast<SyntaxLineEdit*>(sender());
if (!range_se) return;
- pref_t *pref = range_se->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(range_se->property(pref_prop_));
if (!pref) return;
if (prefs_set_stashed_range_value(pref, new_str.toUtf8().constData())) {
@@ -473,7 +473,7 @@ void ModulePreferencesScrollArea::uatPushButtonPressed()
QPushButton *uat_pb = qobject_cast<QPushButton*>(sender());
if (!uat_pb) return;
- pref_t *pref = uat_pb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(uat_pb->property(pref_prop_));
if (!pref) return;
UatDialog uat_dlg(this, pref->varp.uat);
@@ -485,7 +485,7 @@ void ModulePreferencesScrollArea::filenamePushButtonPressed()
QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
if (!filename_pb) return;
- pref_t *pref = filename_pb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(filename_pb->property(pref_prop_));
if (!pref) return;
QString filename = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(pref->title),
@@ -504,7 +504,7 @@ void ModulePreferencesScrollArea::dirnamePushButtonPressed()
QPushButton *dirname_pb = qobject_cast<QPushButton*>(sender());
if (!dirname_pb) return;
- pref_t *pref = dirname_pb->property(pref_prop_).value<pref_t *>();
+ pref_t *pref = VariantPointer<pref_t>::asPtr(dirname_pb->property(pref_prop_));
if (!pref) return;
QString dirname = QFileDialog::getExistingDirectory(this, wsApp->windowTitleString(pref->title),
diff --git a/ui/qt/preferences_dialog.cpp b/ui/qt/preferences_dialog.cpp
index eb805073cb..70c83b68d3 100644
--- a/ui/qt/preferences_dialog.cpp
+++ b/ui/qt/preferences_dialog.cpp
@@ -42,6 +42,8 @@
#include "uat_dialog.h"
#include "wireshark_application.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QColorDialog>
#include <QComboBox>
#include <QFileDialog>
@@ -53,15 +55,24 @@
#include <QSpacerItem>
#include <QTreeWidgetItemIterator>
-Q_DECLARE_METATYPE(ModulePreferencesScrollArea *)
-Q_DECLARE_METATYPE(pref_t *)
-Q_DECLARE_METATYPE(QStackedWidget *)
-
// XXX Should we move this to ui/preference_utils?
-static QHash<void *, pref_t *> pref_ptr_to_pref_;
+static GHashTable * pref_ptr_to_pref_ = NULL;
pref_t *prefFromPrefPtr(void *pref_ptr)
{
- return pref_ptr_to_pref_[pref_ptr];
+ return (pref_t *)g_hash_table_lookup(pref_ptr_to_pref_, (gpointer) pref_ptr);
+}
+
+static void prefInsertPrefPtr(void * pref_ptr, pref_t * pref)
+{
+ if ( ! pref_ptr_to_pref_ )
+ pref_ptr_to_pref_ = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
+
+ gpointer key = (gpointer) pref_ptr;
+ gpointer val = (gpointer) pref;
+
+ /* Already existing entries will be ignored */
+ if ( (pref = (pref_t *)g_hash_table_lookup(pref_ptr_to_pref_, key) ) == NULL )
+ g_hash_table_insert(pref_ptr_to_pref_, key, val);
}
enum {
@@ -244,7 +255,7 @@ fill_advanced_prefs(module_t *module, gpointer root_ptr)
// .uat is a void * so it wins the "useful key value" prize.
if (pref->varp.uat) {
- pref_ptr_to_pref_[pref->varp.uat] = pref;
+ prefInsertPrefPtr(pref->varp.uat, pref);
}
}
tl_item->addChildren(tl_children);
@@ -268,7 +279,7 @@ fill_module_prefs(module_t *module, gpointer ti_ptr)
if (!item) return 0;
- QStackedWidget *stacked_widget = item->data(0, stacked_role_).value<QStackedWidget *>();
+ QStackedWidget *stacked_widget = VariantPointer<QStackedWidget>::asPtr(item->data(0, stacked_role_));
if (!stacked_widget) return 0;
@@ -434,7 +445,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) :
while (tmp_item.childCount() > 0) {
tmp_item.removeChild(tmp_item.child(0));
}
- tmp_item.setData(0, stacked_role_, qVariantFromValue(pd_ui_->stackedWidget));
+ tmp_item.setData(0, stacked_role_, VariantPointer<QStackedWidget>::asQVariant(pd_ui_->stackedWidget));
prefs_modules_foreach_submodules(NULL, fill_module_prefs, (gpointer) &tmp_item);
pd_ui_->prefsTree->invisibleRootItem()->insertChildren(
pd_ui_->prefsTree->invisibleRootItem()->childCount() - 1, tmp_item.takeChildren());
diff --git a/ui/qt/profile_dialog.cpp b/ui/qt/profile_dialog.cpp
index b189a7a4bf..486fad3fb3 100644
--- a/ui/qt/profile_dialog.cpp
+++ b/ui/qt/profile_dialog.cpp
@@ -29,6 +29,8 @@
#include "ui/profile.h"
+#include <ui/qt/variant_pointer.h>
+
#include "profile_dialog.h"
#include <ui_profile_dialog.h>
#include "wireshark_application.h"
@@ -42,8 +44,6 @@
#include <QTreeWidgetItem>
#include <QUrl>
-Q_DECLARE_METATYPE(GList *)
-
ProfileDialog::ProfileDialog(QWidget *parent) :
GeometryStateDialog(parent),
pd_ui_(new Ui::ProfileDialog),
@@ -75,7 +75,7 @@ ProfileDialog::ProfileDialog(QWidget *parent) :
profile = (profile_def *) fl_entry->data;
QTreeWidgetItem *item = new QTreeWidgetItem(pd_ui_->profileTreeWidget);
item->setText(0, profile->name);
- item->setData(0, Qt::UserRole, qVariantFromValue(fl_entry));
+ item->setData(0, Qt::UserRole, VariantPointer<GList>::asQVariant(fl_entry));
if (profile->is_global || profile->status == PROF_STAT_DEFAULT) {
QFont ti_font = item->font(0);
@@ -146,7 +146,7 @@ void ProfileDialog::updateWidgets()
profile_def *current_profile = NULL;
if (item) {
- current_profile = (profile_def *) item->data(0, Qt::UserRole).value<GList *>()->data;
+ current_profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
enable_new = true;
enable_copy = true;
if (!current_profile->is_global && current_profile->status != PROF_STAT_DEFAULT) {
@@ -194,7 +194,7 @@ void ProfileDialog::updateWidgets()
profile_def *profile;
for (int i = 0; i < pd_ui_->profileTreeWidget->topLevelItemCount(); i++) {
item = pd_ui_->profileTreeWidget->topLevelItem(i);
- profile = (profile_def *) item->data(0, Qt::UserRole).value<GList *>()->data;
+ profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
if (profile->is_global) {
item->setToolTip(0, tr("This is a system provided profile."));
continue;
@@ -235,7 +235,7 @@ void ProfileDialog::on_newToolButton_clicked()
profile = (profile_def *) fl_entry->data;
item->setText(0, profile->name);
- item->setData(0, Qt::UserRole, qVariantFromValue(fl_entry));
+ item->setData(0, Qt::UserRole, VariantPointer<GList>::asQVariant(fl_entry));
item->setFlags(item->flags() | Qt::ItemIsEditable);
pd_ui_->profileTreeWidget->addTopLevelItem(item);
pd_ui_->profileTreeWidget->setCurrentItem(item);
@@ -247,7 +247,7 @@ void ProfileDialog::on_deleteToolButton_clicked()
QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem();
if (item) {
- GList *fl_entry = item->data(0, Qt::UserRole).value<GList *>();
+ GList *fl_entry = VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole));
profile_def *profile = (profile_def *) fl_entry->data;
if (profile->is_global || profile->status == PROF_STAT_DEFAULT) {
return;
@@ -266,7 +266,7 @@ void ProfileDialog::on_copyToolButton_clicked()
QTreeWidgetItem *cur_item = pd_ui_->profileTreeWidget->currentItem();
if (!cur_item) return;
- profile_def *cur_profile = (profile_def *) cur_item->data(0, Qt::UserRole).value<GList *>()->data;
+ profile_def *cur_profile = (profile_def *) VariantPointer<GList>::asPtr(cur_item->data(0, Qt::UserRole))->data;
if (!cur_profile) return;
QTreeWidgetItem *new_item = new QTreeWidgetItem();
@@ -291,7 +291,7 @@ void ProfileDialog::on_copyToolButton_clicked()
fl_entry = add_to_profile_list(new_name, parent, PROF_STAT_COPY, FALSE, cur_profile->from_global);
new_profile = (profile_def *) fl_entry->data;
new_item->setText(0, new_profile->name);
- new_item->setData(0, Qt::UserRole, qVariantFromValue(fl_entry));
+ new_item->setData(0, Qt::UserRole, VariantPointer<GList>::asQVariant(fl_entry));
new_item->setFlags(new_item->flags() | Qt::ItemIsEditable);
pd_ui_->profileTreeWidget->addTopLevelItem(new_item);
pd_ui_->profileTreeWidget->setCurrentItem(new_item);
@@ -312,7 +312,7 @@ void ProfileDialog::on_buttonBox_accepted()
}
if (item) {
- profile_def *profile = (profile_def *) item->data(0, Qt::UserRole).value<GList *>()->data;
+ profile_def *profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
if (profile_exists (profile->name, FALSE) || profile_exists (profile->name, TRUE)) {
/* The new profile exists, change */
wsApp->setConfigurationProfile (profile->name);
@@ -334,7 +334,7 @@ void ProfileDialog::editingFinished()
QTreeWidgetItem *item = pd_ui_->profileTreeWidget->currentItem();
if (item) {
- profile_def *profile = (profile_def *) item->data(0, Qt::UserRole).value<GList *>()->data;
+ profile_def *profile = (profile_def *) VariantPointer<GList>::asPtr(item->data(0, Qt::UserRole))->data;
if (item->text(0).compare(profile->name) != 0) {
g_free(profile->name);
profile->name = qstring_strdup(item->text(0));
diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp
index 8f81f06397..2686b2ea69 100644
--- a/ui/qt/proto_tree.cpp
+++ b/ui/qt/proto_tree.cpp
@@ -28,6 +28,8 @@
#include "color_utils.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QApplication>
#include <QContextMenuEvent>
#include <QDesktopServices>
@@ -136,7 +138,7 @@ proto_tree_draw_node(proto_node *node, gpointer data)
}
item->setText(0, label);
- item->setData(0, Qt::UserRole, qVariantFromValue(fi));
+ item->setData(0, Qt::UserRole, VariantPointer<field_info>::asQVariant(fi));
if (is_branch) {
if (tree_expanded(fi->tree_type)) {
@@ -310,7 +312,7 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event)
field_info *fi = NULL;
const char *module_name = NULL;
if (selectedItems().count() > 0) {
- fi = selectedItems()[0]->data(0, Qt::UserRole).value<field_info *>();
+ fi = VariantPointer<field_info>::asPtr(selectedItems()[0]->data(0, Qt::UserRole));
if (fi && fi->hfinfo) {
if (fi->hfinfo->parent == -1) {
module_name = fi->hfinfo->abbrev;
@@ -322,7 +324,7 @@ void ProtoTree::contextMenuEvent(QContextMenuEvent *event)
proto_prefs_menu_.setModule(module_name);
foreach (QAction *action, copy_actions_) {
- action->setData(QVariant::fromValue<field_info *>(fi));
+ action->setData(VariantPointer<field_info>::asQVariant(fi));
}
decode_as_->setData(qVariantFromValue(true));
@@ -398,7 +400,7 @@ void ProtoTree::goToField(int hf_id)
QTreeWidgetItemIterator iter(this);
while (*iter) {
- field_info *fi = (*iter)->data(0, Qt::UserRole).value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr((*iter)->data(0, Qt::UserRole));
if (fi && fi->hfinfo) {
if (fi->hfinfo->id == hf_id) {
@@ -416,7 +418,7 @@ void ProtoTree::updateSelectionStatus(QTreeWidgetItem* item)
field_info *fi;
QString item_info;
- fi = item->data(0, Qt::UserRole).value<field_info *>();
+ fi = VariantPointer<field_info>::asPtr(item->data(0, Qt::UserRole));
if (!fi || !fi->hfinfo) return;
if (fi->hfinfo->blurb != NULL && fi->hfinfo->blurb[0] != '\0') {
@@ -471,7 +473,7 @@ void ProtoTree::updateSelectionStatus(QTreeWidgetItem* item)
void ProtoTree::expand(const QModelIndex & index) {
field_info *fi;
- fi = index.data(Qt::UserRole).value<field_info *>();
+ fi = VariantPointer<field_info>::asPtr(index.data(Qt::UserRole));
if (!fi) return;
if(prefs.gui_auto_scroll_on_expand) {
@@ -500,7 +502,7 @@ void ProtoTree::expand(const QModelIndex & index) {
void ProtoTree::collapse(const QModelIndex & index) {
field_info *fi;
- fi = index.data(Qt::UserRole).value<field_info *>();
+ fi = VariantPointer<field_info>::asPtr(index.data(Qt::UserRole));
if (!fi) return;
/*
@@ -568,7 +570,7 @@ void ProtoTree::collapseAll()
void ProtoTree::itemDoubleClick(QTreeWidgetItem *item, int) {
field_info *fi;
- fi = item->data(0, Qt::UserRole).value<field_info *>();
+ fi = VariantPointer<field_info>::asPtr(item->data(0, Qt::UserRole));
if (!fi || !fi->hfinfo) return;
if (fi->hfinfo->type == FT_FRAMENUM) {
@@ -592,7 +594,7 @@ void ProtoTree::selectField(field_info *fi)
{
QTreeWidgetItemIterator iter(this);
while (*iter) {
- if (fi == (*iter)->data(0, Qt::UserRole).value<field_info *>()) {
+ if (fi == VariantPointer<field_info>::asPtr((*iter)->data(0, Qt::UserRole))) {
setCurrentItem(*iter);
scrollToItem(*iter);
break;
@@ -609,7 +611,7 @@ static QList<int> serializeAsPath(QTreeWidgetItem *item)
{
QList<int> path;
do {
- field_info *fi = item->data(0, Qt::UserRole).value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr(item->data(0, Qt::UserRole));
path.prepend(fi->hfinfo->id);
} while ((item = item->parent()));
return path;
@@ -628,7 +630,7 @@ void ProtoTree::restoreSelectedField()
int last_hf_id = selected_field_path_.last();
QTreeWidgetItemIterator iter(this);
while (*iter) {
- field_info *fi = (*iter)->data(0, Qt::UserRole).value<field_info *>();
+ field_info *fi = VariantPointer<field_info>::asPtr((*iter)->data(0, Qt::UserRole));
if (last_hf_id == fi->hfinfo->id &&
serializeAsPath(*iter) == selected_field_path_) {
setCurrentItem(*iter);
diff --git a/ui/qt/proto_tree.h b/ui/qt/proto_tree.h
index ff2992ea8b..a27aab5faa 100644
--- a/ui/qt/proto_tree.h
+++ b/ui/qt/proto_tree.h
@@ -31,8 +31,6 @@
#include <QTreeWidget>
#include <QMenu>
-Q_DECLARE_METATYPE(field_info *)
-
class ProtoTree : public QTreeWidget
{
Q_OBJECT
diff --git a/ui/qt/protocol_hierarchy_dialog.cpp b/ui/qt/protocol_hierarchy_dialog.cpp
index 6e3cd927c5..2570508eb7 100644
--- a/ui/qt/protocol_hierarchy_dialog.cpp
+++ b/ui/qt/protocol_hierarchy_dialog.cpp
@@ -25,6 +25,9 @@
#include "cfile.h"
#include "ui/proto_hier_stats.h"
+
+#include <ui/qt/variant_pointer.h>
+
#include <wsutil/utf8_entities.h>
#include "qt_ui_utils.h"
@@ -56,8 +59,6 @@ const int end_packets_col_ = 6;
const int end_bytes_col_ = 7;
const int end_bandwidth_col_ = 8;
-Q_DECLARE_METATYPE(ph_stats_t*)
-
class ProtocolHierarchyTreeWidgetItem : public QTreeWidgetItem
{
public:
@@ -75,7 +76,7 @@ public:
filter_name_ = ph_stats_node.hfinfo->abbrev;
if (!parent) return;
- ph_stats_t *ph_stats = parent->treeWidget()->invisibleRootItem()->data(0, Qt::UserRole).value<ph_stats_t*>();
+ ph_stats_t *ph_stats = VariantPointer<ph_stats_t>::asPtr(parent->treeWidget()->invisibleRootItem()->data(0, Qt::UserRole));
if (!ph_stats || ph_stats->tot_packets < 1) return;
percent_packets_ = total_packets_ * 100.0 / ph_stats->tot_packets;
@@ -182,7 +183,7 @@ ProtocolHierarchyDialog::ProtocolHierarchyDialog(QWidget &parent, CaptureFile &c
ui->hierStatsTreeWidget->setItemDelegateForColumn(pct_bytes_col_, &percent_bar_delegate_);
ph_stats_t *ph_stats = ph_stats_new(cap_file_.capFile());
if (ph_stats) {
- ui->hierStatsTreeWidget->invisibleRootItem()->setData(0, Qt::UserRole, qVariantFromValue(ph_stats));
+ ui->hierStatsTreeWidget->invisibleRootItem()->setData(0, Qt::UserRole, VariantPointer<ph_stats_t>::asQVariant(ph_stats));
g_node_children_foreach(ph_stats->stats_tree, G_TRAVERSE_ALL, addTreeNode, ui->hierStatsTreeWidget->invisibleRootItem());
ph_stats_free(ph_stats);
}
diff --git a/ui/qt/rtp_player_dialog.cpp b/ui/qt/rtp_player_dialog.cpp
index 562629e399..896fabd22b 100644
--- a/ui/qt/rtp_player_dialog.cpp
+++ b/ui/qt/rtp_player_dialog.cpp
@@ -40,9 +40,6 @@
#include <QMenu>
#include <QVBoxLayout>
-Q_DECLARE_METATYPE(RtpAudioStream *)
-Q_DECLARE_METATYPE(QCPGraph *)
-
#endif // QT_MULTIMEDIA_LIB
#include <QPushButton>
diff --git a/ui/qt/sparkline_delegate.h b/ui/qt/sparkline_delegate.h
index 5e020cf703..62599abea6 100644
--- a/ui/qt/sparkline_delegate.h
+++ b/ui/qt/sparkline_delegate.h
@@ -42,7 +42,7 @@ public slots:
};
-Q_DECLARE_METATYPE(QList<int> *)
+Q_DECLARE_METATYPE(QList<int>)
#endif // SPARKLINE_DELEGATE_H
diff --git a/ui/qt/stats_tree_dialog.cpp b/ui/qt/stats_tree_dialog.cpp
index 798a15373f..3ac27a0a7e 100644
--- a/ui/qt/stats_tree_dialog.cpp
+++ b/ui/qt/stats_tree_dialog.cpp
@@ -27,6 +27,8 @@
#include "qt_ui_utils.h"
+#include <ui/qt/variant_pointer.h>
+
#include <QHeaderView>
#include <QMessageBox>
#include <QTreeWidget>
@@ -34,8 +36,6 @@
const int item_col_ = 0;
-Q_DECLARE_METATYPE(stat_node *)
-
const int sn_type_ = 1000;
class StatsTreeWidgetItem : public QTreeWidgetItem
{
@@ -48,8 +48,8 @@ public:
}
bool operator< (const QTreeWidgetItem &other) const
{
- stat_node *thisnode = data(item_col_, Qt::UserRole).value<stat_node *>();
- stat_node *othernode = other.data(item_col_, Qt::UserRole).value<stat_node *>();
+ stat_node *thisnode = VariantPointer<stat_node>::asPtr(data(item_col_, Qt::UserRole));
+ stat_node *othernode = VariantPointer<stat_node>::asPtr(other.data(item_col_, Qt::UserRole));
Qt::SortOrder order = treeWidget()->header()->sortIndicatorOrder();
int result;
@@ -96,7 +96,7 @@ void StatsTreeDialog::setupNode(stat_node* node)
QTreeWidgetItem *ti = new StatsTreeWidgetItem(), *parent = NULL;
ti->setText(item_col_, node->name);
- ti->setData(item_col_, Qt::UserRole, qVariantFromValue(node));
+ ti->setData(item_col_, Qt::UserRole, VariantPointer<stat_node>::asQVariant(node));
node->pr = (st_node_pres *) ti;
if (node->parent && node->parent->pr) {
parent = (QTreeWidgetItem *) node->parent->pr;
@@ -176,7 +176,7 @@ void StatsTreeDialog::drawTreeItems(void *st_ptr)
int node_count = 0;
while (*iter) {
- stat_node *node = (*iter)->data(item_col_, Qt::UserRole).value<stat_node *>();
+ stat_node *node = VariantPointer<stat_node>::asPtr((*iter)->data(item_col_, Qt::UserRole));
if (node) {
gchar **valstrs = stats_tree_get_values_from_node(node);
for (int count = 0; count<st->num_columns; count++) {
diff --git a/ui/qt/variant_pointer.h b/ui/qt/variant_pointer.h
new file mode 100644
index 0000000000..7069fc3db1
--- /dev/null
+++ b/ui/qt/variant_pointer.h
@@ -0,0 +1,46 @@
+/*
+ * variant_pointer.h
+ * Range routines
+ *
+ * Roland Knall <rknall@gmail.com>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef UI_QT_VARIANT_POINTER_H_
+#define UI_QT_VARIANT_POINTER_H_
+
+#include <QVariant>
+
+template <typename T> class VariantPointer
+{
+
+public:
+ static T* asPtr(QVariant v)
+ {
+ return (T *) v.value<void *>();
+ }
+
+ static QVariant asQVariant(T* ptr)
+ {
+ return qVariantFromValue((void *) ptr);
+ }
+};
+
+#endif /* UI_QT_VARIANT_POINTER_H_ */
diff --git a/ui/qt/voip_calls_dialog.cpp b/ui/qt/voip_calls_dialog.cpp
index 267ec218cc..439226e9bb 100644
--- a/ui/qt/voip_calls_dialog.cpp
+++ b/ui/qt/voip_calls_dialog.cpp
@@ -64,8 +64,6 @@ const int packets_col_ = 7;
const int state_col_ = 8;
const int comments_col_ = 9;
-Q_DECLARE_METATYPE(voip_calls_info_t*)
-
enum { voip_calls_type_ = 1000 };
class VoipCallsTreeWidgetItem : public QTreeWidgetItem
diff --git a/ui/qt/wireless_frame.cpp b/ui/qt/wireless_frame.cpp
index 3aedeede19..83de2875aa 100644
--- a/ui/qt/wireless_frame.cpp
+++ b/ui/qt/wireless_frame.cpp
@@ -148,7 +148,6 @@ void WirelessFrame::timerEvent(QTimerEvent *event)
}
}
-Q_DECLARE_METATYPE(struct ws80211_interface *)
void WirelessFrame::updateWidgets()
{
bool enable_interface = false;