2014-09-26 15:49:49 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-16 12:00:23 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2014-09-26 15:49:49 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-16 12:00:23 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2014-09-26 15:49:49 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofilernotesmodel.h"
|
2014-09-26 15:49:49 +02:00
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QmlProfilerNotesModel::QmlProfilerNotesModel(QObject *parent) : QObject(parent), m_modelManager(0),
|
|
|
|
|
m_modified(false)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::count() const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
return m_data.count();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::setModelManager(QmlProfilerModelManager *modelManager)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
m_modelManager = modelManager;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-05 17:33:21 +01:00
|
|
|
void QmlProfilerNotesModel::addTimelineModel(const TimelineModel *timelineModel)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
2014-12-05 17:33:21 +01:00
|
|
|
connect(timelineModel, &TimelineModel::destroyed,
|
2014-10-27 17:41:22 +01:00
|
|
|
this, &QmlProfilerNotesModel::removeTimelineModel);
|
2014-09-26 15:49:49 +02:00
|
|
|
m_timelineModels.insert(timelineModel->modelId(), timelineModel);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::typeId(int index) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
const Note ¬e = m_data[index];
|
|
|
|
|
auto it = m_timelineModels.find(note.timelineModel);
|
|
|
|
|
if (it == m_timelineModels.end())
|
|
|
|
|
return -1; // This can happen if one of the timeline models has been removed
|
|
|
|
|
return it.value()->typeId(note.timelineIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QString QmlProfilerNotesModel::text(int index) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
return m_data[index].text;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::timelineModel(int index) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
return m_data[index].timelineModel;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::timelineIndex(int index) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
return m_data[index].timelineIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantList QmlProfilerNotesModel::byTypeId(int selectedType) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
QVariantList ret;
|
|
|
|
|
for (int noteId = 0; noteId < count(); ++noteId) {
|
|
|
|
|
if (selectedType == typeId(noteId))
|
|
|
|
|
ret << noteId;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantList QmlProfilerNotesModel::byTimelineModel(int timelineModel) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
QVariantList ret;
|
|
|
|
|
for (int noteId = 0; noteId < count(); ++noteId) {
|
|
|
|
|
if (m_data[noteId].timelineModel == timelineModel)
|
|
|
|
|
ret << noteId;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::get(int timelineModel, int timelineIndex) const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
for (int noteId = 0; noteId < count(); ++noteId) {
|
|
|
|
|
const Note ¬e = m_data[noteId];
|
|
|
|
|
if (note.timelineModel == timelineModel && note.timelineIndex == timelineIndex)
|
|
|
|
|
return noteId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::add(int timelineModel, int timelineIndex, const QString &text)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
2014-12-05 17:33:21 +01:00
|
|
|
const TimelineModel *model = m_timelineModels[timelineModel];
|
2014-10-27 18:42:39 +01:00
|
|
|
int typeId = model->typeId(timelineIndex);
|
2014-09-26 15:49:49 +02:00
|
|
|
Note note = { text, timelineModel, timelineIndex };
|
|
|
|
|
m_data << note;
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = true;
|
2014-09-26 15:49:49 +02:00
|
|
|
emit changed(typeId, timelineModel, timelineIndex);
|
|
|
|
|
return m_data.count() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::update(int index, const QString &text)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
Note ¬e = m_data[index];
|
|
|
|
|
if (text != note.text) {
|
|
|
|
|
note.text = text;
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = true;
|
2014-09-26 15:49:49 +02:00
|
|
|
emit changed(typeId(index), note.timelineModel, note.timelineIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::remove(int index)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
Note ¬e = m_data[index];
|
|
|
|
|
int noteType = typeId(index);
|
|
|
|
|
int timelineModel = note.timelineModel;
|
|
|
|
|
int timelineIndex = note.timelineIndex;
|
|
|
|
|
m_data.removeAt(index);
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = true;
|
2014-09-26 15:49:49 +02:00
|
|
|
emit changed(noteType, timelineModel, timelineIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
bool QmlProfilerNotesModel::isModified() const
|
2014-11-03 14:19:26 +01:00
|
|
|
{
|
|
|
|
|
return m_modified;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::removeTimelineModel(QObject *timelineModel)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
for (auto i = m_timelineModels.begin(); i != m_timelineModels.end();) {
|
|
|
|
|
if (i.value() == timelineModel)
|
|
|
|
|
i = m_timelineModels.erase(i);
|
|
|
|
|
else
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerNotesModel::add(int typeId, qint64 start, qint64 duration, const QString &text)
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
int timelineModel = -1;
|
|
|
|
|
int timelineIndex = -1;
|
2014-12-05 17:33:21 +01:00
|
|
|
foreach (const TimelineModel *model, m_timelineModels) {
|
|
|
|
|
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;
|
2014-10-27 18:42:39 +01:00
|
|
|
if (model->typeId(i) == typeId && model->startTime(i) == start &&
|
|
|
|
|
model->duration(i) == duration) {
|
2014-09-26 15:49:49 +02:00
|
|
|
timelineModel = model->modelId();
|
|
|
|
|
timelineIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (timelineIndex != -1)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timelineModel == -1 || timelineIndex == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
Note note = { text, timelineModel, timelineIndex };
|
|
|
|
|
m_data << note;
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = true;
|
2014-09-26 15:49:49 +02:00
|
|
|
return m_data.count() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 12:32:25 +01:00
|
|
|
void QmlProfilerNotesModel::setText(int noteId, const QString &text)
|
|
|
|
|
{
|
|
|
|
|
if (text.length() > 0) {
|
|
|
|
|
update(noteId, text);
|
|
|
|
|
} else {
|
|
|
|
|
remove(noteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProfilerNotesModel::setText(int modelIndex, int index, const QString &text)
|
|
|
|
|
{
|
|
|
|
|
int noteId = get(modelIndex, index);
|
|
|
|
|
if (noteId == -1) {
|
|
|
|
|
if (text.length() > 0)
|
|
|
|
|
add(modelIndex, index, text);
|
|
|
|
|
} else {
|
|
|
|
|
setText(noteId, text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::clear()
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
m_data.clear();
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = false;
|
2014-09-26 15:49:49 +02:00
|
|
|
emit changed(-1, -1, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::loadData()
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
m_data.clear();
|
|
|
|
|
const QVector<QmlProfilerDataModel::QmlEventNoteData> ¬es =
|
|
|
|
|
m_modelManager->qmlModel()->getEventNotes();
|
|
|
|
|
for (int i = 0; i != notes.size(); ++i) {
|
|
|
|
|
const QmlProfilerDataModel::QmlEventNoteData ¬e = notes[i];
|
|
|
|
|
add(note.typeIndex, note.startTime, note.duration, note.text);
|
|
|
|
|
}
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = false; // reset after loading
|
2014-09-26 15:49:49 +02:00
|
|
|
emit changed(-1, -1, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerNotesModel::saveData()
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
|
QVector<QmlProfilerDataModel::QmlEventNoteData> notes;
|
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
|
const Note ¬e = m_data[i];
|
|
|
|
|
auto it = m_timelineModels.find(note.timelineModel);
|
|
|
|
|
if (it == m_timelineModels.end())
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-12-05 17:33:21 +01:00
|
|
|
const TimelineModel *model = it.value();
|
2014-09-26 15:49:49 +02:00
|
|
|
QmlProfilerDataModel::QmlEventNoteData save = {
|
2014-10-27 18:42:39 +01:00
|
|
|
model->typeId(note.timelineIndex), model->startTime(note.timelineIndex),
|
|
|
|
|
model->duration(note.timelineIndex), note.text
|
2014-09-26 15:49:49 +02:00
|
|
|
};
|
|
|
|
|
notes.append(save);
|
|
|
|
|
}
|
|
|
|
|
m_modelManager->qmlModel()->setNoteData(notes);
|
2014-11-03 14:19:26 +01:00
|
|
|
m_modified = false;
|
2014-09-26 15:49:49 +02:00
|
|
|
}
|
|
|
|
|
}
|