QmlProfiler: Fix next/previous selection in timeline

If we've changed the model index we don't reuse the item index for
selecting the next item. Also, there are two reasons why
firstIndexNoParents() can return -1. They have to be handled
differently.

Change-Id: Ib33e3bd0e96a39a71658a0e4509926012a91bf27
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2014-09-29 18:15:59 +02:00
parent 0f3f3df36c
commit 4481925b1a

View File

@@ -585,20 +585,23 @@ void TimelineRenderer::selectPrev()
int TimelineRenderer::nextItemFromSelectionId(int modelIndex, int selectionId) const
{
int modelCount = m_profilerModelProxy->count(modelIndex);
if (modelCount == 0)
return -1;
int ndx = -1;
if (m_selectedItem == -1)
if (m_selectedItem == -1 || modelIndex != m_selectedModel)
ndx = m_profilerModelProxy->firstIndexNoParents(modelIndex, m_startTime);
else
ndx = m_selectedItem + 1;
if (ndx < 0)
return -1;
if (ndx >= m_profilerModelProxy->count(modelIndex))
if (ndx < 0 || ndx >= modelCount)
ndx = 0;
int startIndex = ndx;
do {
if (m_profilerModelProxy->selectionId(modelIndex, ndx) == selectionId)
return ndx;
ndx = (ndx + 1) % m_profilerModelProxy->count(modelIndex);
ndx = (ndx + 1) % modelCount;
} while (ndx != startIndex);
return -1;
}
@@ -606,7 +609,7 @@ int TimelineRenderer::nextItemFromSelectionId(int modelIndex, int selectionId) c
int TimelineRenderer::prevItemFromSelectionId(int modelIndex, int selectionId) const
{
int ndx = -1;
if (m_selectedItem == -1)
if (m_selectedItem == -1 || modelIndex != m_selectedModel)
ndx = m_profilerModelProxy->firstIndexNoParents(modelIndex, m_startTime);
else
ndx = m_selectedItem - 1;