2014-09-26 15:49:49 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-09-26 15:49:49 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-09-26 15:49:49 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-09-26 15:49:49 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofilernotesmodel.h"
|
2014-09-26 15:49:49 +02:00
|
|
|
|
2016-07-04 09:52:11 +02:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
2014-09-26 15:49:49 +02:00
|
|
|
namespace QmlProfiler {
|
|
|
|
|
|
2016-04-26 12:26:46 +02:00
|
|
|
QmlProfilerNotesModel::QmlProfilerNotesModel(QObject *parent) : TimelineNotesModel(parent)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 11:34:15 +02:00
|
|
|
int QmlProfilerNotesModel::addQmlNote(int typeId, int collapsedRow, qint64 start, qint64 duration,
|
2016-05-31 14:51:25 +02:00
|
|
|
const QString &text)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
2016-07-06 11:34:15 +02:00
|
|
|
qint64 difference = std::numeric_limits<qint64>::max();
|
|
|
|
|
int foundTypeId = -1;
|
2014-09-26 15:49:49 +02:00
|
|
|
int timelineModel = -1;
|
|
|
|
|
int timelineIndex = -1;
|
2014-12-09 11:01:23 +01:00
|
|
|
foreach (const Timeline::TimelineModel *model, timelineModels()) {
|
2014-12-05 17:33:21 +01:00
|
|
|
if (model->handlesTypeId(typeId)) {
|
2014-09-26 15:49:49 +02:00
|
|
|
for (int i = model->firstIndex(start); i <= model->lastIndex(start + duration); ++i) {
|
|
|
|
|
if (i < 0)
|
|
|
|
|
continue;
|
2016-07-06 11:34:15 +02:00
|
|
|
if (collapsedRow != -1 && collapsedRow != model->collapsedRow(i))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
qint64 modelStart = model->startTime(i);
|
|
|
|
|
qint64 modelDuration = model->duration(i);
|
|
|
|
|
|
|
|
|
|
if (modelStart + modelDuration < start || start + duration < modelStart)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Accept different type IDs if row and time stamps match.
|
|
|
|
|
// Some models base their type IDs on data from secondary events which may get
|
|
|
|
|
// stripped by range restrictions.
|
|
|
|
|
int modelTypeId = model->typeId(i);
|
|
|
|
|
if (foundTypeId == typeId && modelTypeId != typeId)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
qint64 newDifference = qAbs(modelStart - start) + qAbs(modelDuration - duration);
|
|
|
|
|
if (newDifference < difference) {
|
2014-09-26 15:49:49 +02:00
|
|
|
timelineModel = model->modelId();
|
|
|
|
|
timelineIndex = i;
|
2016-07-06 11:34:15 +02:00
|
|
|
difference = newDifference;
|
|
|
|
|
foundTypeId = modelTypeId;
|
|
|
|
|
if (difference == 0 && modelTypeId == typeId)
|
|
|
|
|
break;
|
2014-09-26 15:49:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-06 11:34:15 +02:00
|
|
|
if (difference == 0 && foundTypeId == typeId)
|
2014-09-26 15:49:49 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timelineModel == -1 || timelineIndex == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2014-12-08 16:14:52 +01:00
|
|
|
return TimelineNotesModel::add(timelineModel, timelineIndex, text);
|
2014-11-04 12:32:25 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-26 15:49:49 +02:00
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::loadData()
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
2014-12-08 16:14:52 +01:00
|
|
|
blockSignals(true);
|
2016-04-26 12:26:46 +02:00
|
|
|
for (int i = 0; i != m_notes.size(); ++i) {
|
2016-07-06 11:34:15 +02:00
|
|
|
QmlNote ¬e = m_notes[i];
|
|
|
|
|
note.setLoaded(addQmlNote(note.typeIndex(), note.collapsedRow(), note.startTime(),
|
|
|
|
|
note.duration(), note.text()) != -1);
|
2014-09-26 15:49:49 +02:00
|
|
|
}
|
2014-12-08 16:14:52 +01:00
|
|
|
resetModified();
|
|
|
|
|
blockSignals(false);
|
2014-09-26 15:49:49 +02:00
|
|
|
emit changed(-1, -1, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 11:34:15 +02:00
|
|
|
void QmlProfilerNotesModel::saveData()
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
2016-07-04 09:52:11 +02:00
|
|
|
// Keep notes that are outside the given range, overwrite the ones inside the range.
|
2016-07-06 11:34:15 +02:00
|
|
|
m_notes = Utils::filtered(m_notes, [](const QmlNote ¬e) {
|
|
|
|
|
return !note.loaded();
|
2016-07-04 09:52:11 +02:00
|
|
|
});
|
|
|
|
|
|
2014-09-26 15:49:49 +02:00
|
|
|
for (int i = 0; i < count(); ++i) {
|
2014-12-09 11:01:23 +01:00
|
|
|
const Timeline::TimelineModel *model = timelineModelByModelId(timelineModel(i));
|
2014-12-08 16:14:52 +01:00
|
|
|
if (!model)
|
2014-09-26 15:49:49 +02:00
|
|
|
continue;
|
|
|
|
|
|
2014-12-08 16:14:52 +01:00
|
|
|
int index = timelineIndex(i);
|
2016-04-26 11:50:59 +02:00
|
|
|
QmlNote save = {
|
2014-12-08 16:14:52 +01:00
|
|
|
model->typeId(index),
|
2016-07-06 11:34:15 +02:00
|
|
|
model->collapsedRow(index),
|
2014-12-08 16:14:52 +01:00
|
|
|
model->startTime(index),
|
|
|
|
|
model->duration(index),
|
|
|
|
|
text(i)
|
2014-09-26 15:49:49 +02:00
|
|
|
};
|
2016-04-26 12:26:46 +02:00
|
|
|
m_notes.append(save);
|
2014-09-26 15:49:49 +02:00
|
|
|
}
|
2014-12-08 16:14:52 +01:00
|
|
|
resetModified();
|
2014-09-26 15:49:49 +02:00
|
|
|
}
|
2016-04-26 12:26:46 +02:00
|
|
|
|
|
|
|
|
const QVector<QmlNote> &QmlProfilerNotesModel::notes() const
|
|
|
|
|
{
|
|
|
|
|
return m_notes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerNotesModel::setNotes(const QVector<QmlNote> ¬es)
|
|
|
|
|
{
|
|
|
|
|
m_notes = notes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerNotesModel::clear()
|
|
|
|
|
{
|
|
|
|
|
TimelineNotesModel::clear();
|
|
|
|
|
m_notes.clear();
|
2014-09-26 15:49:49 +02:00
|
|
|
}
|
2016-04-26 12:26:46 +02:00
|
|
|
|
|
|
|
|
} // namespace QmlProfiler
|