Results 1 to 6 of 6

Thread: Adding more than one virtual column in proxy model

  1. #1
    Join Date
    Mar 2012
    Location
    Cracow, Poland
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Adding more than one virtual column in proxy model

    Hi,
    I'm using QSqlTableModel to interact with sqlite database. I have connected QSortFilterProxyModel to filter results in QTableView.
    Now I'm wondering how can I add two and more virtual columns that I don't have in model, but I want to have in view.
    I have read the topic: http://www.qtcentre.org/threads/8070...l-quot-columns and http://www.qtcentre.org/threads/1565...virtual-column but it adds only one of column.
    Which and how should I reimplement QSortFilterProxyModel to add more than one column? More precise, how is realized passing information about position in QTableView to model?

    Thanks in advance for every hint.

  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: Adding more than one virtual column in proxy model

    Subclass QIdentityProxyModel, reimplement columnCount() to return the number of columns in the original model plus the number of artificial columns you want to have. Then reimplement data() and setData() to store and return data for your artificial columns.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2012
    Location
    Cracow, Poland
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding more than one virtual column in proxy model

    I forgot to mention that I have also QWidgetMapper connected to add and edit comments, but I'm not sure if it is possible to pass data to model with QIdentityProxyModel.

    Second thing is that I don't know how can I get infromation about number of column to insert data, for instance I've got three columns in model: value a, value b and comment. I want to add two columns: a+b and a*b. Problem is that I get only indexes from model and the rest of them are invalid, so it's not possible for me to distinguish column.

    Qt Code:
    1. QVariant proxyCalcColumn::data(const QModelIndex &index, int role) const
    2. {
    3.  
    4. QString tempString("Yo");
    5. QVariant dataFromCell(tempString);
    6.  
    7. if (index.column()>=0) { // Here I get invalid number of column
    8. return QSortFilterProxyModel::data(index, role);
    9. } else {
    10. return dataFromCell;
    11. }
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

  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: Adding more than one virtual column in proxy model

    The column information is carried by the index. If you get invalid column number then apparently you're trying to access the model in an invalid way.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2012
    Location
    Cracow, Poland
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding more than one virtual column in proxy model

    But the thing is that I don't want to modify my model (data from SQL database), rather I want to add two virtual columns that are not in the model, but they are visible through QTableView and created (calculated) in a proxy.

  6. #6
    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: Adding more than one virtual column in proxy model

    Quote Originally Posted by qavaxb View Post
    But the thing is that I don't want to modify my model (data from SQL database), rather I want to add two virtual columns that are not in the model
    That's why you're implementing a proxy.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 26th June 2012, 18:08
  2. Source Model Ad Proxy Model
    By sajis997 in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2011, 05:13
  3. Custom Model and Proxy Model
    By frank100 in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2010, 14:30
  4. Replies: 2
    Last Post: 9th December 2010, 17:22
  5. QAbstractProxyModel: adding a virtual column
    By ultim8 in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2008, 17:10

Tags for this Thread

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.