• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kcachegrind

  • sources
  • kde-4.12
  • kdesdk
  • kcachegrind
  • libviews
callview.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2003-2009 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
3 
4  KCachegrind is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation, version 2.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 /*
20  * Call Views
21  */
22 
23 
24 #include "callview.h"
25 
26 #include <QAction>
27 #include <QMenu>
28 #include <QTreeWidget>
29 #include <QHeaderView>
30 #include <QKeyEvent>
31 
32 #include "globalconfig.h"
33 #include "callitem.h"
34 
35 
36 //
37 // CallView
38 //
39 
40 
41 CallView::CallView(bool showCallers, TraceItemView* parentView, QWidget* parent)
42  : QTreeWidget(parent), TraceItemView(parentView)
43 {
44  _showCallers = showCallers;
45 
46  QStringList headerLabels;
47  headerLabels << tr( "Cost" )
48  << tr( "Cost per call" )
49  << tr( "Cost 2" )
50  << tr( "Cost 2 per call" )
51  << tr( "Count" )
52  << ((_showCallers) ? tr( "Caller" ) : tr( "Callee" ));
53  setHeaderLabels(headerLabels);
54 
55  // forbid scaling icon pixmaps to smaller size
56  setIconSize(QSize(99,99));
57  setAllColumnsShowFocus(true);
58  setRootIsDecorated(false);
59  setUniformRowHeights(true);
60  // sorting will be enabled after refresh()
61  sortByColumn(0, Qt::DescendingOrder);
62  setMinimumHeight(50);
63 
64  this->setWhatsThis( whatsThis() );
65 
66  connect( this,
67  SIGNAL( currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
68  SLOT( selectedSlot(QTreeWidgetItem*,QTreeWidgetItem*) ) );
69 
70  setContextMenuPolicy(Qt::CustomContextMenu);
71  connect( this,
72  SIGNAL(customContextMenuRequested(const QPoint &) ),
73  SLOT(context(const QPoint &)));
74 
75  connect(this,
76  SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
77  SLOT(activatedSlot(QTreeWidgetItem*,int)));
78 
79  connect(header(), SIGNAL(sectionClicked(int)),
80  this, SLOT(headerClicked(int)));
81 }
82 
83 QString CallView::whatsThis() const
84 {
85  return _showCallers ?
86  tr( "<b>List of direct Callers</b>"
87  "<p>This list shows all functions calling the "
88  "current selected one directly, together with "
89  "a call count and the cost spent in the current "
90  "selected function while being called from the "
91  "function from the list.</p>"
92  "<p>An icon instead of an inclusive cost specifies "
93  "that this is a call inside of a recursive cycle. "
94  "An inclusive cost makes no sense here.</p>"
95  "<p>Selecting a function makes it the current selected "
96  "one of this information panel. "
97  "If there are two panels (Split mode), the "
98  "function of the other panel is changed instead.</p>") :
99  tr( "<b>List of direct Callees</b>"
100  "<p>This list shows all functions called by the "
101  "current selected one directly, together with "
102  "a call count and the cost spent in this function "
103  "while being called from the selected function.</p>"
104  "<p>Selecting a function makes it the current selected "
105  "one of this information panel. "
106  "If there are two panels (Split mode), the "
107  "function of the other panel is changed instead.</p>");
108 }
109 
110 
111 void CallView::context(const QPoint & p)
112 {
113  QMenu popup;
114 
115  // p is in local coordinates
116  int col = columnAt(p.x());
117  QTreeWidgetItem* i = itemAt(p);
118  TraceCall* c = i ? ((CallItem*) i)->call() : 0;
119  TraceFunction *f = 0, *cycle = 0;
120 
121  QAction* activateFunctionAction = 0;
122  QAction* activateCycleAction = 0;
123  if (c) {
124  QString name = _showCallers ? c->callerName(true) : c->calledName(true);
125  f = _showCallers ? c->caller(true) : c->called(true);
126  cycle = f->cycle();
127 
128  QString menuText = tr("Go to '%1'").arg(GlobalConfig::shortenSymbol(name));
129  activateFunctionAction = popup.addAction(menuText);
130 
131  if (cycle) {
132  name = GlobalConfig::shortenSymbol(cycle->prettyName());
133  QString menuText = tr("Go to '%1'").arg(name);
134  activateCycleAction = popup.addAction(menuText);
135  }
136 
137  popup.addSeparator();
138  }
139 
140  if ((col == 0) || (col == 1)) {
141  addEventTypeMenu(&popup);
142  popup.addSeparator();
143  }
144  addGoMenu(&popup);
145 
146  QAction* a = popup.exec(mapToGlobal(p + QPoint(0,header()->height())));
147  if (a == activateFunctionAction)
148  TraceItemView::activated(f);
149  else if (a == activateCycleAction)
150  TraceItemView::activated(cycle);
151 }
152 
153 void CallView::selectedSlot(QTreeWidgetItem * i, QTreeWidgetItem *)
154 {
155  if (!i) return;
156  TraceCall* c = ((CallItem*) i)->call();
157  // Should we skip cycles here?
158  CostItem* f = _showCallers ? c->caller(false) : c->called(false);
159 
160  _selectedItem = f;
161  selected(f);
162 }
163 
164 void CallView::activatedSlot(QTreeWidgetItem* i,int)
165 {
166  if (!i) return;
167 
168  TraceCall* c = ((CallItem*) i)->call();
169  // skip cycles: use the context menu to get to the cycle...
170  CostItem* f = _showCallers ? c->caller(true) : c->called(true);
171 
172  TraceItemView::activated(f);
173 }
174 
175 void CallView::headerClicked(int col)
176 {
177  // name columns should be sortable in both ways
178  if (col == 3) return;
179 
180  // all others only descending
181  sortByColumn(col, Qt::DescendingOrder);
182 }
183 
184 void CallView::keyPressEvent(QKeyEvent* event)
185 {
186  QTreeWidgetItem *item = currentItem();
187  if (item && ((event->key() == Qt::Key_Return) ||
188  (event->key() == Qt::Key_Space)))
189  {
190  TraceCall* c = ((CallItem*) item)->call();
191  CostItem* f = _showCallers ? c->caller(false) : c->called(false);
192 
193  TraceItemView::activated(f);
194  }
195  QTreeView::keyPressEvent(event);
196 }
197 
198 CostItem* CallView::canShow(CostItem* i)
199 {
200  ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;
201 
202  switch(t) {
203  case ProfileContext::Function:
204  case ProfileContext::FunctionCycle:
205  return i;
206  default:
207  break;
208  }
209  return 0;
210 }
211 
212 void CallView::doUpdate(int changeType, bool)
213 {
214  // Special case ?
215  if (changeType == selectedItemChanged) {
216 
217  if (!_selectedItem) {
218  clearSelection();
219  return;
220  }
221 
222  CallItem* ci = (CallItem*) currentItem();
223  TraceCall* c;
224  CostItem* ti;
225  if (ci) {
226  c = ci->call();
227  ti = _showCallers ? c->caller() : c->called();
228  if (ti == _selectedItem) return;
229  }
230 
231  QTreeWidgetItem *item = 0;
232  for (int i=0; i<topLevelItemCount();i++) {
233  item = topLevelItem(i);
234  c = ((CallItem*) item)->call();
235  ti = _showCallers ? c->caller() : c->called();
236  if (ti == _selectedItem) {
237  scrollToItem(item);
238  setCurrentItem(item);
239  break;
240  }
241  }
242  if (!item && ci) clearSelection();
243  return;
244  }
245 
246  if (changeType == groupTypeChanged) {
247  QTreeWidgetItem *item;
248  for (int i=0; i<topLevelItemCount(); i++){
249  item = topLevelItem(i);
250  ((CallItem*)item)->updateGroup();
251  }
252  return;
253  }
254 
255  refresh();
256 }
257 
258 void CallView::refresh()
259 {
260  clear();
261  setColumnWidth(1, _eventType2 ? 50:0);
262 
263  if (_eventType) {
264  headerItem()->setText(0, _eventType->name());
265  headerItem()->setText(1, tr("%1 per call").arg(_eventType->name()));
266  }
267  if (_eventType2) {
268  headerItem()->setText(2, _eventType2->name());
269  headerItem()->setText(3, tr("%1 per call").arg(_eventType2->name()));
270  }
271 
272  if (!_data || !_activeItem) return;
273 
274  TraceFunction* f = activeFunction();
275  if (!f) return;
276 
277  // In the call lists, we skip cycles to show the real call relations
278  TraceCallList l = _showCallers ? f->callers(true) : f->callings(true);
279 
280  QList<QTreeWidgetItem*> items;
281  foreach(TraceCall* call, l)
282  if (call->subCost(_eventType)>0)
283  items.append(new CallItem(this, 0, call));
284 
285  // when inserting, switch off sorting for performance reason
286  setSortingEnabled(false);
287  addTopLevelItems(items);
288  setSortingEnabled(true);
289  // enabling sorting switches on the indicator, but we want it off
290  header()->setSortIndicatorShown(false);
291  // resize to content now (section size still can be interactively changed)
292  header()->resizeSections(QHeaderView::ResizeToContents);
293 
294  if (!_eventType2) {
295  setColumnWidth(2, 0);
296  setColumnWidth(3, 0);
297  }
298 }
299 
300 #include "callview.moc"
TraceItemView::selectedItemChanged
Definition: traceitemview.h:86
callitem.h
TraceItemView::_selectedItem
CostItem * _selectedItem
Definition: traceitemview.h:211
ProfileCostArray::subCost
SubCost subCost(EventType *)
Returns a sub cost.
Definition: costitem.cpp:591
globalconfig.h
ProfileContext::FunctionCycle
Definition: context.h:46
CallView::whatsThis
QString whatsThis() const
Definition: callview.cpp:83
QTreeWidget
TraceFunction::callings
const TraceCallList & callings(bool skipCycle=false) const
Definition: tracedata.cpp:2302
TraceItemView::addEventTypeMenu
void addEventTypeMenu(QMenu *, bool withCost2=true)
Definition: traceitemview.cpp:456
TraceCall::caller
TraceFunction * caller(bool skipCycle=false) const
Definition: tracedata.cpp:1230
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
QWidget
TraceFunction
A traced function.
Definition: tracedata.h:1122
TraceItemView::_data
TraceData * _data
Definition: traceitemview.h:209
TraceItemView::addGoMenu
void addGoMenu(QMenu *)
Definition: traceitemview.cpp:461
TraceFunction::cycle
TraceFunctionCycle * cycle()
Definition: tracedata.h:1200
CostItem
Base class for cost items.
Definition: costitem.h:37
TraceItemView::activeFunction
TraceFunction * activeFunction()
Definition: traceitemview.cpp:121
TraceFunction::callers
TraceCallList callers(bool skipCycle=false) const
Definition: tracedata.cpp:2278
CallItem::call
TraceCall * call()
Definition: callitem.h:37
TraceItemView::_eventType2
EventType * _eventType2
Definition: traceitemview.h:212
TraceItemView
Abstract Base Class for KCachegrind Views.
Definition: traceitemview.h:70
TraceCall::callerName
QString callerName(bool skipCycle=false) const
Definition: tracedata.cpp:1248
TraceItemView::_eventType
EventType * _eventType
Definition: traceitemview.h:212
CallView::context
void context(const QPoint &)
Definition: callview.cpp:111
CallView::selectedSlot
void selectedSlot(QTreeWidgetItem *, QTreeWidgetItem *)
Definition: callview.cpp:153
CallView::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition: callview.cpp:184
TraceItemView::_activeItem
CostItem * _activeItem
Definition: traceitemview.h:211
GlobalConfig::shortenSymbol
static QString shortenSymbol(const QString &)
Definition: globalconfig.cpp:395
CallView::activatedSlot
void activatedSlot(QTreeWidgetItem *, int)
Definition: callview.cpp:164
CallView::CallView
CallView(bool showCallers, TraceItemView *parentView, QWidget *parent=0)
Definition: callview.cpp:41
TraceItemView::selected
virtual void selected(TraceItemView *sender, CostItem *)
Notification from child views.
Definition: traceitemview.cpp:313
QTreeWidgetItem
TraceItemView::activated
virtual void activated(TraceItemView *sender, CostItem *)
Definition: traceitemview.cpp:342
CallItem
Definition: callitem.h:31
CallView::showCallers
bool showCallers() const
Definition: callview.h:40
ProfileContext::Type
Type
Definition: context.h:36
TraceCall::called
TraceFunction * called(bool skipCycle=false) const
Definition: tracedata.cpp:1235
callview.h
TraceItemView::groupTypeChanged
Definition: traceitemview.h:83
TraceCallList
QList< TraceCall * > TraceCallList
Definition: tracedata.h:184
CallView::headerClicked
void headerClicked(int)
Definition: callview.cpp:175
TraceCall
A call from one to another function.
Definition: tracedata.h:835
TraceCall::calledName
QString calledName(bool skipCycle=false) const
Definition: tracedata.cpp:1264
EventType::name
const QString & name()
Definition: eventtype.h:65
ProfileContext::Function
Definition: context.h:46
QList
ProfileContext::InvalidType
Definition: context.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kcachegrind

Skip menu "kcachegrind"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal