• 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
functionselection.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2002, 2003 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  * For function selection, to be put into a QDockWindow
21  */
22 
23 #include "functionselection.h"
24 
25 #include <QLabel>
26 #include <QPushButton>
27 #include <QComboBox>
28 #include <QLineEdit>
29 #include <QRegExp>
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
32 #include <QAction>
33 #include <QMenu>
34 #include <QDebug>
35 #include <QTreeView>
36 #include <QHeaderView>
37 #include <QToolTip>
38 #include <QHelpEvent>
39 
40 #include "traceitemview.h"
41 #include "stackbrowser.h"
42 #include "costlistitem.h"
43 #include "globalconfig.h"
44 #include "functionlistmodel.h"
45 
46 
47 // custom item delegate for function list
48 AutoToolTipDelegate::AutoToolTipDelegate(QObject* parent)
49  : QStyledItemDelegate(parent)
50 {}
51 
52 AutoToolTipDelegate::~AutoToolTipDelegate()
53 {}
54 
55 bool AutoToolTipDelegate::helpEvent(QHelpEvent* e, QAbstractItemView* view,
56  const QStyleOptionViewItem& option,
57  const QModelIndex& index)
58 {
59  if (!e || !view)
60  return false;
61 
62  if ( e->type() != QEvent::ToolTip )
63  return QStyledItemDelegate::helpEvent(e, view, option, index);
64 
65  QRect rect = view->visualRect(index);
66  QSize size = sizeHint(option, index);
67  if ( rect.width() < size.width() ) {
68  QVariant tooltip = index.data(Qt::DisplayRole);
69  if ( tooltip.canConvert<QString>() ) {
70  QToolTip::showText(e->globalPos(), tooltip.toString(), view );
71  return true;
72  }
73  }
74 
75  if ( !QStyledItemDelegate::helpEvent( e, view, option, index ) )
76  QToolTip::hideText();
77 
78  return true;
79 }
80 
81 
82 
83 
84 //
85 // FunctionSelection
86 //
87 
88 FunctionSelection::FunctionSelection( TopLevelBase* top,
89  QWidget* parent)
90  : QWidget(parent), TraceItemView(0, top)
91 {
92  _group = 0;
93  _inSetGroup = false;
94  _inSetFunction = false;
95  _functionListSortOrder = Qt::DescendingOrder;
96 
97  setTitle(tr("Function Profile"));
98 
99  // first row with search label and group type combo
100  QHBoxLayout* hboxLayout = new QHBoxLayout();
101  hboxLayout->setSpacing(6);
102  hboxLayout->setMargin(0);
103 
104  searchLabel = new QLabel(this);
105  searchLabel->setText(tr("&Search:"));
106  searchLabel->setWordWrap(false);
107  hboxLayout->addWidget(searchLabel);
108 
109  searchEdit = new QLineEdit(this);
110  searchLabel->setBuddy(searchEdit);
111  hboxLayout->addWidget(searchEdit);
112 
113  groupBox = new QComboBox(this);
114  hboxLayout->addWidget(groupBox);
115 
116  // vertical layout: first row, group list, function list
117  QVBoxLayout* vboxLayout = new QVBoxLayout(this);
118  vboxLayout->setSpacing(6);
119  vboxLayout->setMargin(3);
120  vboxLayout->addLayout(hboxLayout);
121 
122  groupList = new QTreeWidget(this);
123  QStringList groupHeader;
124  groupHeader << tr("Self") << tr("Group");
125  groupList->setHeaderLabels(groupHeader);
126 
127 #if QT_VERSION >= 0x050000
128  groupList->header()->setSectionsClickable(true);
129 #else
130  groupList->header()->setClickable(true);
131 #endif
132  groupList->header()->setSortIndicatorShown(false);
133  groupList->header()->stretchLastSection();
134  groupList->setIconSize(QSize(99,99));
135  groupList->setMaximumHeight(150);
136  groupList->setRootIsDecorated(false);
137  groupList->setUniformRowHeights(true);
138  groupList->sortByColumn(0, Qt::AscendingOrder);
139  vboxLayout->addWidget(groupList);
140 
141  functionListModel = new FunctionListModel();
142  functionListModel->setMaxCount(GlobalConfig::maxListCount());
143 
144  functionList = new QTreeView(this);
145  functionList->setRootIsDecorated(false);
146  functionList->setAllColumnsShowFocus(true);
147  functionList->setAutoScroll(false);
148  functionList->setContextMenuPolicy(Qt::CustomContextMenu);
149  functionList->setUniformRowHeights(true);
150 #if QT_VERSION >= 0x050000
151  functionList->header()->setSectionsClickable(true);
152  functionList->header()->setSectionResizeMode(QHeaderView::Interactive);
153 #else
154  functionList->header()->setClickable(true);
155  functionList->header()->setResizeMode(QHeaderView::Interactive);
156 #endif
157  functionList->header()->setSortIndicatorShown(false);
158  functionList->header()->setSortIndicator(0, Qt::DescendingOrder);
159  // for columns 3 and 4 (all others get resized)
160  functionList->header()->setDefaultSectionSize(200);
161  functionList->setModel(functionListModel);
162  functionList->setItemDelegate(new AutoToolTipDelegate(functionList));
163  vboxLayout->addWidget(functionList);
164 
165  // order has to match mapping in groupTypeSelected()
166  QStringList args;
167  args << tr("(No Grouping)")
168  << ProfileContext::i18nTypeName(ProfileContext::Object)
169  << ProfileContext::i18nTypeName(ProfileContext::File)
170  << ProfileContext::i18nTypeName(ProfileContext::Class)
171  << ProfileContext::i18nTypeName(ProfileContext::FunctionCycle);
172  groupBox->addItems(args);
173  connect(groupBox, SIGNAL(activated(int)),
174  this, SLOT(groupTypeSelected(int)));
175 
176  // search while typing...
177  connect(searchEdit, SIGNAL(textChanged(const QString&)),
178  this, SLOT(searchChanged(const QString&)));
179  connect(&_searchTimer, SIGNAL(timeout()),
180  this, SLOT(queryDelayed()));
181  // select first matching group/function on return
182  connect(searchEdit, SIGNAL(returnPressed()),
183  this, SLOT(searchReturnPressed()));
184  searchEdit->setMinimumWidth(50);
185 
186  // single click release activation
187  connect(functionList, SIGNAL(clicked(QModelIndex)),
188  this, SLOT(functionActivated(QModelIndex)));
189  connect(functionList, SIGNAL(activated(QModelIndex)),
190  this, SLOT(functionActivated(QModelIndex)));
191  connect(functionList, SIGNAL(customContextMenuRequested(const QPoint &)),
192  this, SLOT(functionContext(const QPoint &)));
193  connect(functionList->header(), SIGNAL(sectionClicked(int)),
194  this, SLOT(functionHeaderClicked(int)));
195 
196  connect(groupList,
197  SIGNAL( currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
198  this, SLOT( groupSelected(QTreeWidgetItem*,QTreeWidgetItem*) ) );
199  connect(groupList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
200  this, SLOT(groupDoubleClicked(QTreeWidgetItem*,int)));
201 
202  groupList->setContextMenuPolicy(Qt::CustomContextMenu);
203  connect(groupList,
204  SIGNAL(customContextMenuRequested(const QPoint &) ),
205  this, SLOT(groupContext(const QPoint &)));
206  connect(groupList->header(),
207  SIGNAL(sectionClicked(int)), this, SLOT(groupHeaderClicked(int)));
208 
209  // start hidden
210  groupList->hide();
211 
212  setWhatsThis(whatsThis());
213 }
214 
215 QString FunctionSelection::whatsThis() const
216 {
217  return tr(
218  // xgettext: no-c-format
219  "<b>The Flat Profile</b>"
220  "<p>The flat profile contains a group and a function "
221  "selection list. The group list contains all groups "
222  "where costs "
223  "are spent in, depending on the chosen group type. "
224  "The group list is hidden when group type 'Function' "
225  "is selected.</p>"
226  "<p>The function list contains the functions of the "
227  "selected group (or all for 'Function' group type), "
228  "ordered by the costs spent therein. Functions with "
229  "costs less than 1% are hidden on default.</p>");
230 }
231 
232 void FunctionSelection::setData(TraceData* d)
233 {
234  TraceItemView::setData(d);
235 
236  _group = 0;
237  _groupSize.clear();
238  _hc.clear(GlobalConfig::maxListCount());
239  groupList->clear();
240  functionListModel->resetModelData(d, 0, QString(), 0);
241 }
242 
243 void FunctionSelection::searchReturnPressed()
244 {
245  query(searchEdit->text());
246 
247  QTreeWidgetItem* item;
248  if (_groupType != ProfileContext::Function) {
249  // if current group not matching, select first matching group
250  item = groupList->currentItem();
251  if (!item || item->isHidden()) {
252  int i;
253  item = 0;
254  for (i=0; i<groupList->topLevelItemCount(); i++) {
255  item = groupList->topLevelItem(i);
256  if (!item->isHidden()) break;
257  }
258  if (!item) return;
259 
260  setGroup(((CostListItem*)item)->costItem());
261  return;
262  }
263  }
264  // activate top function in functionList
265  selectTopFunction();
266  functionList->setFocus();
267 }
268 
269 // trigger the query after some delay, dependent on length
270 void FunctionSelection::searchChanged(const QString& q)
271 {
272  _searchDelayed = q;
273  int ms = 100;
274  if (q.length()<5) ms = 200;
275  if (q.length()<2) ms = 300;
276  _searchTimer.setSingleShot(true);
277  _searchTimer.start(ms);
278 }
279 
280 void FunctionSelection::queryDelayed()
281 {
282  query(_searchDelayed);
283 }
284 
285 void FunctionSelection::functionContext(const QPoint & p)
286 {
287  QMenu popup;
288  TraceFunction* f = 0;
289 
290  QAction* activateFunctionAction = 0;
291  QModelIndex i = functionList->indexAt(p);
292  if (i.isValid()) {
293  f = functionListModel->function(i);
294  if (f) {
295  QString menuText = tr("Go to '%1'").arg(GlobalConfig::shortenSymbol(f->prettyName()));
296  activateFunctionAction = popup.addAction(menuText);
297  popup.addSeparator();
298  }
299  if ((i.column() == 0) || (i.column() == 1)) {
300  addEventTypeMenu(&popup,false);
301  popup.addSeparator();
302  }
303  }
304 
305  addGroupMenu(&popup);
306  popup.addSeparator();
307  addGoMenu(&popup);
308 
309  QPoint pDiff = QPoint(0, functionList->header()->height());
310  QAction* a = popup.exec(functionList->mapToGlobal(p + pDiff));
311  if (a == activateFunctionAction)
312  activated(f);
313 }
314 
315 void FunctionSelection::groupContext(const QPoint & p)
316 {
317  QMenu popup;
318 
319  int c = groupList->columnAt(p.x());
320  if (c == 0) {
321  addEventTypeMenu(&popup,false);
322  popup.addSeparator();
323  }
324  addGroupMenu(&popup);
325  popup.addSeparator();
326  addGoMenu(&popup);
327 
328  QPoint headerSize = QPoint(0, groupList->header()->height());
329  popup.exec(groupList->mapToGlobal(p + headerSize));
330 }
331 
332 void FunctionSelection::addGroupAction(QMenu* m,
333  ProfileContext::Type v,
334  const QString& s)
335 {
336  QAction* a;
337  if (s.isEmpty())
338  a = m->addAction(ProfileContext::i18nTypeName(v));
339  else
340  a = m->addAction(s);
341  a->setData((int)v);
342  a->setCheckable(true);
343  a->setChecked(_groupType == v);
344 }
345 
346 void FunctionSelection::addGroupMenu(QMenu* menu)
347 {
348  QMenu* m = menu->addMenu(tr("Grouping"));
349 
350  if (_groupType != ProfileContext::Function) {
351  addGroupAction(m, ProfileContext::Function, tr("No Grouping"));
352  m->addSeparator();
353  }
354  addGroupAction(m, ProfileContext::Object);
355  addGroupAction(m, ProfileContext::File);
356  addGroupAction(m, ProfileContext::Class);
357  addGroupAction(m, ProfileContext::FunctionCycle);
358 
359  connect(m, SIGNAL(triggered(QAction*)),
360  this, SLOT(groupTypeSelected(QAction*)));
361 }
362 
363 
364 void FunctionSelection::groupTypeSelected(QAction* a)
365 {
366  selectedGroupType( (ProfileContext::Type) a->data().toInt() );
367 }
368 
369 void FunctionSelection::groupTypeSelected(int cg)
370 {
371  switch(cg) {
372  case 0: selectedGroupType( ProfileContext::Function ); break;
373  case 1: selectedGroupType( ProfileContext::Object ); break;
374  case 2: selectedGroupType( ProfileContext::File ); break;
375  case 3: selectedGroupType( ProfileContext::Class ); break;
376  case 4: selectedGroupType( ProfileContext::FunctionCycle ); break;
377  default: break;
378  }
379 }
380 
381 
382 CostItem* FunctionSelection::canShow(CostItem* i)
383 {
384  ProfileContext::Type t = i ? i->type() : ProfileContext::InvalidType;
385 
386  switch(t) {
387  case ProfileContext::Function:
388  case ProfileContext::FunctionCycle:
389  case ProfileContext::Object:
390  case ProfileContext::File:
391  case ProfileContext::Class:
392  break;
393 
394  case ProfileContext::Instr:
395  i = ((TraceInstr*)i)->function();
396  break;
397 
398  case ProfileContext::Line:
399  i = ((TraceLine*)i)->functionSource()->function();
400  break;
401 
402  default:
403  i = 0;
404  break;
405  }
406  return i;
407 }
408 
409 
410 void FunctionSelection::selectFunction(TraceFunction* f,
411  bool ensureVisible)
412 {
413  QModelIndex i = functionListModel->indexForFunction(f, true);
414  if (!i.isValid()) return;
415 
416  if (ensureVisible)
417  functionList->scrollTo(i, QAbstractItemView::EnsureVisible);
418 
419  _inSetFunction = true;
420  QModelIndex last = functionListModel->index(i.row(), 4);
421  QItemSelection s(i, last);
422  functionList->selectionModel()->select(s, QItemSelectionModel::ClearAndSelect);
423  _inSetFunction = false;
424 }
425 
426 void FunctionSelection::doUpdate(int changeType, bool)
427 {
428  // Special case ?
429  if (changeType == selectedItemChanged) return;
430 
431  // we do not show cost 2 at all...
432  if (changeType == eventType2Changed) return;
433 
434  if (changeType == eventTypeChanged) {
435  int i;
436 
437 #if QT_VERSION >= 0x050000
438  groupList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
439 #else
440  groupList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
441 #endif
442  // need to disable sorting! Otherwise each change of shown cost
443  // reorders list and changes order returned by topLevelItem()
444  groupList->setSortingEnabled(false);
445  for (i=0; i<groupList->topLevelItemCount(); i++) {
446  CostListItem* item = (CostListItem*) groupList->topLevelItem(i);
447  item->setEventType(_eventType);
448  }
449 #if QT_VERSION >= 0x050000
450  groupList->header()->setSectionResizeMode(0, QHeaderView::Interactive);
451 #else
452  groupList->header()->setResizeMode(0, QHeaderView::Interactive);
453 #endif
454  groupList->setSortingEnabled(true);
455  groupList->header()->setSortIndicatorShown(false);
456 
457  functionListModel->setEventType(_eventType);
458  // previous line resets the model: reselect active item
459  selectFunction(dynamic_cast<TraceFunction*>(_activeItem));
460  setCostColumnWidths();
461  return;
462  }
463 
464  if (changeType == activeItemChanged) {
465  if (_activeItem ==0) {
466  functionList->clearSelection();
467  return;
468  }
469  switch(_activeItem->type()) {
470  case ProfileContext::Object:
471  case ProfileContext::File:
472  case ProfileContext::Class:
473  setGroup((TraceCostItem*)_activeItem);
474  return;
475  default: break;
476  }
477 
478  // active item is a function
479  TraceFunction* f = (TraceFunction*) _activeItem;
480 
481  // if already current, nothing to do
482  QModelIndex i = functionList->currentIndex();
483  if (functionListModel->function(i) == f) {
484  return;
485  }
486 
487  // reset search (as not activated from this view)
488  query(QString::null); //krazy:exclude=nullstrassign for old broken gcc
489 
490  // select cost item group of function
491  switch(_groupType) {
492  case ProfileContext::Object: setGroup(f->object()); break;
493  case ProfileContext::Class: setGroup(f->cls()); break;
494  case ProfileContext::File: setGroup(f->file()); break;
495  case ProfileContext::FunctionCycle: setGroup(f->cycle()); break;
496  default:
497  break;
498  }
499 
500  selectFunction(f);
501  return;
502  }
503 
504  if (changeType & groupTypeChanged) {
505  if (_activeItem && (_activeItem->type() == ProfileContext::Function)) {
506  TraceFunction* f = (TraceFunction*) _activeItem;
507 
508  // select cost item group of function
509  switch(_groupType) {
510  case ProfileContext::Object: _group = f->object(); break;
511  case ProfileContext::Class: _group = f->cls(); break;
512  case ProfileContext::File: _group = f->file(); break;
513  case ProfileContext::FunctionCycle: _group = f->cycle(); break;
514  default:
515  _group = 0;
516  break;
517  }
518  }
519 
520  int id;
521  switch(_groupType) {
522  case ProfileContext::Object: id = 1; break;
523  case ProfileContext::File: id = 2; break;
524  case ProfileContext::Class: id = 3; break;
525  case ProfileContext::FunctionCycle: id = 4; break;
526  default: id = 0; break;
527  }
528  groupBox->setCurrentIndex(id);
529 
530  if (_groupType == ProfileContext::Function)
531  groupList->hide();
532  else
533  groupList->show();
534  }
535 
536  // reset searchEdit
537  _searchString = QString();
538  query(QString::null); //krazy:exclude=nullstrassign for old broken gcc
539 
540  refresh();
541 }
542 
543 
544 /*
545  * This set/selects a group of the set available within the
546  * current group type
547  */
548 void FunctionSelection::setGroup(TraceCostItem* g)
549 {
550  if (!g) return;
551  if (g->type() != _groupType) return;
552  if (g == _group) return;
553  _group = g;
554 
555  QTreeWidgetItem* item = 0;
556  int i;
557  for (i=0; i < groupList->topLevelItemCount(); i++) {
558  item = groupList->topLevelItem(i);
559  if (((CostListItem*)item)->costItem() == g)
560  break;
561  }
562 
563  if (item) {
564  groupList->scrollToItem(item);
565  // prohibit signalling of a group selection
566  _inSetGroup = true;
567  _group = 0;
568  groupList->setCurrentItem(item);
569  _inSetGroup = false;
570  }
571  else
572  groupList->clearSelection();
573 }
574 
575 
576 void FunctionSelection::refresh()
577 {
578  groupList->clear();
579 
580  // make cost columns as small as possible:
581  // the new functions make them as wide as needed
582  groupList->setColumnWidth(0, 50);
583  groupList->headerItem()->setText(1, ProfileContext::i18nTypeName(_groupType));
584 
585  functionListModel->setMaxCount(GlobalConfig::maxListCount());
586 
587  if (!_data || _data->parts().count()==0) {
588  functionListModel->resetModelData(0, 0, QString(), 0);
589  selectTopFunction();
590  return;
591  }
592 
593 
594  TraceObjectMap::Iterator oit;
595  TraceClassMap::Iterator cit;
596  TraceFileMap::Iterator fit;
597 
598  // Fill up group list.
599  // Always show group of current function, even if cost below low limit.
600  //
601 
602  _hc.clear(GlobalConfig::maxListCount());
603 
604  switch(_groupType) {
605  case ProfileContext::Object:
606 
607  for ( oit = _data->objectMap().begin();
608  oit != _data->objectMap().end(); ++oit )
609  _hc.addCost(&(*oit), (*oit).subCost(_eventType));
610  break;
611 
612  case ProfileContext::Class:
613 
614  for ( cit = _data->classMap().begin();
615  cit != _data->classMap().end(); ++cit )
616  _hc.addCost(&(*cit), (*cit).subCost(_eventType));
617  break;
618 
619  case ProfileContext::File:
620 
621  for ( fit = _data->fileMap().begin();
622  fit != _data->fileMap().end(); ++fit )
623  _hc.addCost(&(*fit), (*fit).subCost(_eventType));
624  break;
625 
626  case ProfileContext::FunctionCycle:
627  {
628  // add all cycles
629  foreach(TraceCostItem *group, _data->functionCycles())
630  _hc.addCost(group, group->subCost(_eventType));
631  }
632 
633  break;
634 
635  default:
636  {
637  _group = 0;
638  functionListModel->resetModelData(_data, _group, _searchString, _eventType);
639  selectFunction(dynamic_cast<TraceFunction*>(_activeItem));
640  setCostColumnWidths();
641  return;
642  }
643  }
644 
645  // update group from _activeItem if possible
646  if (_activeItem && (_activeItem->type() == _groupType))
647  _group = (TraceCostItem*) _activeItem;
648 
649  QTreeWidgetItem *item = 0, *activeItem = 0;
650  QList<QTreeWidgetItem*> items;
651 
652  // we always put group of active item in list, even if
653  // it would be skipped because of small costs
654  if (_group) {
655  activeItem = new CostListItem(groupList, _group, _eventType);
656  items.append(activeItem);
657  }
658 
659  for(int i=0; i<_hc.realCount(); i++) {
660  TraceCostItem *group = (TraceCostItem*)_hc[i];
661  // do not put group of active item twice into list
662  if (group == _group) continue;
663  item = new CostListItem(groupList, group, _eventType);
664  items.append(item);
665  }
666  if (_hc.hasMore()) {
667  // a placeholder for all the cost items skipped ...
668  item = new CostListItem(groupList, _hc.count() - _hc.maxSize(),
669  (TraceCostItem*)_hc[_hc.maxSize()-1], _eventType);
670  items.append(item);
671  }
672 
673 #if QT_VERSION >= 0x050000
674  groupList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
675 #else
676  groupList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
677 #endif
678  groupList->setSortingEnabled(false);
679  groupList->addTopLevelItems(items);
680  groupList->setSortingEnabled(true);
681  // always reset to cost sorting
682  groupList->sortByColumn(0, Qt::DescendingOrder);
683  groupList->header()->setSortIndicatorShown(false);
684 #if QT_VERSION >= 0x050000
685  groupList->header()->setSectionResizeMode(0, QHeaderView::Interactive);
686 #else
687  groupList->header()->setResizeMode(0, QHeaderView::Interactive);
688 #endif
689 
690  if (activeItem) {
691  groupList->scrollToItem(activeItem);
692  _inSetGroup = true;
693  _group = 0;
694  groupList->setCurrentItem(activeItem);
695  _inSetGroup = false;
696  }
697  else
698  groupList->clearSelection();
699 }
700 
701 
702 void FunctionSelection::groupSelected(QTreeWidgetItem* i, QTreeWidgetItem*)
703 {
704  if (!i) return;
705  if (!_data) return;
706 
707  TraceCostItem* g = ((CostListItem*) i)->costItem();
708  if (!g) return;
709  if (g == _group) return;
710  _group = g;
711 
712  functionListModel->resetModelData(_data, g, _searchString, _eventType);
713  selectFunction(dynamic_cast<TraceFunction*>(_activeItem));
714  setCostColumnWidths();
715 
716  // Do not emit signal if cost item was changed programatically
717  if (!_inSetGroup) {
718  if (_topLevel)
719  _topLevel->setGroupDelayed(g);
720  }
721 }
722 
723 void FunctionSelection::groupDoubleClicked(QTreeWidgetItem* i, int)
724 {
725  if (!i) return;
726  if (!_data) return;
727  TraceCostItem* g = ((CostListItem*) i)->costItem();
728 
729  if (!g) return;
730  // group must be selected first
731  if (g != _group) return;
732 
733  activated(g);
734 }
735 
736 void FunctionSelection::groupHeaderClicked(int col)
737 {
738  groupList->sortByColumn(col, Qt::DescendingOrder);
739 }
740 
741 TraceCostItem* FunctionSelection::group(QString s)
742 {
743  int i;
744  for (i=0; i<groupList->topLevelItemCount(); i++) {
745  CostListItem* item = (CostListItem*) groupList->topLevelItem(i);
746  if (item->costItem()->name() == s)
747  return item->costItem();
748  }
749 
750  return 0;
751 }
752 
753 
754 void FunctionSelection::functionActivated(const QModelIndex& i)
755 {
756  if (!_data) return;
757 
758  TraceFunction* f = functionListModel->function(i);
759  if (!f) return;
760 
761  if (!_inSetFunction)
762  activated(f);
763 }
764 
765 void FunctionSelection::updateGroupSizes(bool hideEmpty)
766 {
767  int i;
768  for (i=0; i<groupList->topLevelItemCount(); i++) {
769  CostListItem* item = (CostListItem*) groupList->topLevelItem(i);
770  int size = (_groupSize.contains(item->costItem())) ?
771  _groupSize[item->costItem()] : -1;
772  item->setSize(size);
773  item->setHidden(hideEmpty && (size<0));
774  }
775 }
776 
777 void FunctionSelection::query(QString query)
778 {
779  if(!_data)
780  return;
781  if (searchEdit->text() != query)
782  searchEdit->setText(query);
783  if (_searchString == query) {
784  // when resetting query, get rid of group sizes
785  if (query.isEmpty()) {
786  _groupSize.clear();
787  updateGroupSizes(false);
788  }
789  return;
790  }
791  _searchString = query;
792 
793  QRegExp re(query, Qt::CaseInsensitive, QRegExp::Wildcard);
794  _groupSize.clear();
795 
796  TraceFunction* f = 0;
797  TraceFunctionList list2;
798 
799  _hc.clear(GlobalConfig::maxListCount());
800 
801  TraceFunctionMap::Iterator it;
802  for ( it = _data->functionMap().begin();
803  it != _data->functionMap().end(); ++it ) {
804  f = &(*it);
805  if (re.indexIn(f->prettyName())>=0) {
806  if (_group) {
807  if (_groupType==ProfileContext::Object) {
808  if (_groupSize.contains(f->object()))
809  _groupSize[f->object()]++;
810  else
811  _groupSize[f->object()] = 1;
812  if (f->object() != _group) continue;
813  }
814  else if (_groupType==ProfileContext::Class) {
815  if (_groupSize.contains(f->cls()))
816  _groupSize[f->cls()]++;
817  else
818  _groupSize[f->cls()] = 1;
819  if (f->cls() != _group) continue;
820  }
821  else if (_groupType==ProfileContext::File) {
822  if (_groupSize.contains(f->file()))
823  _groupSize[f->file()]++;
824  else
825  _groupSize[f->file()] = 1;
826  if (f->file() != _group) continue;
827  }
828  else if (_groupType==ProfileContext::FunctionCycle) {
829  if (_groupSize.contains(f->cycle()))
830  _groupSize[f->cycle()]++;
831  else
832  _groupSize[f->cycle()] = 1;
833  if (f->cycle() != _group) continue;
834  }
835  }
836  _hc.addCost(f, f->inclusive()->subCost(_eventType));
837  }
838  }
839  updateGroupSizes(true);
840 
841  functionListModel->resetModelData(_data, _group, _searchString, _eventType);
842  selectFunction(dynamic_cast<TraceFunction*>(_activeItem));
843  setCostColumnWidths();
844 }
845 
846 bool FunctionSelection::selectTopFunction()
847 {
848  QModelIndex i = functionListModel->index(0,0);
849  TraceFunction* f = functionListModel->function(i);
850 
851  // pre-select before activation to not trigger a refresh of this view
852  _activeItem = f;
853  selectFunction(f);
854 
855  functionActivated(i);
856 
857  return (f!=0);
858 }
859 
860 void FunctionSelection::setCostColumnWidths()
861 {
862  functionList->resizeColumnToContents(1);
863 
864  if (_eventType && (_eventType->subCost(_data->callMax())>0) ) {
865  functionList->resizeColumnToContents(0);
866  functionList->resizeColumnToContents(2);
867  }
868  else {
869  functionList->header()->resizeSection(0, 0);
870  functionList->header()->resizeSection(2, 0);
871  }
872 }
873 
874 void FunctionSelection::functionHeaderClicked(int col)
875 {
876  if ((_functionListSortOrder== Qt::AscendingOrder) || (col<3))
877  _functionListSortOrder = Qt::DescendingOrder;
878  else
879  _functionListSortOrder = Qt::AscendingOrder;
880 
881  functionList->sortByColumn(col, _functionListSortOrder);
882  selectFunction(dynamic_cast<TraceFunction*>(_activeItem), false);
883  setCostColumnWidths();
884 }
885 
886 
887 
888 #include "functionselection.moc"
QWidget::customContextMenuRequested
void customContextMenuRequested(const QPoint &pos)
QVariant::canConvert
bool canConvert(Type t) const
TraceItemView::selectedItemChanged
Definition: traceitemview.h:86
TraceData::callMax
ProfileCostArray * callMax()
Definition: tracedata.h:1445
QModelIndex
TraceItemView::_topLevel
TopLevelBase * _topLevel
Definition: traceitemview.h:207
QWidget
FunctionListModel::setMaxCount
void setMaxCount(int)
Definition: functionlistmodel.cpp:204
CostListItem::setSize
void setSize(int s)
Definition: costlistitem.cpp:80
QEvent::type
Type type() const
CostListItem::setEventType
void setEventType(EventType *et)
Definition: costlistitem.cpp:64
ProfileCostArray::subCost
SubCost subCost(EventType *)
Returns a sub cost.
Definition: costitem.cpp:591
HighestCostList::maxSize
int maxSize()
Definition: subcost.h:88
globalconfig.h
ProfileContext::Line
Definition: context.h:39
QSize::width
int width() const
ProfileContext::FunctionCycle
Definition: context.h:46
QMap::contains
bool contains(const Key &key) const
QAbstractItemView
FunctionListModel::function
TraceFunction * function(const QModelIndex &index)
Definition: functionlistmodel.cpp:59
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
QLineEdit::text
text
ProfileContext::File
Definition: context.h:48
QHeaderView::setDefaultSectionSize
void setDefaultSectionSize(int size)
QTreeWidget::scrollToItem
void scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint)
TraceItemView::addEventTypeMenu
void addEventTypeMenu(QMenu *, bool withCost2=true)
Definition: traceitemview.cpp:466
QAction::setChecked
void setChecked(bool)
stackbrowser.h
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
QAction::data
QVariant data() const
FunctionListModel::index
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const
Definition: functionlistmodel.cpp:137
QWidget::setMinimumWidth
void setMinimumWidth(int minw)
TraceFunction
A traced function.
Definition: tracedata.h:1122
TraceItemView::_data
TraceData * _data
Definition: traceitemview.h:209
TraceCostItem
Definition: tracedata.h:980
QMenu::addAction
void addAction(QAction *action)
FunctionSelection::searchChanged
void searchChanged(const QString &)
Definition: functionselection.cpp:270
HighestCostList::clear
void clear(int maxSize)
Definition: subcost.cpp:75
TraceItemView::addGoMenu
void addGoMenu(QMenu *)
Definition: traceitemview.cpp:471
QWidget::mapToGlobal
QPoint mapToGlobal(const QPoint &pos) const
TraceFunction::object
TraceObject * object() const
Definition: tracedata.h:1164
FunctionListModel::setEventType
void setEventType(EventType *)
Definition: functionlistmodel.cpp:196
FunctionSelection::selectTopFunction
bool selectTopFunction()
Definition: functionselection.cpp:846
QHBoxLayout
TraceFunction::cycle
TraceFunctionCycle * cycle()
Definition: tracedata.h:1200
functionselection.h
QTreeView::setUniformRowHeights
void setUniformRowHeights(bool uniform)
FunctionSelection::searchReturnPressed
void searchReturnPressed()
Definition: functionselection.cpp:243
CostItem
Base class for cost items.
Definition: costitem.h:37
FunctionSelection::setGroup
void setGroup(TraceCostItem *)
Definition: functionselection.cpp:548
QHeaderView::setSortIndicatorShown
void setSortIndicatorShown(bool show)
CostListItem::costItem
TraceCostItem * costItem()
Definition: costlistitem.h:36
traceitemview.h
ProfileContext::Instr
Definition: context.h:38
functionlistmodel.h
QPoint
AutoToolTipDelegate::helpEvent
bool helpEvent(QHelpEvent *e, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
Definition: functionselection.cpp:55
QTreeView::sortByColumn
void sortByColumn(int column, Qt::SortOrder order)
FunctionSelection::group
TraceCostItem * group()
Definition: functionselection.h:53
QMap::clear
void clear()
FunctionSelection::functionContext
void functionContext(const QPoint &)
Definition: functionselection.cpp:285
QToolTip::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
TraceItemView::_groupType
ProfileContext::Type _groupType
Definition: traceitemview.h:213
ProfileContext::Class
Definition: context.h:47
QPoint::x
int x() const
AutoToolTipDelegate
Definition: functionselection.h:117
QTreeWidget::clear
void clear()
TraceItemView
Abstract Base Class for KCachegrind Views.
Definition: traceitemview.h:70
TraceItemView::setData
virtual void setData(TraceData *d)
Definition: traceitemview.cpp:169
FunctionSelection::FunctionSelection
FunctionSelection(TopLevelBase *, QWidget *parent=0)
Definition: functionselection.cpp:88
QAbstractItemView::setAutoScroll
void setAutoScroll(bool enable)
QHeaderView::resizeSection
void resizeSection(int logicalIndex, int size)
TraceFunction::cls
TraceClass * cls() const
Definition: tracedata.h:1162
QLabel::setBuddy
void setBuddy(QWidget *buddy)
TraceData::parts
TracePartList parts() const
Definition: tracedata.h:1397
QWidget::size
QSize size() const
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
QTreeWidget
TraceItemView::_eventType
EventType * _eventType
Definition: traceitemview.h:212
QRect
QModelIndex::isValid
bool isValid() const
TraceItemView::setTitle
void setTitle(QString t)
Definition: traceitemview.h:166
QTreeView::setColumnWidth
void setColumnWidth(int column, int width)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
TraceData::classMap
TraceClassMap & classMap()
Definition: tracedata.h:1440
HighestCostList::realCount
int realCount()
Definition: subcost.h:87
TraceInstr
A code instruction address of the program.
Definition: tracedata.h:887
QVariant::toInt
int toInt(bool *ok) const
QTreeWidget::addTopLevelItems
void addTopLevelItems(const QList< QTreeWidgetItem * > &items)
QTreeView::resizeColumnToContents
void resizeColumnToContents(int column)
QStyleOptionViewItem
QObject
FunctionListModel::indexForFunction
QModelIndex indexForFunction(TraceFunction *f, bool add=false)
Definition: functionlistmodel.cpp:149
QAbstractItemView::setIconSize
void setIconSize(const QSize &size)
QHelpEvent::globalPos
const QPoint & globalPos() const
QWidget::setFocus
void setFocus()
ProfileContext::i18nTypeName
static QString i18nTypeName(Type)
Definition: context.cpp:118
TraceData::functionCycles
const TraceFunctionCycleList & functionCycles()
Definition: tracedata.h:1443
TopLevelBase
Definition: toplevelbase.h:34
QItemSelectionModel::select
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
QString::isEmpty
bool isEmpty() const
QAbstractItemView::setItemDelegate
void setItemDelegate(QAbstractItemDelegate *delegate)
QModelIndex::row
int row() const
FunctionSelection::functionActivated
void functionActivated(const QModelIndex &)
Definition: functionselection.cpp:754
QStyledItemDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
FunctionSelection::functionHeaderClicked
void functionHeaderClicked(int)
Definition: functionselection.cpp:874
QVBoxLayout
TraceCostItem::name
virtual QString name() const
Returns dynamic name info (without type)
Definition: tracedata.h:986
TraceFunction::prettyName
QString prettyName() const
Similar to name, but prettyfied = more descriptive to humans.
Definition: tracedata.cpp:1889
AutoToolTipDelegate::~AutoToolTipDelegate
~AutoToolTipDelegate()
Definition: functionselection.cpp:52
TraceItemView::_activeItem
CostItem * _activeItem
Definition: traceitemview.h:211
QLabel::setText
void setText(const QString &)
QTreeView::setAllColumnsShowFocus
void setAllColumnsShowFocus(bool enable)
QMenu::addSeparator
QAction * addSeparator()
QTreeWidget::currentItem
QTreeWidgetItem * currentItem() const
QString
QList
QWidget::hide
void hide()
FunctionSelection::groupHeaderClicked
void groupHeaderClicked(int)
Definition: functionselection.cpp:736
QMap::end
iterator end()
FunctionSelection::whatsThis
QString whatsThis() const
Definition: functionselection.cpp:215
TraceLine
A source line of the program.
Definition: tracedata.h:935
QLayout::setMargin
void setMargin(int margin)
GlobalConfig::shortenSymbol
static QString shortenSymbol(const QString &)
Definition: globalconfig.cpp:395
QMenu::exec
QAction * exec()
FunctionSelection::query
void query(QString)
Definition: functionselection.cpp:777
FunctionSelection::groupContext
void groupContext(const QPoint &)
Definition: functionselection.cpp:315
QMap::begin
iterator begin()
TraceFunction::file
TraceFile * file() const
Definition: tracedata.h:1163
QStringList
TraceItemView::eventTypeChanged
Definition: traceitemview.h:81
EventType::subCost
SubCost subCost(ProfileCostArray *)
Definition: eventtype.cpp:196
QTreeWidgetItem::setHidden
void setHidden(bool hide)
QAction::setData
void setData(const QVariant &userData)
TraceData::objectMap
TraceObjectMap & objectMap()
Definition: tracedata.h:1438
QMenu
QSize
QHeaderView::setSortIndicator
void setSortIndicator(int logicalIndex, Qt::SortOrder order)
TraceItemView::activated
virtual void activated(TraceItemView *sender, CostItem *)
Definition: traceitemview.cpp:347
FunctionSelection::setData
void setData(TraceData *)
Definition: functionselection.cpp:232
QWidget::setContextMenuPolicy
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
QTreeView::scrollTo
virtual void scrollTo(const QModelIndex &index, ScrollHint hint)
QToolTip::hideText
void hideText()
QAction::setCheckable
void setCheckable(bool)
HighestCostList::addCost
void addCost(ProfileCostArray *, SubCost)
Definition: subcost.cpp:83
QAbstractItemView::visualRect
virtual QRect visualRect(const QModelIndex &index) const =0
QAbstractItemDelegate::helpEvent
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
QTreeWidget::setCurrentItem
void setCurrentItem(QTreeWidgetItem *item)
QTreeWidget::setHeaderLabels
void setHeaderLabels(const QStringList &labels)
QItemSelection
QTreeWidget::headerItem
QTreeWidgetItem * headerItem() const
CostListItem
Definition: costlistitem.h:26
QTreeView::setSortingEnabled
void setSortingEnabled(bool enable)
FunctionSelection::groupDoubleClicked
void groupDoubleClicked(QTreeWidgetItem *, int)
Definition: functionselection.cpp:723
QWidget::setWhatsThis
void setWhatsThis(const QString &)
HighestCostList::count
int count()
Definition: subcost.h:86
QRect::width
int width() const
QModelIndex::data
QVariant data(int role) const
QTreeWidgetItem
FunctionSelection::groupSelected
void groupSelected(QTreeWidgetItem *, QTreeWidgetItem *)
Definition: functionselection.cpp:702
TraceItemView::activeItem
CostItem * activeItem() const
Definition: traceitemview.h:149
TraceItemView::activeItemChanged
Definition: traceitemview.h:85
QTreeView
QWidget::setMaximumHeight
void setMaximumHeight(int maxh)
FunctionSelection::groupTypeSelected
void groupTypeSelected(QAction *)
Definition: functionselection.cpp:364
ProfileContext::Type
Type
Definition: context.h:36
HighestCostList::hasMore
bool hasMore()
Definition: subcost.h:89
TopLevelBase::setGroupDelayed
virtual void setGroupDelayed(TraceCostItem *)=0
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
QMenu::addMenu
QAction * addMenu(QMenu *menu)
QHeaderView::setResizeMode
void setResizeMode(ResizeMode mode)
QAction
FunctionSelection::queryDelayed
void queryDelayed()
Definition: functionselection.cpp:280
QHeaderView::setClickable
void setClickable(bool clickable)
QTreeWidgetItem::setText
void setText(int column, const QString &text)
QComboBox::setCurrentIndex
void setCurrentIndex(int index)
TraceItemView::groupTypeChanged
Definition: traceitemview.h:83
FunctionListModel::resetModelData
void resetModelData(TraceData *data, TraceCostItem *group, QString filter, EventType *eventType)
Definition: functionlistmodel.cpp:211
QModelIndex::column
int column() const
QString::length
int length() const
QTimer::start
void start(int msec)
QTreeView::header
QHeaderView * header() const
TraceItemView::eventType2Changed
Definition: traceitemview.h:82
QComboBox::addItems
void addItems(const QStringList &texts)
QWidget::show
void show()
QLineEdit
TraceData::functionMap
TraceFunctionMap & functionMap()
Definition: tracedata.h:1441
QMap< QString, TraceObject >::Iterator
typedef Iterator
QTreeWidget::topLevelItem
QTreeWidgetItem * topLevelItem(int index) const
ProfileContext::Object
Definition: context.h:49
TraceData
This class holds profiling data of multiple tracefiles generated with cachegrind on one command...
Definition: tracedata.h:1363
QAbstractItemView::currentIndex
QModelIndex currentIndex() const
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
TraceItemView::selectedGroupType
virtual void selectedGroupType(TraceItemView *sender, ProfileContext::Type)
Definition: traceitemview.cpp:378
QTreeWidget::topLevelItemCount
topLevelItemCount
QHeaderView::stretchLastSection
stretchLastSection
QAbstractItemView::clearSelection
void clearSelection()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QHelpEvent
GlobalConfig::maxListCount
static int maxListCount()
Definition: globalconfig.cpp:402
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
QLabel::setWordWrap
void setWordWrap(bool on)
QTreeView::columnAt
int columnAt(int x) const
QBoxLayout::setSpacing
void setSpacing(int spacing)
QWidget::height
height
QTreeView::indexAt
virtual QModelIndex indexAt(const QPoint &point) const
FunctionListModel
Definition: functionlistmodel.h:31
FunctionSelection::addGroupMenu
void addGroupMenu(QMenu *)
Definition: functionselection.cpp:346
AutoToolTipDelegate::AutoToolTipDelegate
AutoToolTipDelegate(QObject *parent=0)
Definition: functionselection.cpp:48
TraceInclusiveCost::inclusive
ProfileCostArray * inclusive()
Definition: tracedata.cpp:163
ProfileContext::Function
Definition: context.h:46
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
costlistitem.h
ProfileContext::InvalidType
Definition: context.h:37
TraceData::fileMap
TraceFileMap & fileMap()
Definition: tracedata.h:1439
QTimer::setSingleShot
void setSingleShot(bool singleShot)
QVariant
QStyledItemDelegate
QComboBox
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