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

kcachegrind

  • sources
  • kde-4.14
  • 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  // add menu items to select event type if column displays cost for a type
141  if (col < 4) {
142  addEventTypeMenu(&popup);
143  popup.addSeparator();
144  }
145  addGoMenu(&popup);
146 
147  QAction* a = popup.exec(mapToGlobal(p + QPoint(0,header()->height())));
148  if (a == activateFunctionAction)
149  TraceItemView::activated(f);
150  else if (a == activateCycleAction)
151  TraceItemView::activated(cycle);
152 }
153 
154 void CallView::selectedSlot(QTreeWidgetItem * i, QTreeWidgetItem *)
155 {
156  if (!i) return;
157  TraceCall* c = ((CallItem*) i)->call();
158  // Should we skip cycles here?
159  CostItem* f = _showCallers ? c->caller(false) : c->called(false);
160 
161  _selectedItem = f;
162  selected(f);
163 }
164 
165 void CallView::activatedSlot(QTreeWidgetItem* i,int)
166 {
167  if (!i) return;
168 
169  TraceCall* c = ((CallItem*) i)->call();
170  // skip cycles: use the context menu to get to the cycle...
171  CostItem* f = _showCallers ? c->caller(true) : c->called(true);
172 
173  TraceItemView::activated(f);
174 }
175 
176 void CallView::headerClicked(int col)
177 {
178  // name columns should be sortable in both ways
179  if (col == 5) return;
180 
181  // all others only descending
182  sortByColumn(col, Qt::DescendingOrder);
183 }
184 
185 void CallView::keyPressEvent(QKeyEvent* event)
186 {
187  QTreeWidgetItem *item = currentItem();
188  if (item && ((event->key() == Qt::Key_Return) ||
189  (event->key() == Qt::Key_Space)))
190  {
191  TraceCall* c = ((CallItem*) item)->call();
192  CostItem* f = _showCallers ? c->caller(false) : c->called(false);
193 
194  TraceItemView::activated(f);
195  }
196  QTreeView::keyPressEvent(event);
197 }
198 
199 CostItem* CallView::canShow(CostItem* i)
200 {
201  ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;
202 
203  switch(t) {
204  case ProfileContext::Function:
205  case ProfileContext::FunctionCycle:
206  return i;
207  default:
208  break;
209  }
210  return 0;
211 }
212 
213 void CallView::doUpdate(int changeType, bool)
214 {
215  // Special case ?
216  if (changeType == selectedItemChanged) {
217 
218  if (!_selectedItem) {
219  clearSelection();
220  return;
221  }
222 
223  CallItem* ci = (CallItem*) currentItem();
224  TraceCall* c;
225  CostItem* ti;
226  if (ci) {
227  c = ci->call();
228  ti = _showCallers ? c->caller() : c->called();
229  if (ti == _selectedItem) return;
230  }
231 
232  QTreeWidgetItem *item = 0;
233  for (int i=0; i<topLevelItemCount();i++) {
234  item = topLevelItem(i);
235  c = ((CallItem*) item)->call();
236  ti = _showCallers ? c->caller() : c->called();
237  if (ti == _selectedItem) {
238  scrollToItem(item);
239  setCurrentItem(item);
240  break;
241  }
242  }
243  if (!item && ci) clearSelection();
244  return;
245  }
246 
247  if (changeType == groupTypeChanged) {
248  QTreeWidgetItem *item;
249  for (int i=0; i<topLevelItemCount(); i++){
250  item = topLevelItem(i);
251  ((CallItem*)item)->updateGroup();
252  }
253  return;
254  }
255 
256  refresh();
257 }
258 
259 void CallView::refresh()
260 {
261  clear();
262  setColumnWidth(1, _eventType2 ? 50:0);
263 
264  if (_eventType) {
265  headerItem()->setText(0, _eventType->name());
266  headerItem()->setText(1, tr("%1 per call").arg(_eventType->name()));
267  }
268  if (_eventType2) {
269  headerItem()->setText(2, _eventType2->name());
270  headerItem()->setText(3, tr("%1 per call").arg(_eventType2->name()));
271  }
272 
273  if (!_data || !_activeItem) return;
274 
275  TraceFunction* f = activeFunction();
276  if (!f) return;
277 
278  // In the call lists, we skip cycles to show the real call relations
279  TraceCallList l = _showCallers ? f->callers(true) : f->callings(true);
280 
281  QList<QTreeWidgetItem*> items;
282  foreach(TraceCall* call, l)
283  if (call->subCost(_eventType)>0)
284  items.append(new CallItem(this, 0, call));
285 
286  // when inserting, switch off sorting for performance reason
287  setSortingEnabled(false);
288  addTopLevelItems(items);
289  setSortingEnabled(true);
290  // enabling sorting switches on the indicator, but we want it off
291  header()->setSortIndicatorShown(false);
292  // resize to content now (section size still can be interactively changed)
293  header()->resizeSections(QHeaderView::ResizeToContents);
294 
295  if (!_eventType2) {
296  setColumnWidth(2, 0);
297  setColumnWidth(3, 0);
298  }
299 }
300 
301 #include "callview.moc"
QWidget::customContextMenuRequested
void customContextMenuRequested(const QPoint &pos)
QHeaderView::resizeSections
void resizeSections(QHeaderView::ResizeMode mode)
TraceItemView::selectedItemChanged
Definition: traceitemview.h:86
callitem.h
QWidget
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::currentItemChanged
void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
TraceFunction::callings
const TraceCallList & callings(bool skipCycle=false) const
Definition: tracedata.cpp:2302
QTreeWidget::scrollToItem
void scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint)
TraceItemView::addEventTypeMenu
void addEventTypeMenu(QMenu *, bool withCost2=true)
Definition: traceitemview.cpp:466
TraceCall::caller
TraceFunction * caller(bool skipCycle=false) const
Definition: tracedata.cpp:1230
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
TraceFunction
A traced function.
Definition: tracedata.h:1122
TraceItemView::_data
TraceData * _data
Definition: traceitemview.h:209
QMenu::addAction
void addAction(QAction *action)
TraceItemView::addGoMenu
void addGoMenu(QMenu *)
Definition: traceitemview.cpp:471
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
TraceFunction::cycle
TraceFunctionCycle * cycle()
Definition: tracedata.h:1200
QTreeWidget::items
QList< QTreeWidgetItem * > items(const QMimeData *data) const
QTreeView::setUniformRowHeights
void setUniformRowHeights(bool uniform)
CostItem
Base class for cost items.
Definition: costitem.h:37
QHeaderView::setSortIndicatorShown
void setSortIndicatorShown(bool show)
QPoint
QTreeView::sortByColumn
void sortByColumn(int column, Qt::SortOrder order)
TraceItemView::activeFunction
TraceFunction * activeFunction()
Definition: traceitemview.cpp:123
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
TraceFunction::callers
TraceCallList callers(bool skipCycle=false) const
Definition: tracedata.cpp:2278
QPoint::x
int x() const
CallItem::call
TraceCall * call()
Definition: callitem.h:37
TraceItemView::_eventType2
EventType * _eventType2
Definition: traceitemview.h:212
QTreeWidget::clear
void clear()
TraceItemView
Abstract Base Class for KCachegrind Views.
Definition: traceitemview.h:70
TraceCall::callerName
QString callerName(bool skipCycle=false) const
Definition: tracedata.cpp:1248
QTreeWidget
TraceItemView::_eventType
EventType * _eventType
Definition: traceitemview.h:212
QObject::name
const char * name() const
QTreeView::setColumnWidth
void setColumnWidth(int column, int width)
QList::append
void append(const T &value)
QTreeWidget::addTopLevelItems
void addTopLevelItems(const QList< QTreeWidgetItem * > &items)
QAbstractItemView::setIconSize
void setIconSize(const QSize &size)
QTreeWidget::itemAt
QTreeWidgetItem * itemAt(const QPoint &p) const
CallView::context
void context(const QPoint &)
Definition: callview.cpp:111
CallView::selectedSlot
void selectedSlot(QTreeWidgetItem *, QTreeWidgetItem *)
Definition: callview.cpp:154
CallView::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition: callview.cpp:185
TraceItemView::_activeItem
CostItem * _activeItem
Definition: traceitemview.h:211
QTreeView::setAllColumnsShowFocus
void setAllColumnsShowFocus(bool enable)
QMenu::addSeparator
QAction * addSeparator()
QTreeWidget::currentItem
QTreeWidgetItem * currentItem() const
QString
QList
GlobalConfig::shortenSymbol
static QString shortenSymbol(const QString &)
Definition: globalconfig.cpp:395
QMenu::exec
QAction * exec()
QStringList
CallView::activatedSlot
void activatedSlot(QTreeWidgetItem *, int)
Definition: callview.cpp:165
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:319
QKeyEvent::key
int key() const
QMenu
QSize
TraceItemView::activated
virtual void activated(TraceItemView *sender, CostItem *)
Definition: traceitemview.cpp:347
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
CallItem
Definition: callitem.h:31
QTreeWidget::setCurrentItem
void setCurrentItem(QTreeWidgetItem *item)
QTreeWidget::setHeaderLabels
void setHeaderLabels(const QStringList &labels)
CallView::showCallers
bool showCallers() const
Definition: callview.h:40
QKeyEvent
QTreeWidget::headerItem
QTreeWidgetItem * headerItem() const
QTreeView::setSortingEnabled
void setSortingEnabled(bool enable)
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QTreeWidgetItem
ProfileContext::Type
Type
Definition: context.h:36
QAction
TraceCall::called
TraceFunction * called(bool skipCycle=false) const
Definition: tracedata.cpp:1235
QTreeWidgetItem::setText
void setText(int column, const QString &text)
callview.h
TraceItemView::groupTypeChanged
Definition: traceitemview.h:83
QWidget::setMinimumHeight
void setMinimumHeight(int minh)
QTreeView::header
QHeaderView * header() const
CallView::headerClicked
void headerClicked(int)
Definition: callview.cpp:176
QTreeWidget::topLevelItem
QTreeWidgetItem * topLevelItem(int index) const
QTreeView::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
QTreeWidget::topLevelItemCount
int topLevelItemCount() const
QAbstractItemView::clearSelection
void clearSelection()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
TraceCall
A call from one to another function.
Definition: tracedata.h:835
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
TraceCall::calledName
QString calledName(bool skipCycle=false) const
Definition: tracedata.cpp:1264
QTreeWidget::itemDoubleClicked
void itemDoubleClicked(QTreeWidgetItem *item, int column)
QTreeView::columnAt
int columnAt(int x) const
QWidget::height
int height() const
EventType::name
const QString & name()
Definition: eventtype.h:65
ProfileContext::Function
Definition: context.h:46
ProfileContext::InvalidType
Definition: context.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:39:50 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
  • 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