File: costlistitem.cpp

package info (click to toggle)
kcachegrind 4%3A16.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,844 kB
  • ctags: 3,250
  • sloc: cpp: 28,541; perl: 325; python: 235; makefile: 7; sh: 5
file content (130 lines) | stat: -rw-r--r-- 3,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* This file is part of KCachegrind.
   Copyright (c) 2002-2015 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program 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
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "costlistitem.h"

#include <math.h>

#include <QPixmap>

#include "listutils.h"
#include "coverage.h"
#include "globalguiconfig.h"


// CostListItem


CostListItem::CostListItem(QTreeWidget* parent, TraceCostItem* costItem,
                           EventType* et, int size)
  :QTreeWidgetItem(parent)
{
  _groupSize = size;
  _skipped = 0;
  _costItem = costItem;
  setEventType(et);

  setTextAlignment(0, Qt::AlignRight);

  if (costItem) {
    updateName();
    setIcon(1, colorPixmap(10, 10,
                           GlobalGUIConfig::groupColor(_costItem)));
  }
}

CostListItem::CostListItem(QTreeWidget* parent, int skipped,
                           TraceCostItem* costItem, EventType* et)
  :QTreeWidgetItem(parent)
{
  _skipped = skipped;
  _costItem = costItem;
  setEventType(et);

  setTextAlignment(0, Qt::AlignRight);

  setText(1, QObject::tr("(%n item(s) skipped)", "", _skipped));
}

void CostListItem::setEventType(EventType* et)
{
  _eventType = et;
  update();
}

void CostListItem::updateName()
{
  if (!_costItem) return;

  QString n = _costItem->prettyName();
  if (_groupSize>=0) n += QString(" (%1)").arg(_groupSize);

  setText(1, n);
}

void CostListItem::setSize(int s)
{
  _groupSize = s;
  updateName();
}

void CostListItem::update()
{
  if (!_costItem) return;
  TraceData* d = _costItem->data();

  double total = d->subCost(_eventType);
  if (total == 0.0) {
    setText(0, QString("---"));
    setIcon(0, QPixmap());
    return;
  }

  _pure = _costItem->subCost(_eventType);
  double pure  = 100.0 * _pure / total;
  QString str;
  if (GlobalConfig::showPercentage())
    str = QString("%1").arg(pure, 0, 'f', GlobalConfig::percentPrecision());
  else
    str = _costItem->prettySubCost(_eventType);

  if (_skipped) {
    // special handling for skip entries...
    setText(0, QString("< %1").arg(str));
    return;
  }

  setText(0, str);
  setIcon(0, costPixmap(_eventType, _costItem, total, false));
}

bool CostListItem::operator< ( const QTreeWidgetItem & other ) const
{
  const CostListItem* fi1 = this;
  const CostListItem* fi2 = (CostListItem*) &other;
  int col = treeWidget()->sortColumn();

  // a skip entry is always sorted last
  if (fi1->_skipped) return true;
  if (fi2->_skipped) return false;

  if (col==0)
      return (fi1->_pure < fi2->_pure);

  return QTreeWidgetItem::operator <(other);
}