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 Utils;
namespace ClassView {
namespace Internal {
namespace ClassView::Internal {
///////////////////////////////// ManagerPrivate //////////////////////////////////
@@ -347,9 +346,9 @@ void Manager::onWidgetVisibilityIsChanged(bool visibility)
\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());
if (textEditor) {
// 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 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) {
// we already are at the symbol, cycle to next location
++it;
@@ -388,7 +387,7 @@ void Manager::gotoLocations(const QList<QVariant> &list)
}
const SymbolLocation &location = *locationIt;
// 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);
}
} // namespace Internal
} // namespace ClassView
} // ClassView::Internal

View File

@@ -7,8 +7,9 @@
#include <QSharedPointer>
#include <QStandardItem>
namespace ClassView {
namespace Internal {
namespace Utils { class FilePath; }
namespace ClassView::Internal {
class ManagerPrivate;
@@ -24,7 +25,7 @@ public:
void fetchMore(QStandardItem *item, bool skipRoot = false);
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 setFlatMode(bool flat);
void onWidgetVisibilityIsChanged(bool visibility);
@@ -41,5 +42,4 @@ private:
ManagerPrivate *d;
};
} // namespace Internal
} // namespace ClassView
} // ClassView::Internal

View File

@@ -101,7 +101,7 @@ void ParserTreeItemPrivate::mergeSymbol(const CPlusPlus::Symbol *symbol)
childItem = ParserTreeItem::ConstPtr(new ParserTreeItem());
// 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());
childItem->d->m_symbolLocations.insert(location);

View File

@@ -5,8 +5,7 @@
#include <QHash>
namespace ClassView {
namespace Internal {
namespace ClassView::Internal {
/*!
\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_line(lineNumber)
, m_column(qMax(columnNumber, 0))
@@ -31,5 +30,4 @@ SymbolLocation::SymbolLocation(const QString &file, int lineNumber, int columnNu
{
}
} // namespace Internal
} // namespace ClassView
} // ClassView::Internal

View File

@@ -3,11 +3,11 @@
#pragma once
#include <QMetaType>
#include <QString>
#include <utils/filepath.h>
namespace ClassView {
namespace Internal {
#include <QMetaType>
namespace ClassView::Internal {
class SymbolLocation
{
@@ -16,20 +16,21 @@ public:
SymbolLocation();
//! 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; }
inline int line() const { return m_line; }
inline int column() const { return m_column; }
inline size_t hash() const { return m_hash; }
inline bool operator==(const SymbolLocation &other) const
const Utils::FilePath &filePath() const { return m_fileName; }
int line() const { return m_line; }
int column() const { return m_column; }
size_t hash() const { return m_hash; }
bool operator==(const SymbolLocation &other) const
{
return hash() == other.hash() && line() == other.line() && column() == other.column()
&& fileName() == other.fileName();
&& filePath() == other.filePath();
}
private:
const QString m_fileName;
const Utils::FilePath m_fileName;
const int m_line;
const int m_column;
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();
}
} // namespace Internal
} // namespace ClassView
} // ClassView::Internal
Q_DECLARE_METATYPE(ClassView::Internal::SymbolLocation)

View File

@@ -162,7 +162,7 @@ QMimeData *TreeItemModel::mimeData(const QModelIndexList &indexes) const
if (locations.isEmpty())
continue;
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()) {
delete mimeData;