summaryrefslogtreecommitdiffstats
path: root/tdecachegrind/tdecachegrind/callview.cpp
blob: 317d137bbdc97dbeb10c91649fd4f03c5ea610d6 (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* 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.
*/

/*
 * Call Views
 */

#include <tqwhatsthis.h>
#include <tqpopupmenu.h>
#include <klocale.h>

#include "configuration.h"
#include "callitem.h"
#include "callview.h"



//
// CallView
//


CallView::CallView(bool showCallers, TraceItemView* parentView,
		   TQWidget* parent, const char* name)
  : TQListView(parent, name), TraceItemView(parentView)
{
    _showCallers = showCallers;

    addColumn( i18n( "Cost" ) );
    addColumn( i18n( "Cost 2" ) );
    if (_showCallers) {
	addColumn( i18n( "Count" ) );
	addColumn( i18n( "Caller" ) );
    }
    else {
	addColumn( i18n( "Count" ) );
	addColumn( i18n( "Callee" ) );
    }

    setSorting(0,false);
    setColumnAlignment(0, TQt::AlignRight);
    setColumnAlignment(1, TQt::AlignRight);
    setColumnAlignment(2, TQt::AlignRight);
    setAllColumnsShowFocus(true);
    setResizeMode(TQListView::LastColumn);
    setMinimumHeight(50);

    connect( this,
	     TQT_SIGNAL( selectionChanged(TQListViewItem*) ),
	     TQT_SLOT( selectedSlot(TQListViewItem*) ) );

    connect( this,
	     TQT_SIGNAL(contextMenuRequested(TQListViewItem*, const TQPoint &, int)),
	     TQT_SLOT(context(TQListViewItem*, const TQPoint &, int)));

    connect(this,
	    TQT_SIGNAL(doubleClicked(TQListViewItem*)),
	    TQT_SLOT(activatedSlot(TQListViewItem*)));

    connect(this,
	    TQT_SIGNAL(returnPressed(TQListViewItem*)),
	    TQT_SLOT(activatedSlot(TQListViewItem*)));

    TQWhatsThis::add( this, whatsThis() );
}

TQString CallView::whatsThis() const
{
    return _showCallers ?
	i18n( "<b>List of direct Callers</b>"
	      "<p>This list shows all functions calling the "
	      "current selected one directly, together with "
	      "a call count and the cost spent in the current "
	      "selected function while being called from the "
	      "function from the list.</p>"
	      "<p>An icon instead of an inclusive cost specifies "
	      "that this is a call inside of a recursive cycle. "
	      "An inclusive cost makes no sense here.</p>"
	      "<p>Selecting a function makes it the current selected "
	      "one of this information panel. "
	      "If there are two panels (Split mode), the "
	      "function of the other panel is changed instead.</p>") :
	i18n( "<b>List of direct Callees</b>"
	      "<p>This list shows all functions called by the "
	      "current selected one directly, together with "
	      "a call count and the cost spent in this function "
	      "while being called from the selected function.</p>"
	      "<p>Selecting a function makes it the current selected "
	      "one of this information panel. "
	      "If there are two panels (Split mode), the "
	      "function of the other panel is changed instead.</p>");
}


void CallView::context(TQListViewItem* i, const TQPoint & p, int col)
{
  TQPopupMenu popup;

  // Menu entry:
  TraceCall* c = i ? ((CallItem*) i)->call() : 0;
  TraceFunction *f = 0, *cycle = 0;

  if (c) {
    TQString name  = _showCallers ? c->callerName(true) : c->calledName(true);
    f = _showCallers ? c->caller(true) : c->called(true);
    cycle = f->cycle();

    popup.insertItem(i18n("Go to '%1'")
		     .arg(Configuration::shortenSymbol(name)), 93);

    if (cycle) {
	name = Configuration::shortenSymbol(cycle->prettyName());
	popup.insertItem(i18n("Go to '%1'").arg(name), 94);
    }

    popup.insertSeparator();
  }

  if ((col == 0) || (col == 1)) {
    addCostMenu(&popup);
    popup.insertSeparator();
  }
  addGoMenu(&popup);

  int r = popup.exec(p);
  if (r == 93) activated(f);
  else if (r == 94) activated(cycle);
}

void CallView::selectedSlot(TQListViewItem * i)
{
  if (!i) return;
  TraceCall* c = ((CallItem*) i)->call();
  // Should we skip cycles here?
  TraceItem* f = _showCallers ? c->caller(false) : c->called(false);

  _selectedItem = f;
  selected(f);
}

void CallView::activatedSlot(TQListViewItem * i)
{
  if (!i) return;
  TraceCall* c = ((CallItem*) i)->call();
  // skip cycles: use the context menu to get to the cycle...
  TraceItem* f = _showCallers ? c->caller(true) : c->called(true);

  activated(f);
}

TraceItem* CallView::canShow(TraceItem* i)
{
  TraceItem::CostType t = i ? i->type() : TraceItem::NoCostType;

  switch(t) {
  case TraceItem::Function:
  case TraceItem::FunctionCycle:
      return i;
  default:
      break;
  }
  return 0;
}

void CallView::doUpdate(int changeType)
{
    // Special case ?
    if (changeType == selectedItemChanged) {

	if (!_selectedItem) {
	    clearSelection();
	    return;
	}

	CallItem* ci = (CallItem*) TQListView::selectedItem();
	TraceCall* c;
	TraceItem* ti;
	if (ci) {
	    c = ci->call();
	    ti = _showCallers ? c->caller() : c->called();
	    if (ti == _selectedItem) return;
	}

	TQListViewItem *item;
	for (item = firstChild();item;item = item->nextSibling()) {
	    c = ((CallItem*) item)->call();
	    ti = _showCallers ? c->caller() : c->called();
	    if (ti == _selectedItem) {
		ensureItemVisible(item);
		setSelected(item,  true);
		break;
	    }
	}
        if (!item && ci) clearSelection();
	return;
    }
    
    if (changeType == groupTypeChanged) {
	TQListViewItem *item;
	for (item = firstChild();item;item = item->nextSibling())
	    ((CallItem*)item)->updateGroup();
	return;
    }

    refresh();
}

void CallView::refresh()
{
    clear();
    setColumnWidth(0, 50);
    setColumnWidth(1, _costType2 ? 50:0);
    setColumnWidth(2, 50);
    if (_costType)
      setColumnText(0, _costType->name());
    if (_costType2)
      setColumnText(1, _costType2->name());

    if (!_data || !_activeItem) return;

    TraceFunction* f = activeFunction();
    if (!f) return;

    TraceCall* call;
    // In the call lists, we skip cycles to show the real call relations
    TraceCallList l = _showCallers ? f->callers(true) : f->callings(true);

    // Allow resizing of column 1
    setColumnWidthMode(1, TQListView::Maximum);

    for (call=l.first();call;call=l.next())
	if (call->subCost(_costType)>0)
	    new CallItem(this, this, call);

    if (!_costType2) {
      setColumnWidthMode(1, TQListView::Manual);
      setColumnWidth(1, 0);
    }
}

#include "callview.moc"