Commit 98c11649 authored by hjk's avatar hjk Committed by hjk
Browse files

valgrind: code cosmetics

Change-Id: I695c7d40aeb0b0b1e6f8cc0856e5fa5d9d1ce2d1
Reviewed-on: http://codereview.qt.nokia.com/1600

Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 0c0ffab1
QT *= network
INCLUDEPATH *= $$PWD
HEADERS += \
$$PWD/callgrindparser.h \
$$PWD/callgrindparsedata.h \
$$PWD/callgrindfunction.h \
$$PWD/callgrindfunction_p.h \
$$PWD/callgrindfunctioncycle.h \
$$PWD/callgrindfunctioncall.h \
$$PWD/callgrindcostitem.h \
$$PWD/callgrinddatamodel.h \
$$PWD/callgrindabstractmodel.h \
$$PWD/callgrindcallmodel.h \
$$PWD/callgrindcontroller.h \
$$PWD/callgrindcycledetection.h \
$$PWD/callgrindproxymodel.h \
$$PWD/callgrindstackbrowser.h \
$$PWD/callgrindrunner.h
SOURCES += \
$$PWD/callgrindparser.cpp \
$$PWD/callgrindparsedata.cpp \
$$PWD/callgrindfunction.cpp \
$$PWD/callgrindfunctioncycle.cpp \
$$PWD/callgrindfunctioncall.cpp \
$$PWD/callgrindcostitem.cpp \
$$PWD/callgrinddatamodel.cpp \
$$PWD/callgrindcallmodel.cpp \
$$PWD/callgrindcontroller.cpp \
$$PWD/callgrindcycledetection.cpp \
$$PWD/callgrindproxymodel.cpp \
$$PWD/callgrindrunner.cpp \
$$PWD/callgrindstackbrowser.cpp
......@@ -35,8 +35,8 @@
#include "callgrindcostview.h"
#include "callgrindhelper.h"
#include <valgrind/callgrind/callgrindabstractmodel.h>
#include <valgrind/callgrind/callgrindparsedata.h>
#include "callgrind/callgrindabstractmodel.h"
#include "callgrind/callgrindparsedata.h"
#include <utils/qtcassert.h>
......@@ -56,7 +56,6 @@ public:
QAbstractItemModel *m_model;
CostDelegate::CostFormat m_format;
static int toNativeRole(CostFormat format);
float relativeCost(const QModelIndex &index) const;
QString displayText(const QModelIndex &index, const QLocale &locale) const;
};
......@@ -66,15 +65,15 @@ CostDelegate::Private::Private()
, m_format(CostDelegate::FormatAbsolute)
{}
int CostDelegate::Private::toNativeRole(CostDelegate::CostFormat format)
static int toNativeRole(CostDelegate::CostFormat format)
{
switch (format)
{
case FormatAbsolute:
case FormatRelative:
return Valgrind::Callgrind::RelativeTotalCostRole;
case FormatRelativeToParent:
return Valgrind::Callgrind::RelativeParentCostRole;
case CostDelegate::FormatAbsolute:
case CostDelegate::FormatRelative:
return Callgrind::RelativeTotalCostRole;
case CostDelegate::FormatRelativeToParent:
return Callgrind::RelativeParentCostRole;
default:
return -1;
}
......@@ -103,14 +102,10 @@ QString CostDelegate::Private::displayText(const QModelIndex &index, const QLoca
return QString();
}
//END CostDelegate::Private
//BEGIN CostDelegate
CostDelegate::CostDelegate(QObject *parent)
: QStyledItemDelegate(parent)
, d(new Private)
: QStyledItemDelegate(parent), d(new Private)
{
}
CostDelegate::~CostDelegate()
......@@ -136,19 +131,18 @@ CostDelegate::CostFormat CostDelegate::format() const
void CostDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
// init
QStyleOptionViewItemV4 opt(option);
initStyleOption(&opt, index);
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
// draw controls, but no text
// Draw controls, but no text.
opt.text.clear();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
painter->save();
// draw bar
// Draw bar.
float ratio = qBound(0.0f, d->relativeCost(index), 1.0f);
QRect barRect = opt.rect;
barRect.setWidth(opt.rect.width() * ratio);
......@@ -156,7 +150,7 @@ void CostDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
painter->setBrush(CallgrindHelper::colorForCostRatio(ratio));
painter->drawRect(barRect);
// draw text
// Draw text.
const QString text = d->displayText(index, opt.locale);
const QBrush &textBrush = (option.state & QStyle::State_Selected ? opt.palette.highlightedText() : opt.palette.text());
painter->setBrush(Qt::NoBrush);
......
......@@ -43,11 +43,6 @@ namespace Internal {
NameDelegate::NameDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
NameDelegate::~NameDelegate()
{
}
void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
......
......@@ -40,14 +40,11 @@ namespace Internal {
class NameDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit NameDelegate(QObject *parent = 0);
virtual ~NameDelegate();
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
};
} // namespace Internal
......
......@@ -34,8 +34,8 @@
#include "callgrindhelper.h"
#include <valgrind/callgrind/callgrinddatamodel.h>
#include <valgrind/callgrind/callgrindfunction.h>
#include "callgrind/callgrinddatamodel.h"
#include "callgrind/callgrindfunction.h"
#include <QtCore/QDebug>
#include <QtGui/QPainter>
......
......@@ -160,8 +160,7 @@ QRectF FunctionGraphicsTextItem::boundingRect() const
}
FunctionGraphicsItem::FunctionGraphicsItem(const QString &text,
qreal x, qreal y, qreal width,
qreal height, QGraphicsItem *parent)
qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent)
: QGraphicsRectItem(x, y, width, height, parent)
, m_text(0)
{
......@@ -180,8 +179,7 @@ FunctionGraphicsTextItem *FunctionGraphicsItem::textItem() const
}
void FunctionGraphicsItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *)
const QStyleOptionGraphicsItem *option, QWidget *)
{
painter->save();
......
......@@ -77,11 +77,10 @@ signals:
protected slots:
void populateScene();
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
protected:
virtual void resizeEvent(QResizeEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void resizeEvent(QResizeEvent *event);
private:
class Private;
......
QT *= network
INCLUDEPATH *= $$PWD
HEADERS += \
$$PWD/memcheckrunner.h
SOURCES += \
$$PWD/memcheckrunner.cpp
......@@ -62,7 +62,7 @@ MemcheckEngine::MemcheckEngine(IAnalyzerTool *tool, const AnalyzerStartParameter
connect(&m_parser, SIGNAL(status(Valgrind::XmlProtocol::Status)),
SLOT(status(Valgrind::XmlProtocol::Status)));
m_progress->setProgressRange(0, Valgrind::XmlProtocol::Status::Finished + 1);
m_progress->setProgressRange(0, XmlProtocol::Status::Finished + 1);
}
QString MemcheckEngine::progressTitle() const
......
......@@ -37,8 +37,8 @@
#include "valgrindengine.h"
#include <valgrind/memcheck/memcheckrunner.h>
#include <valgrind/xmlprotocol/threadedparser.h>
#include "memcheck/memcheckrunner.h"
#include "xmlprotocol/threadedparser.h"
namespace Valgrind {
namespace Internal {
......@@ -64,15 +64,15 @@ signals:
protected:
virtual QString progressTitle() const;
virtual QStringList toolArguments() const;
virtual Valgrind::ValgrindRunner *runner();
virtual ValgrindRunner *runner();
private slots:
void receiveLogMessage(const QByteArray &);
void status(const Valgrind::XmlProtocol::Status &status);
private:
Valgrind::XmlProtocol::ThreadedParser m_parser;
Valgrind::Memcheck::MemcheckRunner m_runner;
XmlProtocol::ThreadedParser m_parser;
Memcheck::MemcheckRunner m_runner;
};
} // namespace Internal
......
......@@ -37,12 +37,12 @@
#include "suppressiondialog.h"
#include "valgrindsettings.h"
#include <valgrind/xmlprotocol/error.h>
#include <valgrind/xmlprotocol/errorlistmodel.h>
#include <valgrind/xmlprotocol/frame.h>
#include <valgrind/xmlprotocol/stack.h>
#include <valgrind/xmlprotocol/modelhelpers.h>
#include <valgrind/xmlprotocol/suppression.h>
#include "xmlprotocol/error.h"
#include "xmlprotocol/errorlistmodel.h"
#include "xmlprotocol/frame.h"
#include "xmlprotocol/stack.h"
#include "xmlprotocol/modelhelpers.h"
#include "xmlprotocol/suppression.h"
#include <texteditor/basetexteditor.h>
......@@ -103,7 +103,7 @@ QSize MemcheckErrorDelegate::sizeHint(const QStyleOptionViewItem &opt, const QMo
m_detailsWidget->setParent(view->viewport()));
m_detailsIndex = index;
} else {
QTC_ASSERT(m_detailsIndex == index, qt_noop());
QTC_ASSERT(m_detailsIndex == index, /**/);
}
const int widthExcludingMargins = viewportWidth - 2 * s_itemMargin;
m_detailsWidget->setFixedWidth(widthExcludingMargins);
......@@ -230,7 +230,7 @@ QWidget *MemcheckErrorDelegate::createDetailsWidget(const QModelIndex &errorInde
int frameNr = 1;
foreach (const Frame &frame, stack.frames()) {
QString frameName = makeFrameName(frame, relativeTo);
QTC_ASSERT(!frameName.isEmpty(), qt_noop());
QTC_ASSERT(!frameName.isEmpty(), /**/);
QLabel *frameLabel = new QLabel(widget);
frameLabel->setAutoFillBackground(true);
......@@ -247,7 +247,7 @@ QWidget *MemcheckErrorDelegate::createDetailsWidget(const QModelIndex &errorInde
.arg(frameNr++, 2).arg(frameName);
frameLabel->setText(displayText);
frameLabel->setToolTip(Valgrind::XmlProtocol::toolTipForFrame(frame));
frameLabel->setToolTip(toolTipForFrame(frame));
frameLabel->setWordWrap(true);
frameLabel->setContentsMargins(0, 0, 0, 0);
frameLabel->setMargin(0);
......@@ -290,7 +290,7 @@ void MemcheckErrorDelegate::paint(QPainter *painter, const QStyleOptionViewItem
if (isSelected) {
// only show detailed widget and let it handle everything
QTC_ASSERT(m_detailsIndex == index, qt_noop());
QTC_ASSERT(m_detailsIndex == index, /**/);
QTC_ASSERT(m_detailsWidget, return); // should have been set in sizeHint()
m_detailsWidget->move(pos);
// when scrolling quickly, the widget can get stuck in a visible part of the scroll area
......@@ -300,8 +300,8 @@ void MemcheckErrorDelegate::paint(QPainter *painter, const QStyleOptionViewItem
const int viewportWidth = view->viewport()->width();
const int widthExcludingMargins = viewportWidth - 2 * s_itemMargin;
QTC_ASSERT(m_detailsWidget->width() == widthExcludingMargins, qt_noop());
QTC_ASSERT(m_detailsWidgetHeight == m_detailsWidget->height(), qt_noop());
QTC_ASSERT(m_detailsWidget->width() == widthExcludingMargins, /**/);
QTC_ASSERT(m_detailsWidgetHeight == m_detailsWidget->height(), /**/);
} else {
// the reference coordinate for text drawing is the text baseline; move it inside the view rect.
pos.ry() += fm.ascent();
......
......@@ -38,6 +38,11 @@
#include "memcheckerrorview.h"
#include "memchecksettings.h"
#include "xmlprotocol/suppression.h"
#include "xmlprotocol/errorlistmodel.h"
#include "xmlprotocol/stack.h"
#include "xmlprotocol/frame.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/project.h>
......@@ -50,25 +55,20 @@
#include <QtCore/QFile>
#include <QtGui/QPushButton>
#include <valgrind/xmlprotocol/suppression.h>
#include <valgrind/xmlprotocol/errorlistmodel.h>
#include <valgrind/xmlprotocol/stack.h>
#include <valgrind/xmlprotocol/frame.h>
using namespace Analyzer;
using namespace Valgrind::XmlProtocol;
namespace {
namespace Valgrind {
namespace Internal {
QString suppressionText(const Error &error)
static QString suppressionText(const Error &error)
{
Suppression sup(error.suppression());
// workaround: https://bugs.kde.org/show_bug.cgi?id=255822
if (sup.frames().size() >= 24) {
if (sup.frames().size() >= 24)
sup.setFrames(sup.frames().mid(0, 23));
}
QTC_ASSERT(sup.frames().size() < 24, qt_noop());
QTC_ASSERT(sup.frames().size() < 24, /**/)
// try to set some useful name automatically, instead of "insert_name_here"
// we take the last stack frame and append the suppression kind, e.g.:
......@@ -82,9 +82,8 @@ QString suppressionText(const Error &error)
else if (!frame.object().isEmpty())
newName = frame.object();
if (!newName.isEmpty()) {
if (!newName.isEmpty())
sup.setName(newName + '[' + sup.kind() + ']');
}
}
return sup.toString();
......@@ -111,10 +110,9 @@ static bool equalSuppression(const Error &error, const Error &suppressed)
if (suppressedFrames.size() < frames)
frames = suppressedFrames.size();
for (int i = 0; i < frames; ++i) {
for (int i = 0; i < frames; ++i)
if (errorFrames.at(i) != suppressedFrames.at(i))
return false;
}
return true;
}
......@@ -124,13 +122,8 @@ bool sortIndizesReverse(const QModelIndex &l, const QModelIndex &r)
return l.row() > r.row();
}
} // namespace anoe
namespace Valgrind {
namespace Internal {
SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, QWidget *parent, Qt::WindowFlags f)
: QDialog(parent, f),
SuppressionDialog::SuppressionDialog(MemcheckErrorView *view)
: QDialog(),
m_view(view),
m_ui(new Ui::SuppressionDialog),
m_settings(view->settings()),
......@@ -138,7 +131,7 @@ SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, QWidget *parent, Q
{
m_ui->setupUi(this);
///NOTE: pathchooser requires existing files...
// NOTE: pathchooser requires existing files.
QFile defaultSuppFile(view->defaultSuppressionFile());
if (!defaultSuppFile.exists()) {
if (defaultSuppFile.open(QIODevice::WriteOnly)) {
......@@ -147,7 +140,7 @@ SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, QWidget *parent, Q
}
}
//NOTE: first set kind, then set path since otherwise the file will be seen as "invalid"
// NOTE: First set kind, then set path. Otherwise the file will be seen as "invalid".
m_ui->fileChooser->setExpectedKind(Utils::PathChooser::File);
m_ui->fileChooser->setPath(defaultSuppFile.fileName());
m_ui->fileChooser->setPromptDialogFilter(QLatin1String("*.supp"));
......@@ -158,15 +151,15 @@ SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, QWidget *parent, Q
SLOT(validate()));
QString suppressions;
QModelIndexList indizes = m_view->selectionModel()->selectedRows();
if (indizes.isEmpty() && m_view->selectionModel()->currentIndex().isValid()) {
QModelIndexList indices = m_view->selectionModel()->selectedRows();
if (indices.isEmpty() && m_view->selectionModel()->currentIndex().isValid()) {
// can happen when using arrow keys to navigate and shortcut to trigger suppression
indizes << m_view->selectionModel()->currentIndex();
indices.append(m_view->selectionModel()->currentIndex());
}
foreach (const QModelIndex &index, indizes) {
foreach (const QModelIndex &index, indices) {
Error error = m_view->model()->data(index, ErrorListModel::ErrorRole).value<Error>();
if (!error.suppression().isNull())
m_errors << error;
m_errors.append(error);
}
foreach (const Error &error, m_errors)
......@@ -208,9 +201,9 @@ void SuppressionDialog::accept()
m_settings->subConfig<AbstractMemcheckSettings>()->addSuppressionFiles(QStringList(path));
QModelIndexList indizes = m_view->selectionModel()->selectedRows();
qSort(indizes.begin(), indizes.end(), sortIndizesReverse);
foreach (const QModelIndex &index, indizes) {
QModelIndexList indices = m_view->selectionModel()->selectedRows();
qSort(indices.begin(), indices.end(), sortIndizesReverse);
foreach (const QModelIndex &index, indices) {
bool removed = m_view->model()->removeRow(index.row());
QTC_ASSERT(removed, qt_noop());
Q_UNUSED(removed);
......@@ -234,7 +227,7 @@ void SuppressionDialog::accept()
}
// select a new item
m_view->setCurrentIndex(indizes.first());
m_view->setCurrentIndex(indices.first());
QDialog::accept();
}
......
......@@ -32,12 +32,12 @@
**
**************************************************************************/
#ifndef ANALYZER_VALGRIND_INTERNAL_SUPPRESSIONDIALOG_H
#define ANALYZER_VALGRIND_INTERNAL_SUPPRESSIONDIALOG_H
#ifndef ANALYZER_VALGRIND_SUPPRESSIONDIALOG_H
#define ANALYZER_VALGRIND_SUPPRESSIONDIALOG_H
#include <QtGui/QDialog>
#include "xmlprotocol/error.h"
#include <valgrind/xmlprotocol/error.h>
#include <QtGui/QDialog>
namespace Analyzer {
class AnalyzerSettings;
......@@ -57,8 +57,8 @@ class SuppressionDialog : public QDialog
Q_OBJECT
public:
explicit SuppressionDialog(MemcheckErrorView *view, QWidget *parent = 0,
Qt::WindowFlags f = 0);
SuppressionDialog(MemcheckErrorView *view);
virtual void accept();
virtual void reject();
......@@ -72,10 +72,10 @@ private:
Ui::SuppressionDialog *m_ui;
Analyzer::AnalyzerSettings *m_settings;
bool m_cleanupIfCanceled;
QList<Valgrind::XmlProtocol::Error> m_errors;
QList<XmlProtocol::Error> m_errors;
};
} // namespace Internal
} // namespace Valgrind
#endif // ANALYZER_VALGRIND_INTERNAL_SUPPRESSIONDIALOG_H
#endif // ANALYZER_VALGRIND_SUPPRESSIONDIALOG_H
......@@ -3,7 +3,9 @@ TARGET = Valgrind
include(../../qtcreatorplugin.pri)
include(valgrind_dependencies.pri)
include(valgrind/valgrind.pri)
include(callgrind/callgrind.pri)
include(memcheck/memcheck.pri)
include(xmlprotocol/xmlprotocol.pri)
QT *= network
INCLUDEPATH *= $$PWD
......@@ -13,6 +15,9 @@ HEADERS += \
valgrindengine.h \
valgrindconfigwidget.h \
valgrindsettings.h \
valgrindrunner.h \
valgrindprocess.h \
\
callgrindconfigwidget.h \
callgrindcostdelegate.h \
callgrindcostview.h \
......@@ -37,6 +42,8 @@ SOURCES += \
valgrindengine.cpp \
valgrindconfigwidget.cpp \
valgrindsettings.cpp \
valgrindrunner.cpp \
valgrindprocess.cpp \
\