Results 1 to 7 of 7

Thread: Better understanding of the ModelView archtecture

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Wink Re: Better understanding of the ModelView archtecture

    Quote Originally Posted by tbscope View Post
    Copying is an action you do on or with the data. The model contains and handles the data, the view only takes care of displaying the data.
    To keep with the model view design pattern, any data handling should be done or initiated by the model. In other words, the copying should be done by the model, or it should be initiated by the model and done in another class (a file manager for example).
    So if I understand you correctly, I should derive my own model and add a function on that which does or initiates the copy. Cool, thank you.
    Quote Originally Posted by tbscope View Post
    Why not store the state in the database itself? This way you don't have to create a more complex model, just use any of the QSql models. A function like GetState could do a query for customer_id. And if you do it in a transaction, you can do it for all your customers at once. Or you can reimplement fetch more so that when you scroll the view and there are some items on the screen that do not have the state filled in, you can get those at that moment via the GetState function. Or, you can run a fetch timer in the background do fill in the blanks in blocks of 100 customers (or more) (asynchronously)
    The issue is that outside forces can and do muck with the images, so any state put into the database can and will become stail.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: Better understanding of the ModelView archtecture

    Quote Originally Posted by scarleton View Post
    So if I understand you correctly, I should derive my own model and add a function on that which does or initiates the copy. Cool, thank you.
    Yes. It shouldn't be difficult.

    Edit: Or, and I don't like this idea myself, create a class that contains the model, and then write functions in this 'super class". Then you don't have to subclass a model.

    The issue is that outside forces can and do muck with the images, so any state put into the database can and will become stail.
    I did understand your wrong. In that case, I guess you can use a file system watcher (also in the model): http://doc.qt.nokia.com/4.6/qfilesystemwatcher.html

  3. #3
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Question Re: Better understanding of the ModelView archtecture

    Quote Originally Posted by tbscope View Post
    I did understand your wrong. In that case, I guess you can use a file system watcher (also in the model): http://doc.qt.nokia.com/4.6/qfilesystemwatcher.html
    Again, a file system watcher is not viable, because as I stated before: outside forces can and DO change the state. Using a file system watcher would mean a service running 24/7 and this is a bit over kill. The safest and cleaned way to accurately show the user the state is to check the state on demand. So, the question remains:

    Q: In a Qt Model, how does one have one column that is dynamic upon display.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: Better understanding of the ModelView archtecture

    Quote Originally Posted by scarleton View Post
    Q: In a Qt Model, how does one have one column that is dynamic upon display.
    A model is (or should be) dynamic by design. You don't need to do anything else but set the new data in the correct place.

  5. #5
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 18 Times in 18 Posts

    Default Re: Better understanding of the ModelView archtecture

    Normally, you implement your own data() method that returns the value for a given ModelIndex. It could look something like this:

    Qt Code:
    1. QVariant CalculatorTapeModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid()) return QVariant();
    4.  
    5.  
    6. if (role == Qt::TextAlignmentRole)
    7. {
    8. ... alignment code ...
    9. }
    10.  
    11.  
    12. if (role == Qt::DisplayRole)
    13. {
    14. *** This is where you should check the state of your dynamic items ***
    15. ... return data for requested item ...
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. I need help understanding QGraphicsView
    By aarelovich in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2009, 21:02
  2. GraphicsView / ModelView Integration ???
    By travlr in forum Qt Programming
    Replies: 11
    Last Post: 8th December 2008, 11:19
  3. understanding QwtPlot::transform()
    By b.mourat in forum Qwt
    Replies: 1
    Last Post: 25th May 2008, 08:43
  4. Problems understanding QGraphicsScene
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2008, 13:43
  5. How customize items of ModelView?
    By istdasklar in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2007, 19:08

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.