Breadcrumbs for your view

Something caught my eye in the recent release announcement of libQxt 0.6.0:

  • Added QxtCrumbView::crumbDelegate()

I was recently working on some model/view code for breadcrumbs, and this looked like it solves a similar problem, but I could already see it took a very different approach to mine.

A QTreeView and a QxtCrumbView

The idea is to create a list of the breadcrumbs above the one item that is currently selected. That means picking out one item from several levels in a tree and putting it in a list. Rather than putting the logic of creating breadcrumbs into a view, I put it into a reimplementation of QItemSelectionModel. I know, I’m pretty predictable.

The KSelectionProxyModel shows the content of a QItemSelectionModel if configured with KSelectionProxyModel::ExactSelection. That means that if I could programmatically create a QItemSelection representing the breadcrumb, I was already on a home straight. The KBreadcrumbSelectionModel encapsulates the concept of “When an item is selected, make a selection which includes its parent and ancestor items until the top is reached”. Like before, this is accomplished with an override of QItemSelectionModel::select.

QTreeView and BreadcrumbNavigationView

The advantage of having the logic of creating the breadcrumb in a proxy model is that it is independent of any ui code, so the proxy model can be used directly to create a breadcrumb view in QML too.

Breadcrumb navigation enables the use of a tree model in QML

The QML there is far from what it should be visually, but as the model of “The breadcrumbs of a selection” is separate from its visualisation, that can be improved separately. I know people want to know how to put a Qt Tree Model into QML, because they keep googling for it🙂. Well it is possible.

So while the QxtCrumbView gives you a perhaps more ready-made solution, this approach gives you the pieces you need to create flexible breadcrumbs for multiple UIs.

One Response to “Breadcrumbs for your view”

  1. Navigating a QAbstractItemModel tree in a QML view « Steveire’s Blog Says:

    […] this concept was actually the motivation behind developing a ui independent breadcrumbs list and a method of proxying selections through complex […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: