Results 1 to 3 of 3

Thread: Custom ProxyModel or Two Sync'd Models ?

  1. #1
    Join Date
    Jul 2011
    Posts
    4
    Qt products
    Qt3
    Platforms
    Windows

    Default Custom ProxyModel or Two Sync'd Models ?

    I have image information stored in a text csv file such as:

    #xPos,yPos,grayScaleValue
    0,0,0.01
    2,3,0.125
    4,3,0.500
    #etc...

    I have two views split vertically. The left view is a standard QTableView and the right view is a custom ImageView (where I will be manually painting the appropriate squares). The TableView's source model is simply the csv file. I need to transform the xPos,yPos data from the source model into actual row,col of a new model which will be the source for the ImageView. So my question is whether I should write a custom ProxyModel to "transform" the source model or to just have two separate synchronized models. The separate model solution intuitively doesn't seem correct since all required data can be referenced from the source model, but I'm having mucho difficulty writing the custom ProxyModel. Specifically, the ::mapFromSource and ::MapToSource functions. Guidance on this dilemma will be much appreciated.

    -Steven

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom ProxyModel or Two Sync'd Models ?

    Well you could make it all work with one model. As you said you already have a standard QTableView (I hope is working, else you may want to fix this first), and then you have custom view, you could do all co-ordinate generation / transformation in the custom view itself.

    IMO proxy models are generally required, if you want to have multiple views to same base model, with slightly (map-able) different visualization. In your case the visulization is generated based on the data itself, so it better to have the position translation in your custom view. And as always try to restrict the custom view to use the QAbstractItemModel interface as much as possible, as a good practice, don't use custom calls / signals / slots between the custom view and model (you might face synchronization issues later on in the development)

    You could explore using a item delegate, which may simply your custom view's complexity.

  3. #3
    Join Date
    Jul 2011
    Posts
    4
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Custom ProxyModel or Two Sync'd Models ?

    Thanks for the advice Santosh. I'm going to abandon the proxy model for now. The reason I started down the path of developing the proxy model was because when I started writing the custom view I kept falling into using a 2D array to hold the desired info and then iterating the through the 2D array and printing it to the screen. I'm new to the MVC architecture. So when I started building the 2D array as the basis for the the custom view from the source model it just felt wrong- after reading several MVC tutorials, I had it ingrained in my head to use a model behind my view to simplify co-selection between the source model table view and the custom view. I'll continue with the aid of your suggestion and hopefully not run into any synchronization issues between the 2D array and source model. Would you please elaborate on your item delegate suggestion?

Similar Threads

  1. Dragging out of a QTreeView with a ProxyModel
    By jmichiel in forum Newbie
    Replies: 4
    Last Post: 19th June 2011, 19:04
  2. ProxyModel problem
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2010, 06:40
  3. Replies: 2
    Last Post: 6th January 2009, 20:55
  4. Proxy models and slection models
    By amunitz in forum The Model-View Framework
    Replies: 1
    Last Post: 23rd September 2008, 14:35
  5. Keeping track of columns in custom models
    By darkadept in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2008, 20:29

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.