I need to write a QAbstractItemModel class that represents a hierarchy of different object types. I want to be able at some point, show a table/list containing only level 1 elements, only level 2, and so on.
I am working on a network protocol analyzer tool, something like wireshark. I am capturing socket.recv
and socket.send
events from a process. In my model those events are called NetworkEvent
. Each network event may contain one or more Packet
. Each packet has one or more Message
, where a message, based on its code, is parsed as a defined struct.
Here is an image of the program class hierarchy:
The main window has a list and a tree. I expect to be able to show:
- a table/list containing only network events including its attributes.
- a table/list containing only packets including its attributes.
- a table/list containing only packets based on a network event.
- a tree containing a packet/message hierarchy (with fields and sub structures)
- a table/list containing only messages
- a table/list containing only messages based on a packet
- a tree containing a message hierarchy (with fields and sub structures).
So I thought the best idea was to model the QAbstractItemModel
as a tree. First problem I encountered is that while each class has the concept of "children", each one has a different field that represents childrens, so I have to take care of that inside the QAbstractItemModel
.
Also, because a table/list of EventNetwork
doesn't have same columns as table/list of Packet
, nor Message
, I can't properly use the same model to define all possible ways to show the data. I suppose the correct way to do this would be defining proxy models for each kind of view.
Is there any better or easy way to approach this? Or is this the way to go?