ClassView: Proliferate FilePath use

Change-Id: I4a8a18d6045557e31571970d671f3cc3f4374493
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-24 15:28:39 +01:00
parent 2119dd4397
commit 7b08e79913
6 changed files with 31 additions and 35 deletions

View File

@@ -19,8 +19,7 @@ using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace ClassView { namespace ClassView::Internal {
namespace Internal {
///////////////////////////////// ManagerPrivate ////////////////////////////////// ///////////////////////////////// ManagerPrivate //////////////////////////////////
@@ -347,9 +346,9 @@ void Manager::onWidgetVisibilityIsChanged(bool visibility)
\a column (0-based). \a column (0-based).
*/ */
void Manager::gotoLocation(const QString &fileName, int line, int column) void Manager::gotoLocation(const FilePath &filePath, int line, int column)
{ {
EditorManager::openEditorAt({FilePath::fromString(fileName), line, column}); EditorManager::openEditorAt({filePath, line, column});
} }
/*! /*!
@@ -372,11 +371,11 @@ void Manager::gotoLocations(const QList<QVariant> &list)
auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor()); auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor());
if (textEditor) { if (textEditor) {
// check if current cursor position is a known location of the symbol // check if current cursor position is a known location of the symbol
const QString fileName = textEditor->document()->filePath().toString(); const FilePath filePath = textEditor->document()->filePath();
int line; int line;
int column; int column;
textEditor->convertPosition(textEditor->position(), &line, &column); textEditor->convertPosition(textEditor->position(), &line, &column);
const SymbolLocation current(fileName, line, column); const SymbolLocation current(filePath, line, column);
if (auto it = locations.constFind(current), end = locations.constEnd(); it != end) { if (auto it = locations.constFind(current), end = locations.constEnd(); it != end) {
// we already are at the symbol, cycle to next location // we already are at the symbol, cycle to next location
++it; ++it;
@@ -388,7 +387,7 @@ void Manager::gotoLocations(const QList<QVariant> &list)
} }
const SymbolLocation &location = *locationIt; const SymbolLocation &location = *locationIt;
// line is 1-based, column is 0-based // line is 1-based, column is 0-based
gotoLocation(location.fileName(), location.line(), location.column() - 1); gotoLocation(location.filePath(), location.line(), location.column() - 1);
} }
/*! /*!
@@ -402,5 +401,4 @@ void Manager::setFlatMode(bool flat)
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
} }
} // namespace Internal } // ClassView::Internal
} // namespace ClassView

View File

@@ -7,8 +7,9 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QStandardItem> #include <QStandardItem>
namespace ClassView { namespace Utils { class FilePath; }
namespace Internal {
namespace ClassView::Internal {
class ManagerPrivate; class ManagerPrivate;
@@ -24,7 +25,7 @@ public:
void fetchMore(QStandardItem *item, bool skipRoot = false); void fetchMore(QStandardItem *item, bool skipRoot = false);
bool hasChildren(QStandardItem *item) const; bool hasChildren(QStandardItem *item) const;
void gotoLocation(const QString &fileName, int line = 0, int column = 0); void gotoLocation(const Utils::FilePath &filePath, int line = 0, int column = 0);
void gotoLocations(const QList<QVariant> &locations); void gotoLocations(const QList<QVariant> &locations);
void setFlatMode(bool flat); void setFlatMode(bool flat);
void onWidgetVisibilityIsChanged(bool visibility); void onWidgetVisibilityIsChanged(bool visibility);
@@ -41,5 +42,4 @@ private:
ManagerPrivate *d; ManagerPrivate *d;
}; };
} // namespace Internal } // ClassView::Internal
} // namespace ClassView

View File

@@ -101,7 +101,7 @@ void ParserTreeItemPrivate::mergeSymbol(const CPlusPlus::Symbol *symbol)
childItem = ParserTreeItem::ConstPtr(new ParserTreeItem()); childItem = ParserTreeItem::ConstPtr(new ParserTreeItem());
// locations have 1-based column in Symbol, use the same here. // locations have 1-based column in Symbol, use the same here.
SymbolLocation location(QString::fromUtf8(symbol->fileName() , symbol->fileNameLength()), SymbolLocation location(symbol->filePath(),
symbol->line(), symbol->column()); symbol->line(), symbol->column());
childItem->d->m_symbolLocations.insert(location); childItem->d->m_symbolLocations.insert(location);

View File

@@ -5,8 +5,7 @@
#include <QHash> #include <QHash>
namespace ClassView { namespace ClassView::Internal {
namespace Internal {
/*! /*!
\class SymbolLocation \class SymbolLocation
@@ -23,7 +22,7 @@ SymbolLocation::SymbolLocation() :
{ {
} }
SymbolLocation::SymbolLocation(const QString &file, int lineNumber, int columnNumber) SymbolLocation::SymbolLocation(const Utils::FilePath &file, int lineNumber, int columnNumber)
: m_fileName(file) : m_fileName(file)
, m_line(lineNumber) , m_line(lineNumber)
, m_column(qMax(columnNumber, 0)) , m_column(qMax(columnNumber, 0))
@@ -31,5 +30,4 @@ SymbolLocation::SymbolLocation(const QString &file, int lineNumber, int columnNu
{ {
} }
} // namespace Internal } // ClassView::Internal
} // namespace ClassView

View File

@@ -3,11 +3,11 @@
#pragma once #pragma once
#include <QMetaType> #include <utils/filepath.h>
#include <QString>
namespace ClassView { #include <QMetaType>
namespace Internal {
namespace ClassView::Internal {
class SymbolLocation class SymbolLocation
{ {
@@ -16,20 +16,21 @@ public:
SymbolLocation(); SymbolLocation();
//! Constructor //! Constructor
explicit SymbolLocation(const QString &file, int lineNumber = 0, int columnNumber = 0); explicit SymbolLocation(const Utils::FilePath &file, int lineNumber = 0, int columnNumber = 0);
inline const QString &fileName() const { return m_fileName; } const Utils::FilePath &filePath() const { return m_fileName; }
inline int line() const { return m_line; } int line() const { return m_line; }
inline int column() const { return m_column; } int column() const { return m_column; }
inline size_t hash() const { return m_hash; } size_t hash() const { return m_hash; }
inline bool operator==(const SymbolLocation &other) const
bool operator==(const SymbolLocation &other) const
{ {
return hash() == other.hash() && line() == other.line() && column() == other.column() return hash() == other.hash() && line() == other.line() && column() == other.column()
&& fileName() == other.fileName(); && filePath() == other.filePath();
} }
private: private:
const QString m_fileName; const Utils::FilePath m_fileName;
const int m_line; const int m_line;
const int m_column; const int m_column;
const size_t m_hash; // precalculated hash value - to speed up qHash const size_t m_hash; // precalculated hash value - to speed up qHash
@@ -41,7 +42,6 @@ inline size_t qHash(const ClassView::Internal::SymbolLocation &location)
return location.hash(); return location.hash();
} }
} // namespace Internal } // ClassView::Internal
} // namespace ClassView
Q_DECLARE_METATYPE(ClassView::Internal::SymbolLocation) Q_DECLARE_METATYPE(ClassView::Internal::SymbolLocation)

View File

@@ -162,7 +162,7 @@ QMimeData *TreeItemModel::mimeData(const QModelIndexList &indexes) const
if (locations.isEmpty()) if (locations.isEmpty())
continue; continue;
const SymbolLocation loc = *locations.constBegin(); const SymbolLocation loc = *locations.constBegin();
mimeData->addFile(Utils::FilePath::fromString(loc.fileName()), loc.line(), loc.column()); mimeData->addFile(loc.filePath(), loc.line(), loc.column());
} }
if (mimeData->files().isEmpty()) { if (mimeData->files().isEmpty()) {
delete mimeData; delete mimeData;