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