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

vokov

macrumors newbie
Original poster
Oct 24, 2012
5
0
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!
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
1
Portland, OR
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!
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.
 
Comment

vokov

macrumors newbie
Original poster
Oct 24, 2012
5
0
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.
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!
 
Comment

vokov

macrumors newbie
Original poster
Oct 24, 2012
5
0
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.
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...
 
Comment

mfram

macrumors 65816
Jan 23, 2010
1,060
141
San Diego, CA USA
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.
 
Comment

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
1
Portland, OR
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!
Changes to the model should be done by the controller layer, which can then also call -setNeedsDisplay: or similar on views.
 
Comment

vokov

macrumors newbie
Original poster
Oct 24, 2012
5
0
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
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.
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.
 
Comment

vokov

macrumors newbie
Original poster
Oct 24, 2012
5
0
Changes to the model should be done by the controller layer, which can then also call -setNeedsDisplay: or similar on views.
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!
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.