File indexing completed on 2024-04-28 05:41:36

0001 /*
0002     This file is part of KCachegrind.
0003 
0004     SPDX-FileCopyrightText: 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only
0007 */
0008 
0009 /*
0010  * Items of stack dockable.
0011  */
0012 
0013 #include "stackitem.h"
0014 
0015 #include <QPixmap>
0016 
0017 #include "globalguiconfig.h"
0018 #include "listutils.h"
0019 #include "stackselection.h"
0020 
0021 
0022 // StackItem
0023 
0024 StackItem::StackItem(StackSelection* ss, 
0025                      QTreeWidget* parent, TraceFunction* f)
0026     :QTreeWidgetItem(parent)
0027 {
0028     _view = ss;
0029     _function = f;
0030     _call = nullptr;
0031 
0032     setTextAlignment(0, Qt::AlignRight);
0033     setTextAlignment(1, Qt::AlignRight);
0034     setTextAlignment(2, Qt::AlignRight);
0035 
0036     updateGroup();
0037     updateCost();
0038 
0039     setText(2, QStringLiteral("-- "));
0040     setText(3, f->prettyName());
0041 }
0042 
0043 StackItem::StackItem(StackSelection* ss,
0044                      QTreeWidget* parent, TraceCall* call)
0045     :QTreeWidgetItem(parent)
0046 {
0047     _view = ss;
0048     _call = call;
0049     _function = call->called();
0050 
0051     setTextAlignment(0, Qt::AlignRight);
0052     setTextAlignment(1, Qt::AlignRight);
0053     setTextAlignment(2, Qt::AlignRight);
0054 
0055     updateGroup();
0056     updateCost();
0057 
0058     setText(3, _function->prettyName());
0059 }
0060 
0061 
0062 void StackItem::updateGroup()
0063 {
0064     QColor c = GlobalGUIConfig::functionColor(_view->groupType(),
0065                                               _function);
0066     setIcon(3, colorPixmap(10, 10, c));
0067 }
0068 
0069 void StackItem::updateCost()
0070 {
0071     if (!_call) return;
0072 
0073     setText(2, _call->prettyCallCount());
0074 
0075     EventType* ct = _view->eventType();
0076     _sum = _call->subCost(ct);
0077     double total = _call->called()->data()->subCost(ct);
0078     if (total == 0.0) {
0079         setText(0, QStringLiteral("-"));
0080         setIcon(0, QPixmap());
0081     }
0082     else {
0083         double sum  = 100.0 * _sum / total;
0084 
0085         if (GlobalConfig::showPercentage())
0086             setText(0, QStringLiteral("%1")
0087                     .arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
0088         else
0089             setText(0, _call->prettySubCost(ct));
0090 
0091         setIcon(0, costPixmap(ct, _call, total, false));
0092     }
0093 
0094     // if _eventType2 is 0, column1 is hidden, no change needed
0095     EventType* ct2 = _view->eventType2();
0096     if (!ct2) return;
0097 
0098     _sum = _call->subCost(ct2);
0099     total = _call->called()->data()->subCost(ct2);
0100     if (total == 0.0) {
0101         setText(1, QStringLiteral("-"));
0102         setIcon(1, QPixmap());
0103     }
0104     else {
0105         double sum  = 100.0 * _sum / total;
0106 
0107         if (GlobalConfig::showPercentage())
0108             setText(1, QStringLiteral("%1")
0109                     .arg(sum, 0, 'f', GlobalConfig::percentPrecision()));
0110         else
0111             setText(1, _call->prettySubCost(ct2));
0112 
0113         setIcon(1, costPixmap(ct2, _call, total, false));
0114     }
0115 }