File indexing completed on 2024-04-28 05:41:32
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #include "costlistitem.h" 0010 0011 #include <math.h> 0012 0013 #include <QPixmap> 0014 0015 #include "listutils.h" 0016 #include "coverage.h" 0017 #include "globalguiconfig.h" 0018 0019 0020 // CostListItem 0021 0022 0023 CostListItem::CostListItem(QTreeWidget* parent, TraceCostItem* costItem, 0024 EventType* et, int size) 0025 :QTreeWidgetItem(parent) 0026 { 0027 _groupSize = size; 0028 _skipped = 0; 0029 _costItem = costItem; 0030 setEventType(et); 0031 0032 setTextAlignment(0, Qt::AlignRight); 0033 0034 if (costItem) { 0035 updateName(); 0036 setIcon(1, colorPixmap(10, 10, 0037 GlobalGUIConfig::groupColor(_costItem))); 0038 } 0039 } 0040 0041 CostListItem::CostListItem(QTreeWidget* parent, int skipped, 0042 TraceCostItem* costItem, EventType* et) 0043 :QTreeWidgetItem(parent) 0044 { 0045 _skipped = skipped; 0046 _costItem = costItem; 0047 setEventType(et); 0048 0049 setTextAlignment(0, Qt::AlignRight); 0050 0051 //~ singular (%n item skipped) 0052 //~ plural (%n items skipped) 0053 setText(1, QObject::tr("(%n item(s) skipped)", "", _skipped)); 0054 } 0055 0056 void CostListItem::setEventType(EventType* et) 0057 { 0058 _eventType = et; 0059 update(); 0060 } 0061 0062 void CostListItem::updateName() 0063 { 0064 if (!_costItem) return; 0065 0066 QString n = _costItem->prettyName(); 0067 if (_groupSize>=0) n += QStringLiteral(" (%1)").arg(_groupSize); 0068 0069 setText(1, n); 0070 } 0071 0072 void CostListItem::setSize(int s) 0073 { 0074 _groupSize = s; 0075 updateName(); 0076 } 0077 0078 void CostListItem::update() 0079 { 0080 if (!_costItem) return; 0081 TraceData* d = _costItem->data(); 0082 0083 double total = d->subCost(_eventType); 0084 if (total == 0.0) { 0085 setText(0, QStringLiteral("---")); 0086 setIcon(0, QPixmap()); 0087 return; 0088 } 0089 0090 _pure = _costItem->subCost(_eventType); 0091 double pure = 100.0 * _pure / total; 0092 QString str; 0093 if (GlobalConfig::showPercentage()) 0094 str = QStringLiteral("%1").arg(pure, 0, 'f', GlobalConfig::percentPrecision()); 0095 else 0096 str = _costItem->prettySubCost(_eventType); 0097 0098 if (_skipped) { 0099 // special handling for skip entries... 0100 setText(0, QStringLiteral("< %1").arg(str)); 0101 return; 0102 } 0103 0104 setText(0, str); 0105 setIcon(0, costPixmap(_eventType, _costItem, total, false)); 0106 } 0107 0108 bool CostListItem::operator< ( const QTreeWidgetItem & other ) const 0109 { 0110 const CostListItem* fi1 = this; 0111 const CostListItem* fi2 = (CostListItem*) &other; 0112 int col = treeWidget()->sortColumn(); 0113 0114 // a skip entry is always sorted last 0115 if (fi1->_skipped) return true; 0116 if (fi2->_skipped) return false; 0117 0118 if (col==0) 0119 return (fi1->_pure < fi2->_pure); 0120 0121 return QTreeWidgetItem::operator <(other); 0122 }