summaryrefslogtreecommitdiffstats
path: root/tdecachegrind/tdecachegrind/functionitem.cpp
blob: 17716e14e62d31203521b6594a6637dea46272af (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* This file is part of KCachegrind.
   Copyright (C) 2003 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.
*/

/*
 * List Item for the FunctionSelection list
 */


//#include <math.h>

//#include <tqpainter.h>
//#include <tqregexp.h>

#include <klocale.h>
#include <kiconloader.h>
#include <tdeapplication.h>

#include "listutils.h"
#include "functionitem.h"
#include "configuration.h"


// FunctionItem

FunctionItem::FunctionItem(TQListView* parent, TraceFunction* f,
                           TraceCostType* ct, TraceCost::CostType gt)
  :TQListViewItem(parent)
{
#if 0
    _costPixValid = false;
    _groupPixValid = false;
#endif

    _function = f;
    _skipped = 0;
    _groupType = TraceCost::NoCostType;
    setGroupType(gt);
    setCostType(ct);

    setText(3, f->prettyName());
    setText(4, f->prettyLocation());
}

FunctionItem::FunctionItem(TQListView* parent, int skipped,
			   TraceFunction* f, TraceCostType* ct)
  :TQListViewItem(parent)
{
#if 0
    _costPixValid = false;
    _groupPixValid = false;
#endif
    _skipped = skipped;
    _function = f;
    _groupType = TraceCost::NoCostType;
    setCostType(ct);

    setText(3, i18n("(%n function skipped)", "(%n functions skipped)", skipped));
}

#if 0
const TQPixmap* FunctionItem::pixmap(int column) const
{
    if (column == 3) {
	if (!_groupPixValid) {
	    TQColor c = Configuration::functionColor(_groupType, _function);
	    _groupPix = colorPixmap(10, 10, c);
	    _groupPixValid = true;
	}
	return &_groupPix;
    }
    if (column == 1) {
	if (!_costPixValid) {
	    _costPix = colorPixmap(10, 10, c);
	    _costPixValid = true;
	}
	return &_costPix;
    }
    return 0;
}
#endif

void  FunctionItem::setGroupType(TraceCost::CostType gt)
{
  if (_skipped) return;
  if (_groupType == gt) return;
  _groupType = gt;


#if 0
  _groupPixValid = false;
  viewList()->repaint();
#else
  TQColor c = Configuration::functionColor(_groupType, _function);
  setPixmap(3, colorPixmap(10, 10, c));
#endif
}

void FunctionItem::setCostType(TraceCostType* c)
{
  _costType = c;
  update();
}

void FunctionItem::update()
{
  double inclTotal = _function->data()->subCost(_costType);
  TQString str;

  TraceCost* selfCost = _function->data();
  if (Configuration::showExpanded()) {
      switch(_groupType) {
      case TraceCost::Object: selfCost = _function->object(); break;
      case TraceCost::Class:  selfCost = _function->cls(); break;
      case TraceCost::File:   selfCost = _function->file(); break;
      default: break;
      }
  }
  double selfTotal = selfCost->subCost(_costType);

  if (_skipped) {
    // special handling for skip entries...

    // only text updates of incl./self

    // for all skipped functions, cost is below the given function
    _sum  = _function->inclusive()->subCost(_costType);
    double incl  = 100.0 * _sum / inclTotal;
    if (Configuration::showPercentage())
      str = TQString("%1").arg(incl, 0, 'f', Configuration::percentPrecision());
    else
      str = _function->inclusive()->prettySubCost(_costType);
    str = "< " + str;
    setText(0, str);
    setText(1, str);
    return;
  }

  // Call count...
  if (_function->calledCount() >0)
    str = _function->prettyCalledCount();
  else {
    if (_function == _function->cycle())
      str = TQString("-");
    else
      str = TQString("(0)");
  }
  setText(2, str);

  // Incl. cost
  _sum  = _function->inclusive()->subCost(_costType);
  if (inclTotal == 0.0) {
    setPixmap(0, TQPixmap());
    setText(0, "-");
  }
  else {
      double incl  = 100.0 * _sum / inclTotal;
      if (Configuration::showPercentage())
	  setText(0, TQString("%1")
		  .arg(incl, 0, 'f', Configuration::percentPrecision()));
      else
	  setText(0, _function->inclusive()->prettySubCost(_costType));

      setPixmap(0, costPixmap(_costType, _function->inclusive(), inclTotal, false));
  }

  // self
  _pure = _function->subCost(_costType);
  if (selfTotal == 0.0) {
    setPixmap(1, TQPixmap());
    setText(1, "-");
  }
  else {
      double self  = 100.0 * _pure / selfTotal;

      if (Configuration::showPercentage())
	  setText(1, TQString("%1")
		  .arg(self, 0, 'f', Configuration::percentPrecision()));
      else
	  setText(1, _function->prettySubCost(_costType));

      setPixmap(1, costPixmap(_costType, _function, selfTotal, false));
  }
}


int FunctionItem::compare(TQListViewItem * i, int col, bool ascending ) const
{
  const FunctionItem* fi1 = this;
  const FunctionItem* fi2 = (FunctionItem*) i;

  // we always want descending order
  if (ascending) {
    fi1 = fi2;
    fi2 = this;
  }

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

  if (col==0) {
    if (fi1->_sum < fi2->_sum) return -1;
    if (fi1->_sum > fi2->_sum) return 1;
    return 0;
  }
  if (col==1) {
    if (fi1->_pure < fi2->_pure) return -1;
    if (fi1->_pure > fi2->_pure) return 1;
    return 0;
  }
  if (col==2) {
    if (fi1->_function->calledCount() <
	fi2->_function->calledCount()) return -1;
    if (fi1->_function->calledCount() >
	fi2->_function->calledCount()) return 1;
    return 0;
  }

  return TQListViewItem::compare(i, col, ascending);
}