File: traceitemview.h

package info (click to toggle)
kcachegrind 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 9,964 kB
  • sloc: cpp: 32,149; xml: 403; perl: 325; python: 235; sh: 8; makefile: 6
file content (226 lines) | stat: -rw-r--r-- 7,667 bytes parent folder | download | duplicates (2)
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
/*
    This file is part of KCachegrind.

    SPDX-FileCopyrightText: 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

    SPDX-License-Identifier: GPL-2.0-only
*/

/*
 * Trace Item View
 */

#ifndef TRACEITEMVIEW_H
#define TRACEITEMVIEW_H

#include <QTimer>

#include "tracedata.h"

class QWidget;
class QMenu;

class TopLevelBase;
class TraceItemView;

/* Helper class for TraceItemView for merging update requests.
 *
 * This can not be directly done in TraceItemView which can not have slots,
 * as this would need TraceItemView to be inherited from QObject. However,
 * we want subclasses of TraceItemView to also inherit from QWidget, and
 * multiple inheritance of a QObject is impossible
 */
class TraceItemViewUpdateTimer: public QTimer
{
    Q_OBJECT

public:
    explicit TraceItemViewUpdateTimer(TraceItemView* view);

private Q_SLOTS:
    void timeoutTriggered();

private:
    TraceItemView* _view;
};


/**
 * Abstract Base Class for KCachegrind Views
 *
 * This class delivers the shared functionality of all KCachegrind
 * Views for one ProfileCost (like Function, Object...), the "active"
 * item. Additional view attributes are current primary cost type,
 * an optional secondary cost type, group type,
 * and possibly a selected costitem in this view.
 * Note that there is a difference in changing the selected item of
 * a view (this usually changes selection in other views, too), and
 * activating that item.
 */
class TraceItemView
{
    friend class TraceItemViewUpdateTimer;

public:

    /**
     * Change type for update functions
     * - @c dataChanged is used if e.g. cycles are recalculated
     */
    enum { nothingChanged      = 0,
           eventTypeChanged    = 1,
           eventType2Changed   = 2,
           groupTypeChanged    = 4,
           partsChanged        = 8,
           activeItemChanged   = 16,
           selectedItemChanged = 32,
           dataChanged         = 64,
           configChanged       = 128 };

    enum Direction { None, Back, Forward, Up };

    // a TraceItemView can have a position in a parent container
    enum Position { Hidden, Top, Right, Left, Bottom };

    explicit TraceItemView(TraceItemView* parentView, TopLevelBase* top = nullptr);
    virtual ~TraceItemView();

    virtual QString whatsThis() const;

    // visualization layout and options (uses ConfigStorage)
    virtual void saveLayout(const QString& prefix, const QString& postfix);
    virtual void restoreLayout(const QString& prefix, const QString& postfix);
    virtual void saveOptions(const QString& prefix, const QString& postfix);
    virtual void restoreOptions(const QString& prefix, const QString& postfix);

    // Immediate remove all references to old data, and set the new.
    // This resets the visualization state.
    // A GUI update has to be triggered with updateView().
    // Overwrite in container views to also set new data for all members.
    virtual void setData(TraceData* d);

    // modify visualization state, updates automatically
    void setEventType(EventType* t) { _newEventType = t; updateView(); }
    void setEventType2(EventType* t) { _newEventType2 = t; updateView(); }
    void set(ProfileContext::Type g) { _newGroupType = g; updateView(); }
    void set(const TracePartList& l) { _newPartList = l; updateView(); }
    // returns false if nothing can be shown for this trace item
    bool activate(CostItem* i);
    void select(CostItem* i);
    void notifyChange(int changeType) { _status |= changeType; updateView(); }
    // all in one
    bool set(int, TraceData*, EventType*, EventType*,
             ProfileContext::Type, const TracePartList&,
             CostItem*, CostItem*);

    // if mergeUpdates is true (default), calls to updateView do not
    // directly trigger an update of the view
    void setMergeUpdates(bool b) { _mergeUpdates = b; }

    // general update request, call if view is/gets visible
    // force: update immediately even if invisible and no change was detected
    void updateView(bool force = false);

    /**
     * Notification from child views.
     * Default implementation notifies parent
     */
    virtual void selected(TraceItemView* sender, CostItem*);
    virtual void partsSelected(TraceItemView* sender, const TracePartList&);
    virtual void directionActivated(TraceItemView* sender, Direction);
    virtual void selectedEventType(TraceItemView* sender, EventType*);
    virtual void selectedEventType2(TraceItemView* sender, EventType*);
    virtual void activated(TraceItemView* sender, CostItem*);
    virtual void selectedGroupType(TraceItemView* sender, ProfileContext::Type);

    // getters...
    // always get the newest values
    TraceData* data() const { return _newData; }
    CostItem* activeItem() const { return _newActiveItem; }
    CostItem* selectedItem() const { return _newSelectedItem; }
    EventType* eventType() const { return _newEventType; }
    EventType* eventType2() const { return _newEventType2; }
    ProfileContext::Type groupType() const { return _newGroupType; }
    const TracePartList& partList() const { return _newPartList; }

    TraceFunction* activeFunction();
    int status() const { return _status; }

    // pointer to top level window to e.g. show status messages
    void setTopLevel(TopLevelBase* t) { _topLevel = t; }
    TopLevelBase* topLevel() const { return _topLevel; }

    void setPosition(Position p) { _pos = p; }
    Position position() const { return _pos; }

    void setTitle(QString t) { _title = t; }
    QString title() const { return _title; }

    // We depend on derived class to be a widget.
    // Force overriding by making this abstract.
    virtual QWidget* widget() = 0;

    /**
     * Called when a new item is about to become active.
     * Itemviews should reimplement this to notify that a
     * given item cannot be shown (return 0) or should be
     * redirected to another item to be shown as active.
     *
     * Use the methods like data() instead of _data here, as
     * _data possibly will give old/wrong information.
     */
    virtual CostItem* canShow(CostItem* i) { return i; }

    /* convenience functions for often used context menu items */
    void addEventTypeMenu(QMenu*,bool withCost2 = true);
    void addGoMenu(QMenu*);

protected:
    // helpers to call selected()/activated() of parentView
    void selected(CostItem*);
    void partsSelected(const TracePartList&);
    void activated(CostItem*);
    void selectedEventType(EventType*);
    void selectedEventType2(EventType*);
    void selectedGroupType(ProfileContext::Type);
    void directionActivated(TraceItemView::Direction);

    /* Is this view visible?
     * if not, doUpdate() will not be called by updateView()
     */
    virtual bool isViewVisible();

    // update handler (to be reimplemented)
    virtual void doUpdate(int changeType, bool force);

    TraceItemView* _parentView;
    TopLevelBase* _topLevel;

    TraceData* _data;
    TracePartList _partList;
    CostItem *_activeItem, *_selectedItem;
    EventType *_eventType, *_eventType2;
    ProfileContext::Type _groupType;

private:
    /* Multiple update requests via updateView() are merged, and result in one
     * call to triggerUpdate() after a timeout (using TraceItemViewUpdateTimer)
     */
    void triggerUpdate(bool force);

    TraceData* _newData;
    TracePartList _newPartList;
    CostItem *_newActiveItem, *_newSelectedItem;
    EventType *_newEventType, *_newEventType2;
    ProfileContext::Type _newGroupType;
    TraceItemViewUpdateTimer* _updateTimer;

    QString _title;
    int _status;
    bool _mergeUpdates, _needsUpdate;
    Position _pos;
};



#endif