using MVC in app with tree, table, and graphics widgets

Discussion in 'Mac Programming' started by vokov, Oct 24, 2012.

  1. macrumors newbie

    Joined:
    Oct 24, 2012
    #1
    Hey everyone! I am trying to decide whether I should use C++/Qt or Objective-C/Cocoa for my
    next project. I am familiar with C++ and Qt, but know nothing about Objective-C/Cocoa (but
    definitely don't mind learning since mac is becoming my primary target platform).

    Qt has a pretty good support for model/view architecture, but using it for apps with tree,
    table, graphics widgets that pull data from the same model seems pretty challenging.

    So, I am wondering how one would go about organizing such an app with Objective-C/Cocoa.

    Basically, I want to store train schedules (involving ~20,000 trains) in a model so that
    (1) The tree widget would display departure cities at the top level, arrival cities on
    the next level, and finally the corresponding trains.

    Like this:
    • Paris
      • Athens
        • train A
        • train B
        • train C
    (2) The table widget would display arrival/departure times and other data for the selected
    trains. Train selection can be facilitated by adding check boxes to the above tree widget.

    (3) Graphics widget would visualize the route of the selected trains on a map.

    I would really appreciate any suggestions! Thank you!
     
  2. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    Seems like you would have an NSOutlineView, an NSTableView, and a custom map view. Then a controller object for each of those that presents your model data to the view in the form that it expects. Your model would be something vaguely database-like where the controllers could query it in a structured way about route information.

    Really, this app sounds like a textbook example of a good place to use MVC.

    You might need two layers of controllers so that there's place for the cross-view logic like selection to live. Haven't thought that part all the way through.
     
  3. thread starter macrumors newbie

    Joined:
    Oct 24, 2012
    #3
    Sounds great! Thanks for the quick reply!

    I am assuming the database-like model your are talking would allow each widget to update itself (the model) and, once updated, would dynamically update all the other widgets that pull the data from this model. Right? Sorry, I really have no clue how MVC works in Cocoa!
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    Cocoa Core Competencies

    For details, use link at end of article.

    I advise reading all the articles in Cocoa Core Competencies, along with each of the reference guides linked to.


    There's also Cocoa Fundamentals Guide which has a bunch of important fundamentals in it.
     
  5. thread starter macrumors newbie

    Joined:
    Oct 24, 2012
    #5
    Will do; thanks! I am also considering Cocoa Design Patterns (http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022/) as its first chapter is about MVC. Unless someone can suggest a better book...
     
  6. macrumors newbie

    Joined:
    Feb 21, 2010
    Location:
    Scotland
    #6
    The Cocoa Fundamentals Guide that chown33 mentioned is full of great information that you will find useful.

    If you're new to Cocoa and Objective-C then I highly recommend Cocoa Programming for Mac OS X
     
  7. macrumors 6502a

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #7
    Cocoa Design Patterns is really more of an "advanced" book. It assumes you are already familiar with Cocoa and Objective-C. I think it's a great book, but it doesn't teach the fundamentals.

    You can certainly get it to browse through to see "what's out there" for Cocoa. But recognize you will need other books.
     
  8. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #8
    Changes to the model should be done by the controller layer, which can then also call -setNeedsDisplay: or similar on views.
     
  9. thread starter macrumors newbie

    Joined:
    Oct 24, 2012
    #9
    Thanks to both of you. I'll start with "Cocoa Programming for Mac OS X" (luckily available in my university's library) and "The Cocoa Fundamentals Guide." I just want to first be completely confident that Cocoa's MVC is suitable for my project. This is why I am also ordering the design patterns book.
     
  10. thread starter macrumors newbie

    Joined:
    Oct 24, 2012
    #10
    Makes sense. I am definitely going to try using Cocoa on this project. I am very curious whether I can get a cleaner implementation compared to what's possible in Qt. Thanks for getting me started!
     

Share This Page