PDA

View Full Version : QTreeView with QStandardItemModel



steg90
15th May 2007, 07:38
Hi,

I'm needing a view which shows hierarchical data, hence a tree. The objects I want rendering in the tree consist of N amount of messages (which have message data) which in turn have N amount of signals where each signal has a signal data field and a unit conversion type. Thus the message will be the parent node for the signal(s). I will have a view which will have four columns, first column will be the messages with the signal nodes, second column the message data, third column signal data and fourth signal unit.

What I want to know is, as the signal and message data can change every millisecond, I need the tree to reflect this, would the QStandardItemModel be fast enough? There will only ever be a maximum of ten messages in the tree although these can also have upto ten signals each. I guess, deleting all items in the tree and updating again would be very slow, what I've tended to do in my MFC apps is just change the corresponding tree item.

Any advice is much appreciated,
Regards,
Steve

PS - this is the object structure for messages and signals ( not all the variables in each object are needed for the tree view ):



class CSignal
{
public:
char m_name[256];
char m_unit[256];
double m_dmaximum;
double m_dminimum;
double m_dfactor;
double m_doffset;
UINT m_istartbit;
UINT m_ilength;
double m_drealvalue;
long m_lrawvalue;
double m_dbyteorder;
};

// Holds a message along with its list of signals
class CMessage
{
public:
char m_name[256]; // message user friendly name
CString m_strId;
CString m_strData; // data for message
CString m_strRawData;
QList<QObject*> m_oSignals;
};
Q_DECLARE_METATYPE(CDADcb::CMessage*)

QHash<QString,QObject*> m_oMessages;



The variable m_oMessages is the hash map that holds the messages and signals.

wysota
15th May 2007, 09:07
Yes, the standard model will be fine, although with having such a structure, I'd implement a custom model that uses this structure directly. It'll save you some work...

steg90
15th May 2007, 09:10
Thanks for the reply. I'm pretty new to Qt and although I've done custom model for a tableview, was wondering how I'd go about doing one for the treeview?

Kind regards,
Steve

wysota
16th May 2007, 09:28
Take a look at the simpletreemodel example bundled with Qt.