diff --git a/src/plugins/qmlprofiler/sortedtimelinemodel.cpp b/src/plugins/qmlprofiler/sortedtimelinemodel.cpp index 9453b636946..6a39b96d5b7 100644 --- a/src/plugins/qmlprofiler/sortedtimelinemodel.cpp +++ b/src/plugins/qmlprofiler/sortedtimelinemodel.cpp @@ -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. */ /*! diff --git a/src/plugins/qmlprofiler/sortedtimelinemodel.h b/src/plugins/qmlprofiler/sortedtimelinemodel.h index 883b3e30b26..3aac863c610 100644 --- a/src/plugins/qmlprofiler/sortedtimelinemodel.h +++ b/src/plugins/qmlprofiler/sortedtimelinemodel.h @@ -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 static inline int insertSorted(QVector &container, const RangeDelimiter &item) {