Utils: Use Utils::Link instead of TaskView::Location

Same layout, effectively the same purpose

Change-Id: I742d85ed06c07009ebb9696734f00894275859a3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-05-28 12:04:56 +02:00
parent b768ba2412
commit b9c7ca0096
4 changed files with 27 additions and 36 deletions

View File

@@ -28,6 +28,7 @@
#include "algorithm.h" #include "algorithm.h"
#include "ansiescapecodehandler.h" #include "ansiescapecodehandler.h"
#include "fileinprojectfinder.h" #include "fileinprojectfinder.h"
#include "link.h"
#include "qtcassert.h" #include "qtcassert.h"
#include "qtcprocess.h" #include "qtcprocess.h"
#include "theme/theme.h" #include "theme/theme.h"
@@ -72,15 +73,14 @@ bool OutputLineParser::isLinkTarget(const QString &target)
return target.startsWith(*linkPrefix()); return target.startsWith(*linkPrefix());
} }
void OutputLineParser::parseLinkTarget(const QString &target, FilePath &filePath, int &line, Link OutputLineParser::parseLinkTarget(const QString &target)
int &column)
{ {
const QStringList parts = target.mid(linkPrefix()->length()).split(*linkSep()); const QStringList parts = target.mid(linkPrefix()->length()).split(*linkSep());
if (parts.isEmpty()) if (parts.isEmpty())
return; return {};
filePath = FilePath::fromString(parts.first()); return Link(FilePath::fromString(parts.first()),
line = parts.length() > 1 ? parts.at(1).toInt() : 0; parts.length() > 1 ? parts.at(1).toInt() : 0,
column = parts.length() > 2 ? parts.at(2).toInt() : 0; parts.length() > 2 ? parts.at(2).toInt() : 0);
} }
// The redirection mechanism is needed for broken build tools (e.g. xcodebuild) that get invoked // The redirection mechanism is needed for broken build tools (e.g. xcodebuild) that get invoked
@@ -528,12 +528,10 @@ bool OutputFormatter::handleFileLink(const QString &href)
{ {
if (!OutputLineParser::isLinkTarget(href)) if (!OutputLineParser::isLinkTarget(href))
return false; return false;
FilePath filePath;
int line; Link link = OutputLineParser::parseLinkTarget(href);
int column; QTC_ASSERT(!link.targetFilePath.isEmpty(), return false);
OutputLineParser::parseLinkTarget(href, filePath, line, column); emit openInEditorRequested(link);
QTC_ASSERT(!filePath.isEmpty(), return false);
emit openInEditorRequested(filePath, line, column);
return true; return true;
} }

View File

@@ -44,6 +44,7 @@ QT_END_NAMESPACE
namespace Utils { namespace Utils {
class FileInProjectFinder; class FileInProjectFinder;
class FormattedText; class FormattedText;
class Link;
class QTCREATOR_UTILS_EXPORT OutputLineParser : public QObject class QTCREATOR_UTILS_EXPORT OutputLineParser : public QObject
{ {
@@ -72,7 +73,7 @@ public:
}; };
static bool isLinkTarget(const QString &target); static bool isLinkTarget(const QString &target);
static void parseLinkTarget(const QString &target, FilePath &filePath, int &line, int &column); static Utils::Link parseLinkTarget(const QString &target);
void addSearchDir(const Utils::FilePath &dir); void addSearchDir(const Utils::FilePath &dir);
void dropSearchDir(const Utils::FilePath &dir); void dropSearchDir(const Utils::FilePath &dir);
@@ -172,7 +173,7 @@ private:
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href); static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href);
signals: signals:
void openInEditorRequested(const FilePath &filePath, int line, int column); void openInEditorRequested(const Utils::Link &link);
private: private:
void doAppendMessage(const QString &text, OutputFormat format); void doAppendMessage(const QString &text, OutputFormat format);

View File

@@ -148,9 +148,8 @@ OutputWindow::OutputWindow(Context context, const QString &settingsKey, QWidget
Core::ICore::settings()->setValueWithDefault(d->settingsKey, fontZoom(), 0.f); Core::ICore::settings()->setValueWithDefault(d->settingsKey, fontZoom(), 0.f);
}); });
connect(outputFormatter(), &OutputFormatter::openInEditorRequested, this, connect(outputFormatter(), &OutputFormatter::openInEditorRequested, this, [](const Link &link) {
[](const Utils::FilePath &fp, int line, int column) { EditorManager::openEditorAt(link);
EditorManager::openEditorAt(fp.toString(), line, column);
}); });
connect(verticalScrollBar(), &QAbstractSlider::actionTriggered, connect(verticalScrollBar(), &QAbstractSlider::actionTriggered,

View File

@@ -52,6 +52,8 @@
#include <QToolButton> #include <QToolButton>
#include <QScrollBar> #include <QScrollBar>
using namespace Utils;
namespace { namespace {
const int ELLIPSIS_GRADIENT_WIDTH = 16; const int ELLIPSIS_GRADIENT_WIDTH = 16;
const char SESSION_FILTER_CATEGORIES[] = "TaskWindow.Categories"; const char SESSION_FILTER_CATEGORIES[] = "TaskWindow.Categories";
@@ -86,13 +88,7 @@ private:
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override;
class Location { Utils::Link locationForPos(const QPoint &pos);
public:
Utils::FilePath file;
int line;
int column;
};
Location locationForPos(const QPoint &pos);
bool m_linksActive = true; bool m_linksActive = true;
Qt::MouseButton m_mouseButtonPressed = Qt::NoButton; Qt::MouseButton m_mouseButtonPressed = Qt::NoButton;
@@ -229,9 +225,9 @@ void TaskView::mousePressEvent(QMouseEvent *e)
void TaskView::mouseReleaseEvent(QMouseEvent *e) void TaskView::mouseReleaseEvent(QMouseEvent *e)
{ {
if (m_linksActive && m_mouseButtonPressed == Qt::LeftButton) { if (m_linksActive && m_mouseButtonPressed == Qt::LeftButton) {
const Location loc = locationForPos(e->pos()); const Link loc = locationForPos(e->pos());
if (!loc.file.isEmpty()) { if (!loc.targetFilePath.isEmpty()) {
Core::EditorManager::openEditorAt(loc.file.toString(), loc.line, loc.column, {}, Core::EditorManager::openEditorAt(loc, {},
Core::EditorManager::SwitchSplitIfAlreadyVisible); Core::EditorManager::SwitchSplitIfAlreadyVisible);
} }
} }
@@ -248,23 +244,20 @@ void TaskView::mouseMoveEvent(QMouseEvent *e)
if (m_mouseButtonPressed != Qt::NoButton) if (m_mouseButtonPressed != Qt::NoButton)
m_linksActive = false; m_linksActive = false;
viewport()->setCursor(m_linksActive && !locationForPos(e->pos()).file.isEmpty() viewport()->setCursor(m_linksActive && !locationForPos(e->pos()).targetFilePath.isEmpty()
? Qt::PointingHandCursor : Qt::ArrowCursor); ? Qt::PointingHandCursor : Qt::ArrowCursor);
ListView::mouseMoveEvent(e); ListView::mouseMoveEvent(e);
} }
TaskView::Location TaskView::locationForPos(const QPoint &pos) Link TaskView::locationForPos(const QPoint &pos)
{ {
const auto delegate = qobject_cast<TaskDelegate *>(itemDelegate(indexAt(pos))); const auto delegate = qobject_cast<TaskDelegate *>(itemDelegate(indexAt(pos)));
if (!delegate) if (!delegate)
return {}; return {};
Utils::OutputFormatter formatter; OutputFormatter formatter;
Location loc; Link loc;
connect(&formatter, &Utils::OutputFormatter::openInEditorRequested, this, connect(&formatter, &OutputFormatter::openInEditorRequested, this, [&loc](const Link &link) {
[&loc](const Utils::FilePath &fp, int line, int column) { loc = link;
loc.file = fp;
loc.line = line;
loc.column = column;
}); });
const QString href = delegate->hrefForPos(pos); const QString href = delegate->hrefForPos(pos);