PDA

View Full Version : Delete duplicates proxy model



mau_igna_06
22nd September 2014, 22:17
Hi, I'm using a LineEdit with QCompleter that reads its data from a tablemodel, as delegate of a tableview to edit data. The only problem I'm having is that the LineEdit suggest many times the same because data is not unique for the column I set up to act as filter.

So I think I need a proxy to delete duplicates first. I think this can't be done subclassing QSortFilterProxyModel because the proxy compears the data not with a criteria but with itself. Therefore, QAbstractProxyModel should be subclassed and at least mapToSource and mapFromSource must be reimplemmented.

I would need the following:
When setSourceModel is called the proxy should select all unique data and filter out duplicates (acording to a column passed to the constructor). In addition to that it should save all the indexes of the rows of data that according to the filtering column are unique, so that if one labeled unique row is deleted and it had duplicates, a duplicate can take the place of the recently deleted "unique".

So mapFromSource should give null indexes to repeated data. I think some slots should be set up to update the uniques when the ones before are deleted in the source model.

Can you tell me if you think the idea is right, and guide me a little on how to do it, an example would be much appreciated since I have no experience on subclassing proxies.