Qt: Workaround for Qt model() bug

model() on the TreeView should return a value, but instead returns a null
pointer. Moving the methods to the model would be the next step, but until
then, this workaround regains functionality

Change-Id: Iaa0b6470af41b297a821c0dd6e3a238481752886
Reviewed-on: https://code.wireshark.org/review/33839
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2019-07-04 12:43:11 +02:00
parent 66e92e7276
commit ca4b950bfa
2 changed files with 9 additions and 13 deletions

View File

@ -96,16 +96,12 @@ packet_list_append(column_info *, frame_data *fdata)
if (!gbl_cur_packet_list)
return 0;
PacketListModel * model = qobject_cast<PacketListModel *>(gbl_cur_packet_list->model());
if ( ! model )
return 0;
/* fdata should be filled with the stuff we need
* strings are built at display time.
*/
guint visible_pos;
visible_pos = model->appendPacket(fdata);
visible_pos = gbl_cur_packet_list->packetListModel()->appendPacket(fdata);
return visible_pos;
}
@ -135,14 +131,10 @@ packet_list_select_row_from_data(frame_data *fdata_needle)
if ( !gbl_cur_packet_list )
return FALSE;
PacketListModel * model = qobject_cast<PacketListModel *>(gbl_cur_packet_list->model());
if ( ! model )
return FALSE;
model->flushVisibleRows();
int row = model->visibleIndexOf(fdata_needle);
gbl_cur_packet_list->packetListModel()->flushVisibleRows();
int row = gbl_cur_packet_list->packetListModel()->visibleIndexOf(fdata_needle);
if (row >= 0) {
gbl_cur_packet_list->setCurrentIndex(model->index(row, 0));
gbl_cur_packet_list->setCurrentIndex(gbl_cur_packet_list->packetListModel()->index(row, 0));
return TRUE;
}
@ -412,6 +404,10 @@ void PacketList::setProtoTree (ProtoTree *proto_tree) {
&related_packet_delegate_, SLOT(addRelatedFrame(int,ft_framenum_type_t)));
}
PacketListModel *PacketList::packetListModel() const {
return packet_list_model_;
}
void PacketList::selectionChanged (const QItemSelection & selected, const QItemSelection & deselected)
{
QTreeView::selectionChanged(selected, deselected);

View File

@ -33,7 +33,7 @@ class PacketList : public QTreeView
Q_OBJECT
public:
explicit PacketList(QWidget *parent = 0);
PacketListModel *packetListModel() const;
QMenu *conversationMenu() { return &conv_menu_; }
QMenu *colorizeMenu() { return &colorize_menu_; }
void setProtoTree(ProtoTree *proto_tree);