From 3970a834bcc0b158a577134b32cb9992c847cd1a Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 8 Aug 2023 13:58:56 +0200 Subject: [PATCH] Valgrind: Replace global toolTipForFrame() with Frame::toolTip() Change-Id: I66cc481d588c468b9388e3b3863ed35aab406fa2 Reviewed-by: Reviewed-by: hjk Reviewed-by: Qt CI Bot --- src/plugins/valgrind/CMakeLists.txt | 1 - src/plugins/valgrind/valgrind.qbs | 1 - .../valgrind/xmlprotocol/errorlistmodel.cpp | 7 ++- src/plugins/valgrind/xmlprotocol/frame.cpp | 48 +++++++++++++++-- src/plugins/valgrind/xmlprotocol/frame.h | 8 +-- .../valgrind/xmlprotocol/modelhelpers.cpp | 53 ------------------- .../valgrind/xmlprotocol/modelhelpers.h | 20 ------- .../valgrind/xmlprotocol/stackmodel.cpp | 3 +- tests/auto/valgrind/valgrind.cmake | 1 - .../testdata/projecttree_creator.tsv | 4 -- .../testdata/projecttree_creator.tsv | 6 --- 11 files changed, 52 insertions(+), 100 deletions(-) delete mode 100644 src/plugins/valgrind/xmlprotocol/modelhelpers.cpp delete mode 100644 src/plugins/valgrind/xmlprotocol/modelhelpers.h diff --git a/src/plugins/valgrind/CMakeLists.txt b/src/plugins/valgrind/CMakeLists.txt index f3f1fce9bcb..df4c430ea00 100644 --- a/src/plugins/valgrind/CMakeLists.txt +++ b/src/plugins/valgrind/CMakeLists.txt @@ -34,7 +34,6 @@ add_qtc_plugin(Valgrind xmlprotocol/error.cpp xmlprotocol/error.h xmlprotocol/errorlistmodel.cpp xmlprotocol/errorlistmodel.h xmlprotocol/frame.cpp xmlprotocol/frame.h - xmlprotocol/modelhelpers.cpp xmlprotocol/modelhelpers.h xmlprotocol/parser.cpp xmlprotocol/parser.h xmlprotocol/stack.cpp xmlprotocol/stack.h xmlprotocol/stackmodel.cpp xmlprotocol/stackmodel.h diff --git a/src/plugins/valgrind/valgrind.qbs b/src/plugins/valgrind/valgrind.qbs index d5ca08f7806..378f0a57bb8 100644 --- a/src/plugins/valgrind/valgrind.qbs +++ b/src/plugins/valgrind/valgrind.qbs @@ -64,7 +64,6 @@ QtcPlugin { "error.cpp", "error.h", "errorlistmodel.cpp", "errorlistmodel.h", "frame.cpp", "frame.h", - "modelhelpers.cpp", "modelhelpers.h", "parser.cpp", "parser.h", "stack.cpp", "stack.h", "stackmodel.cpp", "stackmodel.h", diff --git a/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp b/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp index aa5fa1c016a..96c1819b284 100644 --- a/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp +++ b/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp @@ -5,7 +5,6 @@ #include "error.h" #include "frame.h" #include "stack.h" -#include "modelhelpers.h" #include "../valgrindtr.h" #include @@ -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(); } diff --git a/src/plugins/valgrind/xmlprotocol/frame.cpp b/src/plugins/valgrind/xmlprotocol/frame.cpp index 17c8e951719..a7e157c8fd5 100644 --- a/src/plugins/valgrind/xmlprotocol/frame.cpp +++ b/src/plugins/valgrind/xmlprotocol/frame.cpp @@ -3,12 +3,15 @@ #include "frame.h" +#include "../valgrindtr.h" + +#include +#include #include #include -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; + QList 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 = "" + "\n" + "
"; + + for (const StringPair &pair : std::as_const(lines)) { + html += "
"; + html += pair.first; + html += "
"; + html += pair.second; + html += "
\n"; + } + html += "
"; + return html; +} + +} // namespace Valgrind::XmlProtocol diff --git a/src/plugins/valgrind/xmlprotocol/frame.h b/src/plugins/valgrind/xmlprotocol/frame.h index 727466e74d1..07c6e9c6576 100644 --- a/src/plugins/valgrind/xmlprotocol/frame.h +++ b/src/plugins/valgrind/xmlprotocol/frame.h @@ -5,8 +5,7 @@ #include -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 d; }; -} // namespace XmlProtocol -} // namespace Valgrind +} // namespace Valgrind::XmlProtocol diff --git a/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp b/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp deleted file mode 100644 index 9df22ef9a06..00000000000 --- a/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp +++ /dev/null @@ -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 -#include -#include - -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; - QList 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 = "" - "\n" - "
"; - - for (const StringPair &pair : std::as_const(lines)) { - html += "
"; - html += pair.first; - html += "
"; - html += pair.second; - html += "
\n"; - } - html += "
"; - return html; -} - -} // namespace XmlProtocol -} // namespace Valgrind diff --git a/src/plugins/valgrind/xmlprotocol/modelhelpers.h b/src/plugins/valgrind/xmlprotocol/modelhelpers.h deleted file mode 100644 index 000d57c4bf0..00000000000 --- a/src/plugins/valgrind/xmlprotocol/modelhelpers.h +++ /dev/null @@ -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 - -QT_BEGIN_NAMESPACE -class QString; -QT_END_NAMESPACE - -namespace Valgrind { -namespace XmlProtocol { - -class Frame; - -QString toolTipForFrame(const Frame &frame); - -} // namespace XmlProtocol -} // namespace Valgrind diff --git a/src/plugins/valgrind/xmlprotocol/stackmodel.cpp b/src/plugins/valgrind/xmlprotocol/stackmodel.cpp index 99ff1cacb25..535ceb38f9b 100644 --- a/src/plugins/valgrind/xmlprotocol/stackmodel.cpp +++ b/src/plugins/valgrind/xmlprotocol/stackmodel.cpp @@ -5,7 +5,6 @@ #include "error.h" #include "frame.h" #include "stack.h" -#include "modelhelpers.h" #include "../valgrindtr.h" #include @@ -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: diff --git a/tests/auto/valgrind/valgrind.cmake b/tests/auto/valgrind/valgrind.cmake index fa7d8b4b60b..945e86fe09a 100644 --- a/tests/auto/valgrind/valgrind.cmake +++ b/tests/auto/valgrind/valgrind.cmake @@ -19,7 +19,6 @@ function(extend_valgrind_test targetName) xmlprotocol/error.h xmlprotocol/error.cpp xmlprotocol/errorlistmodel.h xmlprotocol/errorlistmodel.cpp xmlprotocol/frame.h xmlprotocol/frame.cpp - xmlprotocol/modelhelpers.h xmlprotocol/modelhelpers.cpp xmlprotocol/parser.h xmlprotocol/parser.cpp xmlprotocol/stack.h xmlprotocol/stack.cpp xmlprotocol/stackmodel.h xmlprotocol/stackmodel.cpp diff --git a/tests/system/suite_general/tst_opencreator_qbs/testdata/projecttree_creator.tsv b/tests/system/suite_general/tst_opencreator_qbs/testdata/projecttree_creator.tsv index 241ce7f8791..b9eb11f57d5 100644 --- a/tests/system/suite_general/tst_opencreator_qbs/testdata/projecttree_creator.tsv +++ b/tests/system/suite_general/tst_opencreator_qbs/testdata/projecttree_creator.tsv @@ -12738,8 +12738,6 @@ "errorlistmodel.h" "4" "frame.cpp" "4" "frame.h" "4" -"modelhelpers.cpp" "4" -"modelhelpers.h" "4" "parser.cpp" "4" "parser.h" "4" "stack.cpp" "4" @@ -14811,8 +14809,6 @@ "errorlistmodel.h" "6" "frame.cpp" "6" "frame.h" "6" -"modelhelpers.cpp" "6" -"modelhelpers.h" "6" "parser.cpp" "6" "parser.h" "6" "stack.cpp" "6" diff --git a/tests/system/suite_general/tst_openqt_creator/testdata/projecttree_creator.tsv b/tests/system/suite_general/tst_openqt_creator/testdata/projecttree_creator.tsv index 662eb4fe255..adf91e771ab 100644 --- a/tests/system/suite_general/tst_openqt_creator/testdata/projecttree_creator.tsv +++ b/tests/system/suite_general/tst_openqt_creator/testdata/projecttree_creator.tsv @@ -15805,7 +15805,6 @@ "error.h" "5" "errorlistmodel.h" "5" "frame.h" "5" -"modelhelpers.h" "5" "parser.h" "5" "stack.h" "5" "stackmodel.h" "5" @@ -15817,7 +15816,6 @@ "error.cpp" "5" "errorlistmodel.cpp" "5" "frame.cpp" "5" -"modelhelpers.cpp" "5" "parser.cpp" "5" "stack.cpp" "5" "stackmodel.cpp" "5" @@ -20145,7 +20143,6 @@ "error.h" "8" "errorlistmodel.h" "8" "frame.h" "8" -"modelhelpers.h" "8" "parser.h" "8" "stack.h" "8" "stackmodel.h" "8" @@ -20172,7 +20169,6 @@ "error.cpp" "8" "errorlistmodel.cpp" "8" "frame.cpp" "8" -"modelhelpers.cpp" "8" "parser.cpp" "8" "stack.cpp" "8" "stackmodel.cpp" "8" @@ -20258,7 +20254,6 @@ "error.h" "8" "errorlistmodel.h" "8" "frame.h" "8" -"modelhelpers.h" "8" "parser.h" "8" "stack.h" "8" "stackmodel.h" "8" @@ -20285,7 +20280,6 @@ "error.cpp" "8" "errorlistmodel.cpp" "8" "frame.cpp" "8" -"modelhelpers.cpp" "8" "parser.cpp" "8" "stack.cpp" "8" "stackmodel.cpp" "8"