Results 1 to 3 of 3

Thread: Copying data within model/widgetmapper

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Thanks
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Copying data within model/widgetmapper

    Tired of pulling my hair out over this. I'm trying to take a parent/children set or records from within my sqltablemodel and copy them into a new parent/children set of data. Effectively, this:

    Parent(1)
    Child(1)(1)
    Child(2)(1)

    copied and create:
    Parent(2)
    Child(1)(2)
    Child(2)(2)

    I've done this before using filters in another application and had it working fine, but instead of displaying my data (in a typical master/detail manner) via tableviews, I'm now displaying it via a QDataWidgetMapper. This may be a red herring, though.

    I'm creating the parent/child relationship via my app, which is fine, but when I try to copy, the new parent record (Parent(2)) is created correctly, but while trying to copy the children, my insertRow() command is returning a QSqlError(-1, "", "") and for the life of me I can't see why. Could be that I'm looking at it too long -- anyone see something?

    ed: I checked the index of flowlinemapper after the second setfilter on flowlinemodel and it's = -1 which is a clue

    Qt Code:
    1. //*******************************************************
    2. //* Get a copy of the current record, go create a new *
    3. //* one, and copy this one's contents over to it... *
    4. //*******************************************************
    5. old_region_index = regionmapper->currentIndex ();
    6. old_region_record = regionmodel->record (old_region_index);
    7.  
    8. riser_id = old_region_record.value("region_riser_id").toInt ();
    9. old_region_seq_no = old_region_record.value ("region_seq_no").toInt ();
    10.  
    11.  
    12. row = regionmodel->rowCount ();
    13. regionmodel->insertRow (row);
    14.  
    15. //******************************************
    16. //* Get hold of the new sequence number *
    17. //* because we're gonna need it later... *
    18. //******************************************
    19. new_region_seq_no = sqldb.generate_seq_noDB ("REGION");
    20.  
    21. regionmodel->setData (regionmodel->index (row, 33), new_region_seq_no);
    22. regionmodel->setData (regionmodel->index (row, 34), riser_id);
    23. regionmodel->setData (regionmodel->index (row, 35), user);
    24. regionmodel->setData (regionmodel->index (row, 36),
    25. QDateTime::currentDateTime ());
    26.  
    27.  
    28. //***************************************************************
    29. //* Now copy the flowline data associated with this region... *
    30. //* We have to make sure we reset the flowline data to the *
    31. //* first record associated with this region and loop thru *
    32. //* all those records, copying them to the new set of data... *
    33. //***************************************************************
    34. flowlinemapper->toFirst ();
    35. old_flowline_rowcount = flowlinemodel->rowCount ();
    36.  
    37. for (int i = 0; i < old_flowline_rowcount; i++)
    38. {
    39. flowline_filter = QString("flowline_riser_id = %1").arg (riser_id);
    40. flowline_filter.append (" and ");
    41. flowline_filter.append (QString("flowline_region_seq_no = %2").
    42. arg (old_region_seq_no));
    43. flowlinemodel->setFilter (flowline_filter);
    44.  
    45. //* This correctly returns the record to be copied...
    46. old_flowline_record = flowlinemodel->record (i);
    47.  
    48. flowline_filter = QString("flowline_riser_id = %1").arg (riser_id);
    49. flowline_filter.append (" and ");
    50. flowline_filter.append (QString("flowline_region_seq_no = %2").
    51. arg (new_region_seq_no));
    52. flowlinemodel->setFilter (flowline_filter);
    53.  
    54. if (!flowlinemodel->insertRow (i))
    55. qDebug() << flowlinemodel->lastError ();
    56. else
    57. {
    58. flowlinemodel->setData (flowlinemodel->index (i, 7),
    59. sqldb.generate_seq_noDB ("FLOWLINE"));
    60. flowlinemodel->setData (flowlinemodel->index (i, 8), new_region_seq_no);
    61. flowlinemodel->setData (flowlinemodel->index (i, 9), riser_id);
    62. flowlinemodel->setData (flowlinemodel->index (i, 10), user);
    63. flowlinemodel->setData (flowlinemodel->index (i, 11),
    64. QDateTime::currentDateTime ());
    65. }
    66. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!


    scott
    Last edited by scott_hollen; 5th May 2011 at 19:48.

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. Replies: 1
    Last Post: 24th February 2011, 05:54
  3. memory leak when copying Qimage data
    By klobauster_toomc in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2010, 08:33
  4. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14

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.