13.6. Exercises: Models and Views

[ fromfile: ex-modelview.xml id: ex-modelview ]

  1. Write a file system browser, with an address bar, Up button, and optionally other commonly found buttons and features of your favorite file browser. Use the QFileSystemModel and at least two View classes separated by a QSplitter. One of the Views should be a QTableView. You can choose a Windows Explorer-style tree on the side of the table, or a Mac OSX-style browser with a QColumnView and a table, as shown in Figure 13.14. Make it possible to select a directory in the tree/columnview, addressbar, or with the Up button, so that any of them will update the contents of the table to reflect the newly selected directory.

    Figure 13.14.  ColumnView File Browser

    ColumnView File Browser

  2. Extend QAbstractTableModel and define a PlayListModel. It should represent a list of MetaDataValue (or MetaDataObject) objects. These can be based on audio tracks or videos, your choice.

    Generate and display test data either based on real media files and MetaDataLoader, or using your own test data/factory method. Implement actions for load/save playlist to disk.

  3. Revisiting the program in Section 11.6, implement a GUI for showing friendslists, or a bidirectional relationship between symbols. The GUI should show two QListViews or QListWidgets, like Figure 13.15.

    Figure 13.15.  Friends Lists

    Friends Lists


    • Both lists should show the set of symbols available.

    • Click add to add a new symbol to both lists.

    • When a symbol is selected on the left, the right list shows the friends checked and the strangers unchecked.

    • Checking/unchecking a box on the right adds/removes a relationship between the two people.

    • Do not allow the user to uncheck a contact if it is the same as the selected one on the left. Always show it as checked.

  4. Rewrite the ShortcutEditor example to use in-place editing. You need to write a delegate class for the table view, which provides a custom editor when the user wants to change a shortcut.