Commit 4c5cab8d authored by Josef Weidendorfer's avatar Josef Weidendorfer
Browse files

Add global option to hide C++ template parameters in symbols

This adds a toolbar button (+icon) and a menu item under "View".
When template parameters are hidden, you get the full symbol
by hovering over the active symbol name label. The later even
shows the structure of a C++ symbol.

Works both with KCachegrind and QCachegrind.

(done with the help of / partly by Michael Dengler)

svn path=/trunk/KDE/kdesdk/kcachegrind/; revision=1078313
parent d6d0d262
......@@ -27,6 +27,7 @@
<Action name="view_percentage"/>
<Action name="view_expanded"/>
<Action name="view_cycles"/>
<Action name="hide_templates"/>
</Menu>
<Menu name="settings">
<Menu append="show_toolbar_merge"><text>Sidebars</text>
......@@ -48,6 +49,7 @@
<Action name="view_percentage"/>
<Action name="view_cycles"/>
<Action name="view_expanded"/>
<Action name="hide_templates"/>
</ToolBar>
<ToolBar name="stateToolBar" noMerge="1"><text>State Toolbar</text>
<Action name="view_cost_type"/>
......
......@@ -123,9 +123,11 @@ TopLevel::TopLevel()
_showPercentage = GlobalConfig::showPercentage();
_showExpanded = GlobalConfig::showExpanded();
_showCycles = GlobalConfig::showCycles();
_hideTemplates = GlobalConfig::hideTemplates();
_taPercentage->setChecked(_showPercentage);
_taExpanded->setChecked(_showExpanded);
_taCycles->setChecked(_showCycles);
_taHideTemplates->setChecked(_hideTemplates);
setupPartSelection(_partSelection);
......@@ -573,6 +575,20 @@ void TopLevel::createMiscActions()
"is the option to switch this off.</p>");
_taCycles->setWhatsThis( hint );
_taHideTemplates = actionCollection()->add<KToggleAction>("hide_templates");
_taHideTemplates->setIcon(KIcon("hidetemplates"));
_taHideTemplates->setText(i18n( "Shorten Templates" ));
connect(_taHideTemplates, SIGNAL(triggered(bool) ), SLOT( toggleHideTemplates() ));
_taHideTemplates->setToolTip(i18n( "Hide Template Parameters in C++ Symbols" ));
hint = i18n("<b>Hide Template Parameters in C++ Symbols</b>"
"<p>If this is switched on, every symbol displayed will have "
"any C++ template parameters hidden, just showing &lt;&gt; "
"instead of a potentially nested template parameter.</p>"
"<p>In this mode, you can hover the mouse pointer over the "
"activated symbol label to show a tooltip with the "
"unabbreviated symbol.</p>");
_taHideTemplates->setWhatsThis(hint);
KStandardAction::quit(this, SLOT(close()), actionCollection());
KStandardAction::preferences(this, SLOT(configure()), actionCollection());
KStandardAction::keyBindings(this, SLOT(configureKeys()), actionCollection());
......@@ -829,6 +845,19 @@ void TopLevel::toggleCycles()
updateViewsOnChange(TraceItemView::configChanged);
}
void TopLevel::toggleHideTemplates()
{
bool b = _taHideTemplates->isChecked();
if (_hideTemplates == b) return;
_hideTemplates = b;
GlobalConfig::setHideTemplates(_hideTemplates);
_stackSelection->refresh();
updateViewsOnChange(TraceItemView::configChanged);
}
void TopLevel::partVisibilityChanged(bool v)
{
_partDockShown->setChecked(v);
......@@ -1859,6 +1888,7 @@ bool TopLevel::queryExit()
GlobalConfig::setShowPercentage(_showPercentage);
GlobalConfig::setShowExpanded(_showExpanded);
GlobalConfig::setShowCycles(_showCycles);
GlobalConfig::setHideTemplates(_hideTemplates);
GlobalConfig::config()->saveOptions();
saveCurrentState(QString::null); //krazy:exclude=nullstrassign for old broken gcc
......
......@@ -146,6 +146,7 @@ public slots:
void setRelativeCost();
void toggleExpanded();
void toggleCycles();
void toggleHideTemplates();
void forceTrace();
void forceTraceReload();
void forwardAboutToShow();
......@@ -240,7 +241,7 @@ private:
KSelectAction *_saCost, *_saCost2, *saGroup;
KToggleAction *_partDockShown, *_stackDockShown;
KToggleAction *_functionDockShown, *_dumpDockShown;
KToggleAction *_taPercentage, *_taExpanded, *_taCycles;
KToggleAction *_taPercentage, *_taExpanded, *_taCycles, *_taHideTemplates;
KToggleAction *_taDump, *_taSplit, *_taSplitDir;
KToolBarPopupAction *_paForward, *_paBack, *_paUp;
......@@ -278,7 +279,7 @@ private:
QProgressBar* _progressBar;
// toplevel configuration options
bool _showPercentage, _showExpanded, _showCycles;
bool _showPercentage, _showExpanded, _showCycles, _hideTemplates;
};
#endif
......@@ -68,6 +68,10 @@ QString CostItem::prettyName() const
return name();
}
QString CostItem::formattedName() const
{
return QString();
}
QString CostItem::fullName() const
{
......
......@@ -50,10 +50,15 @@ public:
virtual QString name() const;
/**
* Same as name, but sometimes nicer for humans :-)
* Similar to name, but prettyfied = more descriptive to humans
*/
virtual QString prettyName() const;
/**
* A HTMLified version of name, can return empty string
*/
virtual QString formattedName() const;
/**
* Returns text of all cost metrics
*/
......
......@@ -32,6 +32,7 @@
#define DEFAULT_SHOWPERCENTAGE true
#define DEFAULT_SHOWEXPANDED false
#define DEFAULT_SHOWCYCLES true
#define DEFAULT_HIDETEMPLATES false
#define DEFAULT_CYCLECUT 0.0
#define DEFAULT_PERCENTPRECISION 2
#define DEFAULT_MAXSYMBOLLENGTH 30
......@@ -157,6 +158,7 @@ GlobalConfig::GlobalConfig()
_showCycles = DEFAULT_SHOWCYCLES;
_cycleCut = DEFAULT_CYCLECUT;
_percentPrecision = DEFAULT_PERCENTPRECISION;
_hideTemplates = DEFAULT_HIDETEMPLATES;
// max symbol count/length in tooltip/popup
_maxSymbolLength = DEFAULT_MAXSYMBOLLENGTH;
......@@ -238,6 +240,8 @@ void GlobalConfig::saveOptions()
DEFAULT_CONTEXT);
generalConfig->setValue("NoCostInside", _noCostInside,
DEFAULT_NOCOSTINSIDE);
generalConfig->setValue("HideTemplates", _hideTemplates,
DEFAULT_HIDETEMPLATES);
delete generalConfig;
// event types
......@@ -332,6 +336,8 @@ void GlobalConfig::readOptions()
DEFAULT_CONTEXT).toInt();
_noCostInside = generalConfig->value("NoCostInside",
DEFAULT_NOCOSTINSIDE).toInt();
_hideTemplates = generalConfig->value("HideTemplates",
DEFAULT_HIDETEMPLATES).toBool();
delete generalConfig;
// event types
......@@ -489,6 +495,11 @@ bool GlobalConfig::showCycles()
return config()->_showCycles;
}
bool GlobalConfig::hideTemplates()
{
return config()->_hideTemplates;
}
void GlobalConfig::setShowPercentage(bool s)
{
GlobalConfig* c = config();
......@@ -513,6 +524,14 @@ void GlobalConfig::setShowCycles(bool s)
c->_showCycles = s;
}
void GlobalConfig::setHideTemplates(bool s)
{
GlobalConfig* c = config();
if (c->_hideTemplates == s) return;
c->_hideTemplates = s;
}
double GlobalConfig::cycleCut()
{
return config()->_cycleCut;
......
......@@ -94,6 +94,7 @@ public:
static bool showPercentage();
static bool showExpanded();
static bool showCycles();
static bool hideTemplates();
// lower percentage limit of cost items filled into lists
static int percentPrecision();
......@@ -125,6 +126,8 @@ public:
static void setShowExpanded(bool);
static void setShowCycles(bool);
static void setHideTemplates(bool);
// upper limit for cutting of a call in cycle detection
static double cycleCut();
......@@ -141,7 +144,7 @@ protected:
QStringList _generalSourceDirs;
QHash<QString, QStringList> _objectSourceDirs;
bool _showPercentage, _showExpanded, _showCycles;
bool _showPercentage, _showExpanded, _showCycles, _hideTemplates;
double _cycleCut;
int _percentPrecision;
int _maxSymbolLength, _maxSymbolCount, _maxListCount;
......
......@@ -2011,6 +2011,25 @@ QString TraceFunction::prettyName() const
if (_name.isEmpty())
return prettyEmptyName();
if (GlobalConfig::hideTemplates()) {
res = QString();
int d = 0;
for(int i=0;i<_name.length();i++) {
switch(_name[i].toAscii()) {
case '<':
if (d<=0) res.append(_name[i]);
d++;
break;
case '>':
d--;
// fall trough
default:
if (d<=0) res.append(_name[i]);
break;
}
}
}
#if 0
// TODO: make it a configuration, but disabled by default.
//
......@@ -2042,6 +2061,46 @@ QString TraceFunction::prettyName() const
return res;
}
QString TraceFunction::formattedName() const
{
// produce a "rich" name only if templates are hidden
if (!GlobalConfig::hideTemplates() || _name.isEmpty()) return QString();
// bold, but inside template parameters normal, function arguments italic
QString rich("<b>");
int d = 0;
for(int i=0;i<_name.length();i++) {
switch(_name[i].toAscii()) {
case '&':
rich.append("&amp;");
break;
case '<':
d++;
rich.append("&lt;");
if (d==1)
rich.append("</b>");
break;
case '>':
d--;
if (d==0)
rich.append("<b>");
rich.append("&gt; "); // add space to allow for line break
break;
case '(':
rich.append("</b>(<i><b>");
break;
case ')':
rich.append("</b></i>)<b>");
break;
default:
rich.append(_name[i]);
break;
}
}
rich.append("</b>");
return rich;
}
QString TraceFunction::prettyEmptyName()
{
return QObject::tr("(unknown)");
......
......@@ -1184,6 +1184,7 @@ class TraceFunction: public TraceCostItem
QString location(int maxFiles = 0) const;
QString prettyName() const;
QString formattedName() const;
static QString prettyEmptyName();
QString prettyLocation(int maxFiles = 0) const;
QString prettyNameWithLocation(int maxFiles = 1) const;
......
......@@ -38,6 +38,7 @@
#include <QMenu>
#include "config.h"
#include "globalconfig.h"
#include "eventtypeview.h"
#include "partview.h"
#include "callview.h"
......@@ -422,6 +423,8 @@ void TabView::updateNameLabel(QString n)
_nameLabel->setText(_nameLabelText);
_nameLabel->setToolTip(QString());
}
if (!_nameLabelTooltip.isEmpty())
_nameLabel->setToolTip(_nameLabelTooltip);
}
void TabView::setData(TraceData* d)
......@@ -720,9 +723,16 @@ void TabView::doUpdate(int changeType, bool force)
configChanged |
dataChanged))
{
updateNameLabel( !_data ? tr("(No profile data file loaded)") :
!_activeItem ? tr("(No function selected)") :
_activeItem->prettyName() );
if (_data && _activeItem) {
_nameLabelTooltip = _activeItem->formattedName();
updateNameLabel(_activeItem->prettyName());
}
else {
_nameLabelTooltip = QString();
updateNameLabel( !_data ?
tr("(No profile data file loaded)") :
tr("(No function selected)"));
}
}
bool canShow;
......
......@@ -172,7 +172,7 @@ private:
bool _isCollapsed;
QLabel* _nameLabel;
QString _nameLabelText;
QString _nameLabelText, _nameLabelTooltip;
int _textWidth;
QSplitter *_mainSplitter, *_leftSplitter, *_bottomSplitter;
......
......@@ -2,6 +2,7 @@
<qresource>
<file alias="percent.png">../pics/hicolor/hi32-action-percent.png</file>
<file alias="move.png">../pics/hicolor/hi22-action-move.png</file>
<file alias="hidetemplates.png">../pics/hicolor/hi22-action-hidetemplates.png</file>
<file alias="app.png">../kcachegrind/hi48-app-kcachegrind.png</file>
</qresource>
</RCC>
......@@ -418,6 +418,23 @@ void QCGTopLevel::createActions()
this, SLOT(togglePercentage()));
_percentageToggleAction->setChecked(GlobalConfig::showPercentage());
_hideTemplatesToggleAction = new QAction(QIcon(":/hidetemplates.png"),
tr("Shorten Templates"), this);
_hideTemplatesToggleAction->setCheckable(true);
_hideTemplatesToggleAction->setStatusTip(tr("Hide Template Parameters "
"in C++ Symbols"));
connect(_hideTemplatesToggleAction, SIGNAL(triggered(bool)),
this, SLOT(toggleHideTemplates()));
_hideTemplatesToggleAction->setChecked(GlobalConfig::hideTemplates());
hint = tr("<b>Hide Template Parameters in C++ Symbols</b>"
"<p>If this is switched on, every symbol displayed will have "
"any C++ template parameters hidden, just showing &lt;&gt; "
"instead of a potentially nested template parameter.</p>"
"<p>In this mode, you can hover the mouse pointer over the "
"activated symbol label to show a tooltip with the "
"unabbreviated symbol.</p>");
_hideTemplatesToggleAction->setWhatsThis(hint);
_expandedToggleAction = new QAction(QIcon(":/move.png"),
tr("Relative to Parent"), this);
_expandedToggleAction->setCheckable(true);
......@@ -578,6 +595,7 @@ void QCGTopLevel::createMenu()
viewMenu->addAction(_cyclesToggleAction);
viewMenu->addAction(_percentageToggleAction);
viewMenu->addAction(_expandedToggleAction);
viewMenu->addAction(_hideTemplatesToggleAction);
viewMenu->addSeparator();
viewMenu->addAction(_splittedToggleAction);
viewMenu->addAction(_splitDirectionToggleAction);
......@@ -612,6 +630,7 @@ void QCGTopLevel::createToolbar()
tb->addAction(_cyclesToggleAction);
tb->addAction(_percentageToggleAction);
tb->addAction(_expandedToggleAction);
tb->addAction(_hideTemplatesToggleAction);
tb->addSeparator();
tb->addAction(_backAction);
......@@ -686,6 +705,7 @@ void QCGTopLevel::togglePercentage()
setPercentage(_percentageToggleAction->isChecked());
}
void QCGTopLevel::setAbsoluteCost()
{
setPercentage(false);
......@@ -710,6 +730,18 @@ void QCGTopLevel::setPercentage(bool show)
_multiView->notifyChange(TraceItemView::configChanged);
}
void QCGTopLevel::toggleHideTemplates()
{
bool show = _hideTemplatesToggleAction->isChecked();
if (GlobalConfig::hideTemplates() == show) return;
GlobalConfig::setHideTemplates(show);
_partSelection->notifyChange(TraceItemView::configChanged);
_stackSelection->refresh();
_functionSelection->notifyChange(TraceItemView::configChanged);
_multiView->notifyChange(TraceItemView::configChanged);
}
void QCGTopLevel::toggleExpanded()
{
bool show = _expandedToggleAction->isChecked();
......
......@@ -122,6 +122,7 @@ public slots:
void setPercentage(bool);
void setAbsoluteCost();
void setRelativeCost();
void toggleHideTemplates();
void toggleExpanded();
void toggleCycles();
void forceTrace();
......@@ -219,7 +220,7 @@ private:
QAction *_exportAction, *_dumpToggleAction, *_exitAction;
QAction *_sidebarMenuAction, *_recentFilesMenuAction;
QAction *_cyclesToggleAction, *_percentageToggleAction;
QAction *_expandedToggleAction;
QAction *_expandedToggleAction, *_hideTemplatesToggleAction;
QAction *_splittedToggleAction, *_splitDirectionToggleAction;
QAction *_layoutNext, *_layoutPrev, *_layoutRemove, *_layoutDup;
QAction *_layoutRestore, *_layoutSave;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment