Valgrind: Replace global toolTipForFrame() with Frame::toolTip()

Change-Id: I66cc481d588c468b9388e3b3863ed35aab406fa2
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-08-08 13:58:56 +02:00
parent bb6c26cac9
commit 3970a834bc
11 changed files with 52 additions and 100 deletions

View File

@@ -5,7 +5,6 @@
#include "error.h"
#include "frame.h"
#include "stack.h"
#include "modelhelpers.h"
#include "../valgrindtr.h"
#include <debugger/analyzer/diagnosticlocation.h>
@@ -201,7 +200,7 @@ QVariant ErrorItem::data(int column, int role) const
return Tr::tr("%1 in function %2")
.arg(m_error.what(), m_error.stacks().constFirst().frames().constFirst().functionName());
case Qt::ToolTipRole:
return toolTipForFrame(m_model->findRelevantFrame(m_error));
return m_model->findRelevantFrame(m_error).toolTip();
default:
return QVariant();
}
@@ -228,7 +227,7 @@ QVariant StackItem::data(int column, int role) const
case Qt::DisplayRole:
return m_stack.auxWhat().isEmpty() ? errorItem->error().what() : m_stack.auxWhat();
case Qt::ToolTipRole:
return toolTipForFrame(errorItem->modelPrivate()->findRelevantFrame(errorItem->error()));
return errorItem->modelPrivate()->findRelevantFrame(errorItem->error()).toolTip();
default:
return QVariant();
}
@@ -263,7 +262,7 @@ QVariant FrameItem::data(int column, int role) const
.arg(makeFrameName(m_frame, false));
}
case Qt::ToolTipRole:
return toolTipForFrame(m_frame);
return m_frame.toolTip();
default:
return QVariant();
}

View File

@@ -3,12 +3,15 @@
#include "frame.h"
#include "../valgrindtr.h"
#include <QList>
#include <QPair>
#include <QString>
#include <algorithm>
namespace Valgrind {
namespace XmlProtocol {
namespace Valgrind::XmlProtocol {
class Frame::Private : public QSharedData
{
@@ -129,5 +132,42 @@ void Frame::setLine(int line)
d->line = line;
}
} // namespace XmlProtocol
} // namespace Valgrind
QString Frame::toolTip() const
{
QString location;
if (!fileName().isEmpty()) {
location = filePath();
if (line() > 0)
location += ':' + QString::number(line());
}
using StringPair = QPair<QString, QString>;
QList<StringPair> lines;
if (!functionName().isEmpty())
lines.append({Tr::tr("Function:"), functionName()});
if (!location.isEmpty())
lines.append({Tr::tr("Location:"), location});
if (instructionPointer()) {
lines.append({Tr::tr("Instruction pointer:"),
QString("0x%1").arg(instructionPointer(), 0, 16)});
}
if (!object().isEmpty())
lines.append({Tr::tr("Object:"), object()});
QString html = "<html><head>"
"<style>dt { font-weight:bold; } dd { font-family: monospace; }</style>\n"
"</head><body><dl>";
for (const StringPair &pair : std::as_const(lines)) {
html += "<dt>";
html += pair.first;
html += "</dt><dd>";
html += pair.second;
html += "</dd>\n";
}
html += "</dl></body></html>";
return html;
}
} // namespace Valgrind::XmlProtocol

View File

@@ -5,8 +5,7 @@
#include <QSharedDataPointer>
namespace Valgrind {
namespace XmlProtocol {
namespace Valgrind::XmlProtocol {
class Frame
{
@@ -41,10 +40,11 @@ public:
int line() const;
void setLine(int line);
QString toolTip() const;
private:
class Private;
QSharedDataPointer<Private> d;
};
} // namespace XmlProtocol
} // namespace Valgrind
} // namespace Valgrind::XmlProtocol

View File

@@ -1,53 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "modelhelpers.h"
#include "frame.h"
#include "../valgrindtr.h"
#include <QString>
#include <QDir>
#include <QPair>
namespace Valgrind {
namespace XmlProtocol {
QString toolTipForFrame(const Frame &frame)
{
QString location;
if (!frame.fileName().isEmpty()) {
location = frame.filePath();
if (frame.line() > 0)
location += ':' + QString::number(frame.line());
}
using StringPair = QPair<QString, QString>;
QList<StringPair> lines;
if (!frame.functionName().isEmpty())
lines << qMakePair(Tr::tr("Function:"), frame.functionName());
if (!location.isEmpty())
lines << qMakePair(Tr::tr("Location:"), location);
if (frame.instructionPointer())
lines << qMakePair(Tr::tr("Instruction pointer:"),
QString("0x%1").arg(frame.instructionPointer(), 0, 16));
if (!frame.object().isEmpty())
lines << qMakePair(Tr::tr("Object:"), frame.object());
QString html = "<html><head>"
"<style>dt { font-weight:bold; } dd { font-family: monospace; }</style>\n"
"</head><body><dl>";
for (const StringPair &pair : std::as_const(lines)) {
html += "<dt>";
html += pair.first;
html += "</dt><dd>";
html += pair.second;
html += "</dd>\n";
}
html += "</dl></body></html>";
return html;
}
} // namespace XmlProtocol
} // namespace Valgrind

View File

@@ -1,20 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <QtGlobal>
QT_BEGIN_NAMESPACE
class QString;
QT_END_NAMESPACE
namespace Valgrind {
namespace XmlProtocol {
class Frame;
QString toolTipForFrame(const Frame &frame);
} // namespace XmlProtocol
} // namespace Valgrind

View File

@@ -5,7 +5,6 @@
#include "error.h"
#include "frame.h"
#include "stack.h"
#include "modelhelpers.h"
#include "../valgrindtr.h"
#include <utils/qtcassert.h>
@@ -106,7 +105,7 @@ QVariant StackModel::data(const QModelIndex &index, int role) const
break;
}
case Qt::ToolTipRole:
return toolTipForFrame(frame);
return frame.toolTip();
case ObjectRole:
return frame.object();
case FunctionNameRole: