forked from qt-creator/qt-creator
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 <ulf.hermann@qt.io>
This commit is contained in:
@@ -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 <QLabel>
|
||||
#include <QLayout>
|
||||
@@ -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<TextMarkId> 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);
|
||||
|
@@ -25,16 +25,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "qmleventlocation.h"
|
||||
#include "qmlprofilertool.h"
|
||||
#include <texteditor/textmark.h>
|
||||
|
||||
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<int> 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 {
|
||||
|
@@ -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<int> &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);
|
||||
|
@@ -55,9 +55,6 @@ public:
|
||||
bool prepareTool();
|
||||
void attachToWaitingApplication();
|
||||
|
||||
QString summary(const QVector<int> &typeIds) const;
|
||||
QStringList details(int typeId) const;
|
||||
|
||||
static QList <QAction *> 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();
|
||||
|
Reference in New Issue
Block a user