Question about model/view design
I'm having trouble getting my functionality to fit with Qt's model/view architecture. Instead of explaining my exact situation, it's easier to do an analogy:
The analogous app has a folder list on the left, and a list of files on the right (in a table). The user can select multiple folders in the list on the left and I need to show all the selected folders' files in a single sorted table on the right.
My model extends QAbstractItemModel and has a list of all the folders displayed on the left from which it builds a single list of all the files contained by all the folders. My table view of files extends QTableView and uses the selectionChanged(QItemSelection selected, QItemSelection deselected) method to receive notification of folder selection changes.
My problem is that I can't figure out how to get a filtered list of files from the model without telling the model which folders are selected, which would break the model/view separation. Qt's model/view classes and methods are still a bit new to me, so I may be missing an obvious solution.
What you are looking for, I think, is the proxy model idea. A proxy model is a QAbstractItemModel that sits between another QAbstractItemModel that supplies data, and a view (or yet another proxy model) on top of that. There are several, but you are looking for [[doc:QSortFilterProxyModel]] I think.
Well, I tried QSortFilterProxyModel and I think it will work for what I need. However, the JRE is now crashing with an "EXCEPTION_ACCESS_VIOLATION" in QtGui4.dll whenever I call the "reset()" or "invalidate()" method in my model after the data has changed. If my model class extends QAbstractItemModel, then I get no error when calling reset(). Also, the "Problematic frame" in QtGui4.dll as reported by the dump is the same whether I call reset() or invalidate(). It seems the issue is in the native code in QSortFilterProxyModel. I've tried 4.5.2 and 4.6.3 on win32. Ugh.
Sorry, I know nothing about java and its possible problems with model-view. Note that a QSortFilterProxyModel does not replace a QAbstractItemModel, but is used on top of it.