Table proxy model for list view



  • Hello,

    I have a custom list model which, at its simplest, encapsulates an array of bytes. (In reality, these bytes are actually my own objects which also record a timestamp and other metadata associated with the byte.) I would then like to create some form of proxy model which will be used to display filtered data in a tabular form. I want the proxy view to use some method (most likely regular expressions) to search through the underlying model for matches then display those matches in a table form where the first column is the timestamp associated with the first byte in the match.

    For example, lets say my list mode/byte array contains the following:

    01 AB CD 55 68 FF 56 40 01 DE FF
    

    And I want to filter out all sequences that start with 01 and end with FF. I want these to be displayed in a table view via the proxy model as such:

    05:31:00.100 01 AB CD 55 68 FF
    05:31:01.568 01 DE FF
    

    I am a little confused since I want to both filter the data and change how it is organized simultaneously. I would like to use a proxy so that the filtered view to automatically update if a byte in the base model were to change. If it is too difficult to have the first column of the filtered data be the timestamp (which isn't truly its own index in the base model), I can live without it and find another way to display it.

    Could someone point me to some ideas as to how to start going about this? Also, if the underlying model is updated, how does the proxy handle researching through the data for new matches in the most efficient way? I am assuming I can somehow use a signal which contains the from and to model indexes of what was updated so that I only have to search through the new data for matches.

    Thanks!



  • @Patrick-Wright said in Table proxy model for list view:

    For example, lets say my list mode/byte array contains the following:
    01 AB CD 55 68 FF 56 40 01 DE FF

    How many rows is that model? 2 or 11?



  • @VRonin said in Table proxy model for list view:

    How many rows is that model? 2 or 11?

    The base model which contains the array of bytes would have 11 "rows"; one row for each byte in the model. The table proxy model would have 2 rows where row 1 is made up of the first occurrence of the 01 ... FF sequence and row 2 is made up of the second occurrence.



  • Last questions.
    What is the structure of the data that contains the timestamps and bytes?
    can you change such structure if necessary to make it more efficient?
    In your example: 05:31:00.100 01 AB CD 55 68 FF how many columns is this? 2 or 7?



  • @VRonin

    My model structure currently is a QVector containing TerminalByte objects with the following structure:

    class TerminalByte {
        char byte_;
        QDateTime timestamp_;
        //More will be added as needed
    }
    

    So, in the QListModel implementation, I just return the byte at each index as a hex string.

    In the table proxy model, I had envisioned the first column being a timestamp (coming from the first TerminalByte of the sequence) and the remaining columns being the bytes in the sequence (Thus, in the example you quoted, there would be 7 columns). Each row is a new sequence (detected via a regular expression or some other means). Essentially, the proxy model is its own unique model with a whole different layout (and possibly data structure), it just pulls its original data from the list model.

    I have no problem changing up my data structures if there is a better way to accomplish what I want.



  • After thinking about this problem more and looking at the interface for QAbstractProxyModel, I am beginning to think that a subclass of a proxy model is not the answer. I am wondering if the best course of action would be to create a new model which keeps a pointer to my base model. Every time the various data changed signals are emitted from the base model, my "proxy" model determines if a new sequence has been found. It then keeps track of all the various sequences in its own internal data structure which keeps QPersistenModelIndex indexes into the base model. Then my "proxy's" data() method would use these indexes to get the real data from the underlying model but parsed into the correct format.

    Do this sound like a better approach?

    In this case, I am also wondering how to display my data as a table where each row could have a different number of columns. Perhaps I could keep track of the row with the maximum number of columns and return this in columnCount()? Then my data() method would just return QVariant() for columns that don't exist in a given row.


Log in to reply