Changing our contact management to Qt Models & Views

Starting with revision 2734, KMess2 has support for the Qt Model/View paradigm.

This means that the Contact List is now an abstract Model - other than being the usual Contact List class. With it, we can now create lists,trees,tables, or whatever just connecting our desired View to the Contact List model and filtering the items as we please. Available pre-made Views are QListWidget, QTreeWidget, QTableWidget, and their more basic counterparts with -View instead of -Widget.

The Model

The model items are instances of a base class, Contact List Model Item, which implements the basic tree model logic. The list has a root item, which contains both Groups and Contacts (contacts without group). Contacts may not contain sub-items. Groups, instead, will need to contain Contacts.
To simplify the design, I have modified the model item class to be also able to contain other Groups: this allows to just use a Group as root item of the Model. Only the root Group is allowed to inherit other Groups - normal Groups with Contacts are not able to have other Groups as children; just like in Windows Live Messenger the groups cannot have sub-groups.

In the Views associated to this Model, the root item is hidden, therefore their visual aspect is identical to the one of KMess 1.5; groupless contacts and groups shown as root items.

Contact List Window

Regarding the actual contact list as we see it in the main window, I've implemented a delegate, which simply creates a couple QLabels and uses them to render the various contact list items.

The possibilities, however, are endless. Just look at the Amarok2's playlist: that's a QGraphicsView rendered from a Model1 :)

Enjoy!