forked from qt-creator/qt-creator
QmlProfiler: make sure indices in SortedTimelineModel are correct
In the rare case that a new item is not appended but inserted in the middle of already existing data, the end times were confused. On that occasion, also add a note explaining how the indices work, Change-Id: I587b8285cd5482a9ffb1592302b442192e5944b8 Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
@@ -39,6 +39,10 @@
|
||||
range. Mind that you can always make that happen by defining a range that spans the whole
|
||||
available time span. That, however, will make any code that uses firstStartTime() and
|
||||
lastEndTime() for selecting subsets of the model always select all of it.
|
||||
|
||||
\note Indices returned from the various methods are only valid until a new range is inserted
|
||||
before them. Inserting a new range before a given index moves the range pointed to by the
|
||||
index by one. Incrementing the index by one will make it point to the item again.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
||||
@@ -83,13 +83,18 @@ public:
|
||||
/* Doing insert-sort here is preferable as most of the time the times will actually be
|
||||
* presorted in the right way. So usually this will just result in appending. */
|
||||
int index = insertSorted(ranges, Range(startTime, duration, item));
|
||||
if (index < ranges.size() - 1)
|
||||
incrementStartIndices(index);
|
||||
insertSorted(endTimes, RangeEnd(index, startTime + duration));
|
||||
return index;
|
||||
}
|
||||
|
||||
inline int insertStart(qint64 startTime, const Data &item)
|
||||
{
|
||||
return insertSorted(ranges, Range(startTime, 0, item));
|
||||
int index = insertSorted(ranges, Range(startTime, 0, item));
|
||||
if (index < ranges.size() - 1)
|
||||
incrementStartIndices(index);
|
||||
return index;
|
||||
}
|
||||
|
||||
inline void insertEnd(int index, qint64 duration)
|
||||
@@ -154,6 +159,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void incrementStartIndices(int index)
|
||||
{
|
||||
for (int i = 0; i < endTimes.size(); ++i) {
|
||||
if (endTimes[i].startIndex >= index)
|
||||
endTimes[i].startIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename RangeDelimiter>
|
||||
static inline int insertSorted(QVector<RangeDelimiter> &container, const RangeDelimiter &item)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user