File indexing completed on 2024-04-28 05:41:33
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 /* 0010 * For function selection, to be put into a QDockWindow 0011 */ 0012 0013 #ifndef FUNCTIONSELECTION_H 0014 #define FUNCTIONSELECTION_H 0015 0016 #include <QTimer> 0017 #include <QWidget> 0018 #include <QModelIndex> 0019 #include <QStyledItemDelegate> 0020 0021 #include "tracedata.h" 0022 #include "traceitemview.h" 0023 #include "listutils.h" 0024 #include "toplevelbase.h" 0025 0026 class QAction; 0027 class QMenu; 0028 class QLabel; 0029 class QComboBox; 0030 class QLineEdit; 0031 class QTreeView; 0032 class QTreeWidget; 0033 class QTreeWidgetItem; 0034 class FunctionListModel; 0035 0036 class FunctionSelection: public QWidget, public TraceItemView 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 explicit FunctionSelection(TopLevelBase*, QWidget* parent = nullptr); 0042 0043 TraceCostItem* group() { return _group; } 0044 TraceCostItem* group(QString); 0045 void setGroup(TraceCostItem*); 0046 void query(QString); 0047 bool selectTopFunction(); 0048 0049 QWidget* widget() override { return this; } 0050 QString whatsThis() const override; 0051 void setData(TraceData*) override; 0052 0053 void updateGroupingMenu(QMenu*); 0054 0055 public Q_SLOTS: 0056 void searchReturnPressed(); 0057 void searchChanged(const QString&); 0058 void queryDelayed(); 0059 0060 void groupTypeSelected(QAction*); 0061 void groupTypeSelected(int); 0062 void groupDoubleClicked(QTreeWidgetItem*, int); 0063 void groupSelected(QTreeWidgetItem*, QTreeWidgetItem*); 0064 void groupContext(const QPoint &); 0065 void groupHeaderClicked(int); 0066 0067 void functionActivated(const QModelIndex&); 0068 void functionContext(const QPoint &); 0069 void functionHeaderClicked(int); 0070 0071 private: 0072 CostItem* canShow(CostItem* i) override; 0073 void doUpdate(int, bool) override; 0074 void selectFunction(); 0075 void refresh(); 0076 void setCostColumnWidths(); 0077 void updateGroupSizes(bool hideEmpty); 0078 void addGroupAction(QMenu*, ProfileContext::Type, 0079 const QString& s = QString()); 0080 void selectFunction(TraceFunction* f, bool ensureVisible = true); 0081 0082 TraceCostItem* _group; 0083 0084 QString _searchString, _searchDelayed; 0085 QTimer _searchTimer; 0086 QMap<TraceCostItem*,int> _groupSize; 0087 0088 HighestCostList _hc; 0089 // when setting a 0090 bool _inSetGroup, _inSetFunction; 0091 0092 QLabel *searchLabel; 0093 QLineEdit *searchEdit; 0094 QComboBox *groupBox; 0095 QTreeWidget *groupList; 0096 QTreeView *functionList; 0097 FunctionListModel* functionListModel; 0098 0099 Qt::SortOrder _functionListSortOrder; 0100 }; 0101 0102 0103 /* Custom item delegate for function list: 0104 * show tooltip for function name if truncated. 0105 * (thanks to https://www.mimec.org/blog/tooltips-for-truncated-items-in-a-qtreeview) 0106 */ 0107 class AutoToolTipDelegate : public QStyledItemDelegate 0108 { 0109 Q_OBJECT 0110 public: 0111 explicit AutoToolTipDelegate(QObject* parent = nullptr); 0112 ~AutoToolTipDelegate() override; 0113 0114 public Q_SLOTS: 0115 bool helpEvent( QHelpEvent* e, QAbstractItemView* view, 0116 const QStyleOptionViewItem& option, 0117 const QModelIndex& index ) override; 0118 }; 0119 0120 #endif