• 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
tabview.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  * Tab View, enclosing detailed views for one trace item in
21  * two tab widgets, separated by a splitter
22  */
23 
24 
25 #include "tabview.h"
26 
27 #include <QLabel>
28 #include <QSplitter>
29 #include <QTabWidget>
30 #include <QHideEvent>
31 #include <QMoveEvent>
32 #include <QEvent>
33 #include <QShowEvent>
34 #include <QVBoxLayout>
35 #include <QResizeEvent>
36 #include <QMouseEvent>
37 #include <QAction>
38 #include <QMenu>
39 
40 #include "config.h"
41 #include "globalconfig.h"
42 #include "eventtypeview.h"
43 #include "partview.h"
44 #include "callview.h"
45 #include "coverageview.h"
46 #include "callmapview.h"
47 #include "instrview.h"
48 #include "sourceview.h"
49 #include "callgraphview.h"
50 
51 
52 // defaults for subviews in TabView
53 
54 #define DEFAULT_TOPTABS \
55  "EventTypeView" << "CallerView" << "AllCallerView" \
56  << "CalleeMapView" << "SourceView"
57 #define DEFAULT_BOTTOMTABS \
58  "PartView" << "CalleeView" << "CallGraphView" \
59  << "AllCalleeView" << "CallerMapView" << "InstrView"
60 
61 #define DEFAULT_ACTIVETOP "CallerView"
62 #define DEFAULT_ACTIVEBOTTOM "CalleeView"
63 
64 #define DEFAULT_RIGHTSIZE 0
65 #define DEFAULT_TOPSIZE 50
66 #define DEFAULT_LEFTSIZE 0
67 
68 // TabBar
69 
70 TabBar::TabBar(TabView* v, QTabWidget* parent, const char *name) :
71  QTabBar(parent)
72 {
73  setObjectName(name);
74  _tabWidget = parent;
75  _tabView = v;
76 }
77 
78 void TabBar::mousePressEvent(QMouseEvent *e)
79 {
80  if (e->button() == Qt::RightButton) {
81  int idx = tabAt(e->pos());
82  QWidget* page = 0;
83  if (idx >=0) {
84  setCurrentIndex(idx);
85  page = _tabWidget->widget(idx);
86  }
87  context(page, e->globalPos());
88  }
89  QTabBar::mousePressEvent(e );
90 }
91 
92 void TabBar::context(QWidget* page, const QPoint & pos)
93 {
94  QMenu popup, popup2, popup3;
95 
96  QAction* pageToTopAction = 0;
97  QAction* areaToTopAction = 0;
98  QAction* showOnTopAction = 0;
99  QAction* pageToRightAction = 0;
100  QAction* areaToRightAction = 0;
101  QAction* showOnRightAction = 0;
102  QAction* pageToBottomAction = 0;
103  QAction* areaToBottomAction = 0;
104  QAction* showOnBottomAction = 0;
105  QAction* pageToLeftAction = 0;
106  QAction* areaToLeftAction = 0;
107  QAction* showOnLeftAction = 0;
108  QAction* hidePageAction = 0;
109  QAction* hideAreaAction = 0;
110 
111  if (page) {
112  TraceItemView::Position p = _tabView->tabPosition(page);
113  if (p != TraceItemView::Top) {
114  pageToTopAction = popup.addAction(tr("Move to Top"));
115  areaToTopAction = popup2.addAction(tr("Top", "Move to Top"));
116  }
117  if (p != TraceItemView::Right) {
118  pageToRightAction = popup.addAction(tr("Move to Right"));
119  areaToRightAction = popup2.addAction(tr("Right", "Move to Right"));
120  }
121  if (p != TraceItemView::Bottom) {
122  pageToBottomAction = popup.addAction(tr("Move to Bottom"));
123  areaToBottomAction = popup2.addAction(tr("Bottom", "Move to Bottom"));
124  }
125  if (p != TraceItemView::Left) {
126  pageToLeftAction = popup.addAction(tr("Move to Bottom Left"));
127  areaToLeftAction = popup2.addAction(tr("Bottom Left", "Move to Bottom Left"));
128  }
129  popup2.setTitle(tr("Move Area To"));
130  popup.addMenu(&popup2);
131  popup.addSeparator();
132  hidePageAction = popup.addAction(tr("Hide This Tab"));
133  hideAreaAction = popup.addAction(tr("Hide Area"));
134 
135  if (_tabView->visibleTabs() <2) {
136  hidePageAction->setEnabled(false);
137  hideAreaAction->setEnabled(false);
138  } else if (_tabView->visibleAreas() <2)
139  hideAreaAction->setEnabled(false);
140  }
141 
142  showOnTopAction = popup3.addAction(tr("Top", "Show on Top"));
143  showOnRightAction = popup3.addAction(tr("Right", "Show on Right"));
144  showOnBottomAction = popup3.addAction(tr("Bottom", "Show on Bottom"));
145  showOnLeftAction = popup3.addAction(tr("Bottom Left", "Show on Bottom Left"));
146  popup3.setTitle(tr("Show Hidden On"));
147  popup.addMenu(&popup3);
148 
149  QAction* a = popup.exec(pos);
150  if (a == hidePageAction)
151  _tabView->moveTab(page, TraceItemView::Hidden, false);
152  else if (a == hideAreaAction)
153  _tabView->moveTab(page, TraceItemView::Hidden, true);
154 
155  else if (a == pageToTopAction)
156  _tabView->moveTab(page, TraceItemView::Top, false);
157  else if (a == pageToRightAction)
158  _tabView->moveTab(page, TraceItemView::Right, false);
159  else if (a == pageToBottomAction)
160  _tabView->moveTab(page, TraceItemView::Bottom, false);
161  else if (a == pageToLeftAction)
162  _tabView->moveTab(page, TraceItemView::Left, false);
163 
164  else if (a == areaToTopAction)
165  _tabView->moveTab(page, TraceItemView::Top, true);
166  else if (a == areaToRightAction)
167  _tabView->moveTab(page, TraceItemView::Right, true);
168  else if (a == areaToBottomAction)
169  _tabView->moveTab(page, TraceItemView::Bottom, true);
170  else if (a == areaToLeftAction)
171  _tabView->moveTab(page, TraceItemView::Left, true);
172 
173  else if (a == showOnTopAction)
174  _tabView->moveTab(0, TraceItemView::Top, true);
175  else if (a == showOnRightAction)
176  _tabView->moveTab(0, TraceItemView::Right, true);
177  else if (a == showOnBottomAction)
178  _tabView->moveTab(0, TraceItemView::Bottom, true);
179  else if (a == showOnLeftAction)
180  _tabView->moveTab(0, TraceItemView::Left, true);
181 }
182 
183 
184 //
185 // Splitter
186 //
187 
188 Splitter::Splitter(Qt::Orientation o, QWidget* parent)
189  : QSplitter(o, parent)
190 {}
191 
192 void Splitter::moveEvent(QMoveEvent* e)
193 {
194  QSplitter::moveEvent(e);
195 
196  if (0) qDebug("Splitter %s: Move", qPrintable(objectName()));
197  checkVisiblity();
198 }
199 
200 void Splitter::checkVisiblity()
201 {
202 #if 0
203  const QObjectList l = children();
204  QObjectList::Iterator it( l );
205  QObject *obj;
206  while ( (obj = it.current()) != 0 ) {
207  ++it;
208  if (obj->isA("Splitter")) ((Splitter*)obj)->checkVisiblity();
209  else if (obj->isA("TabWidget")) ((TabWidget*)obj)->checkVisibility();
210  }
211 #endif
212 }
213 
214 
215 
216 
217 //
218 // TabWidget
219 //
220 
221 TabWidget::TabWidget(TabView* v, QWidget* parent)
222  : QTabWidget(parent)
223 {
224  _hasVisibleRect = false;
225  setTabBar(new TabBar(v, this));
226 }
227 
228 void TabWidget::checkVisibility()
229 {
230  bool hasVisibleRect = (visibleRegion().boundingRect().width()>1) &&
231  (visibleRegion().boundingRect().height()>1);
232 
233  if (0) qDebug("TabWidget %s: VR (%dx%d) HasVisibleRect: %s => %s",
234  qPrintable(objectName()),
235  visibleRegion().boundingRect().width(),
236  visibleRegion().boundingRect().height(),
237  _hasVisibleRect ? "Yes":"No",
238  hasVisibleRect ? "Yes":"No");
239 
240  if (hasVisibleRect != _hasVisibleRect) {
241  _hasVisibleRect = hasVisibleRect;
242  emit visibleRectChanged(this);
243  }
244 }
245 
246 void TabWidget::resizeEvent(QResizeEvent *e)
247 {
248  QTabWidget::resizeEvent(e);
249  if (0) qDebug("TabWidget %s:\n Resize from (%d/%d) to (%d/%d)",
250  objectName().toLatin1().constData(),
251  e->oldSize().width(), e->oldSize().height(),
252  e->size().width(), e->size().height());
253  checkVisibility();
254 }
255 
256 void TabWidget::showEvent(QShowEvent* e)
257 {
258  QTabWidget::showEvent(e);
259 
260  if (0) qDebug("TabWidget %s: Show", objectName().toLatin1().constData());
261  checkVisibility();
262 }
263 
264 void TabWidget::hideEvent(QHideEvent* e)
265 {
266  QTabWidget::hideEvent(e);
267 
268  if (0) qDebug("TabWidget %s: Hide", objectName().toLatin1().constData());
269  checkVisibility();
270 }
271 
272 void TabWidget::moveEvent(QMoveEvent* e)
273 {
274  QTabWidget::moveEvent(e);
275 
276  if (0) qDebug("TabWidget %s: Move", objectName().toLatin1().constData());
277  checkVisibility();
278 }
279 
280 
281 
282 //
283 // TabView
284 //
285 
286 /*
287  * Areas for child views
288  *
289  * leftSplitter
290  * |
291  * | ----- -----
292  * | _/ \_______________/ \____
293  * | | Top | Right |
294  * | | | |
295  * -> |---------------------| |
296  * | BottomLeft | Bottom | |
297  * | | | |
298  * -\_____/------\____/--------------
299  *
300  * ^ ^
301  * bottomSplitter mainSplitter
302  */
303 
304 TabView::TabView(TraceItemView* parentView, QWidget* parent)
305  : QWidget(parent), TraceItemView(parentView)
306 {
307  setFocusPolicy(Qt::StrongFocus);
308 
309  _isCollapsed = true;
310 
311  QVBoxLayout* vbox = new QVBoxLayout( this );
312  vbox->setSpacing( 6 );
313  vbox->setMargin( 6 );
314 
315  _nameLabel = new QLabel(this); //KSqueezedTextLabel( this);
316  _nameLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored,
317  QSizePolicy::Fixed ));
318  _nameLabel->setObjectName( "nameLabel" );
319  _nameLabel->setText(tr("(No profile data file loaded)"));
320  vbox->addWidget( _nameLabel );
321  updateNameLabel(tr("(No profile data file loaded)"));
322 
323  _mainSplitter = new QSplitter(Qt::Horizontal, this);
324  _leftSplitter = new Splitter(Qt::Vertical, _mainSplitter);
325  _leftSplitter->setObjectName("Left");
326  vbox->addWidget( _mainSplitter );
327 
328  _rightTW = new TabWidget(this, _mainSplitter);
329  _rightTW->setObjectName("Right");
330  connect(_rightTW, SIGNAL(currentChanged(int)),
331  this, SLOT(tabChanged(int)));
332  connect(_rightTW, SIGNAL(visibleRectChanged(TabWidget*)),
333  this, SLOT(visibleRectChangedSlot(TabWidget*)));
334 
335  _topTW = new TabWidget(this, _leftSplitter);
336  _topTW->setObjectName("Top");
337  connect(_topTW, SIGNAL(currentChanged(int)),
338  this, SLOT(tabChanged(int)));
339  connect(_topTW, SIGNAL(visibleRectChanged(TabWidget*)),
340  this, SLOT(visibleRectChangedSlot(TabWidget*)));
341 
342  _bottomSplitter = new Splitter(Qt::Horizontal, _leftSplitter);
343  _bottomSplitter->setObjectName("Bottom");
344 
345  _leftTW = new TabWidget(this, _bottomSplitter);
346  _leftTW->setObjectName("Left");
347  _leftTW->setTabPosition(QTabWidget::South);
348  connect(_leftTW, SIGNAL(currentChanged(int)),
349  this, SLOT(tabChanged(int)));
350  connect(_leftTW, SIGNAL(visibleRectChanged(TabWidget*)),
351  this, SLOT(visibleRectChangedSlot(TabWidget*)));
352 
353  _bottomTW = new TabWidget(this, _bottomSplitter);
354  _bottomTW->setObjectName("Bottom");
355  _bottomTW->setTabPosition(QTabWidget::South);
356  connect(_bottomTW, SIGNAL(currentChanged(int)),
357  this, SLOT(tabChanged(int)));
358  connect(_bottomTW, SIGNAL(visibleRectChanged(TabWidget*)),
359  this, SLOT(visibleRectChangedSlot(TabWidget*)));
360 
361  CallView* callerView = new CallView(true, this);
362  CallView* calleeView = new CallView(false, this);
363  CoverageView * allCallerView = new CoverageView(true, this);
364  CoverageView * allCalleeView = new CoverageView(false, this);
365  SourceView* sourceView = new SourceView(this);
366  InstrView* instrView = new InstrView(this);
367  PartView* partView = new PartView(this);
368 
369  // Options of visualization views are stored by their view name
370  callerView->setObjectName("CallerView");
371  calleeView->setObjectName("CalleeView");
372  allCallerView->setObjectName("AllCallerView");
373  allCalleeView->setObjectName("AllCalleeView");
374  sourceView->setObjectName("SourceView");
375  instrView->setObjectName("InstrView");
376  partView->setObjectName("PartView");
377 
378  // default positions...
379  // Keep following order in sync with DEFAULT_xxxTABS defines!
380 
381  addTop( addTab( tr("Types"),
382  new EventTypeView(this, 0,
383  "EventTypeView")));
384  addTop( addTab( tr("Callers"), callerView) );
385  addTop( addTab( tr("All Callers"), allCallerView) );
386  addTop( addTab( tr("Callee Map"),
387  new CallMapView(false, this, 0,
388  "CalleeMapView")));
389  addTop( addTab( tr("Source Code"), sourceView) );
390 
391  addBottom( addTab( tr("Parts"), partView ) );
392  addBottom( addTab( tr("Callees"), calleeView) );
393  addBottom( addTab( tr("Call Graph"),
394  new CallGraphView(this, 0,
395  "CallGraphView")));
396  addBottom( addTab( tr("All Callees"), allCalleeView) );
397  addBottom( addTab( tr("Caller Map"),
398  new CallMapView(true, this, 0,
399  "CallerMapView")));
400  addBottom( addTab( tr("Machine Code"), instrView) );
401 
402  // after all child widgets are created...
403  _lastFocus = 0;
404  _active = false;
405  installFocusFilters();
406 
407  updateVisibility();
408 
409  this->setWhatsThis( whatsThis() );
410 }
411 
412 void TabView::updateNameLabel(QString n)
413 {
414  QFontMetrics fm(_nameLabel->fontMetrics());
415 
416  if (!n.isNull()) {
417  _nameLabelText = n;
418  _textWidth = fm.width(_nameLabelText);
419  }
420 
421  int labelWidth = _nameLabel->size().width();
422  if (_textWidth > labelWidth) {
423  _nameLabel->setText(fm.elidedText(_nameLabelText,
424  Qt::ElideMiddle, labelWidth));
425  _nameLabel->setToolTip(_nameLabelText);
426  }
427  else {
428  _nameLabel->setText(_nameLabelText);
429  _nameLabel->setToolTip(QString());
430  }
431  if (!_nameLabelTooltip.isEmpty())
432  _nameLabel->setToolTip(_nameLabelTooltip);
433 }
434 
435 void TabView::setData(TraceData* d)
436 {
437  TraceItemView::setData(d);
438 
439  foreach(TraceItemView* v, _tabs)
440  v->setData(d);
441 }
442 
443 TraceItemView* TabView::addTab(const QString& label, TraceItemView* view)
444 {
445  view->setTitle(label);
446  _tabs.append(view);
447  return view;
448 }
449 
450 void TabView::addTop(TraceItemView* view)
451 {
452  view->setPosition(TraceItemView::Top);
453  _topTW->addTab(view->widget(), view->title());
454 }
455 
456 void TabView::addBottom(TraceItemView* view)
457 {
458  view->setPosition(TraceItemView::Bottom);
459  _bottomTW->addTab(view->widget(), view->title());
460 }
461 
462 TraceItemView::Position TabView::tabPosition(QWidget* w)
463 {
464  foreach(TraceItemView* v, _tabs)
465  if (v->widget() == w) return v->position();
466 
467  return Hidden;
468 }
469 
470 int TabView::visibleTabs()
471 {
472  int c = 0;
473  foreach(TraceItemView* v, _tabs) {
474  if (v->position() == Hidden) continue;
475  c++;
476  }
477  return c;
478 }
479 
480 // calculate count of tabs in areas
481 void TabView::tabCounts(int& top, int& bottom,
482  int& left, int& right)
483 {
484  top = bottom = left = right = 0;
485 
486  foreach(TraceItemView* v, _tabs) {
487  switch(v->position()) {
488  case TraceItemView::Top:
489  top++;
490  break;
491  case TraceItemView::Bottom:
492  bottom++;
493  break;
494  case TraceItemView::Left:
495  left++;
496  break;
497  case TraceItemView::Right:
498  right++;
499  break;
500  default:
501  break;
502  }
503  }
504 
505  if (0) qDebug("TabView::tabCounts top %d, bottom %d, left %d, right %d",
506  top, bottom, left, right);
507 }
508 
509 int TabView::visibleAreas()
510 {
511  int count, top, bottom, left, right;
512 
513  tabCounts(top, bottom, left, right);
514  count = 0;
515  if (top>0) count++;
516  if (bottom>0) count++;
517  if (left>0) count++;
518  if (right>0) count++;
519 
520  return count;
521 }
522 
523 // This hides/shows splitters and tabwidgets according to tab children
524 void TabView::updateVisibility()
525 {
526  int top, bottom, left, right;
527 
528  tabCounts(top, bottom, left, right);
529 
530  QList<int> s;
531  s.append(100);
532 
533  // children of mainSplitter
534  if (_rightTW->isHidden() != (right == 0)) {
535  if (right == 0) {
536  _rightTW->hide();
537  }
538  else
539  _rightTW->show();
540  }
541  if (_leftSplitter->isHidden() != (top+bottom+left == 0)) {
542  if (top+bottom+left == 0) {
543  _leftSplitter->hide();
544  }
545  else
546  _leftSplitter->show();
547  }
548 
549  // children of leftSplitter
550  if (_topTW->isHidden() != (top == 0)) {
551  if (top == 0) {
552  _topTW->hide();
553  }
554  else
555  _topTW->show();
556  }
557 
558  if (_bottomSplitter->isHidden() != (bottom+left == 0)) {
559  if (bottom+left == 0) {
560  _bottomSplitter->hide();
561  }
562  else
563  _bottomSplitter->show();
564  }
565 
566  // children of bottomSplitter
567  if (_bottomTW->isHidden() != (bottom == 0)) {
568  if (bottom == 0) {
569  _bottomTW->hide();
570  }
571  else
572  _bottomTW->show();
573  }
574  if (_leftTW->isHidden() != (left == 0)) {
575  if (left == 0) {
576  _leftTW->hide();
577  }
578  else
579  _leftTW->show();
580  }
581 }
582 
583 TabWidget* TabView::tabWidget(Position p)
584 {
585  switch(p) {
586  case TraceItemView::Top:
587  return _topTW;
588  case TraceItemView::Bottom:
589  return _bottomTW;
590  case TraceItemView::Left:
591  return _leftTW;
592  case TraceItemView::Right:
593  return _rightTW;
594  default:
595  break;
596  }
597  return 0;
598 }
599 
600 void TabView::moveTab(QWidget* w, Position p, bool wholeArea)
601 {
602  Position origPos = Hidden;
603  if (w) {
604  TraceItemView* found = 0;
605  foreach(TraceItemView* v, _tabs)
606  if (v->widget() == w) { found = v; break; }
607 
608  if (!found) return;
609  origPos = found->position();
610  }
611  if (origPos == p) return;
612 
613  TabWidget *from, *to;
614  from = tabWidget(origPos);
615  to = tabWidget(p);
616 
617  QList<TraceItemView*> tabs;
618  foreach(TraceItemView* v, _tabs)
619  if ((v->position() == origPos) &&
620  (wholeArea || (v->widget() == w))) tabs.append(v);
621 
622  bool isEnabled;
623  foreach(TraceItemView* v, tabs) {
624  v->setPosition(p);
625  w = v->widget();
626 
627  if (from) {
628  isEnabled = from->isTabEnabled(from->indexOf(w));
629  from->removeTab(from->indexOf(w));
630  }
631  else isEnabled = (v->canShow(_activeItem)!=0);
632 
633  if (to) {
634  int idx = -1, i;
635  foreach(TraceItemView* vv, _tabs) {
636  if (v == vv) continue;
637  i = to->indexOf(vv->widget());
638  if (i>=0) idx = i;
639  }
640  to->insertTab(idx+1, w, v->title());
641  to->setTabEnabled(to->indexOf(w), isEnabled);
642  if (isEnabled) {
643  to->setCurrentIndex(to->indexOf(w));
644  v->updateView();
645  }
646  }
647  }
648  updateVisibility();
649 }
650 
651 
652 QString TabView::whatsThis() const
653 {
654  return tr( "<b>Information Tabs</b>"
655  "<p>This widget shows information for the "
656  "currently selected function in different tabs: "
657  "<ul>"
658  "<li>The Costs tab shows a list of available event types "
659  "and the inclusive and self-costs related to these types.</li>"
660  "<li>The Parts tab shows a list of trace parts "
661  "if the trace consists of more than one part (otherwise, "
662  "this tab is hidden). "
663  "The cost of the selected function spent in the different "
664  "parts together with the calls happening is shown.</li>"
665  "<li>The Call Lists tab shows direct callers and "
666  "callees of the function in more detail.</li>"
667  "<li>The Coverage tab shows the same as the Call "
668  "Lists tab, but also shows indirect callers and callees, "
669  "not just direct ones.</li>"
670  "<li>The Call Graph tab shows a graphical "
671  "visualization of the calls made by this function.</li>"
672  "<li>The Source Code tab presents annotated source code "
673  "if debugging information and the source file "
674  "are available.</li>"
675  "<li>The Machine Code tab presents annotated assembly "
676  "instructions if profile information at instruction level "
677  "is available.</li></ul>"
678  "For more information, see the <em>What's This?</em> "
679  "help of the corresponding tab widget.</p>");
680 }
681 
682 void TabView::installFocusFilters()
683 {
684  QList<QWidget*> wList = findChildren<QWidget*>();
685  foreach(QWidget* w, wList) {
686  if (w->focusPolicy() != Qt::NoFocus)
687  w->installEventFilter(this);
688  }
689 }
690 
691 
692 bool TabView::eventFilter(QObject* o, QEvent* e)
693 {
694  if (e->type() == QEvent::FocusIn) {
695  _lastFocus = o->isWidgetType() ? (QWidget*) o : 0;
696  setActive(_lastFocus != 0);
697  }
698  return QWidget::eventFilter(o,e);
699 }
700 
701 void TabView::mousePressEvent(QMouseEvent*)
702 {
703  if (_lastFocus)
704  _lastFocus->setFocus();
705  setActive(true);
706 }
707 
708 void TabView::setActive(bool a)
709 {
710  if (a == _active) return;
711  _active = a;
712 
713  QFont nameLabel_font( _nameLabel->font() );
714  nameLabel_font.setBold(a);
715  _nameLabel->setFont( nameLabel_font );
716  // force recalculation of label width by passing current label text
717  updateNameLabel(_nameLabelText);
718 
719  if (0) qDebug("%s::setActive(%s)", objectName().toLatin1().constData(),
720  a ? "true":"false");
721 
722  if (a) emit tabActivated(this);
723 }
724 
725 void TabView::doUpdate(int changeType, bool force)
726 {
727  if (changeType & (activeItemChanged |
728  configChanged |
729  dataChanged))
730  {
731  if (_data && _activeItem) {
732  _nameLabelTooltip = _activeItem->formattedName();
733  updateNameLabel(_activeItem->prettyName());
734  }
735  else {
736  _nameLabelTooltip = QString();
737  updateNameLabel( !_data ?
738  tr("(No profile data file loaded)") :
739  tr("(No function selected)"));
740  }
741  }
742 
743  bool canShow;
744  foreach(TraceItemView *v, _tabs) {
745 
746  TabWidget *tw = 0;
747  switch(v->position()) {
748  case TraceItemView::Top: tw = _topTW; break;
749  case TraceItemView::Bottom: tw = _bottomTW; break;
750  case TraceItemView::Left: tw = _leftTW; break;
751  case TraceItemView::Right: tw = _rightTW; break;
752  default: break;
753  }
754 
755  // update even if hidden
756  if (tw) {
757  if (!tw->hasVisibleRect()) continue;
758  }
759  canShow = v->set(changeType, _data, _eventType, _eventType2,
760  _groupType, _partList,
761  _activeItem, _selectedItem);
762  v->notifyChange(changeType);
763 
764  if (!tw) continue;
765  int idx = tw->indexOf(v->widget());
766  if (tw->isTabEnabled(idx) != canShow)
767  tw->setTabEnabled(idx, canShow);
768 
769  if (v->widget() == tw->currentWidget())
770  v->updateView(force);
771  }
772 }
773 
774 
775 void TabView::tabChanged(int i)
776 {
777  TabWidget* tw = qobject_cast<TabWidget*>(sender());
778  if (!tw) return;
779  QWidget* w = tw->widget(i);
780 
781  foreach(TraceItemView *v, _tabs)
782  if (v->widget() == w) v->updateView();
783 }
784 
785 void TabView::visibleRectChangedSlot(TabWidget* tw)
786 {
787  if (0) qDebug("%s: %svisible !",
788  tw->objectName().toLatin1().constData(),
789  tw->hasVisibleRect() ? "":"un");
790 
791  if (tw->hasVisibleRect()) doUpdate(0, false);
792 }
793 
794 void TabView::resizeEvent(QResizeEvent* e)
795 {
796  QWidget::resizeEvent(e);
797 
798  updateNameLabel();
799 
800  bool collapsed = (e->size().width()<=1) || (e->size().height()<=1);
801  if (_isCollapsed != collapsed) {
802  _isCollapsed = collapsed;
803  updateView();
804  }
805 
806  if (0) qDebug("TabView::Resize from (%d/%d) to (%d/%d)",
807  e->oldSize().width(), e->oldSize().height(),
808  e->size().width(), e->size().height());
809 }
810 
811 void TabView::selected(TraceItemView*, CostItem* s)
812 {
813  // we set selected item for our own children
814  select(s);
815 
816  // still forward to parent
817  if (_parentView) _parentView->selected(this, s);
818 }
819 
820 void TabView::restoreLayout(const QString& prefix, const QString& postfix)
821 {
822  ConfigGroup* g = ConfigStorage::group(prefix, postfix);
823 
824  int rightSize = g->value("RightSize", DEFAULT_RIGHTSIZE).toInt();
825  int topSize = g->value("TopSize", DEFAULT_TOPSIZE).toInt();
826  int leftSize = g->value("LeftSize", DEFAULT_LEFTSIZE).toInt();
827 
828  QList<int> mainSizes, leftSizes, bottomSizes;
829 
830  int mainWidth = _mainSplitter->width();
831  mainSizes << (100 - rightSize)*mainWidth/100 << rightSize*mainWidth/100;
832  _mainSplitter->setSizes(mainSizes);
833 
834  int leftHeight = _leftSplitter->height();
835  leftSizes << topSize*leftHeight/100 << (100 - topSize)*leftHeight/100;
836  _leftSplitter->setSizes(leftSizes);
837 
838  int bottomWidth = _bottomSplitter->width();
839  bottomSizes << leftSize*bottomWidth/100 << (100 - leftSize)*bottomWidth/100;
840  _bottomSplitter->setSizes(bottomSizes);
841 
842  QString activeT = g->value("ActiveTop", QString(DEFAULT_ACTIVETOP)).toString();
843  QString activeB = g->value("ActiveBottom", QString(DEFAULT_ACTIVEBOTTOM)).toString();
844  QString activeL = g->value("ActiveLeft", QString()).toString();
845  QString activeR = g->value("ActiveRight", QString()).toString();
846 
847  QStringList topTabsDefault, bottomTabsDefault;
848  topTabsDefault << DEFAULT_TOPTABS;
849  bottomTabsDefault << DEFAULT_BOTTOMTABS;
850 
851  QStringList topTabs = g->value("TopTabs",topTabsDefault).toStringList();
852  QStringList bottomTabs = g->value("BottomTabs",bottomTabsDefault).toStringList();
853  QStringList leftTabs = g->value("LeftTabs",QStringList()).toStringList();
854  QStringList rightTabs = g->value("RightTabs",QStringList()).toStringList();
855 
856  delete g;
857 
858  if (topTabs.isEmpty() && bottomTabs.isEmpty() &&
859  rightTabs.isEmpty() && leftTabs.isEmpty()) {
860  // no tabs visible ?! Reset to default
861  topTabs = topTabsDefault;
862  bottomTabs = bottomTabsDefault;
863  }
864 
865  TraceItemView *activeTop = 0, *activeBottom = 0;
866  TraceItemView *activeLeft = 0, *activeRight = 0;
867 
868  moveTab(0, TraceItemView::Top, true);
869  foreach(TraceItemView *v, _tabs) {
870  QString n = v->widget()->objectName();
871  if (topTabs.contains(n)) {
872  moveTab(v->widget(), TraceItemView::Top);
873  if (n == activeT) activeTop = v;
874  }
875  else if (bottomTabs.contains(n)) {
876  moveTab(v->widget(), TraceItemView::Bottom);
877  if (n == activeB) activeBottom = v;
878  }
879  else if (leftTabs.contains(n)) {
880  moveTab(v->widget(), TraceItemView::Left);
881  if (n == activeL) activeLeft = v;
882  }
883  else if (rightTabs.contains(n)) {
884  moveTab(v->widget(), TraceItemView::Right);
885  if (n == activeR) activeRight = v;
886  }
887  else moveTab(v->widget(), Hidden);
888  }
889  if (activeTop)
890  _topTW->setCurrentIndex(_topTW->indexOf(activeTop->widget()));
891  if (activeBottom)
892  _bottomTW->setCurrentIndex(_bottomTW->indexOf(activeBottom->widget()));
893  if (activeLeft)
894  _leftTW->setCurrentIndex(_leftTW->indexOf(activeLeft->widget()));
895  if (activeRight)
896  _rightTW->setCurrentIndex(_rightTW->indexOf(activeRight->widget()));
897 
898  if (!_data) return;
899 
900  updateView();
901 }
902 
903 void TabView::saveLayout(const QString& prefix, const QString& postfix)
904 {
905  ConfigGroup* g = ConfigStorage::group(prefix + postfix);
906 
907  // convert splitter sizes into percentage numbers
908  QList<int> s;
909  s = _mainSplitter->sizes();
910  int rightSize = (s[0]+s[1]==0) ? 0 : (100 * s[1]/(s[0]+s[1]));
911  s = _leftSplitter->sizes();
912  int topSize = (s[0]+s[1]==0) ? 0 : (100 * s[0]/(s[0]+s[1]));
913  s = _bottomSplitter->sizes();
914  int leftSize = (s[0]+s[1]==0) ? 0 : (100 * s[0]/(s[0]+s[1]));
915 
916  g->setValue("RightSize", rightSize, DEFAULT_RIGHTSIZE);
917  g->setValue("TopSize", topSize, DEFAULT_TOPSIZE);
918  g->setValue("LeftSize", leftSize, DEFAULT_LEFTSIZE);
919 
920  QString a;
921  QWidget* w;
922  w = _topTW->currentWidget();
923  if ((_topTW->count()>0) &&
924  (_topTW->isTabEnabled(_topTW->indexOf(w))))
925  a = w->objectName();
926  g->setValue("ActiveTop", a, QString(DEFAULT_ACTIVETOP));
927 
928  a = QString();
929  w = _bottomTW->currentWidget();
930  if ((_bottomTW->count()>0) &&
931  (_bottomTW->isTabEnabled(_bottomTW->indexOf(w))))
932  a = w->objectName();
933  g->setValue("ActiveBottom", a, QString(DEFAULT_ACTIVEBOTTOM));
934 
935  a = QString();
936  w = _leftTW->currentWidget();
937  if ((_leftTW->count()>0) &&
938  (_leftTW->isTabEnabled(_leftTW->indexOf(w))))
939  a = w->objectName();
940  g->setValue("ActiveLeft", a, QString());
941 
942  a= QString();
943  w = _rightTW->currentWidget();
944  if ((_rightTW->count()>0) &&
945  (_rightTW->isTabEnabled(_rightTW->indexOf(w))))
946  a = w->objectName();
947  g->setValue("ActiveRight", a, QString());
948 
949  QStringList topList, bottomList, leftList, rightList;
950  foreach(TraceItemView *v, _tabs) {
951  switch(v->position()) {
952  case TraceItemView::Top:
953  topList << v->widget()->objectName();
954  break;
955 
956  case TraceItemView::Bottom:
957  bottomList << v->widget()->objectName();
958  break;
959 
960  case TraceItemView::Left:
961  leftList << v->widget()->objectName();
962  break;
963 
964  case TraceItemView::Right:
965  rightList << v->widget()->objectName();
966  break;
967 
968  default: break;
969  }
970  }
971 
972  QStringList topTabsDefault, bottomTabsDefault;
973  topTabsDefault << DEFAULT_TOPTABS;
974  bottomTabsDefault << DEFAULT_BOTTOMTABS;
975 
976  g->setValue("TopTabs", topList, topTabsDefault);
977  g->setValue("BottomTabs", bottomList, bottomTabsDefault);
978  g->setValue("LeftTabs", leftList, QStringList());
979  g->setValue("RightTabs", rightList, QStringList());
980 
981  delete g;
982 }
983 
984 void TabView::restoreOptions(const QString& prefix, const QString& postfix)
985 {
986  foreach(TraceItemView *v, _tabs)
987  v->restoreOptions(QString("%1-%2").arg(prefix).arg(v->widget()->objectName()),
988  postfix);
989 
990  if (!_data) return;
991 
992  ConfigGroup* g = ConfigStorage::group(prefix, postfix);
993 
994  QString activeType = g->value("ActiveItemType", QString()).toString();
995  QString activeName = g->value("ActiveItemName", QString()).toString();
996  QString selectedType = g->value("SelectedItemType", QString()).toString();
997  QString selectedName = g->value("SelectedItemName", QString()).toString();
998 
999  delete g;
1000 
1001  // restore active item
1002  ProfileContext::Type t = ProfileContext::type(activeType);
1003  if (t==ProfileContext::InvalidType) t = ProfileContext::Function;
1004  ProfileCostArray* activeItem = _data->search(t, activeName, _eventType);
1005  if (!activeItem) return;
1006  activated(activeItem);
1007 
1008  // restore selected item
1009  t = ProfileContext::type(selectedType);
1010  if (t==ProfileContext::InvalidType) t = ProfileContext::Function;
1011  ProfileCostArray* selectedItem;
1012  selectedItem = _data->search(t, selectedName, _eventType, activeItem);
1013  if (selectedItem)
1014  selected(this, selectedItem);
1015 }
1016 
1017 void TabView::saveOptions(const QString& prefix, const QString& postfix)
1018 {
1019  if (_activeItem) {
1020  ConfigGroup* g = ConfigStorage::group(prefix + postfix);
1021 
1022  g->setValue("ActiveItemType",
1023  ProfileContext::typeName(_activeItem->type()));
1024  g->setValue("ActiveItemName", _activeItem->name());
1025 
1026  if (_selectedItem) {
1027  g->setValue("SelectedItemType",
1028  ProfileContext::typeName(_selectedItem->type()));
1029  g->setValue("SelectedItemName", _selectedItem->name());
1030  }
1031  delete g;
1032  }
1033 
1034  foreach(TraceItemView *v, _tabs)
1035  v->saveOptions(QString("%1-%2").arg(prefix)
1036  .arg(v->widget()->objectName()), postfix);
1037 }
1038 
1039 #include "tabview.moc"
CallView
Definition: callview.h:30
TabView::selected
void selected(TraceItemView *, CostItem *)
Notification from child views.
Definition: tabview.cpp:811
DEFAULT_RIGHTSIZE
#define DEFAULT_RIGHTSIZE
Definition: tabview.cpp:64
TabWidget::visibleRectChanged
void visibleRectChanged(TabWidget *)
TabView::TabView
TabView(TraceItemView *parentView, QWidget *parent=0)
Definition: tabview.cpp:304
ProfileContext::type
ProfileContext::Type type()
Definition: context.h:55
TraceItemView::_parentView
TraceItemView * _parentView
Definition: traceitemview.h:206
TraceItemView::_selectedItem
CostItem * _selectedItem
Definition: traceitemview.h:211
globalconfig.h
TabWidget
Own TabView:
Definition: tabview.h:89
TabWidget::hideEvent
void hideEvent(QHideEvent *)
Definition: tabview.cpp:264
PartView
Definition: partview.h:31
TraceItemView::set
void set(ProfileContext::Type g)
Definition: traceitemview.h:115
DEFAULT_BOTTOMTABS
#define DEFAULT_BOTTOMTABS
Definition: tabview.cpp:57
coverageview.h
TabView::resizeEvent
void resizeEvent(QResizeEvent *)
Definition: tabview.cpp:794
TabWidget::moveEvent
void moveEvent(QMoveEvent *)
Definition: tabview.cpp:272
Splitter::checkVisiblity
void checkVisiblity()
Definition: tabview.cpp:200
TraceItemView::Position
Position
Definition: traceitemview.h:93
CoverageView
Definition: coverageview.h:32
TabView::eventFilter
bool eventFilter(QObject *, QEvent *)
Definition: tabview.cpp:692
TabWidget::showEvent
void showEvent(QShowEvent *)
Definition: tabview.cpp:256
ProfileContext::typeName
static QString typeName(Type)
Definition: context.cpp:62
DEFAULT_TOPSIZE
#define DEFAULT_TOPSIZE
Definition: tabview.cpp:65
TraceData::search
ProfileCostArray * search(ProfileContext::Type, QString, EventType *ct=0, ProfileCostArray *parent=0)
Search for item with given name and highest subcost of given cost type.
Definition: tracedata.cpp:3522
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
TabView::setData
void setData(TraceData *)
Definition: tabview.cpp:435
TraceItemView::configChanged
Definition: traceitemview.h:88
TabWidget::hasVisibleRect
bool hasVisibleRect()
Definition: tabview.h:97
QWidget
DEFAULT_LEFTSIZE
#define DEFAULT_LEFTSIZE
Definition: tabview.cpp:66
TraceItemView::_data
TraceData * _data
Definition: traceitemview.h:209
ConfigGroup::setValue
virtual void setValue(const QString &key, const QVariant &value, const QVariant &defaultValue=QVariant())
Definition: config.cpp:57
CallMapView
Definition: callmapview.h:35
CostItem
Base class for cost items.
Definition: costitem.h:37
config.h
DEFAULT_ACTIVETOP
#define DEFAULT_ACTIVETOP
Definition: tabview.cpp:61
QTabBar
TraceItemView::updateView
void updateView(bool force=false)
Definition: traceitemview.cpp:185
EventTypeView
Definition: eventtypeview.h:31
TraceItemView::position
Position position() const
Definition: traceitemview.h:164
TraceItemView::title
QString title() const
Definition: traceitemview.h:167
TraceItemView::_groupType
ProfileContext::Type _groupType
Definition: traceitemview.h:213
sourceview.h
TraceItemView::_eventType2
EventType * _eventType2
Definition: traceitemview.h:212
ConfigStorage::group
static ConfigGroup * group(const QString &group, const QString &optSuffix=QString())
Definition: config.cpp:80
TraceItemView
Abstract Base Class for KCachegrind Views.
Definition: traceitemview.h:70
TraceItemView::setData
virtual void setData(TraceData *d)
Definition: traceitemview.cpp:165
CostItem::formattedName
virtual QString formattedName() const
A HTMLified version of name, can return empty string.
Definition: costitem.cpp:71
TabWidget::checkVisibility
void checkVisibility()
Definition: tabview.cpp:228
TraceItemView::selectedItem
CostItem * selectedItem() const
Definition: traceitemview.h:150
TraceItemView::_eventType
EventType * _eventType
Definition: traceitemview.h:212
ProfileCostArray
An array of basic cost metrics for a trace item.
Definition: costitem.h:144
TraceItemView::setTitle
void setTitle(QString t)
Definition: traceitemview.h:166
TraceItemView::Right
Definition: traceitemview.h:93
TraceItemView::dataChanged
Definition: traceitemview.h:87
TabView::moveTab
void moveTab(QWidget *w, Position, bool wholeArea=false)
Rearrange tabs if == 0, move hidden tabs.
Definition: tabview.cpp:600
Splitter::moveEvent
void moveEvent(QMoveEvent *)
Definition: tabview.cpp:192
CostItem::name
virtual QString name() const
Returns dynamic name info (without type)
Definition: costitem.cpp:53
TabView::visibleRectChangedSlot
void visibleRectChangedSlot(TabWidget *)
Definition: tabview.cpp:785
DEFAULT_ACTIVEBOTTOM
#define DEFAULT_ACTIVEBOTTOM
Definition: tabview.cpp:62
TabView::visibleTabs
int visibleTabs()
Definition: tabview.cpp:470
TraceItemView::canShow
virtual CostItem * canShow(CostItem *i)
This function is called when a new item should become active.
Definition: traceitemview.h:182
TabView::tabActivated
void tabActivated(TabView *)
TraceItemView::Bottom
Definition: traceitemview.h:93
TraceItemView::_activeItem
CostItem * _activeItem
Definition: traceitemview.h:211
TabView::tabPosition
Position tabPosition(QWidget *)
Definition: tabview.cpp:462
TabView::restoreOptions
void restoreOptions(const QString &prefix, const QString &postfix)
Definition: tabview.cpp:984
ConfigGroup
A group of configuration settings.
Definition: config.h:35
TraceItemView::notifyChange
void notifyChange(int changeType)
Definition: traceitemview.h:120
TraceItemView::selected
virtual void selected(TraceItemView *sender, CostItem *)
Notification from child views.
Definition: traceitemview.cpp:313
TraceItemView::activated
virtual void activated(TraceItemView *sender, CostItem *)
Definition: traceitemview.cpp:342
TabBar::TabBar
TabBar(TabView *, QTabWidget *parent, const char *name=0)
Definition: tabview.cpp:70
instrview.h
TabWidget::TabWidget
TabWidget(TabView *, QWidget *parent=0)
Definition: tabview.cpp:221
TabView::whatsThis
QString whatsThis() const
Definition: tabview.cpp:652
SourceView
Definition: sourceview.h:31
callmapview.h
DEFAULT_TOPTABS
#define DEFAULT_TOPTABS
Definition: tabview.cpp:54
TabView::setActive
void setActive(bool)
Definition: tabview.cpp:708
Splitter::Splitter
Splitter(Qt::Orientation o, QWidget *parent=0)
Definition: tabview.cpp:188
TraceItemView::saveOptions
virtual void saveOptions(const QString &prefix, const QString &postfix)
Definition: traceitemview.cpp:95
TraceItemView::restoreOptions
virtual void restoreOptions(const QString &prefix, const QString &postfix)
Definition: traceitemview.cpp:106
TabView::restoreLayout
void restoreLayout(const QString &prefix, const QString &postfix)
Definition: tabview.cpp:820
TraceItemView::activeItem
CostItem * activeItem() const
Definition: traceitemview.h:149
TraceItemView::activeItemChanged
Definition: traceitemview.h:85
TabView::saveLayout
void saveLayout(const QString &prefix, const QString &postfix)
Definition: tabview.cpp:903
InstrView
Definition: instrview.h:32
ProfileContext::Type
Type
Definition: context.h:36
TabBar::mousePressEvent
void mousePressEvent(QMouseEvent *e)
Definition: tabview.cpp:78
TraceItemView::Hidden
Definition: traceitemview.h:93
callview.h
eventtypeview.h
TabBar
Subclass of QTabBar to enable context menu on tabs.
Definition: tabview.h:47
TabView::visibleAreas
int visibleAreas()
Definition: tabview.cpp:509
TabView::saveOptions
void saveOptions(const QString &prefix, const QString &postfix)
Definition: tabview.cpp:1017
CallGraphView
A QGraphicsView showing a part of the call graph and another zoomed out CanvasView in a border acting...
Definition: callgraphview.h:574
TraceItemView::setPosition
void setPosition(Position p)
Definition: traceitemview.h:163
TabWidget::resizeEvent
void resizeEvent(QResizeEvent *)
Definition: tabview.cpp:246
TabView::tabChanged
void tabChanged(int)
Definition: tabview.cpp:775
TabView::mousePressEvent
void mousePressEvent(QMouseEvent *)
Definition: tabview.cpp:701
QTabWidget
TraceItemView::widget
virtual QWidget * widget()=0
TabView
Definition: tabview.h:115
TraceData
This class holds profiling data of multiple tracefiles generated with cachegrind on one command...
Definition: tracedata.h:1363
TraceItemView::select
void select(CostItem *i)
Definition: traceitemview.cpp:79
CostItem::prettyName
virtual QString prettyName() const
Similar to name, but prettyfied = more descriptive to humans.
Definition: costitem.cpp:65
tabview.h
callgraphview.h
partview.h
TraceItemView::_partList
TracePartList _partList
Definition: traceitemview.h:210
TraceItemView::Top
Definition: traceitemview.h:93
QSplitter
TraceItemView::Left
Definition: traceitemview.h:93
ProfileContext::Function
Definition: context.h:46
QList
ProfileContext::InvalidType
Definition: context.h:37
ConfigGroup::value
virtual QVariant value(const QString &key, const QVariant &defaultValue) const
Definition: config.cpp:60
Splitter
Own Splitter: Call checkVisiblity for all TabWidget children of the splitter on a MoveEvent...
Definition: tabview.h:70
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