• 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
stackselection.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 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  * StackSelection for KCachegrind
21  * For function selection of a most expected stack,
22  * to be put into a QDockWindow
23  */
24 
25 #include "stackselection.h"
26 
27 #include <QPushButton>
28 #include <QVBoxLayout>
29 #include <QTreeWidget>
30 #include <QHeaderView>
31 
32 #include "stackbrowser.h"
33 #include "stackitem.h"
34 
35 
36 StackSelection::StackSelection(QWidget* parent)
37  : QWidget(parent)
38 {
39  _data = 0;
40  _browser = new StackBrowser();
41  _function = 0;
42  _eventType = 0;
43  _eventType2 = 0;
44  _groupType = ProfileContext::Function;
45 
46  setWindowTitle(tr("Stack Selection"));
47 
48  QVBoxLayout* vboxLayout = new QVBoxLayout(this);
49  vboxLayout->setSpacing(6);
50  vboxLayout->setMargin(3);
51 
52  _stackList = new QTreeWidget(this);
53  QStringList headerLabels;
54  headerLabels << tr("Cost")
55  << tr("Cost2")
56  << tr("Calls")
57  << tr("Function");
58  _stackList->setHeaderLabels(headerLabels);
59  _stackList->setRootIsDecorated(false);
60  _stackList->setAllColumnsShowFocus(true);
61  _stackList->setUniformRowHeights(true);
62  _stackList->setSortingEnabled(false);
63  _stackList->setColumnWidth(0, 50);
64  // 2nd cost column hidden at first (_eventType2 == 0)
65  _stackList->setColumnWidth(1, 0);
66  _stackList->setColumnWidth(2, 50);
67  vboxLayout->addWidget(_stackList);
68 
69  connect(_stackList,
70  SIGNAL( currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
71  this, SLOT( stackSelected(QTreeWidgetItem*,QTreeWidgetItem*) ) );
72 }
73 
74 StackSelection::~StackSelection()
75 {
76  delete _browser;
77 }
78 
79 void StackSelection::setData(TraceData* data)
80 {
81  if (_data == data) return;
82 
83  _data = data;
84 
85  _stackList->clear();
86  delete _browser;
87  _browser = new StackBrowser();
88  _function = 0;
89 }
90 
91 
92 void StackSelection::setFunction(TraceFunction* f)
93 {
94  if (_function == f) return;
95  _function = f;
96 
97  if (!_data || !_function) return;
98 
99  //qDebug() << "StackSelection::setFunction " << f->name();
100 
101  HistoryItem* item = _browser->current();
102  if (!item || item->function() != f) {
103  _browser->select(f);
104  rebuildStackList();
105  }
106 }
107 
108 
109 void StackSelection::rebuildStackList()
110 {
111  HistoryItem* item = _browser->current();
112  _stackList->clear();
113  _stackList->setColumnWidth(0, 50);
114  _stackList->setColumnWidth(1, _eventType2 ? 50:0);
115  _stackList->setColumnWidth(2, 50);
116  if (!item || !item->stack()) return;
117 
118  TraceFunction* top = item->stack()->top();
119  if (!top) return;
120 
121 
122  QList<QTreeWidgetItem*> items;
123  QTreeWidgetItem* activeItem = 0;
124  TraceCallList l = item->stack()->calls();
125  for(int i=l.count()-1; i>=0; i--) {
126  StackItem* si = new StackItem(this, 0, l.at(i));
127  if (si->function() == item->function())
128  activeItem = si;
129  items.prepend(si);
130  }
131  StackItem* si = new StackItem(this, 0, top);
132  if (si->function() == item->function())
133  activeItem = si;
134  items.prepend(si);
135 
136 #if QT_VERSION >= 0x050000
137  _stackList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
138  _stackList->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
139  _stackList->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
140 #else
141  _stackList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
142  _stackList->header()->setResizeMode(1, QHeaderView::ResizeToContents);
143  _stackList->header()->setResizeMode(2, QHeaderView::ResizeToContents);
144 #endif
145 
146  _stackList->addTopLevelItems(items);
147  if (activeItem) {
148  // this calls stackFunctionSelected()
149  _stackList->setCurrentItem(activeItem);
150  _stackList->scrollToItem(activeItem);
151  }
152 
153 #if QT_VERSION >= 0x050000
154  _stackList->header()->setSectionResizeMode(0, QHeaderView::Interactive);
155  _stackList->header()->setSectionResizeMode(1, QHeaderView::Interactive);
156  _stackList->header()->setSectionResizeMode(2, QHeaderView::Interactive);
157 #else
158  _stackList->header()->setResizeMode(0, QHeaderView::Interactive);
159  _stackList->header()->setResizeMode(1, QHeaderView::Interactive);
160  _stackList->header()->setResizeMode(2, QHeaderView::Interactive);
161 #endif
162 
163  if (!_eventType2) {
164  _stackList->setColumnWidth(1, 0);
165  }
166 }
167 
168 void StackSelection::stackSelected(QTreeWidgetItem* i, QTreeWidgetItem*)
169 {
170  if (!i) return;
171 
172  TraceFunction* f = ((StackItem*)i)->function();
173  emit functionSelected(f);
174 }
175 
176 
177 void StackSelection::browserBack()
178 {
179  if (_browser && _browser->canGoBack()) {
180  _browser->goBack();
181  rebuildStackList();
182  }
183 }
184 
185 void StackSelection::browserForward()
186 {
187  if (_browser && _browser->canGoForward()) {
188  _browser->goForward();
189  rebuildStackList();
190  }
191 }
192 
193 void StackSelection::browserUp()
194 {
195  if (_browser) {
196  _browser->goUp();
197  rebuildStackList();
198  }
199 }
200 
201 void StackSelection::browserDown()
202 {
203  if (_browser) {
204  _browser->goDown();
205  rebuildStackList();
206  }
207 }
208 
209 void StackSelection::refresh()
210 {
211 #if QT_VERSION >= 0x050000
212  _stackList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
213  _stackList->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
214 #else
215  _stackList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
216  _stackList->header()->setResizeMode(1, QHeaderView::ResizeToContents);
217 #endif
218 
219  // there is no resorting allowed, so this is save
220  for(int i = 0; i < _stackList->topLevelItemCount(); i++) {
221  QTreeWidgetItem* item = _stackList->topLevelItem(i);
222  ((StackItem*)item)->updateCost();
223  }
224 
225  if (!_eventType2) {
226 #if QT_VERSION >= 0x050000
227  _stackList->header()->setSectionResizeMode(1, QHeaderView::Interactive);
228 #else
229  _stackList->header()->setResizeMode(1, QHeaderView::Interactive);
230 #endif
231  _stackList->setColumnWidth(1, 0);
232  }
233 }
234 
235 void StackSelection::setEventType(EventType* ct)
236 {
237  if (ct == _eventType) return;
238  _eventType = ct;
239 
240  if (_eventType)
241  _stackList->headerItem()->setText(0, _eventType->name());
242 
243  refresh();
244 }
245 
246 void StackSelection::setEventType2(EventType* ct)
247 {
248  if (ct == _eventType2) return;
249  _eventType2 = ct;
250 
251  if (_eventType2)
252  _stackList->headerItem()->setText(1, _eventType2->name());
253 
254  refresh();
255 }
256 
257 void StackSelection::setGroupType(ProfileContext::Type gt)
258 {
259  if (_groupType == gt) return;
260  _groupType = gt;
261 
262  for(int i = 0; i < _stackList->topLevelItemCount(); i++) {
263  QTreeWidgetItem* item = _stackList->topLevelItem(i);
264  ((StackItem*)item)->updateGroup();
265  }
266 }
267 
268 #include "stackselection.moc"
StackSelection::functionSelected
void functionSelected(CostItem *)
StackSelection::setEventType2
void setEventType2(EventType *)
Definition: stackselection.cpp:246
HistoryItem::function
TraceFunction * function()
Definition: stackbrowser.h:71
StackBrowser::goUp
HistoryItem * goUp()
Definition: stackbrowser.cpp:355
StackSelection::rebuildStackList
void rebuildStackList()
Definition: stackselection.cpp:109
QTreeWidget
StackBrowser::goBack
HistoryItem * goBack()
Definition: stackbrowser.cpp:339
stackbrowser.h
StackSelection::data
TraceData * data() const
Definition: stackselection.h:46
StackSelection::setFunction
void setFunction(TraceFunction *)
Definition: stackselection.cpp:92
StackBrowser
Definition: stackbrowser.h:85
QWidget
TraceFunction
A traced function.
Definition: tracedata.h:1122
StackSelection::browserUp
void browserUp()
Definition: stackselection.cpp:193
StackBrowser::goForward
HistoryItem * goForward()
Definition: stackbrowser.cpp:347
stackselection.h
EventType
A cost type, e.g.
Definition: eventtype.h:43
StackSelection::setData
void setData(TraceData *)
Definition: stackselection.cpp:79
StackSelection::browserBack
void browserBack()
Definition: stackselection.cpp:177
StackSelection::refresh
void refresh()
Definition: stackselection.cpp:209
StackBrowser::canGoBack
bool canGoBack()
Definition: stackbrowser.cpp:377
StackSelection::browserForward
void browserForward()
Definition: stackselection.cpp:185
HistoryItem::stack
Stack * stack()
Definition: stackbrowser.h:70
StackSelection::setEventType
void setEventType(EventType *)
Definition: stackselection.cpp:235
StackBrowser::select
HistoryItem * select(TraceFunction *)
Definition: stackbrowser.cpp:301
QTreeWidgetItem
StackSelection::StackSelection
StackSelection(QWidget *parent=0)
Definition: stackselection.cpp:36
stackitem.h
Stack::calls
TraceCallList calls()
Definition: stackbrowser.h:48
StackSelection::~StackSelection
~StackSelection()
Definition: stackselection.cpp:74
StackSelection::browserDown
void browserDown()
Definition: stackselection.cpp:201
ProfileContext::Type
Type
Definition: context.h:36
StackItem
Definition: stackitem.h:35
Stack::top
TraceFunction * top()
Definition: stackbrowser.h:47
TraceCallList
QList< TraceCall * > TraceCallList
Definition: tracedata.h:184
HistoryItem
Definition: stackbrowser.h:64
TraceData
This class holds profiling data of multiple tracefiles generated with cachegrind on one command...
Definition: tracedata.h:1363
StackSelection::setGroupType
void setGroupType(ProfileContext::Type)
Definition: stackselection.cpp:257
StackBrowser::current
HistoryItem * current()
Definition: stackbrowser.h:94
StackSelection::stackSelected
void stackSelected(QTreeWidgetItem *, QTreeWidgetItem *)
Definition: stackselection.cpp:168
StackBrowser::goDown
HistoryItem * goDown()
Definition: stackbrowser.cpp:366
StackBrowser::canGoForward
bool canGoForward()
Definition: stackbrowser.cpp:382
EventType::name
const QString & name()
Definition: eventtype.h:65
ProfileContext::Function
Definition: context.h:46
QList
StackItem::function
TraceFunction * function()
Definition: stackitem.h:42
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:27 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