From 4342eeab33ce9dbacdb95fb6d03140c1261e289d Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 15 Aug 2017 18:44:18 +0200 Subject: [PATCH] QmlProfiler: Don't access QmlProfilerTool from QmlProfilerTextMark Only QmlProfilerViewManager is needed, so use that, as a step to reduce the interface of the QmlProfilerTool singleton. Change-Id: I19e55e3b22b3c64ff98b8ea29cbc5164a60ee15d Reviewed-by: Ulf Hermann --- .../qmlprofiler/qmlprofilertextmark.cpp | 22 ++++++++++++------- src/plugins/qmlprofiler/qmlprofilertextmark.h | 10 +++++---- src/plugins/qmlprofiler/qmlprofilertool.cpp | 19 ++-------------- src/plugins/qmlprofiler/qmlprofilertool.h | 4 ---- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilertextmark.cpp b/src/plugins/qmlprofiler/qmlprofilertextmark.cpp index bbc0bf3fc0b..4a7bf4ae389 100644 --- a/src/plugins/qmlprofiler/qmlprofilertextmark.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertextmark.cpp @@ -22,8 +22,12 @@ ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ****************************************************************************/ + #include "qmlprofilertextmark.h" + #include "qmlprofilerconstants.h" +#include "qmlprofilerviewmanager.h" +#include "qmlprofilerstatisticsview.h" #include #include @@ -32,9 +36,9 @@ namespace QmlProfiler { namespace Internal { -QmlProfilerTextMark::QmlProfilerTextMark(QmlProfilerTool *tool, int typeId, const QString &fileName, - int lineNumber) : - TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY, 3.5), m_tool(tool), +QmlProfilerTextMark::QmlProfilerTextMark(QmlProfilerViewManager *viewManager, int typeId, + const QString &fileName, int lineNumber) : + TextMark(fileName, lineNumber, Constants::TEXT_MARK_CATEGORY, 3.5), m_viewManager(viewManager), m_typeIds(1, typeId) { } @@ -50,7 +54,8 @@ void QmlProfilerTextMark::paintIcon(QPainter *painter, const QRect &paintRect) c painter->setPen(Qt::black); painter->fillRect(paintRect, Qt::white); painter->drawRect(paintRect); - painter->drawText(paintRect, m_tool->summary(m_typeIds), Qt::AlignRight | Qt::AlignVCenter); + painter->drawText(paintRect, m_viewManager->statisticsView()->summary(m_typeIds), + Qt::AlignRight | Qt::AlignVCenter); painter->restore(); } @@ -58,7 +63,7 @@ void QmlProfilerTextMark::clicked() { int typeId = m_typeIds.takeFirst(); m_typeIds.append(typeId); - m_tool->selectType(typeId); + m_viewManager->typeSelected(typeId); } QmlProfilerTextMarkModel::QmlProfilerTextMarkModel(QObject *parent) : QObject(parent) @@ -82,7 +87,8 @@ void QmlProfilerTextMarkModel::addTextMarkId(int typeId, const QmlEventLocation m_ids.insert(location.filename(), {typeId, location.line(), location.column()}); } -void QmlProfilerTextMarkModel::createMarks(QmlProfilerTool *tool, const QString &fileName) +void QmlProfilerTextMarkModel::createMarks(QmlProfilerViewManager *viewManager, + const QString &fileName) { auto first = m_ids.find(fileName); QVarLengthArray ids; @@ -103,7 +109,7 @@ void QmlProfilerTextMarkModel::createMarks(QmlProfilerTool *tool, const QString m_marks.last()->addTypeId(it->typeId); } else { lineNumber = it->lineNumber; - m_marks.append(new QmlProfilerTextMark(tool, it->typeId, fileName, it->lineNumber)); + m_marks << new QmlProfilerTextMark(viewManager, it->typeId, fileName, it->lineNumber); } } } @@ -113,7 +119,7 @@ bool QmlProfilerTextMark::addToolTipContent(QLayout *target) const QGridLayout *layout = new QGridLayout; layout->setHorizontalSpacing(10); for (int row = 0, rowEnd = m_typeIds.length(); row != rowEnd; ++row) { - const QStringList typeDetails = m_tool->details(m_typeIds[row]); + const QStringList typeDetails = m_viewManager->statisticsView()->details(m_typeIds[row]); for (int column = 0, columnEnd = typeDetails.length(); column != columnEnd; ++column) { QLabel *label = new QLabel; label->setAlignment(column == columnEnd - 1 ? Qt::AlignRight : Qt::AlignLeft); diff --git a/src/plugins/qmlprofiler/qmlprofilertextmark.h b/src/plugins/qmlprofiler/qmlprofilertextmark.h index 894e5fc5178..19d13dcf79b 100644 --- a/src/plugins/qmlprofiler/qmlprofilertextmark.h +++ b/src/plugins/qmlprofiler/qmlprofilertextmark.h @@ -25,16 +25,18 @@ #pragma once #include "qmleventlocation.h" -#include "qmlprofilertool.h" #include namespace QmlProfiler { namespace Internal { +class QmlProfilerViewManager; + class QmlProfilerTextMark : public TextEditor::TextMark { public: - QmlProfilerTextMark(QmlProfilerTool *tool, int typeId, const QString &fileName, int lineNumber); + QmlProfilerTextMark(QmlProfilerViewManager *viewManager, int typeId, + const QString &fileName, int lineNumber); void addTypeId(int typeId); void paintIcon(QPainter *painter, const QRect &rect) const override; @@ -43,7 +45,7 @@ public: bool addToolTipContent(QLayout *target) const override; private: - QmlProfilerTool *m_tool; + QmlProfilerViewManager *m_viewManager; QVector m_typeIds; }; @@ -55,7 +57,7 @@ public: void clear(); void addTextMarkId(int typeId, const QmlEventLocation &location); - void createMarks(QmlProfilerTool *tool, const QString &fileName); + void createMarks(QmlProfilerViewManager *viewManager, const QString &fileName); private: struct TextMarkId { diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index 8bad426a8ee..3488c93f14d 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -290,7 +290,7 @@ QmlProfilerTool::QmlProfilerTool(QObject *parent) connect(editorManager, &EditorManager::editorCreated, model, [this, model](Core::IEditor *editor, const QString &fileName) { Q_UNUSED(editor); - model->createMarks(this, fileName); + model->createMarks(d->m_viewContainer, fileName); }); } @@ -437,11 +437,6 @@ void QmlProfilerTool::gotoSourceLocation(const QString &fileUrl, int lineNumber, EditorManager::DoNotSwitchToDesignMode | EditorManager::DoNotSwitchToEditMode); } -void QmlProfilerTool::selectType(int typeId) -{ - d->m_viewContainer->typeSelected(typeId); -} - void QmlProfilerTool::updateTimeDisplay() { double seconds = 0; @@ -500,7 +495,7 @@ void QmlProfilerTool::createTextMarks() { QmlProfilerTextMarkModel *model = d->m_profilerModelManager->textMarkModel(); foreach (IDocument *document, DocumentModel::openedDocuments()) - model->createMarks(this, document->filePath().toString()); + model->createMarks(d->m_viewContainer, document->filePath().toString()); } void QmlProfilerTool::clearTextMarks() @@ -569,16 +564,6 @@ void QmlProfilerTool::attachToWaitingApplication() ProjectExplorerPlugin::startRunControl(runControl); } -QString QmlProfilerTool::summary(const QVector &typeIds) const -{ - return d->m_viewContainer->statisticsView()->summary(typeIds); -} - -QStringList QmlProfilerTool::details(int typeId) const -{ - return d->m_viewContainer->statisticsView()->details(typeId); -} - void QmlProfilerTool::logState(const QString &msg) { MessageManager::write(msg, MessageManager::Flash); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h index c50747e85b1..e3fcdfb8d5e 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.h +++ b/src/plugins/qmlprofiler/qmlprofilertool.h @@ -55,9 +55,6 @@ public: bool prepareTool(); void attachToWaitingApplication(); - QString summary(const QVector &typeIds) const; - QStringList details(int typeId) const; - static QList profilerContextMenuActions(); // display dialogs / log output @@ -76,7 +73,6 @@ public slots: void recordingButtonChanged(bool recording); void gotoSourceLocation(const QString &fileUrl, int lineNumber, int columnNumber); - void selectType(int typeId); private slots: void clearData();