forked from qt-creator/qt-creator
Debugger: Remove DetailedErrorDelegate
Change-Id: I08cd9af5e11e705378a53075c7fade44fc3246ce Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -34,7 +34,6 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -232,18 +231,6 @@ Qt::ItemFlags DiagnosticItem::flags(int column) const
|
|||||||
return itemFlags;
|
return itemFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVariant locationData(int role, const Debugger::DiagnosticLocation &location)
|
|
||||||
{
|
|
||||||
switch (role) {
|
|
||||||
case Debugger::DetailedErrorView::LocationRole:
|
|
||||||
return QVariant::fromValue(location);
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
return location.filePath.isEmpty() ? QVariant() : QVariant(location.filePath);
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static QVariant iconData(const QString &type)
|
static QVariant iconData(const QString &type)
|
||||||
{
|
{
|
||||||
if (type == "warning")
|
if (type == "warning")
|
||||||
@@ -260,7 +247,7 @@ static QVariant iconData(const QString &type)
|
|||||||
QVariant DiagnosticItem::data(int column, int role) const
|
QVariant DiagnosticItem::data(int column, int role) const
|
||||||
{
|
{
|
||||||
if (column == Debugger::DetailedErrorView::LocationColumn)
|
if (column == Debugger::DetailedErrorView::LocationColumn)
|
||||||
return locationData(role, m_diagnostic.location);
|
return Debugger::DetailedErrorView::locationData(role, m_diagnostic.location);
|
||||||
|
|
||||||
if (column == DiagnosticView::FixItColumn) {
|
if (column == DiagnosticView::FixItColumn) {
|
||||||
if (role == Qt::CheckStateRole)
|
if (role == Qt::CheckStateRole)
|
||||||
@@ -305,7 +292,7 @@ ExplainingStepItem::ExplainingStepItem(const ExplainingStep &step) : m_step(step
|
|||||||
QVariant ExplainingStepItem::data(int column, int role) const
|
QVariant ExplainingStepItem::data(int column, int role) const
|
||||||
{
|
{
|
||||||
if (column == Debugger::DetailedErrorView::LocationColumn)
|
if (column == Debugger::DetailedErrorView::LocationColumn)
|
||||||
return locationData(role, m_step.location);
|
return Debugger::DetailedErrorView::locationData(role, m_step.location);
|
||||||
|
|
||||||
if (column == DiagnosticView::FixItColumn)
|
if (column == DiagnosticView::FixItColumn)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|||||||
@@ -41,91 +41,14 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QTextDocument>
|
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class DetailedErrorDelegate : public QStyledItemDelegate
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
DetailedErrorDelegate(QTreeView *parent) : QStyledItemDelegate(parent) { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString actualText(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
const auto location = index.model()->data(index, DetailedErrorView::LocationRole)
|
|
||||||
.value<DiagnosticLocation>();
|
|
||||||
return location.isValid()
|
|
||||||
? QString::fromLatin1("<a href=\"file://%1\">%2:%3:%4")
|
|
||||||
.arg(location.filePath, QFileInfo(location.filePath).fileName())
|
|
||||||
.arg(location.line)
|
|
||||||
.arg(location.column)
|
|
||||||
: QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
using DocConstPtr = QSharedPointer<const QTextDocument>;
|
|
||||||
DocConstPtr document(const QStyleOptionViewItem &option) const
|
|
||||||
{
|
|
||||||
const auto doc = QSharedPointer<QTextDocument>::create();
|
|
||||||
doc->setHtml(option.text);
|
|
||||||
doc->setTextWidth(option.rect.width());
|
|
||||||
doc->setDocumentMargin(0);
|
|
||||||
return doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
|
||||||
{
|
|
||||||
QStyleOptionViewItem opt = option;
|
|
||||||
opt.text = actualText(index);
|
|
||||||
initStyleOption(&opt, index);
|
|
||||||
|
|
||||||
const DocConstPtr doc = document(opt);
|
|
||||||
return QSize(doc->idealWidth(), doc->size().height());
|
|
||||||
}
|
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
||||||
const QModelIndex &index) const override
|
|
||||||
{
|
|
||||||
QStyleOptionViewItem opt = option;
|
|
||||||
initStyleOption(&opt, index);
|
|
||||||
|
|
||||||
QStyle *style = opt.widget? opt.widget->style() : QApplication::style();
|
|
||||||
|
|
||||||
// Painting item without text
|
|
||||||
opt.text.clear();
|
|
||||||
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
|
|
||||||
opt.text = actualText(index);
|
|
||||||
|
|
||||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
|
||||||
|
|
||||||
// Highlighting text if item is selected
|
|
||||||
if (opt.state & QStyle::State_Selected) {
|
|
||||||
ctx.palette.setColor(QPalette::Text, opt.palette.color(QPalette::Active,
|
|
||||||
QPalette::HighlightedText));
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt);
|
|
||||||
painter->save();
|
|
||||||
painter->translate(textRect.topLeft());
|
|
||||||
painter->setClipRect(textRect.translated(-textRect.topLeft()));
|
|
||||||
document(opt)->documentLayout()->draw(painter, ctx);
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
|
|
||||||
|
|
||||||
DetailedErrorView::DetailedErrorView(QWidget *parent) :
|
DetailedErrorView::DetailedErrorView(QWidget *parent) :
|
||||||
QTreeView(parent),
|
QTreeView(parent),
|
||||||
m_copyAction(new QAction(this))
|
m_copyAction(new QAction(this))
|
||||||
{
|
{
|
||||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
setItemDelegateForColumn(LocationColumn, new Internal::DetailedErrorDelegate(this));
|
|
||||||
|
|
||||||
m_copyAction->setText(tr("Copy"));
|
m_copyAction->setText(tr("Copy"));
|
||||||
m_copyAction->setIcon(Utils::Icons::COPY.icon());
|
m_copyAction->setIcon(Utils::Icons::COPY.icon());
|
||||||
@@ -187,6 +110,31 @@ void DetailedErrorView::goBack()
|
|||||||
setCurrentRow(prevRow >= 0 ? prevRow : rowCount() - 1);
|
setCurrentRow(prevRow >= 0 ? prevRow : rowCount() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant DetailedErrorView::locationData(int role, const DiagnosticLocation &location)
|
||||||
|
{
|
||||||
|
switch (role) {
|
||||||
|
case Debugger::DetailedErrorView::LocationRole:
|
||||||
|
return QVariant::fromValue(location);
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return location.isValid() ? QString::fromLatin1("%1:%2:%3")
|
||||||
|
.arg(QFileInfo(location.filePath).fileName())
|
||||||
|
.arg(location.line)
|
||||||
|
.arg(location.column)
|
||||||
|
: QString();
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
return location.filePath.isEmpty() ? QVariant() : QVariant(location.filePath);
|
||||||
|
case Qt::FontRole: {
|
||||||
|
QFont font = QApplication::font();
|
||||||
|
font.setUnderline(true);
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
case Qt::ForegroundRole:
|
||||||
|
return QApplication::palette().link().color();
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int DetailedErrorView::rowCount() const
|
int DetailedErrorView::rowCount() const
|
||||||
{
|
{
|
||||||
return model() ? model()->rowCount() : 0;
|
return model() ? model()->rowCount() : 0;
|
||||||
@@ -218,5 +166,3 @@ void DetailedErrorView::setCurrentRow(int row)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Debugger
|
} // namespace Debugger
|
||||||
|
|
||||||
#include "detailederrorview.moc"
|
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
|
|
||||||
|
class DiagnosticLocation;
|
||||||
|
|
||||||
class DEBUGGER_EXPORT DetailedErrorView : public QTreeView
|
class DEBUGGER_EXPORT DetailedErrorView : public QTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -53,6 +55,8 @@ public:
|
|||||||
LocationColumn,
|
LocationColumn,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static QVariant locationData(int role, const DiagnosticLocation &location);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override;
|
||||||
|
|||||||
@@ -173,24 +173,16 @@ ErrorItem::ErrorItem(const ErrorListModel *model, const Error &error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVariant location(const Frame &frame, int role)
|
static QVariant locationData(int role, const Frame &frame)
|
||||||
{
|
{
|
||||||
switch (role) {
|
const Debugger::DiagnosticLocation location(frame.filePath(), frame.line(), 0);
|
||||||
case Debugger::DetailedErrorView::LocationRole:
|
return Debugger::DetailedErrorView::locationData(role, location);
|
||||||
return QVariant::fromValue(Debugger::DiagnosticLocation(frame.filePath(), frame.line(), 0));
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
return frame.filePath().isEmpty() ? QVariant() : QVariant(frame.filePath());
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ErrorItem::data(int column, int role) const
|
QVariant ErrorItem::data(int column, int role) const
|
||||||
{
|
{
|
||||||
if (column == Debugger::DetailedErrorView::LocationColumn) {
|
if (column == Debugger::DetailedErrorView::LocationColumn)
|
||||||
const Frame frame = m_model->findRelevantFrame(m_error);
|
return locationData(role, m_model->findRelevantFrame(m_error));
|
||||||
return location(frame, role);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DiagnosticColumn
|
// DiagnosticColumn
|
||||||
switch (role) {
|
switch (role) {
|
||||||
@@ -243,7 +235,7 @@ QVariant StackItem::data(int column, int role) const
|
|||||||
{
|
{
|
||||||
const ErrorItem * const errorItem = getErrorItem();
|
const ErrorItem * const errorItem = getErrorItem();
|
||||||
if (column == Debugger::DetailedErrorView::LocationColumn)
|
if (column == Debugger::DetailedErrorView::LocationColumn)
|
||||||
return location(errorItem->modelPrivate()->findRelevantFrame(errorItem->error()), role);
|
return locationData(role, errorItem->modelPrivate()->findRelevantFrame(errorItem->error()));
|
||||||
|
|
||||||
// DiagnosticColumn
|
// DiagnosticColumn
|
||||||
switch (role) {
|
switch (role) {
|
||||||
@@ -271,7 +263,7 @@ FrameItem::FrameItem(const Frame &frame) : m_frame(frame)
|
|||||||
QVariant FrameItem::data(int column, int role) const
|
QVariant FrameItem::data(int column, int role) const
|
||||||
{
|
{
|
||||||
if (column == Debugger::DetailedErrorView::LocationColumn)
|
if (column == Debugger::DetailedErrorView::LocationColumn)
|
||||||
return location(m_frame, role);
|
return locationData(role, m_frame);
|
||||||
|
|
||||||
// DiagnosticColumn
|
// DiagnosticColumn
|
||||||
switch (role) {
|
switch (role) {
|
||||||
|
|||||||
Reference in New Issue
Block a user