26 #include <QPushButton>
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
36 #include <QHeaderView>
56 const QStyleOptionViewItem& option,
57 const QModelIndex& index)
62 if ( e->type() != QEvent::ToolTip )
63 return QStyledItemDelegate::helpEvent(e, view, option, index);
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 );
75 if ( !QStyledItemDelegate::helpEvent( e, view, option, index ) )
94 _inSetFunction =
false;
95 _functionListSortOrder = Qt::DescendingOrder;
100 QHBoxLayout* hboxLayout =
new QHBoxLayout();
101 hboxLayout->setSpacing(6);
102 hboxLayout->setMargin(0);
104 searchLabel =
new QLabel(
this);
105 searchLabel->setText(tr(
"&Search:"));
106 searchLabel->setWordWrap(
false);
107 hboxLayout->addWidget(searchLabel);
109 searchEdit =
new QLineEdit(
this);
110 searchLabel->setBuddy(searchEdit);
111 hboxLayout->addWidget(searchEdit);
113 groupBox =
new QComboBox(
this);
114 hboxLayout->addWidget(groupBox);
117 QVBoxLayout* vboxLayout =
new QVBoxLayout(
this);
118 vboxLayout->setSpacing(6);
119 vboxLayout->setMargin(3);
120 vboxLayout->addLayout(hboxLayout);
123 QStringList groupHeader;
124 groupHeader << tr(
"Self") << tr(
"Group");
125 groupList->setHeaderLabels(groupHeader);
127 #if QT_VERSION >= 0x050000
128 groupList->header()->setSectionsClickable(
true);
130 groupList->header()->setClickable(
true);
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);
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);
154 functionList->header()->setClickable(
true);
155 functionList->header()->setResizeMode(QHeaderView::Interactive);
157 functionList->header()->setSortIndicatorShown(
false);
158 functionList->header()->setSortIndicator(0, Qt::DescendingOrder);
160 functionList->header()->setDefaultSectionSize(200);
161 functionList->setModel(functionListModel);
163 vboxLayout->addWidget(functionList);
167 args << tr(
"(No Grouping)")
172 groupBox->addItems(args);
173 connect(groupBox, SIGNAL(
activated(
int)),
177 connect(searchEdit, SIGNAL(textChanged(
const QString&)),
179 connect(&_searchTimer, SIGNAL(timeout()),
182 connect(searchEdit, SIGNAL(returnPressed()),
184 searchEdit->setMinimumWidth(50);
187 connect(functionList, SIGNAL(clicked(QModelIndex)),
189 connect(functionList, SIGNAL(
activated(QModelIndex)),
191 connect(functionList, SIGNAL(customContextMenuRequested(
const QPoint &)),
193 connect(functionList->header(), SIGNAL(sectionClicked(
int)),
202 groupList->setContextMenuPolicy(Qt::CustomContextMenu);
204 SIGNAL(customContextMenuRequested(
const QPoint &) ),
206 connect(groupList->header(),
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 "
223 "are spent in, depending on the chosen group type. "
224 "The group list is hidden when group type 'Function' "
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>");
245 query(searchEdit->text());
250 item = groupList->currentItem();
251 if (!item || item->isHidden()) {
254 for (i=0; i<groupList->topLevelItemCount(); i++) {
255 item = groupList->topLevelItem(i);
256 if (!item->isHidden())
break;
266 functionList->setFocus();
274 if (q.length()<5) ms = 200;
275 if (q.length()<2) ms = 300;
276 _searchTimer.setSingleShot(
true);
277 _searchTimer.start(ms);
282 query(_searchDelayed);
290 QAction* activateFunctionAction = 0;
291 QModelIndex i = functionList->indexAt(p);
296 activateFunctionAction = popup.addAction(menuText);
297 popup.addSeparator();
299 if ((i.column() == 0) || (i.column() == 1)) {
301 popup.addSeparator();
306 popup.addSeparator();
309 QPoint pDiff = QPoint(0, functionList->header()->height());
310 QAction* a = popup.exec(functionList->mapToGlobal(p + pDiff));
311 if (a == activateFunctionAction)
319 int c = groupList->columnAt(p.x());
322 popup.addSeparator();
325 popup.addSeparator();
328 QPoint headerSize = QPoint(0, groupList->header()->height());
329 popup.exec(groupList->mapToGlobal(p + headerSize));
332 void FunctionSelection::addGroupAction(QMenu* m,
342 a->setCheckable(
true);
348 QMenu* m = menu->addMenu(tr(
"Grouping"));
359 connect(m, SIGNAL(triggered(QAction*)),
399 i = ((
TraceLine*)i)->functionSource()->function();
414 if (!i.isValid())
return;
417 functionList->scrollTo(i, QAbstractItemView::EnsureVisible);
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;
426 void FunctionSelection::doUpdate(
int changeType,
bool)
437 #if QT_VERSION >= 0x050000
438 groupList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
440 groupList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
444 groupList->setSortingEnabled(
false);
445 for (i=0; i<groupList->topLevelItemCount(); i++) {
449 #if QT_VERSION >= 0x050000
450 groupList->header()->setSectionResizeMode(0, QHeaderView::Interactive);
452 groupList->header()->setResizeMode(0, QHeaderView::Interactive);
454 groupList->setSortingEnabled(
true);
455 groupList->header()->setSortIndicatorShown(
false);
459 selectFunction(dynamic_cast<TraceFunction*>(
_activeItem));
460 setCostColumnWidths();
466 functionList->clearSelection();
482 QModelIndex i = functionList->currentIndex();
483 if (functionListModel->
function(i) == f) {
488 query(QString::null);
526 default:
id = 0;
break;
528 groupBox->setCurrentIndex(
id);
537 _searchString = QString();
538 query(QString::null);
552 if (g == _group)
return;
557 for (i=0; i < groupList->topLevelItemCount(); i++) {
558 item = groupList->topLevelItem(i);
564 groupList->scrollToItem(item);
568 groupList->setCurrentItem(item);
572 groupList->clearSelection();
576 void FunctionSelection::refresh()
582 groupList->setColumnWidth(0, 50);
594 TraceObjectMap::Iterator oit;
595 TraceClassMap::Iterator cit;
596 TraceFileMap::Iterator fit;
639 selectFunction(dynamic_cast<TraceFunction*>(
_activeItem));
640 setCostColumnWidths();
662 if (group == _group)
continue;
673 #if QT_VERSION >= 0x050000
674 groupList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
676 groupList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
678 groupList->setSortingEnabled(
false);
679 groupList->addTopLevelItems(items);
680 groupList->setSortingEnabled(
true);
682 groupList->sortByColumn(0, Qt::DescendingOrder);
683 groupList->header()->setSortIndicatorShown(
false);
684 #if QT_VERSION >= 0x050000
685 groupList->header()->setSectionResizeMode(0, QHeaderView::Interactive);
687 groupList->header()->setResizeMode(0, QHeaderView::Interactive);
698 groupList->clearSelection();
709 if (g == _group)
return;
713 selectFunction(dynamic_cast<TraceFunction*>(
_activeItem));
714 setCostColumnWidths();
731 if (g != _group)
return;
738 groupList->sortByColumn(col, Qt::DescendingOrder);
744 for (i=0; i<groupList->topLevelItemCount(); i++) {
765 void FunctionSelection::updateGroupSizes(
bool hideEmpty)
768 for (i=0; i<groupList->topLevelItemCount(); i++) {
770 int size = (_groupSize.contains(item->
costItem())) ?
773 item->setHidden(hideEmpty && (size<0));
781 if (searchEdit->text() !=
query)
782 searchEdit->setText(query);
783 if (_searchString == query) {
785 if (query.isEmpty()) {
787 updateGroupSizes(
false);
791 _searchString =
query;
793 QRegExp re(query, Qt::CaseInsensitive, QRegExp::Wildcard);
801 TraceFunctionMap::Iterator it;
808 if (_groupSize.contains(f->
object()))
809 _groupSize[f->
object()]++;
811 _groupSize[f->
object()] = 1;
812 if (f->
object() != _group)
continue;
815 if (_groupSize.contains(f->
cls()))
816 _groupSize[f->
cls()]++;
818 _groupSize[f->
cls()] = 1;
819 if (f->
cls() != _group)
continue;
822 if (_groupSize.contains(f->
file()))
823 _groupSize[f->
file()]++;
825 _groupSize[f->
file()] = 1;
826 if (f->
file() != _group)
continue;
829 if (_groupSize.contains(f->
cycle()))
830 _groupSize[f->
cycle()]++;
832 _groupSize[f->
cycle()] = 1;
833 if (f->
cycle() != _group)
continue;
839 updateGroupSizes(
true);
842 selectFunction(dynamic_cast<TraceFunction*>(
_activeItem));
843 setCostColumnWidths();
848 QModelIndex i = functionListModel->
index(0,0);
860 void FunctionSelection::setCostColumnWidths()
862 functionList->resizeColumnToContents(1);
865 functionList->resizeColumnToContents(0);
866 functionList->resizeColumnToContents(2);
869 functionList->header()->resizeSection(0, 0);
870 functionList->header()->resizeSection(2, 0);
876 if ((_functionListSortOrder== Qt::AscendingOrder) || (col<3))
877 _functionListSortOrder = Qt::DescendingOrder;
879 _functionListSortOrder = Qt::AscendingOrder;
881 functionList->sortByColumn(col, _functionListSortOrder);
882 selectFunction(dynamic_cast<TraceFunction*>(
_activeItem),
false);
883 setCostColumnWidths();
888 #include "functionselection.moc"
ProfileCostArray * callMax()
void setEventType(EventType *et)
SubCost subCost(EventType *)
Returns a sub cost.
TraceFunction * function(const QModelIndex &index)
void addEventTypeMenu(QMenu *, bool withCost2=true)
ProfileContext::Type type() const
QModelIndex index(int row, int column=0, const QModelIndex &parent=QModelIndex()) const
void searchChanged(const QString &)
TraceObject * object() const
void setEventType(EventType *)
TraceFunctionCycle * cycle()
void searchReturnPressed()
Base class for cost items.
void setGroup(TraceCostItem *)
TraceCostItem * costItem()
void functionContext(const QPoint &)
ProfileContext::Type _groupType
Abstract Base Class for KCachegrind Views.
virtual void setData(TraceData *d)
FunctionSelection(TopLevelBase *, QWidget *parent=0)
QList< TraceFunction * > TraceFunctionList
TracePartList parts() const
TraceClassMap & classMap()
A code instruction address of the program.
QModelIndex indexForFunction(TraceFunction *f, bool add=false)
static QString i18nTypeName(Type)
const TraceFunctionCycleList & functionCycles()
void functionActivated(const QModelIndex &)
void functionHeaderClicked(int)
virtual QString name() const
Returns dynamic name info (without type)
QString prettyName() const
Similar to name, but prettyfied = more descriptive to humans.
void groupHeaderClicked(int)
QString whatsThis() const
A source line of the program.
static QString shortenSymbol(const QString &)
void groupContext(const QPoint &)
SubCost subCost(ProfileCostArray *)
TraceObjectMap & objectMap()
virtual void activated(TraceItemView *sender, CostItem *)
void setData(TraceData *)
void addCost(ProfileCostArray *, SubCost)
void groupDoubleClicked(QTreeWidgetItem *, int)
void groupSelected(QTreeWidgetItem *, QTreeWidgetItem *)
CostItem * activeItem() const
void groupTypeSelected(QAction *)
virtual void setGroupDelayed(TraceCostItem *)=0
void resetModelData(TraceData *data, TraceCostItem *group, QString filter, EventType *eventType)
TraceFunctionMap & functionMap()
This class holds profiling data of multiple tracefiles generated with cachegrind on one command...
virtual void selectedGroupType(TraceItemView *sender, ProfileContext::Type)
static int maxListCount()
void addGroupMenu(QMenu *)
ProfileCostArray * inclusive()