diff --git a/massifdata/CMakeLists.txt b/massifdata/CMakeLists.txt index d1b0678..2fb8a8e 100644 --- a/massifdata/CMakeLists.txt +++ b/massifdata/CMakeLists.txt @@ -1,26 +1,24 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) set(massifdata_SRCS filedata.cpp snapshotitem.cpp treeleafitem.cpp parser.cpp parserprivate.cpp parseworker.cpp util.cpp ) add_library(mv-massifdata ${massifdata_SRCS}) target_link_libraries(mv-massifdata KF5::Archive KF5::KIOCore KF5::I18n KF5::CoreAddons Qt5::Core - # required for Qt::escape() in QTextDocument - Qt5::Gui ) diff --git a/massifdata/util.cpp b/massifdata/util.cpp index 0a118fc..2da320c 100644 --- a/massifdata/util.cpp +++ b/massifdata/util.cpp @@ -1,162 +1,160 @@ /* This file is part of Massif Visualizer Copyright 2010 Milian Wolff This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "util.h" #include "snapshotitem.h" #include "treeleafitem.h" #include #include #include #include -#include - namespace Massif { QString prettyCost(quint64 cost) { Q_ASSERT(KSharedConfig::openConfig()); KConfigGroup conf = KSharedConfig::openConfig()->group(QLatin1String("Settings")); int precision = conf.readEntry(QLatin1String("prettyCostPrecision"), 1); KFormat format(QLocale::system()); return format.formatByteSize(cost, precision); } void shortenTemplates(QByteArray& function) { Q_ASSERT(KSharedConfig::openConfig()); KConfigGroup conf = KSharedConfig::openConfig()->group(QLatin1String("Settings")); if (conf.readEntry(QLatin1String("shortenTemplates"), false)) { // remove template arguments between <...> int depth = 0; int open = 0; for (int i = 0; i < function.length(); ++i) { if (function.at(i) == '<') { if (!depth) { open = i; } ++depth; } else if (function.at(i) == '>') { --depth; if (!depth) { function.remove(open + 1, i - open - 1); i = open + 1; open = 0; } } } } } struct ParsedLabel { QByteArray address; QByteArray function; QByteArray location; }; ParsedLabel parseLabel(const QByteArray& label) { ParsedLabel ret; int functionStart = 0; int functionEnd = label.length(); if (label.startsWith("0x")) { int colonPos = label.indexOf(": "); if (colonPos != -1) { ret.address = label.left(colonPos); functionStart = colonPos + 2; } } if (label.endsWith(')')) { int locationPos = label.lastIndexOf(" ("); if (locationPos != -1) { ret.location = label.mid(locationPos + 2, label.length() - locationPos - 3); functionEnd = locationPos; } } ret.function = label.mid(functionStart, functionEnd - functionStart); return ret; } QByteArray prettyLabel(const QByteArray& label) { ParsedLabel parsed = parseLabel(label); shortenTemplates(parsed.function); if (!parsed.location.isEmpty()) { return parsed.function + " (" + parsed.location + ")"; } else { return parsed.function; } } QByteArray functionInLabel(const QByteArray& label) { return parseLabel(label).function; } QByteArray addressInLabel(const QByteArray& label) { return parseLabel(label).address; } QByteArray locationInLabel(const QByteArray& label) { return parseLabel(label).location; } bool isBelowThreshold(const QByteArray& label) { return label.indexOf("all below massif's threshold") != -1; } QString formatLabel(const QByteArray& label) { ParsedLabel parsed = parseLabel(label); QString ret; if (!parsed.function.isEmpty()) { ret += i18n("
function:
%1
\n", QString(parsed.function).toHtmlEscaped()); } if (!parsed.location.isEmpty()) { ret += i18n("
location:
%1
\n", QString(parsed.location).toHtmlEscaped()); } if (!parsed.address.isEmpty()) { ret += i18n("
address:
%1
\n", QString(parsed.address).toHtmlEscaped()); } return ret; } QString tooltipForTreeLeaf(TreeLeafItem* node, SnapshotItem* snapshot, const QByteArray& label) { QString tooltip = "
\n"; tooltip += i18n("
cost:
%1, i.e. %2% of snapshot #%3
", prettyCost(node ? node->cost() : 0), // yeah nice how I round to two decimals, right? :D double(int(double(node ? node->cost() : 0)/snapshot->cost()*10000))/100, snapshot->number()); tooltip += formatLabel(label); tooltip += "
"; return tooltip; } }