Commit 7b3ba73a authored by hjk's avatar hjk Committed by hjk

analyzer: code cosmetics

Change-Id: Id00cf1be9d07e47f7b61b8cc7e940629c84a48c1
Reviewed-on: http://codereview.qt.nokia.com/2707Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 1f36bcac
......@@ -44,33 +44,65 @@
#include "xmlprotocol/modelhelpers.h"
#include "xmlprotocol/suppression.h"
#include <texteditor/basetexteditor.h>
#include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
#include <coreplugin/coreconstants.h>
#include <texteditor/basetexteditor.h>
#include <utils/qtcassert.h>
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QClipboard>
#include <QtGui/QLabel>
#include <QtGui/QListView>
#include <QtGui/QMenu>
#include <QtGui/QPainter>
#include <QtGui/QScrollBar>
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QStyledItemDelegate>
#include <QtGui/QVBoxLayout>
#include <QtGui/QAction>
#include <QtGui/QClipboard>
#include <QtGui/QApplication>
#include <QtGui/QMenu>
using namespace Valgrind::XmlProtocol;
namespace Valgrind {
namespace Internal {
class MemcheckErrorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
/// This delegate can only work on one view at a time, parent. parent will also be the parent
/// in the QObject parent-child system.
explicit MemcheckErrorDelegate(QListView *parent);
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
public slots:
void currentChanged(const QModelIndex &now, const QModelIndex &previous);
void viewResized();
void layoutChanged();
void copy();
private slots:
void verticalScrolled();
void openLinkInEditor(const QString &link);
private:
// the constness of this method is a necessary lie because it is called from paint() const.
QWidget *createDetailsWidget(const QModelIndex &errorIndex, QWidget *parent) const;
static const int s_itemMargin = 2;
mutable QPersistentModelIndex m_detailsIndex;
mutable QWidget *m_detailsWidget;
mutable int m_detailsWidgetHeight;
};
MemcheckErrorDelegate::MemcheckErrorDelegate(QListView *parent)
: QStyledItemDelegate(parent),
m_detailsWidget(0)
......@@ -84,8 +116,7 @@ QSize MemcheckErrorDelegate::sizeHint(const QStyleOptionViewItem &opt, const QMo
const QListView *view = qobject_cast<const QListView *>(parent());
const int viewportWidth = view->viewport()->width();
const bool isSelected = view->selectionModel()->currentIndex() == index;
int dy = 2 * s_itemMargin;
const int dy = 2 * s_itemMargin;
if (!isSelected) {
QFontMetrics fm(opt.font);
......@@ -153,20 +184,20 @@ static QString makeFrameName(const Frame &frame, const QString &relativeTo,
return QString("0x%1").arg(frame.instructionPointer(), 0, 16);
}
QString relativeToPath()
static QString relativeToPath()
{
// project for which we insert the snippet
// The project for which we insert the snippet.
const ProjectExplorer::Project *project =
ProjectExplorer::ProjectExplorerPlugin::instance()->startupProject();
QString relativeTo( project ? project->projectDirectory() : QDir::homePath() );
QString relativeTo(project ? project->projectDirectory() : QDir::homePath());
if (!relativeTo.endsWith(QDir::separator()))
relativeTo.append(QDir::separator());
return relativeTo;
}
QString errorLocation(const QModelIndex &index, const Error &error,
static QString errorLocation(const QModelIndex &index, const Error &error,
bool link = false, const QString &linkAttr = QString())
{
const ErrorListModel *model = 0;
......@@ -190,9 +221,7 @@ QWidget *MemcheckErrorDelegate::createDetailsWidget(const QModelIndex &errorInde
// don't include frameName here as it should wrap if required and pre-line is not supported
// by Qt yet it seems
const QString displayTextTemplate = QString("<code style='white-space:pre'>%1:</code> %2");
QString relativeTo = relativeToPath();
const QString relativeTo = relativeToPath();
const Error error = errorIndex.data(ErrorListModel::ErrorRole).value<Error>();
QLabel *errorLabel = new QLabel();
......@@ -541,3 +570,5 @@ void MemcheckErrorView::setCurrentRow(int row)
} // namespace Internal
} // namespace Valgrind
#include "memcheckerrorview.moc"
......@@ -36,53 +36,14 @@
#define MEMCHECKERRORVIEW_H
#include <QtGui/QListView>
#include <QtGui/QStyledItemDelegate>
#include <QtGui/QLabel>
namespace Analyzer {
class AnalyzerSettings;
}
namespace ProjectExplorer {
class Project;
}
namespace Valgrind {
namespace Internal {
class MemcheckErrorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
/// This delegate can only work on one view at a time, parent. parent will also be the parent
/// in the QObject parent-child system.
explicit MemcheckErrorDelegate(QListView *parent);
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
public slots:
void currentChanged(const QModelIndex &now, const QModelIndex &previous);
void viewResized();
void layoutChanged();
void copy();
private slots:
void verticalScrolled();
void openLinkInEditor(const QString &link);
private:
// the constness of this method is a necessary lie because it is called from paint() const.
QWidget *createDetailsWidget(const QModelIndex &errorIndex, QWidget *parent) const;
static const int s_itemMargin = 2;
mutable QPersistentModelIndex m_detailsIndex;
mutable QWidget *m_detailsWidget;
mutable int m_detailsWidgetHeight;
};
class MemcheckErrorView : public QListView
{
Q_OBJECT
......
......@@ -137,17 +137,23 @@ QString ErrorListModel::Private::formatLocation(const Error &error) const
QVariant ErrorListModel::Private::errorData(int row, int column, int role) const
{
// A dummy entry.
if (row == 0 && errors.isEmpty()) {
if (role == Qt::DisplayRole)
return tr("No errors found");
if (role == ErrorRole)
return tr("No errors found");
return QVariant();
}
if (row < 0 || row >= errors.size())
return QVariant();
const Error &error = errors[row];
const QVector<Stack> stacks = error.stacks();
const Stack stack = !stacks.isEmpty() ? stacks.first() : Stack();
const Error &error = errors.at(row);
if (error.stacks().count())
switch (role) {
case Qt::DisplayRole:
{
case Qt::DisplayRole: {
switch (column) {
case WhatColumn:
return error.what();
......@@ -155,8 +161,7 @@ QVariant ErrorListModel::Private::errorData(int row, int column, int role) const
return formatLocation(error);
case AbsoluteFilePathColumn:
return formatAbsoluteFilePath(error);
case LineColumn:
{
case LineColumn: {
const qint64 line = findRelevantFrame(error).line();
return line > 0 ? line : QVariant();
}
......@@ -177,17 +182,14 @@ QVariant ErrorListModel::Private::errorData(int row, int column, int role) const
}
}
case Qt::ToolTipRole:
{
return toolTipForFrame(findRelevantFrame(error));
}
case ErrorRole:
return QVariant::fromValue<Error>(error);
case AbsoluteFilePathRole:
return formatAbsoluteFilePath(error);
case FileRole:
return findRelevantFrame(error).file();
case LineRole:
{
case LineRole: {
const qint64 line = findRelevantFrame(error).line();
return line > 0 ? line : QVariant();
}
......@@ -200,8 +202,6 @@ QVariant ErrorListModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
QTC_ASSERT(index.model() == this, return QVariant());
if (!index.parent().isValid())
return d->errorData(index.row(), index.column(), role);
......@@ -241,13 +241,9 @@ QVariant ErrorListModel::headerData(int section, Qt::Orientation orientation, in
int ErrorListModel::rowCount(const QModelIndex &parent) const
{
//root
if (!parent.isValid())
return d->errors.count();
QTC_ASSERT(parent.model() == this, return 0);
return 0;
if (parent.isValid())
return 0;
return qMax(1, d->errors.count());
}
int ErrorListModel::columnCount(const QModelIndex &parent) const
......@@ -286,7 +282,7 @@ Error ErrorListModel::error(const QModelIndex &index) const
const int r = index.row();
if (r < 0 || r >= d->errors.size())
return Error();
return d->errors[r];
return d->errors.at(r);
}
void ErrorListModel::clear()
......
......@@ -47,9 +47,10 @@ class Frame;
class ErrorListModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum Column {
WhatColumn=0,
WhatColumn = 0,
LocationColumn,
AbsoluteFilePathColumn,
LineColumn,
......@@ -63,7 +64,7 @@ public:
};
enum Role {
ErrorRole=Qt::UserRole,
ErrorRole = Qt::UserRole,
AbsoluteFilePathRole,
FileRole,
LineRole
......@@ -96,7 +97,7 @@ public:
void clear();
public Q_SLOTS:
public slots:
void addError(const Valgrind::XmlProtocol::Error &error);
private:
......
This diff is collapsed.
......@@ -39,8 +39,6 @@
#include <QtCore/QString>
#include <QtCore/QVector>
#include <algorithm>
namespace Valgrind {
namespace XmlProtocol {
......@@ -80,11 +78,10 @@ void Stack::swap(Stack &other)
qSwap(d, other.d);
}
Stack &Stack::operator=(const Stack &other)
void Stack::operator=(const Stack &other)
{
Stack tmp(other);
swap(tmp);
return *this;
}
bool Stack::operator==(const Stack &other) const
......
......@@ -32,8 +32,8 @@
**
**************************************************************************/
#ifndef LIBVALGRIND_PROTOCOL_STACK_H
#define LIBVALGRIND_PROTOCOL_STACK_H
#ifndef VALGRIND_PROTOCOL_STACK_H
#define VALGRIND_PROTOCOL_STACK_H
#include <QtCore/QSharedDataPointer>
......@@ -52,7 +52,7 @@ public:
Stack();
Stack(const Stack &other);
~Stack();
Stack &operator=(const Stack &other);
void operator=(const Stack &other);
void swap(Stack &other);
bool operator==(const Stack &other) const;
......@@ -84,4 +84,4 @@ private:
} // namespace XmlProtocol
} // namespace Stack
#endif // LIBVALGRIND_PROTOCOL_STACK_H
#endif // VALGRIND_PROTOCOL_STACK_H
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