Files
qt-creator/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp

54 lines
1.6 KiB
C++
Raw Normal View History

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