Results 1 to 6 of 6

Thread: How to remove row from Model without removing from source

  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How to remove row from Model without removing from source

    I have a tableView created from a QSqlRelationalTableModel and a proxy model. I use the table to let the user display data to their needs. I use the proxyModel to highlight the high and low values in a column. The user needs to be able to sort the table and remove certain rows. BUT I don't want the underlying source to be modified. I tried to remove the row from the model, but it removed it from the source as well. I tried to hide the row, but then if the user sorted the column, the hidden data becomes available. What would be the best way to do this? The table is not going to be very big. If there isn't a better method, one idea I had was to create another table in my database and store the "original" data (the filtered data from the SQLRelation and filtered data) when the dialog is created. Then if the user wants to revert back to the original data, the dialog could "DROP" the table, Create the table again and repopulate the table row by row. This way the original data would be intact. Is there a method to remove items from a model/view without removing them from the source?

  2. #2
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to remove row from Model without removing from source

    removeRow() and editStrategy:: onManualSubmit shoud do the work done Brother ;]

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to remove row from Model without removing from source

    Thanks,
    I thought I had tried that, but I guess I didn't


    Added after 1 15 minutes:


    A quick add on, I don't know if I should create a new thread. I use a proxymodel to highlight cells. After the delete function, I need to have the tableView updated (call data()) I was thinking that I need to emit dataChanged() to repopulate the tableView. But it didn't work. The compiler stated
    'virtual void QAbstractItemView::dataChanged(const QModelIndex&, const QModelIndex&)' is protected
    I this the correct way or is there a better way?
    Last edited by poporacer; 2nd May 2011 at 05:29.

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to remove row from Model without removing from source

    Make sure dataChanged is emitted from your model when data has changed. If that is the case, let your proxy model invalidate its filter when data has changed. Your view will then be automatically updated.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to remove row from Model without removing from source

    Make sure dataChanged is emitted from your model when data has changed
    I do not know how to check that.
    If that is the case, let your proxy model invalidate its filter when data has changed. Your view will then be automatically updated.
    And how do I do that?

  6. #6
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to remove row from Model without removing from source

    connect that dataChanged to a slot inside which there is a qDebug or message box.Later on put there this invalidating of the filter.

Similar Threads

  1. Replies: 2
    Last Post: 21st March 2012, 14:30
  2. QFileSystemModel::remove not removing index from model
    By revorgm in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:24
  3. Flat data source for QTreeView/Model
    By mawt in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 16:20
  4. removing model Items
    By gyre in forum Newbie
    Replies: 2
    Last Post: 25th November 2007, 20:10
  5. Removing rows from table model
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 20:36

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
  •  
Qt is a trademark of The Qt Company.