forked from qt-creator/qt-creator
analyzer: add a button to shorten names of function templates
Task-number: QTCREATORBUG-7746 Change-Id: I5ba6c5b63c319d7b65239c6b730c0da90ef20c4f Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -67,6 +67,7 @@ public:
|
||||
, m_event(0)
|
||||
, m_verboseToolTips(true)
|
||||
, m_cycleDetection(false)
|
||||
, m_shortenTemplates(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -76,6 +77,7 @@ public:
|
||||
int m_event;
|
||||
bool m_verboseToolTips;
|
||||
bool m_cycleDetection;
|
||||
bool m_shortenTemplates;
|
||||
QVector<const Function *> m_functions;
|
||||
};
|
||||
|
||||
@@ -214,6 +216,23 @@ static QString noWrap(const QString &str)
|
||||
return escapedStr.replace(QLatin1Char('-'), "‑");
|
||||
}
|
||||
|
||||
static QString shortenTemplate(QString str)
|
||||
{
|
||||
int depth = 0;
|
||||
int j = 0;
|
||||
for (int i = 0, n = str.size(); i != n; ++i) {
|
||||
int c = str.at(i).unicode();
|
||||
if (c == '>')
|
||||
--depth;
|
||||
if (depth == 0)
|
||||
str[j++] = str.at(i);
|
||||
if (c == '<')
|
||||
++depth;
|
||||
}
|
||||
str.truncate(j);
|
||||
return str;
|
||||
}
|
||||
|
||||
QVariant DataModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
//QTC_ASSERT(index.isValid() && index.model() == this, return QVariant());
|
||||
@@ -224,7 +243,7 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (index.column() == NameColumn)
|
||||
return func->name();
|
||||
return d->m_shortenTemplates ? shortenTemplate(func->name()) : func->name();
|
||||
if (index.column() == LocationColumn)
|
||||
return func->location();
|
||||
if (index.column() == CalledColumn)
|
||||
@@ -368,5 +387,13 @@ void DataModel::enableCycleDetection(bool enabled)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void DataModel::setShortenTemplates(bool enabled)
|
||||
{
|
||||
beginResetModel();
|
||||
d->m_shortenTemplates = enabled;
|
||||
d->updateFunctions();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
} // namespace Valgrind
|
||||
} // namespace Callgrind
|
||||
|
@@ -87,6 +87,7 @@ public:
|
||||
public slots:
|
||||
/// enable/disable cycle detection
|
||||
void enableCycleDetection(bool enabled);
|
||||
void setShortenTemplates(bool enabled);
|
||||
|
||||
/// Only one cost event column will be shown, this decides which one it is.
|
||||
/// By default it is the first event in the @c ParseData, i.e. 0.
|
||||
|
@@ -134,6 +134,7 @@ public slots:
|
||||
void selectFunction(const Valgrind::Callgrind::Function *);
|
||||
void setCostFormat(Valgrind::Internal::CostDelegate::CostFormat format);
|
||||
void enableCycleDetection(bool enabled);
|
||||
void shortenTemplates(bool enabled);
|
||||
void setCostEvent(int index);
|
||||
|
||||
/// This function will add custom text marks to the editor
|
||||
@@ -196,6 +197,7 @@ public:
|
||||
QAction *m_costRelative;
|
||||
QAction *m_costRelativeToParent;
|
||||
QAction *m_cycleDetection;
|
||||
QAction *m_shortenTemplates;
|
||||
QComboBox *m_eventCombo;
|
||||
|
||||
QTimer *m_updateTimer;
|
||||
@@ -370,6 +372,11 @@ void CallgrindToolPrivate::enableCycleDetection(bool enabled)
|
||||
m_cycleDetection->setChecked(enabled);
|
||||
}
|
||||
|
||||
void CallgrindToolPrivate::shortenTemplates(bool enabled)
|
||||
{
|
||||
m_shortenTemplates->setChecked(enabled);
|
||||
}
|
||||
|
||||
// Following functions can be called with actions=0 or widgets=0
|
||||
// depending on initialization sequence (whether callgrind was current).
|
||||
CostDelegate::CostFormat CallgrindToolPrivate::costFormat() const
|
||||
@@ -763,7 +770,6 @@ QWidget *CallgrindToolPrivate::createWidgets()
|
||||
|
||||
// show costs as absolute numbers
|
||||
m_costAbsolute = new QAction(tr("Absolute Costs"), this);
|
||||
///FIXME: icon
|
||||
m_costAbsolute->setToolTip(tr("Show costs as absolute numbers."));
|
||||
m_costAbsolute->setCheckable(true);
|
||||
m_costAbsolute->setChecked(true);
|
||||
@@ -773,7 +779,6 @@ QWidget *CallgrindToolPrivate::createWidgets()
|
||||
|
||||
// show costs in percentages
|
||||
m_costRelative = new QAction(tr("Relative Costs"), this);
|
||||
///FIXME: icon (percentage sign?)
|
||||
m_costRelative->setToolTip(tr("Show costs relative to total inclusive cost."));
|
||||
m_costRelative->setCheckable(true);
|
||||
connect(m_costRelative, SIGNAL(toggled(bool)), SLOT(updateCostFormat()));
|
||||
@@ -782,7 +787,6 @@ QWidget *CallgrindToolPrivate::createWidgets()
|
||||
|
||||
// show costs relative to parent
|
||||
m_costRelativeToParent = new QAction(tr("Relative Costs to Parent"), this);
|
||||
///FIXME: icon
|
||||
m_costRelativeToParent->setToolTip(tr("Show costs relative to parent functions inclusive cost."));
|
||||
m_costRelativeToParent->setCheckable(true);
|
||||
connect(m_costRelativeToParent, SIGNAL(toggled(bool)), SLOT(updateCostFormat()));
|
||||
@@ -792,12 +796,14 @@ QWidget *CallgrindToolPrivate::createWidgets()
|
||||
QToolButton *button = new QToolButton;
|
||||
button->setMenu(menu);
|
||||
button->setPopupMode(QToolButton::InstantPopup);
|
||||
button->setText(tr("Cost Format"));
|
||||
button->setText(QLatin1String("$"));
|
||||
button->setToolTip(tr("Cost Format"));
|
||||
layout->addWidget(button);
|
||||
}
|
||||
|
||||
// cycle detection
|
||||
action = new QAction(tr("Cycle Detection"), this); ///FIXME: icon
|
||||
//action = new QAction(QLatin1String("Cycle Detection"), this); ///FIXME: icon
|
||||
action = new QAction(QLatin1String("O"), this); ///FIXME: icon
|
||||
action->setToolTip(tr("Enable cycle detection to properly handle recursive or circular function calls."));
|
||||
action->setCheckable(true);
|
||||
connect(action, SIGNAL(toggled(bool)), m_dataModel, SLOT(enableCycleDetection(bool)));
|
||||
@@ -805,6 +811,15 @@ QWidget *CallgrindToolPrivate::createWidgets()
|
||||
layout->addWidget(createToolButton(action));
|
||||
m_cycleDetection = action;
|
||||
|
||||
// shorter template signature
|
||||
action = new QAction(QLatin1String("<>"), this);
|
||||
action->setToolTip(tr("This removes template parameter lists when displaying function names."));
|
||||
action->setCheckable(true);
|
||||
connect(action, SIGNAL(toggled(bool)), m_dataModel, SLOT(setShortenTemplates(bool)));
|
||||
connect(action, SIGNAL(toggled(bool)), m_settings, SLOT(setShortenTemplates(bool)));
|
||||
layout->addWidget(createToolButton(action));
|
||||
m_shortenTemplates = action;
|
||||
|
||||
// filtering
|
||||
action = new QAction(tr("Show Project Costs Only"), this);
|
||||
action->setIcon(QIcon(Core::Constants::ICON_FILTER));
|
||||
|
@@ -43,29 +43,30 @@
|
||||
|
||||
using namespace Analyzer;
|
||||
|
||||
static const char numCallersC[] = "Analyzer.Valgrind.NumCallers";
|
||||
static const char trackOriginsC[] = "Analyzer.Valgrind.TrackOrigins";
|
||||
static const char suppressionFilesC[] = "Analyzer.Valgrind.SupressionFiles";
|
||||
static const char removedSuppressionFilesC[] = "Analyzer.Valgrind.RemovedSuppressionFiles";
|
||||
static const char addedSuppressionFilesC[] = "Analyzer.Valgrind.AddedSuppressionFiles";
|
||||
static const char filterExternalIssuesC[] = "Analyzer.Valgrind.FilterExternalIssues";
|
||||
static const char visibleErrorKindsC[] = "Analyzer.Valgrind.VisibleErrorKinds";
|
||||
const char numCallersC[] = "Analyzer.Valgrind.NumCallers";
|
||||
const char trackOriginsC[] = "Analyzer.Valgrind.TrackOrigins";
|
||||
const char suppressionFilesC[] = "Analyzer.Valgrind.SupressionFiles";
|
||||
const char removedSuppressionFilesC[] = "Analyzer.Valgrind.RemovedSuppressionFiles";
|
||||
const char addedSuppressionFilesC[] = "Analyzer.Valgrind.AddedSuppressionFiles";
|
||||
const char filterExternalIssuesC[] = "Analyzer.Valgrind.FilterExternalIssues";
|
||||
const char visibleErrorKindsC[] = "Analyzer.Valgrind.VisibleErrorKinds";
|
||||
|
||||
static const char lastSuppressionDirectoryC[] = "Analyzer.Valgrind.LastSuppressionDirectory";
|
||||
static const char lastSuppressionHistoryC[] = "Analyzer.Valgrind.LastSuppressionHistory";
|
||||
const char lastSuppressionDirectoryC[] = "Analyzer.Valgrind.LastSuppressionDirectory";
|
||||
const char lastSuppressionHistoryC[] = "Analyzer.Valgrind.LastSuppressionHistory";
|
||||
|
||||
static const char callgrindEnableCacheSimC[] = "Analyzer.Valgrind.Callgrind.EnableCacheSim";
|
||||
static const char callgrindEnableBranchSimC[] = "Analyzer.Valgrind.Callgrind.EnableBranchSim";
|
||||
static const char callgrindCollectSystimeC[] = "Analyzer.Valgrind.Callgrind.CollectSystime";
|
||||
static const char callgrindCollectBusEventsC[] = "Analyzer.Valgrind.Callgrind.CollectBusEvents";
|
||||
static const char callgrindEnableEventToolTipsC[] = "Analyzer.Valgrind.Callgrind.EnableEventToolTips";
|
||||
static const char callgrindMinimumCostRatioC[] = "Analyzer.Valgrind.Callgrind.MinimumCostRatio";
|
||||
static const char callgrindVisualisationMinimumCostRatioC[] = "Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio";
|
||||
const char callgrindEnableCacheSimC[] = "Analyzer.Valgrind.Callgrind.EnableCacheSim";
|
||||
const char callgrindEnableBranchSimC[] = "Analyzer.Valgrind.Callgrind.EnableBranchSim";
|
||||
const char callgrindCollectSystimeC[] = "Analyzer.Valgrind.Callgrind.CollectSystime";
|
||||
const char callgrindCollectBusEventsC[] = "Analyzer.Valgrind.Callgrind.CollectBusEvents";
|
||||
const char callgrindEnableEventToolTipsC[] = "Analyzer.Valgrind.Callgrind.EnableEventToolTips";
|
||||
const char callgrindMinimumCostRatioC[] = "Analyzer.Valgrind.Callgrind.MinimumCostRatio";
|
||||
const char callgrindVisualisationMinimumCostRatioC[] = "Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio";
|
||||
|
||||
static const char callgrindCycleDetectionC[] = "Analyzer.Valgrind.Callgrind.CycleDetection";
|
||||
static const char callgrindCostFormatC[] = "Analyzer.Valgrind.Callgrind.CostFormat";
|
||||
const char callgrindCycleDetectionC[] = "Analyzer.Valgrind.Callgrind.CycleDetection";
|
||||
const char callgrindShortenTemplates[] = "Analyzer.Valgrind.Callgrind.ShortenTemplates";
|
||||
const char callgrindCostFormatC[] = "Analyzer.Valgrind.Callgrind.CostFormat";
|
||||
|
||||
static const char valgrindExeC[] = "Analyzer.Valgrind.ValgrindExecutable";
|
||||
const char valgrindExeC[] = "Analyzer.Valgrind.ValgrindExecutable";
|
||||
|
||||
namespace Valgrind {
|
||||
namespace Internal {
|
||||
@@ -322,6 +323,7 @@ void ValgrindGlobalSettings::fromMap(const QVariantMap &map)
|
||||
if (map.contains(QLatin1String(callgrindCostFormatC)))
|
||||
m_costFormat = static_cast<CostDelegate::CostFormat>(map.value(QLatin1String(callgrindCostFormatC)).toInt());
|
||||
setIfPresent(map, QLatin1String(callgrindCycleDetectionC), &m_detectCycles);
|
||||
setIfPresent(map, QLatin1String(callgrindShortenTemplates), &m_shortenTemplates);
|
||||
}
|
||||
|
||||
QVariantMap ValgrindGlobalSettings::toMap() const
|
||||
@@ -336,6 +338,7 @@ QVariantMap ValgrindGlobalSettings::toMap() const
|
||||
// Callgrind
|
||||
map.insert(QLatin1String(callgrindCostFormatC), m_costFormat);
|
||||
map.insert(QLatin1String(callgrindCycleDetectionC), m_detectCycles);
|
||||
map.insert(QLatin1String(callgrindShortenTemplates), m_shortenTemplates);
|
||||
|
||||
return map;
|
||||
}
|
||||
@@ -401,9 +404,20 @@ bool ValgrindGlobalSettings::detectCycles() const
|
||||
return m_detectCycles;
|
||||
}
|
||||
|
||||
void ValgrindGlobalSettings::setDetectCycles(bool detect)
|
||||
void ValgrindGlobalSettings::setDetectCycles(bool on)
|
||||
{
|
||||
m_detectCycles = detect;
|
||||
m_detectCycles = on;
|
||||
AnalyzerGlobalSettings::instance()->writeSettings();
|
||||
}
|
||||
|
||||
bool ValgrindGlobalSettings::shortenTemplates() const
|
||||
{
|
||||
return m_shortenTemplates;
|
||||
}
|
||||
|
||||
void ValgrindGlobalSettings::setShortenTemplates(bool on)
|
||||
{
|
||||
m_shortenTemplates = on;
|
||||
AnalyzerGlobalSettings::instance()->writeSettings();
|
||||
}
|
||||
|
||||
|
@@ -202,17 +202,19 @@ private:
|
||||
* Global callgrind settings
|
||||
*/
|
||||
public:
|
||||
|
||||
CostDelegate::CostFormat costFormat() const;
|
||||
bool detectCycles() const;
|
||||
bool shortenTemplates() const;
|
||||
|
||||
public slots:
|
||||
void setCostFormat(Valgrind::Internal::CostDelegate::CostFormat format);
|
||||
void setDetectCycles(bool detect);
|
||||
void setDetectCycles(bool on);
|
||||
void setShortenTemplates(bool on);
|
||||
|
||||
private:
|
||||
CostDelegate::CostFormat m_costFormat;
|
||||
bool m_detectCycles;
|
||||
bool m_shortenTemplates;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user