forked from qt-creator/qt-creator
QmlProfiler: split notes model in generic and specific classes
Change-Id: I633dc6a862f344a7e5e86c25e44e400e3000f644 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
@@ -40,7 +40,8 @@ SOURCES += \
|
||||
timelineselectionrenderpass.cpp \
|
||||
timelinenotesrenderpass.cpp \
|
||||
timelinerenderpass.cpp \
|
||||
timelinerenderstate.cpp
|
||||
timelinerenderstate.cpp \
|
||||
timelinenotesmodel.cpp
|
||||
|
||||
HEADERS += \
|
||||
abstractqmlprofilerrunner.h \
|
||||
@@ -83,7 +84,9 @@ HEADERS += \
|
||||
timelineselectionrenderpass.h \
|
||||
timelinenotesrenderpass.h \
|
||||
timelinerenderpass.h \
|
||||
timelinerenderstate.h
|
||||
timelinerenderstate.h \
|
||||
timelinenotesmodel.h \
|
||||
timelinenotesmodel_p.h
|
||||
|
||||
RESOURCES += \
|
||||
qml/qmlprofiler.qrc
|
||||
|
||||
@@ -53,6 +53,7 @@ QtcPlugin {
|
||||
"timelineitemsrenderpass.cpp", "timelineitemsrenderpass.h",
|
||||
"timelinemodel.cpp", "timelinemodel.h", "timelinemodel_p.h",
|
||||
"timelinemodelaggregator.cpp", "timelinemodelaggregator.h",
|
||||
"timelinenotesmodel.cpp", "timelinenotesmodel.h", "timelinenotesmodel_p.h",
|
||||
"timelinenotesrenderpass.cpp", "timelinenotesrenderpass.h",
|
||||
"timelinerenderer.cpp", "timelinerenderer.h",
|
||||
"timelinerenderpass.cpp", "timelinerenderpass.h",
|
||||
|
||||
@@ -32,135 +32,21 @@
|
||||
|
||||
namespace QmlProfiler {
|
||||
|
||||
QmlProfilerNotesModel::QmlProfilerNotesModel(QObject *parent) : QObject(parent), m_modelManager(0),
|
||||
m_modified(false)
|
||||
QmlProfilerNotesModel::QmlProfilerNotesModel(QObject *parent) : TimelineNotesModel(parent),
|
||||
m_modelManager(0)
|
||||
{
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::count() const
|
||||
{
|
||||
return m_data.count();
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::setModelManager(QmlProfilerModelManager *modelManager)
|
||||
{
|
||||
m_modelManager = modelManager;
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::addTimelineModel(const TimelineModel *timelineModel)
|
||||
{
|
||||
connect(timelineModel, &TimelineModel::destroyed,
|
||||
this, &QmlProfilerNotesModel::removeTimelineModel);
|
||||
m_timelineModels.insert(timelineModel->modelId(), timelineModel);
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::typeId(int index) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
QString QmlProfilerNotesModel::text(int index) const
|
||||
{
|
||||
return m_data[index].text;
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::timelineModel(int index) const
|
||||
{
|
||||
return m_data[index].timelineModel;
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::timelineIndex(int index) const
|
||||
{
|
||||
return m_data[index].timelineIndex;
|
||||
}
|
||||
|
||||
QVariantList QmlProfilerNotesModel::byTypeId(int selectedType) const
|
||||
{
|
||||
QVariantList ret;
|
||||
for (int noteId = 0; noteId < count(); ++noteId) {
|
||||
if (selectedType == typeId(noteId))
|
||||
ret << noteId;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QVariantList QmlProfilerNotesModel::byTimelineModel(int timelineModel) const
|
||||
{
|
||||
QVariantList ret;
|
||||
for (int noteId = 0; noteId < count(); ++noteId) {
|
||||
if (m_data[noteId].timelineModel == timelineModel)
|
||||
ret << noteId;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::get(int timelineModel, int timelineIndex) const
|
||||
{
|
||||
for (int noteId = 0; noteId < count(); ++noteId) {
|
||||
const Note ¬e = m_data[noteId];
|
||||
if (note.timelineModel == timelineModel && note.timelineIndex == timelineIndex)
|
||||
return noteId;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::add(int timelineModel, int timelineIndex, const QString &text)
|
||||
{
|
||||
const TimelineModel *model = m_timelineModels[timelineModel];
|
||||
int typeId = model->typeId(timelineIndex);
|
||||
Note note = { text, timelineModel, timelineIndex };
|
||||
m_data << note;
|
||||
m_modified = true;
|
||||
emit changed(typeId, timelineModel, timelineIndex);
|
||||
return m_data.count() - 1;
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::update(int index, const QString &text)
|
||||
{
|
||||
Note ¬e = m_data[index];
|
||||
if (text != note.text) {
|
||||
note.text = text;
|
||||
m_modified = true;
|
||||
emit changed(typeId(index), note.timelineModel, note.timelineIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::remove(int index)
|
||||
{
|
||||
Note ¬e = m_data[index];
|
||||
int noteType = typeId(index);
|
||||
int timelineModel = note.timelineModel;
|
||||
int timelineIndex = note.timelineIndex;
|
||||
m_data.removeAt(index);
|
||||
m_modified = true;
|
||||
emit changed(noteType, timelineModel, timelineIndex);
|
||||
}
|
||||
|
||||
bool QmlProfilerNotesModel::isModified() const
|
||||
{
|
||||
return m_modified;
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::removeTimelineModel(QObject *timelineModel)
|
||||
{
|
||||
for (auto i = m_timelineModels.begin(); i != m_timelineModels.end();) {
|
||||
if (i.value() == timelineModel)
|
||||
i = m_timelineModels.erase(i);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
int QmlProfilerNotesModel::add(int typeId, qint64 start, qint64 duration, const QString &text)
|
||||
{
|
||||
int timelineModel = -1;
|
||||
int timelineIndex = -1;
|
||||
foreach (const TimelineModel *model, m_timelineModels) {
|
||||
foreach (const TimelineModel *model, timelineModels()) {
|
||||
if (model->handlesTypeId(typeId)) {
|
||||
for (int i = model->firstIndex(start); i <= model->lastIndex(start + duration); ++i) {
|
||||
if (i < 0)
|
||||
@@ -180,49 +66,22 @@ int QmlProfilerNotesModel::add(int typeId, qint64 start, qint64 duration, const
|
||||
if (timelineModel == -1 || timelineIndex == -1)
|
||||
return -1;
|
||||
|
||||
Note note = { text, timelineModel, timelineIndex };
|
||||
m_data << note;
|
||||
m_modified = true;
|
||||
return m_data.count() - 1;
|
||||
return TimelineNotesModel::add(timelineModel, timelineIndex, text);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::clear()
|
||||
{
|
||||
m_data.clear();
|
||||
m_modified = false;
|
||||
emit changed(-1, -1, -1);
|
||||
}
|
||||
|
||||
void QmlProfilerNotesModel::loadData()
|
||||
{
|
||||
m_data.clear();
|
||||
blockSignals(true);
|
||||
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);
|
||||
}
|
||||
m_modified = false; // reset after loading
|
||||
resetModified();
|
||||
blockSignals(false);
|
||||
emit changed(-1, -1, -1);
|
||||
}
|
||||
|
||||
@@ -230,19 +89,20 @@ void QmlProfilerNotesModel::saveData()
|
||||
{
|
||||
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())
|
||||
const TimelineModel *model = timelineModelByModelId(timelineModel(i));
|
||||
if (!model)
|
||||
continue;
|
||||
|
||||
const TimelineModel *model = it.value();
|
||||
int index = timelineIndex(i);
|
||||
QmlProfilerDataModel::QmlEventNoteData save = {
|
||||
model->typeId(note.timelineIndex), model->startTime(note.timelineIndex),
|
||||
model->duration(note.timelineIndex), note.text
|
||||
model->typeId(index),
|
||||
model->startTime(index),
|
||||
model->duration(index),
|
||||
text(i)
|
||||
};
|
||||
notes.append(save);
|
||||
}
|
||||
m_modelManager->qmlModel()->setNoteData(notes);
|
||||
m_modified = false;
|
||||
resetModified();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,66 +28,26 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NOTESMODEL_H
|
||||
#define NOTESMODEL_H
|
||||
#ifndef QMLPROFILERNOTESMODEL_H
|
||||
#define QMLPROFILERNOTESMODEL_H
|
||||
|
||||
#include "qmlprofilertimelinemodel.h"
|
||||
#include "qmlprofilermodelmanager.h"
|
||||
#include "timelinenotesmodel.h"
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
|
||||
namespace QmlProfiler {
|
||||
class QMLPROFILER_EXPORT QmlProfilerNotesModel : public QObject {
|
||||
class QMLPROFILER_EXPORT QmlProfilerNotesModel : public TimelineNotesModel {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ count NOTIFY changed)
|
||||
public:
|
||||
struct Note {
|
||||
// Saved properties
|
||||
QString text;
|
||||
|
||||
// Cache, created on loading
|
||||
int timelineModel;
|
||||
int timelineIndex;
|
||||
};
|
||||
|
||||
QmlProfilerNotesModel(QObject *parent);
|
||||
int count() const;
|
||||
|
||||
void setModelManager(QmlProfilerModelManager *modelManager);
|
||||
void addTimelineModel(const TimelineModel *timelineModel);
|
||||
|
||||
Q_INVOKABLE int typeId(int index) const;
|
||||
Q_INVOKABLE QString text(int index) const;
|
||||
Q_INVOKABLE int timelineModel(int index) const;
|
||||
Q_INVOKABLE int timelineIndex(int index) const;
|
||||
|
||||
Q_INVOKABLE QVariantList byTypeId(int typeId) const;
|
||||
Q_INVOKABLE QVariantList byTimelineModel(int timelineModel) const;
|
||||
|
||||
Q_INVOKABLE int get(int timelineModel, int timelineIndex) const;
|
||||
Q_INVOKABLE int add(int timelineModel, int timelineIndex, const QString &text);
|
||||
Q_INVOKABLE void update(int index, const QString &text);
|
||||
Q_INVOKABLE void remove(int index);
|
||||
|
||||
Q_INVOKABLE void setText(int noteId, const QString &text);
|
||||
Q_INVOKABLE void setText(int modelIndex, int index, const QString &text);
|
||||
|
||||
bool isModified() const;
|
||||
void loadData();
|
||||
void saveData();
|
||||
void clear();
|
||||
|
||||
signals:
|
||||
void changed(int typeId, int timelineModel, int timelineIndex);
|
||||
|
||||
private slots:
|
||||
void removeTimelineModel(QObject *timelineModel);
|
||||
|
||||
protected:
|
||||
QmlProfilerModelManager *m_modelManager;
|
||||
QList<Note> m_data;
|
||||
QHash<int, const TimelineModel *> m_timelineModels;
|
||||
bool m_modified;
|
||||
|
||||
int add(int typeId, qint64 startTime, qint64 duration, const QString &text);
|
||||
};
|
||||
|
||||
@@ -106,7 +106,7 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, Analyzer::IAnalyzerT
|
||||
|
||||
qmlRegisterType<TimelineZoomControl>();
|
||||
qmlRegisterType<TimelineModel>();
|
||||
qmlRegisterType<QmlProfilerNotesModel>();
|
||||
qmlRegisterType<TimelineNotesModel>();
|
||||
|
||||
d->m_mainView = new QmlProfilerQuickView(this);
|
||||
d->m_mainView->setResizeMode(QQuickView::SizeRootObjectToView);
|
||||
|
||||
@@ -50,10 +50,10 @@ public:
|
||||
TimelineModelAggregator *q;
|
||||
|
||||
QList <TimelineModel *> modelList;
|
||||
QmlProfilerNotesModel *notesModel;
|
||||
TimelineNotesModel *notesModel;
|
||||
};
|
||||
|
||||
TimelineModelAggregator::TimelineModelAggregator(QmlProfilerNotesModel *notes, QObject *parent)
|
||||
TimelineModelAggregator::TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent)
|
||||
: QObject(parent), d(new TimelineModelAggregatorPrivate(this))
|
||||
{
|
||||
d->notesModel = notes;
|
||||
@@ -92,7 +92,7 @@ QVariantList TimelineModelAggregator::models() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
QmlProfilerNotesModel *TimelineModelAggregator::notes() const
|
||||
TimelineNotesModel *TimelineModelAggregator::notes() const
|
||||
{
|
||||
return d->notesModel;
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ class TimelineModelAggregator : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int height READ height NOTIFY heightChanged)
|
||||
Q_PROPERTY(QVariantList models READ models NOTIFY modelsChanged)
|
||||
Q_PROPERTY(QmlProfiler::QmlProfilerNotesModel *notes READ notes CONSTANT)
|
||||
Q_PROPERTY(QmlProfiler::TimelineNotesModel *notes READ notes CONSTANT)
|
||||
public:
|
||||
TimelineModelAggregator(QmlProfilerNotesModel *notes, QObject *parent = 0);
|
||||
TimelineModelAggregator(TimelineNotesModel *notes, QObject *parent = 0);
|
||||
~TimelineModelAggregator();
|
||||
|
||||
int height() const;
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
const TimelineModel *model(int modelIndex) const;
|
||||
QVariantList models() const;
|
||||
|
||||
QmlProfilerNotesModel *notes() const;
|
||||
TimelineNotesModel *notes() const;
|
||||
void clear();
|
||||
int modelCount() const;
|
||||
|
||||
|
||||
225
src/plugins/qmlprofiler/timelinenotesmodel.cpp
Normal file
225
src/plugins/qmlprofiler/timelinenotesmodel.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "timelinenotesmodel_p.h"
|
||||
|
||||
namespace QmlProfiler {
|
||||
|
||||
TimelineNotesModel::TimelineNotesModelPrivate::TimelineNotesModelPrivate(TimelineNotesModel *q) :
|
||||
modified(false), q_ptr(q)
|
||||
{
|
||||
}
|
||||
|
||||
TimelineNotesModel::TimelineNotesModel(QObject *parent) : QObject(parent),
|
||||
d_ptr(new TimelineNotesModelPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
TimelineNotesModel::~TimelineNotesModel()
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
delete d;
|
||||
}
|
||||
|
||||
int TimelineNotesModel::count() const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
return d->data.count();
|
||||
}
|
||||
|
||||
void TimelineNotesModel::addTimelineModel(const TimelineModel *timelineModel)
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
connect(timelineModel, SIGNAL(destroyed(QObject*)),
|
||||
this, SLOT(_q_removeTimelineModel(QObject*)));
|
||||
d->timelineModels.insert(timelineModel->modelId(), timelineModel);
|
||||
}
|
||||
|
||||
const TimelineModel *TimelineNotesModel::timelineModelByModelId(int timelineModel) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
auto it = d->timelineModels.find(timelineModel);
|
||||
return it == d->timelineModels.end() ? 0 : it.value();
|
||||
}
|
||||
|
||||
QList<const TimelineModel *> TimelineNotesModel::timelineModels() const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
return d->timelineModels.values();
|
||||
}
|
||||
|
||||
int TimelineNotesModel::typeId(int index) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
const TimelineNotesModelPrivate::Note ¬e = d->data[index];
|
||||
const TimelineModel *model = timelineModelByModelId(note.timelineModel);
|
||||
if (!model)
|
||||
return -1; // This can happen if one of the timeline models has been removed
|
||||
return model->typeId(note.timelineIndex);
|
||||
}
|
||||
|
||||
QString TimelineNotesModel::text(int index) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
return d->data[index].text;
|
||||
}
|
||||
|
||||
int TimelineNotesModel::timelineModel(int index) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
return d->data[index].timelineModel;
|
||||
}
|
||||
|
||||
int TimelineNotesModel::timelineIndex(int index) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
return d->data[index].timelineIndex;
|
||||
}
|
||||
|
||||
QVariantList TimelineNotesModel::byTypeId(int selectedType) const
|
||||
{
|
||||
QVariantList ret;
|
||||
for (int noteId = 0; noteId < count(); ++noteId) {
|
||||
if (selectedType == typeId(noteId))
|
||||
ret << noteId;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QVariantList TimelineNotesModel::byTimelineModel(int timelineModel) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
QVariantList ret;
|
||||
for (int noteId = 0; noteId < count(); ++noteId) {
|
||||
if (d->data[noteId].timelineModel == timelineModel)
|
||||
ret << noteId;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TimelineNotesModel::get(int timelineModel, int timelineIndex) const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
for (int noteId = 0; noteId < count(); ++noteId) {
|
||||
const TimelineNotesModelPrivate::Note ¬e = d->data[noteId];
|
||||
if (note.timelineModel == timelineModel && note.timelineIndex == timelineIndex)
|
||||
return noteId;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int TimelineNotesModel::add(int timelineModel, int timelineIndex, const QString &text)
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
const TimelineModel *model = d->timelineModels[timelineModel];
|
||||
int typeId = model->typeId(timelineIndex);
|
||||
TimelineNotesModelPrivate::Note note = { text, timelineModel, timelineIndex };
|
||||
d->data << note;
|
||||
d->modified = true;
|
||||
emit changed(typeId, timelineModel, timelineIndex);
|
||||
return d->data.count() - 1;
|
||||
}
|
||||
|
||||
void TimelineNotesModel::update(int index, const QString &text)
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
TimelineNotesModelPrivate::Note ¬e = d->data[index];
|
||||
if (text != note.text) {
|
||||
note.text = text;
|
||||
d->modified = true;
|
||||
emit changed(typeId(index), note.timelineModel, note.timelineIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineNotesModel::remove(int index)
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
TimelineNotesModelPrivate::Note ¬e = d->data[index];
|
||||
int noteType = typeId(index);
|
||||
int timelineModel = note.timelineModel;
|
||||
int timelineIndex = note.timelineIndex;
|
||||
d->data.removeAt(index);
|
||||
d->modified = true;
|
||||
emit changed(noteType, timelineModel, timelineIndex);
|
||||
}
|
||||
|
||||
bool TimelineNotesModel::isModified() const
|
||||
{
|
||||
Q_D(const TimelineNotesModel);
|
||||
return d->modified;
|
||||
}
|
||||
|
||||
void TimelineNotesModel::resetModified()
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
d->modified = false;
|
||||
}
|
||||
|
||||
void TimelineNotesModel::TimelineNotesModelPrivate::_q_removeTimelineModel(QObject *timelineModel)
|
||||
{
|
||||
for (auto i = timelineModels.begin(); i != timelineModels.end();) {
|
||||
if (i.value() == timelineModel)
|
||||
i = timelineModels.erase(i);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineNotesModel::setText(int noteId, const QString &text)
|
||||
{
|
||||
if (text.length() > 0)
|
||||
update(noteId, text);
|
||||
else
|
||||
remove(noteId);
|
||||
}
|
||||
|
||||
void TimelineNotesModel::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);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineNotesModel::clear()
|
||||
{
|
||||
Q_D(TimelineNotesModel);
|
||||
d->data.clear();
|
||||
d->modified = false;
|
||||
emit changed(-1, -1, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_timelinenotesmodel.cpp"
|
||||
85
src/plugins/qmlprofiler/timelinenotesmodel.h
Normal file
85
src/plugins/qmlprofiler/timelinenotesmodel.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef TIMELINENOTESMODEL_H
|
||||
#define TIMELINENOTESMODEL_H
|
||||
|
||||
#include "timelinemodel.h"
|
||||
|
||||
namespace QmlProfiler {
|
||||
|
||||
class QMLPROFILER_EXPORT TimelineNotesModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ count NOTIFY changed)
|
||||
public:
|
||||
TimelineNotesModel(QObject *parent);
|
||||
~TimelineNotesModel();
|
||||
|
||||
int count() const;
|
||||
void addTimelineModel(const TimelineModel *timelineModel);
|
||||
const TimelineModel *timelineModelByModelId(int timelineModel) const;
|
||||
QList<const TimelineModel *> timelineModels() const;
|
||||
|
||||
Q_INVOKABLE int typeId(int index) const;
|
||||
Q_INVOKABLE QString text(int index) const;
|
||||
Q_INVOKABLE int timelineModel(int index) const;
|
||||
Q_INVOKABLE int timelineIndex(int index) const;
|
||||
|
||||
Q_INVOKABLE QVariantList byTypeId(int typeId) const;
|
||||
Q_INVOKABLE QVariantList byTimelineModel(int timelineModel) const;
|
||||
|
||||
Q_INVOKABLE int get(int timelineModel, int timelineIndex) const;
|
||||
Q_INVOKABLE int add(int timelineModel, int timelineIndex, const QString &text);
|
||||
Q_INVOKABLE void update(int index, const QString &text);
|
||||
Q_INVOKABLE void remove(int index);
|
||||
|
||||
Q_INVOKABLE void setText(int noteId, const QString &text);
|
||||
Q_INVOKABLE void setText(int modelIndex, int index, const QString &text);
|
||||
|
||||
bool isModified() const;
|
||||
void resetModified();
|
||||
|
||||
void clear();
|
||||
|
||||
signals:
|
||||
void changed(int typeId, int timelineModel, int timelineIndex);
|
||||
|
||||
private:
|
||||
class TimelineNotesModelPrivate;
|
||||
TimelineNotesModelPrivate *d_ptr;
|
||||
|
||||
Q_DECLARE_PRIVATE(TimelineNotesModel)
|
||||
Q_PRIVATE_SLOT(d_ptr, void _q_removeTimelineModel(QObject *timelineModel))
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TIMELINENOTESMODEL_H
|
||||
64
src/plugins/qmlprofiler/timelinenotesmodel_p.h
Normal file
64
src/plugins/qmlprofiler/timelinenotesmodel_p.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
** conditions see http://www.qt.io/licensing. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** 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.
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef TIMELINENOTESMODEL_P_H
|
||||
#define TIMELINENOTESMODEL_P_H
|
||||
|
||||
#include "timelinenotesmodel.h"
|
||||
|
||||
namespace QmlProfiler {
|
||||
|
||||
class TimelineNotesModel::TimelineNotesModelPrivate {
|
||||
public:
|
||||
TimelineNotesModelPrivate(TimelineNotesModel *q);
|
||||
|
||||
struct Note {
|
||||
// Saved properties
|
||||
QString text;
|
||||
|
||||
// Cache, created on loading
|
||||
int timelineModel;
|
||||
int timelineIndex;
|
||||
};
|
||||
|
||||
QList<Note> data;
|
||||
QHash<int, const TimelineModel *> timelineModels;
|
||||
bool modified;
|
||||
|
||||
void _q_removeTimelineModel(QObject *model);
|
||||
|
||||
private:
|
||||
TimelineNotesModel *q_ptr;
|
||||
Q_DECLARE_PUBLIC(TimelineNotesModel)
|
||||
};
|
||||
|
||||
}
|
||||
#endif // TIMELINENOTESMODEL_P_H
|
||||
|
||||
@@ -102,7 +102,7 @@ TimelineRenderPass::State *TimelineNotesRenderPass::update(const TimelineRendere
|
||||
Q_UNUSED(lastIndex);
|
||||
Q_UNUSED(spacing);
|
||||
|
||||
const QmlProfilerNotesModel *notes = renderer->notes();
|
||||
const TimelineNotesModel *notes = renderer->notes();
|
||||
const TimelineModel *model = renderer->model();
|
||||
|
||||
TimelineNotesRenderPassState *state;
|
||||
|
||||
@@ -108,18 +108,18 @@ void TimelineRenderer::setZoomer(TimelineZoomControl *zoomer)
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineRenderer::setNotes(QmlProfilerNotesModel *notes)
|
||||
void TimelineRenderer::setNotes(TimelineNotesModel *notes)
|
||||
{
|
||||
if (m_notes == notes)
|
||||
return;
|
||||
|
||||
if (m_notes)
|
||||
disconnect(m_notes, &QmlProfilerNotesModel::changed,
|
||||
disconnect(m_notes, &TimelineNotesModel::changed,
|
||||
this, &TimelineRenderer::setNotesDirty);
|
||||
|
||||
m_notes = notes;
|
||||
if (m_notes)
|
||||
connect(m_notes, &QmlProfilerNotesModel::changed,
|
||||
connect(m_notes, &TimelineNotesModel::changed,
|
||||
this, &TimelineRenderer::setNotesDirty);
|
||||
|
||||
emit notesChanged(m_notes);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include <QQuickItem>
|
||||
#include "timelinezoomcontrol.h"
|
||||
#include "timelinemodel.h"
|
||||
#include "qmlprofilernotesmodel.h"
|
||||
#include "timelinenotesmodel.h"
|
||||
#include "timelinerenderpass.h"
|
||||
|
||||
namespace QmlProfiler {
|
||||
@@ -49,7 +49,7 @@ class TimelineRenderer : public QQuickItem
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QmlProfiler::TimelineModel *model READ model WRITE setModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(QmlProfiler::TimelineZoomControl *zoomer READ zoomer WRITE setZoomer NOTIFY zoomerChanged)
|
||||
Q_PROPERTY(QmlProfiler::QmlProfilerNotesModel *notes READ notes WRITE setNotes NOTIFY notesChanged)
|
||||
Q_PROPERTY(QmlProfiler::TimelineNotesModel *notes READ notes WRITE setNotes NOTIFY notesChanged)
|
||||
Q_PROPERTY(bool selectionLocked READ selectionLocked WRITE setSelectionLocked NOTIFY selectionLockedChanged)
|
||||
Q_PROPERTY(int selectedItem READ selectedItem WRITE setSelectedItem NOTIFY selectedItemChanged)
|
||||
|
||||
@@ -73,8 +73,8 @@ public:
|
||||
TimelineZoomControl *zoomer() const { return m_zoomer; }
|
||||
void setZoomer(TimelineZoomControl *zoomer);
|
||||
|
||||
QmlProfilerNotesModel *notes() const { return m_notes; }
|
||||
void setNotes(QmlProfilerNotesModel *notes);
|
||||
TimelineNotesModel *notes() const { return m_notes; }
|
||||
void setNotes(TimelineNotesModel *notes);
|
||||
|
||||
bool modelDirty() const;
|
||||
bool notesDirty() const;
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
signals:
|
||||
void modelChanged(const TimelineModel *model);
|
||||
void zoomerChanged(TimelineZoomControl *zoomer);
|
||||
void notesChanged(QmlProfilerNotesModel *notes);
|
||||
void notesChanged(TimelineNotesModel *notes);
|
||||
|
||||
void selectionLockedChanged(bool locked);
|
||||
void selectedItemChanged(int itemIndex);
|
||||
@@ -143,7 +143,7 @@ private:
|
||||
|
||||
TimelineModel *m_model;
|
||||
TimelineZoomControl *m_zoomer;
|
||||
QmlProfilerNotesModel *m_notes;
|
||||
TimelineNotesModel *m_notes;
|
||||
|
||||
struct {
|
||||
qint64 startTime;
|
||||
|
||||
Reference in New Issue
Block a user