PDA

View Full Version : Data model



steg90
17th September 2007, 11:56
Hi,

I have a data model which displays items of information in a QTableView. The data is just stored in a simple QList<QString> and displayed from the model like so :



if( role == Qt::DisplayRole )
{
// just return data at given column
int nPos = index.column() + ( 4 * index.row() );
if( nPos < m_Data.size() )
data = m_Data.at( nPos );
}


Now what I want to also be able to do, is show this information in another view without it scrolling. m_Data contains the following data : can Id, message data, time data, count and thus is displayed like the following in the table view :

CanId Message time count
0x7e8 00112233 08082 1
0x9ea 11223344 09088 2
0x7e8 00112233 0a023 3

Now, as can be seen, there are two canId's with same id, I want this to be displayed on the same line, thus :

CanId Message time count
0x7e8 00112233 0a023 2
0x9ea 11223344 09088 1

Obviously my data structure ( m_Data ) is limited and thought of having a QHash map of the following object :



class CCanMessage
{
QString m_strMessage;
QString m_strTime;
QString m_strCount;
};


This would get stored in the QHash map key'd on the CanId. Does this seem a way of doing this?

Regards,
Steve

wysota
17th September 2007, 12:02
You mean you want to display in the tree view aggregated data of the same data source as the one displayed in the table view? I suggest wrapping the original model into a proxy model (QAbstractProxyModel) then.

steg90
17th September 2007, 12:05
I want to display the data still in a tableview, but not scroll it. I.e. show the same can Id on the same line.

Thanks,
Steve

wysota
17th September 2007, 12:14
Sorry... I must have read your post wrong. Do you need to have individual records separated from each other even if they contain the same data? If not, then using a simple structure that contains a count of each message "type" is indeed the simplest choice.