Results 1 to 4 of 4

Thread: Data model

  1. #1
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Data model

    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 :

    Qt Code:
    1. if( role == Qt::DisplayRole )
    2. {
    3. // just return data at given column
    4. int nPos = index.column() + ( 4 * index.row() );
    5. if( nPos < m_Data.size() )
    6. data = m_Data.at( nPos );
    7. }
    To copy to clipboard, switch view to plain text mode 

    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 :

    Qt Code:
    1. class CCanMessage
    2. {
    3. QString m_strMessage;
    4. QString m_strTime;
    5. QString m_strCount;
    6. };
    To copy to clipboard, switch view to plain text mode 

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

    Regards,
    Steve

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Data model

    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.

  3. #3
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Data model

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Data model

    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.

Similar Threads

  1. Custom Model Class
    By mattjgalloway in forum Qt Programming
    Replies: 12
    Last Post: 4th June 2007, 17:30
  2. Informing a model its data has changed
    By saknopper in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 19:58
  3. Modify model data in QTreeView
    By YuriyRusinov in forum Qt Programming
    Replies: 6
    Last Post: 26th October 2006, 17:28
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.