summaryrefslogtreecommitdiffstats
path: root/kcachegrind/kcachegrind/traceitemview.h
blob: f83aa8969f0395a2a5d9484afe7e6898b3cc43c8 (plain)
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
/* This file is part of KCachegrind.
   Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/*
 * Trace Item View
 */

#ifndef TRACEITEMVIEW_H
#define TRACEITEMVIEW_H

#include "tracedata.h"

class TQWidget;
class TQPopupMenu;

class KConfig;
class KConfigGroup;
class KConfigBase;

class TopLevel;

/**
 * Abstract Base Class for KCachegrind Views
 *
 * This class delivers the shared functionality of all KCachegrind
 * Views for one TraceItem (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
{
public:

  /**
   * Change type for update functions
   * - <dataChanged> is used if e.g. cycles are recalculated
   */
  enum { nothingChanged      = 0,
	 costTypeChanged     = 1,
	 costType2Changed    = 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 };

  TraceItemView(TraceItemView* parentView, TopLevel* top = 0);
  virtual ~TraceItemView() {}

  virtual TQString whatsThis() const;

  static KConfigGroup* configGroup(KConfig*, TQString prefix, TQString postfix);
  static void writeConfigEntry(KConfigBase*, const char* pKey, TQString value,
                               const char* def, bool bNLS = false);
  static void writeConfigEntry(KConfigBase*, const char* pKey,
                               int value, int def);
  static void writeConfigEntry(KConfigBase*, const char* pKey,
                               bool value, bool def);
  static void writeConfigEntry(KConfigBase*, const char* pKey,
                               double value, double def);
  virtual void readViewConfig(KConfig*, TQString prefix, TQString postfix,
			      bool withOptions);
  virtual void saveViewConfig(KConfig*, TQString prefix, TQString postfix,
			      bool withOptions);

  // 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);

  // change from parent, call updateView() to update lazily (only if visible)
  void setCostType(TraceCostType* t) { _newCostType = t; }
  void setCostType2(TraceCostType* t) { _newCostType2 = t; }
  void set(TraceItem::CostType g) { _newGroupType = g; }
  void set(const TracePartList& l) { _newPartList = l; }
  // returns false if nothing can be shown for this trace item
  bool activate(TraceItem* i);
  void select(TraceItem* i);
  void notifyChange(int changeType) { _status |= changeType; }
  // all in one
  bool set(int, TraceData*, TraceCostType*, TraceCostType*,
	   TraceItem::CostType, const TracePartList&,
	   TraceItem*, TraceItem*);

  // general update request, call if view is/gets visible
  void updateView(bool force = false);

  /**
   * Notification from child views.
   * Default implementation notifies parent
   */
  virtual void selected(TraceItemView* sender, TraceItem*);
  virtual void selected(TraceItemView* sender, const TracePartList&);
  virtual void activated(TraceItemView* sender, Direction);
  virtual void selectedCostType(TraceItemView* sender, TraceCostType*);
  virtual void selectedCostType2(TraceItemView* sender, TraceCostType*);
  virtual void activated(TraceItemView* sender, TraceItem*);

  // getters...
  // always get the newest values
  TraceData* data() const { return _newData; }
  TraceItem* activeItem() const { return _newActiveItem; }
  TraceItem* selectedItem() const { return _newSelectedItem; }
  TraceCostType* costType() const { return _newCostType; }
  TraceCostType* costType2() const { return _newCostType2; }
  TraceItem::CostType 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(TopLevel* t) { _topLevel = t; }
  TopLevel* topLevel() const { return _topLevel; }

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

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

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

  /**
   * This function is called when a new item should become active.
   * Reimplement this in subclasses.
   *
   * Returns the real item to become active. You can call select() here.
   * Return 0 if nothing can be shown.
   * Use the methods like data() instead of _data here, as
   * _data possibly will give old/wrong information.
   */
  virtual TraceItem* canShow(TraceItem* i) { return i; }

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

protected:
  // helpers to call selected()/activated() of parentView
  void selected(TraceItem*);
  void selected(const TracePartList&);
  void activated(TraceItem*);
  void selectedCostType(TraceCostType*);
  void selectedCostType2(TraceCostType*);
  void activated(Direction);

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

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

  TraceItemView* _parentView;
  TopLevel* _topLevel;

  TraceData* _data;
  TracePartList _partList;
  TraceItem *_activeItem, *_selectedItem;
  TraceCostType *_costType, *_costType2;
  TraceItem::CostType _groupType;

private:
  TraceData* _newData;
  TracePartList _newPartList;
  TraceItem *_newActiveItem, *_newSelectedItem;
  TraceCostType *_newCostType, *_newCostType2;
  TraceItem::CostType _newGroupType;

  TQString _title;
  int _status;
  bool _inUpdate;
  Position _pos;
};

#endif