File indexing completed on 2024-04-28 05:41:31

0001 /*
0002     This file is part of KCachegrind.
0003 
0004     SPDX-FileCopyrightText: 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only
0007 */
0008 
0009 /*
0010  * Call Map View
0011  */
0012 
0013 #ifndef CALLMAPVIEW_H
0014 #define CALLMAPVIEW_H
0015 
0016 #include <QPixmap>
0017 
0018 #include "treemap.h"
0019 #include "tracedata.h"
0020 #include "traceitemview.h"
0021 
0022 class QAction;
0023 class QMenu;
0024 
0025 class CallMapView: public TreeMapWidget, public TraceItemView
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030 
0031     CallMapView(bool showCallers, TraceItemView* parentView,
0032                 QWidget* parent, const QString& name);
0033 
0034     QWidget* widget() override { return this; }
0035     QString whatsThis() const override;
0036     void setData(TraceData*) override;
0037 
0038     void restoreOptions(const QString& prefix, const QString& postfix) override;
0039     void saveOptions(const QString& prefix, const QString& postfix) override;
0040 
0041     bool showCallers() const { return _showCallers; }
0042     ProfileCostArray* totalCost();
0043     QString tipString(TreeMapItem*) const override;
0044     QColor groupColor(TraceFunction*) const;
0045 
0046 private Q_SLOTS:
0047     void context(TreeMapItem*,const QPoint &);
0048     void selectedSlot(TreeMapItem*, bool);
0049     void activatedSlot(TreeMapItem*);
0050     void mapItemTriggered(QAction*);
0051     void drawingDepthTriggered(QAction*);
0052     void stopFunctionTriggered(QAction*);
0053     void areaLimitTriggered(QAction*);
0054     void borderWidthTriggered(QAction*);
0055 
0056 private:
0057     CostItem* canShow(CostItem*) override;
0058     void doUpdate(int, bool) override;
0059 
0060     // context menu builders
0061     void addItemListMenu(QMenu*,TreeMapItem*);
0062     QAction* addDrawingDepthAction(QMenu*, const QString&, int);
0063     void addDrawingDepthMenu(QMenu*, TreeMapItem*, const QString&);
0064     QAction* addStopFunctionAction(QMenu*, const QString&, const QString&);
0065     void addStopFunctionMenu(QMenu*, TreeMapItem*);
0066     QAction* addAreaLimitAction(QMenu*, const QString&, int);
0067     void addAreaLimitMenu(QMenu*, TreeMapItem*, const QString&);
0068     QAction* addBorderWidthAction(QMenu*, const QString&, int);
0069 
0070     bool _showCallers;
0071 };
0072 
0073 
0074 
0075 // Subitems in CallMapView
0076 
0077 // text field indexes: lower indexes get priority if space is not enough
0078 #define IDX_COST      0
0079 #define IDX_FUNCNAME  1
0080 #define IDX_LOCATION  2
0081 #define IDX_CALLCOUNT 3
0082 
0083 // base class providing same layout configuration
0084 class CallMapItemBase: public TreeMapItem
0085 {
0086 public:
0087     int maxLines(int) const override;
0088     bool allowBreak(int) const override;
0089     bool allowTruncation(int) const override;
0090     Position position(int) const override;
0091 };
0092 
0093 class CallMapRootItem: public CallMapItemBase
0094 {
0095 public:
0096     CallMapRootItem();
0097 
0098     void setFunction(TraceFunction* f);
0099     TraceFunction* function() { return _f; }
0100     int rtti() const override { return 1; }
0101     double sum() const override;
0102     double value() const override;
0103     bool isMarked(int) const override;
0104     QString text(int) const override;
0105     QPixmap pixmap(int) const override;
0106     TreeMapItemList* children() override;
0107     QColor backColor() const override;
0108 
0109 private:
0110     TraceFunction* _f;
0111 };
0112 
0113 
0114 class CallMapCallingItem: public CallMapItemBase
0115 {
0116 public:
0117     CallMapCallingItem(double factor, TraceCall* c);
0118     void init();
0119     int rtti() const override { return 2; }
0120     int borderWidth() const override { return widget()->borderWidth(); }
0121     TraceFunction* function() { return _c->called(); }
0122     double value() const override;
0123     double sum() const override;
0124     bool isMarked(int) const override;
0125     QString text(int) const override;
0126     QPixmap pixmap(int) const override;
0127     TreeMapItemList* children() override;
0128     QColor backColor() const override;
0129 
0130 private:
0131     TraceCall* _c;
0132     double _factor;
0133 };
0134 
0135 class CallMapCallerItem: public CallMapItemBase
0136 {
0137 public:
0138     CallMapCallerItem(double factor, TraceCall* c);
0139     int rtti() const override { return 3; }
0140     int borderWidth() const override { return widget()->borderWidth(); }
0141     TraceFunction* function() { return _c->caller(); }
0142     double value() const override;
0143     bool isMarked(int) const override;
0144     QString text(int i) const override;
0145     QPixmap pixmap(int) const override;
0146     TreeMapItemList* children() override;
0147     QColor backColor() const override;
0148 
0149 private:
0150     TraceCall* _c;
0151     double _factor;
0152 };
0153 
0154 
0155 #endif