• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kcachegrind

  • sources
  • kde-4.12
  • kdesdk
  • kcachegrind
  • libviews
globalguiconfig.cpp
Go to the documentation of this file.
1 /* This file is part of KCachegrind.
2  Copyright (C) 2010 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
3 
4  KCachegrind is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation, version 2.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 /*
20  * Global configuration for GUI components of KCachegrind
21  */
22 
23 #include "globalguiconfig.h"
24 
25 #include "config.h"
26 
27 
28 //
29 // ConfigColorSettings
30 //
31 
32 ConfigColorSetting::ConfigColorSetting(QString n)
33 {
34  _name = n;
35  reset();
36 }
37 
38 ConfigColorSetting::ConfigColorSetting(QString n, QColor c)
39 {
40  _name = n;
41  setColor(c);
42 }
43 
44 void ConfigColorSetting::setColor(const QColor& c)
45 {
46  _color = c;
47  _automatic = (c == colorForName(_name));
48 }
49 
50 QColor ConfigColorSetting::colorForName(QString n)
51 {
52  int h = 0, s = 100;
53  foreach(const QChar c, n) {
54  h = (h * 37 + s* c.unicode()) % 256;
55  s = (s * 17 + h* c.unicode()) % 192;
56  }
57 
58  return QColor::fromHsv(h, 64+s, 192);
59 }
60 
61 QColor ConfigColorSetting::autoColor() const
62 {
63  return colorForName(_name);
64 }
65 
66 void ConfigColorSetting::reset()
67 {
68  _automatic = true;
69  _color = colorForName(_name);
70 }
71 
72 
73 //
74 // GlobalGUIConfig
75 //
76 
77 GlobalGUIConfig::GlobalGUIConfig()
78  : GlobalConfig()
79 {
80 }
81 
82 GlobalGUIConfig::~GlobalGUIConfig()
83 {
84  qDeleteAll(_colors);
85  _colors.clear();
86 }
87 
88 GlobalGUIConfig* GlobalGUIConfig::config()
89 {
90  GlobalGUIConfig* gc;
91 
92  if (_config == 0) {
93  gc = new GlobalGUIConfig();
94  _config = gc;
95  }
96  else {
97  gc = dynamic_cast<GlobalGUIConfig*>(_config);
98  if (gc == 0)
99  qFatal("Internal error: config object is not a GlobalGUIConfig.");
100  }
101 
102  return gc;
103 }
104 
105 void GlobalGUIConfig::saveOptions()
106 {
107  // color options
108  ConfigGroup* colorConfig = ConfigStorage::group("CostColors");
109  int count = 1;
110  foreach(ConfigColorSetting* cs, _colors) {
111  if ( !cs->_automatic ) {
112  colorConfig->setValue( QString("Name%1").arg(count),
113  cs->_name);
114  colorConfig->setValue( QString("Color%1").arg(count),
115  cs->_color);
116  count++;
117  }
118  }
119  colorConfig->setValue("Count", count-1);
120  delete colorConfig;
121 
122  GlobalConfig::saveOptions();
123 }
124 
125 void GlobalGUIConfig::readOptions()
126 {
127  int i, count;
128 
129  // color options
130  _colors.clear();
131  // colors for default event types:
132  // red for LL/L2 misses
133  colorSetting("EventType-I2mr")->_color = QColor(240, 0, 0);
134  colorSetting("EventType-D2mr")->_color = QColor(180,40,40);
135  colorSetting("EventType-D2mw")->_color = QColor(120,80,80);
136  colorSetting("EventType-ILmr")->_color = QColor(240, 0, 0);
137  colorSetting("EventType-DLmr")->_color = QColor(180,40,40);
138  colorSetting("EventType-DLmw")->_color = QColor(120,80,80);
139  // green for L1 misses
140  colorSetting("EventType-I1mr")->_color = QColor(0, 240, 0);
141  colorSetting("EventType-D1mr")->_color = QColor(40,180,40);
142  colorSetting("EventType-D1mw")->_color = QColor(80,120,80);
143  // yellow for branches/mispredictions
144  colorSetting("EventType-Bc") ->_color = QColor(240,240, 0);
145  colorSetting("EventType-Bcm")->_color = QColor(200,200,30);
146  colorSetting("EventType-Bi") ->_color = QColor(160,160,60);
147  colorSetting("EventType-Bim")->_color = QColor(120,120,90);
148  // blue for normal accesses
149  colorSetting("EventType-Ir")->_color = QColor(0, 0, 240);
150  colorSetting("EventType-Dr")->_color = QColor(40,40,180);
151  colorSetting("EventType-Dw")->_color = QColor(80,80,120);
152 
153  ConfigGroup* colorConfig = ConfigStorage::group("CostColors");
154  count = colorConfig->value("Count", 0).toInt();
155  for (i=1;i<=count;i++) {
156  QString n = colorConfig->value(QString("Name%1").arg(i),
157  QString()).toString();
158  QColor color = colorConfig->value<QColor>(QString("Color%1").arg(i),
159  QColor(Qt::black));
160 
161  if (n.isEmpty()) continue;
162 
163  ConfigColorSetting* cs = new ConfigColorSetting(n,color);
164  _colors.insert(n, cs);
165  }
166  delete colorConfig;
167 
168  GlobalConfig::readOptions();
169 }
170 
171 ConfigColorSetting* GlobalGUIConfig::groupColorSetting(CostItem* cost)
172 {
173  QString n;
174 
175  if (!cost)
176  return colorSetting(QString("default"));
177 
178  return groupColorSetting(cost->type(), cost->name());
179 }
180 
181 ConfigColorSetting* GlobalGUIConfig::groupColorSetting(ProfileContext::Type t,
182  QString name)
183 {
184  QString n = ProfileContext::typeName(t) + '-' + name;
185  return colorSetting(n);
186 }
187 
188 QColor GlobalGUIConfig::groupColor(CostItem* cost)
189 {
190  return groupColorSetting(cost)->color();
191 }
192 
193 QColor GlobalGUIConfig::eventTypeColor(EventType* t)
194 {
195  QString n;
196 
197  if (!t)
198  n = QString("EventType-default");
199  else
200  n = QString("EventType-%1").arg(t->name());
201 
202  return colorSetting(n)->color();
203 }
204 
205 QColor GlobalGUIConfig::functionColor(ProfileContext::Type gt,
206  TraceFunction* f)
207 {
208  ProfileCostArray* group = f;
209  QString n;
210 
211  switch(gt) {
212  case ProfileContext::Object: group = f->object(); break;
213  case ProfileContext::Class: group = f->cls(); break;
214  case ProfileContext::File: group = f->file(); break;
215  default:
216  break;
217  }
218 
219  if (group != f) {
220  // first look for manual color of a function in a group
221  n = ProfileContext::typeName(group->type()) +
222  '-' + group->name() +
223  '-' + f->name();
224 
225  ConfigColorSetting* cs = colorSetting(n, false);
226  if (cs) return cs->color();
227  }
228  return groupColor(group);
229 }
230 
231 ConfigColorSetting* GlobalGUIConfig::colorSetting(const QString& n,
232  bool createNew)
233 {
234  // predefined ?
235  GlobalGUIConfig* c = config();
236  ConfigColorSetting* cs = c->_colors.value(n, 0);
237  if (cs || !createNew) return cs;
238 
239  cs = new ConfigColorSetting(n);
240  c->_colors.insert(n, cs);
241 
242  return cs;
243 }
244 
GlobalGUIConfig::colorSetting
static ConfigColorSetting * colorSetting(const QString &, bool createNew=true)
Definition: globalguiconfig.cpp:231
ConfigColorSetting::colorForName
static QColor colorForName(QString)
Definition: globalguiconfig.cpp:50
GlobalConfig::readOptions
virtual void readOptions()
Definition: globalconfig.cpp:214
ProfileContext::File
Definition: context.h:48
ProfileContext::typeName
static QString typeName(Type)
Definition: context.cpp:62
GlobalGUIConfig::eventTypeColor
static QColor eventTypeColor(EventType *)
Definition: globalguiconfig.cpp:193
CostItem::type
ProfileContext::Type type() const
Definition: costitem.h:45
GlobalGUIConfig::functionColor
static QColor functionColor(ProfileContext::Type gt, TraceFunction *)
Definition: globalguiconfig.cpp:205
TraceFunction
A traced function.
Definition: tracedata.h:1122
TraceFunction::object
TraceObject * object() const
Definition: tracedata.h:1164
ConfigGroup::setValue
virtual void setValue(const QString &key, const QVariant &value, const QVariant &defaultValue=QVariant())
Definition: config.cpp:57
CostItem
Base class for cost items.
Definition: costitem.h:37
config.h
GlobalGUIConfig::GlobalGUIConfig
GlobalGUIConfig()
Definition: globalguiconfig.cpp:77
EventType
A cost type, e.g.
Definition: eventtype.h:43
ProfileContext::Class
Definition: context.h:47
ConfigStorage::group
static ConfigGroup * group(const QString &group, const QString &optSuffix=QString())
Definition: config.cpp:80
TraceFunction::cls
TraceClass * cls() const
Definition: tracedata.h:1162
GlobalGUIConfig::groupColor
static QColor groupColor(CostItem *)
Definition: globalguiconfig.cpp:188
GlobalGUIConfig::groupColorSetting
static ConfigColorSetting * groupColorSetting(CostItem *)
Definition: globalguiconfig.cpp:171
ProfileCostArray
An array of basic cost metrics for a trace item.
Definition: costitem.h:144
CostItem::name
virtual QString name() const
Returns dynamic name info (without type)
Definition: costitem.cpp:53
GlobalGUIConfig
Extension of global configuration for GUI options.
Definition: globalguiconfig.h:71
GlobalGUIConfig::readOptions
void readOptions()
Definition: globalguiconfig.cpp:125
GlobalConfig::_config
static GlobalConfig * _config
Definition: globalconfig.h:108
TraceCostItem::name
virtual QString name() const
Returns dynamic name info (without type)
Definition: tracedata.h:986
globalguiconfig.h
ConfigGroup
A group of configuration settings.
Definition: config.h:35
TraceFunction::file
TraceFile * file() const
Definition: tracedata.h:1163
GlobalGUIConfig::config
static GlobalGUIConfig * config()
Definition: globalguiconfig.cpp:88
ConfigColorSetting::setColor
void setColor(const QColor &)
Definition: globalguiconfig.cpp:44
ConfigColorSetting::color
QColor color() const
Definition: globalguiconfig.h:45
GlobalConfig
Global configuration (only non-GUI options).
Definition: globalconfig.h:37
ProfileContext::Type
Type
Definition: context.h:36
ConfigColorSetting
Color setting for a cost item Helper class for color settings in configuration.
Definition: globalguiconfig.h:39
GlobalGUIConfig::saveOptions
void saveOptions()
Definition: globalguiconfig.cpp:105
ConfigColorSetting::reset
void reset()
Definition: globalguiconfig.cpp:66
GlobalConfig::saveOptions
virtual void saveOptions()
Definition: globalconfig.cpp:154
GlobalGUIConfig::_colors
QHash< QString, ConfigColorSetting * > _colors
Definition: globalguiconfig.h:94
ProfileContext::Object
Definition: context.h:49
GlobalGUIConfig::~GlobalGUIConfig
~GlobalGUIConfig()
Definition: globalguiconfig.cpp:82
EventType::name
const QString & name()
Definition: eventtype.h:65
ConfigColorSetting::autoColor
QColor autoColor() const
Definition: globalguiconfig.cpp:61
ConfigGroup::value
virtual QVariant value(const QString &key, const QVariant &defaultValue) const
Definition: config.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kcachegrind

Skip menu "kcachegrind"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal