Results 1 to 12 of 12

Thread: Moving items between two views.

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Moving items between two views.

    Hello, All !

    I have two similar QTreeView's with sorted data in everywhere for move data from one model to another.
    QTreeView
    |
    QSortFIlterProxyModel
    ||
    QStandardItemModel.

    I manipulate with model data using methods data()/setData() from one model to another, but if I try to select very many rows (~1000) then time of moving became very very big. Any ideas ? Can I do it without copying ?

    Thanks in advance.
    Best regards,
    Yuriy Rusinov.

  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: Moving items between two views.

    How do you perform the insertion into a model?

  3. #3
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Moving items between two views.

    Quote Originally Posted by wysota View Post
    How do you perform the insertion into a model?
    Using insertRows function.
    Best regards,
    Yuriy Rusinov.

  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: Moving items between two views.

    Try implementing a custom method that will add all the items at once instead of adding one by one. Blocking the signals for the time of insertion might speed up the action as well.

  5. #5
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Moving items between two views.

    OK, Which way I have to block signals from models ? I use QStandardModel class.
    Best regards,
    Yuriy Rusinov.

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving items between two views.

    Quote Originally Posted by YuriyRusinov View Post
    OK, Which way I have to block signals from models ? I use QStandardModel class.
    QObject::blockSignals(bool)
    Current Qt projects : QCodeEdit, RotiDeCode

  7. The following user says thank you to fullmetalcoder for this useful post:

    YuriyRusinov (2nd April 2007)

  8. #7
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Moving items between two views.

    Thanks, model works fine. But one more question is arisen. Because these views have one type of data, can I define one source model for all and two proxy models for sorting and filtering. Such as
    View
    ||
    <Sort and Filter proxy>
    ||
    <Displayed custom proxy>
    |
    Source Model ?

    Would it faster ?

    Thanks in advance.
    Best regards,
    Yuriy Rusinov.

  9. #8
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving items between two views.

    Quote Originally Posted by YuriyRusinov View Post
    Thanks, model works fine. But one more question is arisen. Because these views have one type of data, can I define one source model for all and two proxy models for sorting and filtering. Such as
    View
    ||
    <Sort and Filter proxy>
    ||
    <Displayed custom proxy>
    |
    Source Model ?

    Would it faster ?

    Thanks in advance.
    I don't understand you... You used two views with different models in them and moved items from a view to another rigth? So it wouldn't make sense to make them share a single model through proxies... Unless you change the design of your app and stop moving items from a view to another (which does not mean that the user can move them, just that filter rules change). If you do so it would probably be faster and less memory consumming because it would avoid some duplications and deep copies but I'm not sure how much... I guess it depends on what you're actually doing.
    Current Qt projects : QCodeEdit, RotiDeCode

  10. #9
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    63
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Moving items between two views.

    These views have to be contains single items set, but every item have to be contained in one and only one view. Before this I do it using available model and selected model. This approach results in very slow time in interaction. Now I try to another approach to have single source model and different list of displayed data.
    Best regards,
    Yuriy Rusinov.

  11. #10
    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: Moving items between two views.

    If you mean applying two different model proxies to the same source model and using those two resulting models for different views, then the answer is "yes, you can do that". Then if you manipulate the source model both views will be updated accordingly through the proxies.

  12. The following 2 users say thank you to wysota for this useful post:

    shaneljsss (6th March 2012), YuriyRusinov (2nd April 2007)

  13. #11
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving items between two views.

    Quote Originally Posted by YuriyRusinov View Post
    These views have to be contains single items set, but every item have to be contained in one and only one view. Before this I do it using available model and selected model. This approach results in very slow time in interaction. Now I try to another approach to have single source model and different list of displayed data.
    Well I suggest you add a flag/property/whatever-you-name-it to your items which will define in which view it shall be displayed. Then each view will be fed by a proxy which will display only items with the matching flag. This flag can be any type for which it exists comparisions operators (QString, QChar, QPoint, ...) but an integer is probably the best solution if you're looking for speed.

    Then moving an item from a view to another will be as simple as :
    • changing the aforementionned flag
    • notifying a change to the view (either a dataChanged(parentIndex, parentIndex) or a complexer but possibly more efficient computation and {begin,end}{Insert,Remove}Rows()...)
    Current Qt projects : QCodeEdit, RotiDeCode

  14. The following user says thank you to fullmetalcoder for this useful post:

    YuriyRusinov (3rd April 2007)

  15. #12
    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: Moving items between two views.

    If both views don't share any data from the model (for example one displays all odd rows and the other all even rows), then I'd say it might be better to have two separate source models. But it is hard to make that a rule of thumb.

  16. The following user says thank you to wysota for this useful post:

    YuriyRusinov (3rd April 2007)

Similar Threads

  1. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 18:32
  2. Moving multiple QGraphicItems
    By StefanHirche in forum Newbie
    Replies: 2
    Last Post: 11th January 2007, 22:27
  3. Drag Drop between Different Views
    By aamer4yu in forum Qt Programming
    Replies: 13
    Last Post: 8th December 2006, 05:29
  4. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 13:20
  5. moving Qlistview items
    By :db:sStrong in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2006, 13:25

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.