1 /* 2 This file is part of KCachegrind. 3 4 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 5 6 SPDX-License-Identifier: GPL-2.0-only 7 */ 8 9 /* 10 * For function selection, to be put into a QDockWindow 11 */ 12 13 #ifndef FUNCTIONSELECTION_H 14 #define FUNCTIONSELECTION_H 15 16 #include <QTimer> 17 #include <QWidget> 18 #include <QModelIndex> 19 #include <QStyledItemDelegate> 20 21 #include "tracedata.h" 22 #include "traceitemview.h" 23 #include "listutils.h" 24 #include "toplevelbase.h" 25 26 class QAction; 27 class QMenu; 28 class QLabel; 29 class QComboBox; 30 class QLineEdit; 31 class QTreeView; 32 class QTreeWidget; 33 class QTreeWidgetItem; 34 class FunctionListModel; 35 36 class FunctionSelection: public QWidget, public TraceItemView 37 { 38 Q_OBJECT 39 40 public: 41 explicit FunctionSelection(TopLevelBase*, QWidget* parent = nullptr); 42 group()43 TraceCostItem* group() { return _group; } 44 TraceCostItem* group(QString); 45 void setGroup(TraceCostItem*); 46 void query(QString); 47 bool selectTopFunction(); 48 widget()49 QWidget* widget() override { return this; } 50 QString whatsThis() const override; 51 void setData(TraceData*) override; 52 53 void updateGroupingMenu(QMenu*); 54 55 public Q_SLOTS: 56 void searchReturnPressed(); 57 void searchChanged(const QString&); 58 void queryDelayed(); 59 60 void groupTypeSelected(QAction*); 61 void groupTypeSelected(int); 62 void groupDoubleClicked(QTreeWidgetItem*, int); 63 void groupSelected(QTreeWidgetItem*, QTreeWidgetItem*); 64 void groupContext(const QPoint &); 65 void groupHeaderClicked(int); 66 67 void functionActivated(const QModelIndex&); 68 void functionContext(const QPoint &); 69 void functionHeaderClicked(int); 70 71 private: 72 CostItem* canShow(CostItem* i) override; 73 void doUpdate(int, bool) override; 74 void selectFunction(); 75 void refresh(); 76 void setCostColumnWidths(); 77 void updateGroupSizes(bool hideEmpty); 78 void addGroupAction(QMenu*, ProfileContext::Type, 79 const QString& s = QString()); 80 void selectFunction(TraceFunction* f, bool ensureVisible = true); 81 82 TraceCostItem* _group; 83 84 QString _searchString, _searchDelayed; 85 QTimer _searchTimer; 86 QMap<TraceCostItem*,int> _groupSize; 87 88 HighestCostList _hc; 89 // when setting a 90 bool _inSetGroup, _inSetFunction; 91 92 QLabel *searchLabel; 93 QLineEdit *searchEdit; 94 QComboBox *groupBox; 95 QTreeWidget *groupList; 96 QTreeView *functionList; 97 FunctionListModel* functionListModel; 98 99 Qt::SortOrder _functionListSortOrder; 100 }; 101 102 103 /* Custom item delegate for function list: 104 * show tooltip for function name if truncated. 105 * (thanks to https://www.mimec.org/blog/tooltips-for-truncated-items-in-a-qtreeview) 106 */ 107 class AutoToolTipDelegate : public QStyledItemDelegate 108 { 109 Q_OBJECT 110 public: 111 explicit AutoToolTipDelegate(QObject* parent = nullptr); 112 ~AutoToolTipDelegate() override; 113 114 public Q_SLOTS: 115 bool helpEvent( QHelpEvent* e, QAbstractItemView* view, 116 const QStyleOptionViewItem& option, 117 const QModelIndex& index ) override; 118 }; 119 120 #endif 121