From 6239de07a4bda106d11a4e240c0ba598ee80a95a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 8 Dec 2014 16:14:52 +0100 Subject: [PATCH] QmlProfiler: split notes model in generic and specific classes Change-Id: I633dc6a862f344a7e5e86c25e44e400e3000f644 Reviewed-by: Kai Koehne --- src/plugins/qmlprofiler/qmlprofiler.pro | 7 +- src/plugins/qmlprofiler/qmlprofiler.qbs | 1 + .../qmlprofiler/qmlprofilernotesmodel.cpp | 172 ++----------- .../qmlprofiler/qmlprofilernotesmodel.h | 48 +--- .../qmlprofiler/qmlprofilertraceview.cpp | 2 +- .../qmlprofiler/timelinemodelaggregator.cpp | 6 +- .../qmlprofiler/timelinemodelaggregator.h | 6 +- .../qmlprofiler/timelinenotesmodel.cpp | 225 ++++++++++++++++++ src/plugins/qmlprofiler/timelinenotesmodel.h | 85 +++++++ .../qmlprofiler/timelinenotesmodel_p.h | 64 +++++ .../qmlprofiler/timelinenotesrenderpass.cpp | 2 +- src/plugins/qmlprofiler/timelinerenderer.cpp | 6 +- src/plugins/qmlprofiler/timelinerenderer.h | 12 +- 13 files changed, 417 insertions(+), 219 deletions(-) create mode 100644 src/plugins/qmlprofiler/timelinenotesmodel.cpp create mode 100644 src/plugins/qmlprofiler/timelinenotesmodel.h create mode 100644 src/plugins/qmlprofiler/timelinenotesmodel_p.h diff --git a/src/plugins/qmlprofiler/qmlprofiler.pro b/src/plugins/qmlprofiler/qmlprofiler.pro index 75e90ce924f..792aeb8689a 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.pro +++ b/src/plugins/qmlprofiler/qmlprofiler.pro @@ -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 diff --git a/src/plugins/qmlprofiler/qmlprofiler.qbs b/src/plugins/qmlprofiler/qmlprofiler.qbs index c309383a92d..f3701c1ba76 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.qbs +++ b/src/plugins/qmlprofiler/qmlprofiler.qbs @@ -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", diff --git a/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp b/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp index 5f1b87f7bb0..042b5573c99 100644 --- a/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilernotesmodel.cpp @@ -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 ¬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 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(); } } diff --git a/src/plugins/qmlprofiler/qmlprofilernotesmodel.h b/src/plugins/qmlprofiler/qmlprofilernotesmodel.h index 9f6f77d89a5..0caa0a8d602 100644 --- a/src/plugins/qmlprofiler/qmlprofilernotesmodel.h +++ b/src/plugins/qmlprofiler/qmlprofilernotesmodel.h @@ -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 #include 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 m_data; - QHash m_timelineModels; - bool m_modified; int add(int typeId, qint64 startTime, qint64 duration, const QString &text); }; diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp index 33a85eaaafd..eef1af7fe05 100644 --- a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp @@ -106,7 +106,7 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, Analyzer::IAnalyzerT qmlRegisterType(); qmlRegisterType(); - qmlRegisterType(); + qmlRegisterType(); d->m_mainView = new QmlProfilerQuickView(this); d->m_mainView->setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/src/plugins/qmlprofiler/timelinemodelaggregator.cpp b/src/plugins/qmlprofiler/timelinemodelaggregator.cpp index a686bd4e98b..c9f08aaac0f 100644 --- a/src/plugins/qmlprofiler/timelinemodelaggregator.cpp +++ b/src/plugins/qmlprofiler/timelinemodelaggregator.cpp @@ -50,10 +50,10 @@ public: TimelineModelAggregator *q; QList 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; } diff --git a/src/plugins/qmlprofiler/timelinemodelaggregator.h b/src/plugins/qmlprofiler/timelinemodelaggregator.h index b1961065242..83c5dde471f 100644 --- a/src/plugins/qmlprofiler/timelinemodelaggregator.h +++ b/src/plugins/qmlprofiler/timelinemodelaggregator.h @@ -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; diff --git a/src/plugins/qmlprofiler/timelinenotesmodel.cpp b/src/plugins/qmlprofiler/timelinenotesmodel.cpp new file mode 100644 index 00000000000..62befc20464 --- /dev/null +++ b/src/plugins/qmlprofiler/timelinenotesmodel.cpp @@ -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 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" diff --git a/src/plugins/qmlprofiler/timelinenotesmodel.h b/src/plugins/qmlprofiler/timelinenotesmodel.h new file mode 100644 index 00000000000..3cf6caa5622 --- /dev/null +++ b/src/plugins/qmlprofiler/timelinenotesmodel.h @@ -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 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 diff --git a/src/plugins/qmlprofiler/timelinenotesmodel_p.h b/src/plugins/qmlprofiler/timelinenotesmodel_p.h new file mode 100644 index 00000000000..9f152b4441e --- /dev/null +++ b/src/plugins/qmlprofiler/timelinenotesmodel_p.h @@ -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 data; + QHash timelineModels; + bool modified; + + void _q_removeTimelineModel(QObject *model); + +private: + TimelineNotesModel *q_ptr; + Q_DECLARE_PUBLIC(TimelineNotesModel) +}; + +} +#endif // TIMELINENOTESMODEL_P_H + diff --git a/src/plugins/qmlprofiler/timelinenotesrenderpass.cpp b/src/plugins/qmlprofiler/timelinenotesrenderpass.cpp index 0e03731e0b7..d5b6fb26f65 100644 --- a/src/plugins/qmlprofiler/timelinenotesrenderpass.cpp +++ b/src/plugins/qmlprofiler/timelinenotesrenderpass.cpp @@ -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; diff --git a/src/plugins/qmlprofiler/timelinerenderer.cpp b/src/plugins/qmlprofiler/timelinerenderer.cpp index 5ef83f23d93..a6f325c4922 100644 --- a/src/plugins/qmlprofiler/timelinerenderer.cpp +++ b/src/plugins/qmlprofiler/timelinerenderer.cpp @@ -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); diff --git a/src/plugins/qmlprofiler/timelinerenderer.h b/src/plugins/qmlprofiler/timelinerenderer.h index ebfa08da29e..483842d188d 100644 --- a/src/plugins/qmlprofiler/timelinerenderer.h +++ b/src/plugins/qmlprofiler/timelinerenderer.h @@ -35,7 +35,7 @@ #include #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;