PDA

View Full Version : 2 Questions about QListWidget



SkripT
23rd March 2006, 01:21
Hi all, in my application I use a QListWidget of icons, an I've got 2 questions about it:
1) In some moments I need to do a processation of all the selected items in the list. What do you think that's the best way to do it: calling QListWidget::selectedItems and then process all the returned items or directly search for all the items in the list which is selected and process it. I have read the source code to see if "selectedItems" method saves internally a list with the current selected items (as I think) or simply it makes a search for all the items of the list to see which are selected. But I haven't found it. Anyone knows it?

2) This question is related with previous. Do you think that QListWidget::findItems uses an eficient way to make the search (i.e a kind of dictionary or hash with the items of the list) or simply it searches for all the items in the list testing which of they matches with the text and the flags of the search?

Thanks.

ePharaoh
23rd March 2006, 07:27
I have read the source code to see if "selectedItems" method saves internally a list with the current selected items (as I think) or simply it makes a search for all the items of the list to see which are selected.

Well, without looking at the source code I can say, it is better to use a method like 'selectedItems', because, it can always be optimised in the future.

Basically, in OOP methodology, the details of the implementation should not be exposed to the clients. So, if a feature is being provided by an object, you can assume it has been implemented in the best possible way internally by that object.

SkripT
23rd March 2006, 11:18
Well, without looking at the source code I can say...

Thanks ePharaoh for the suggestion, but I want to know it as exactly as possible because I could have a list of several items, and I don't want to go through it two times ;)

jpn
23rd March 2006, 11:35
You could find answers to these kind of questions by looking at the source code by yourself.. ;)

1) Item based views have a same kind of selection model than model based views. So it doesn't iterate through all items and check for selected ones. The selection model keeps track of selected items.

2) See QAbstractItemModel::match(). It iterates through appropriate indexes.