360 \private |
360 \private |
361 */ |
361 */ |
362 HbAbstractViewItem* HbAbstractItemContainerPrivate::item(const QModelIndex &index) const |
362 HbAbstractViewItem* HbAbstractItemContainerPrivate::item(const QModelIndex &index) const |
363 { |
363 { |
364 int itemCount = mItems.count(); |
364 int itemCount = mItems.count(); |
365 for (int i = 0; i < itemCount; ++i) { |
365 if (index.isValid()) { |
366 // This could use binary search as model indexes are in sorted. |
366 if (itemCount > 0) { |
367 if (mItems.at(i)->modelIndex() == index) { |
367 HbModelIterator *iterator = mItemView->modelIterator(); |
368 return mItems.at(i); |
368 int positionFirstIndex = iterator->indexPosition(mItems.first()->modelIndex()); |
369 } |
369 |
370 } |
370 // when new items are inserted, they will appear in the end of container before a model index is assigned to them |
371 |
371 if (positionFirstIndex >= 0) { |
372 // TODO: The lower (commented out) part of the code is an optimized version of the above. |
372 int positionIndex = iterator->indexPosition(index); |
373 // However, there are problems with TreeView's deep models concerning the optimized version. |
373 HbAbstractViewItem *item = mItems.value(positionIndex - positionFirstIndex); |
374 // The optimized version should be fixed and taken into use later on. |
374 if ( item |
375 |
375 && item->modelIndex() == index) { |
376 /* |
|
377 int itemCount = mItems.count(); |
|
378 if (itemCount > 0) { |
|
379 if (index.isValid()) { |
|
380 int itemIndex = mItemView->indexPosition(index) - mItemView->indexPosition(mItems.first()->modelIndex()); |
|
381 return mItems.value(itemIndex); |
|
382 } else { |
|
383 for (int i = 0; i < itemCount; ++i) { |
|
384 // This could use binary search as model indexes are in sorted. |
|
385 HbAbstractViewItem *item = mItems.at(i); |
|
386 if (item->modelIndex() == index) { |
|
387 return item; |
376 return item; |
388 } |
377 } |
389 } |
378 } |
390 } |
379 } |
391 } |
380 } else { |
392 */ |
381 // searching items e.g. removed from model |
393 |
382 for (int i = 0; i < itemCount; ++i) { |
|
383 if (!mItems.at(i)->modelIndex().isValid()) { |
|
384 return mItems.at(i); |
|
385 } |
|
386 } |
|
387 } |
394 return 0; |
388 return 0; |
395 } |
389 } |
396 |
390 |
397 /*! |
391 /*! |
398 \private |
392 \private |