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.
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.
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.
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.