diff options
author | hjk <hjk@qt.io> | 2022-11-21 16:48:50 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2022-11-22 15:30:00 +0000 |
commit | fa1adf4d4001207902a5572b39da4f1cbc8752f1 (patch) | |
tree | ff9cbc1c951ab862f03902d38fc4495c3e1a3ae9 /src/plugins/cppeditor/cppcodemodelinspectordialog.cpp | |
parent | 822e2a224a283581b38948d4626f873c6b38c044 (diff) | |
download | qt-creator-fa1adf4d4001207902a5572b39da4f1cbc8752f1.tar.gz |
CPlusPlus: Proliferate FilePath use
The starts with CppDocument::filePath(), plus a bit of the fallout
This is one patch of potentially many. It is hard to draw the
line where to stop this kind of chunk, this here converts a few
additional functions for which including it in the patch looked
like less churn than without.
Converting is mostly fromString/toString, with a few exceptions
for "already seem" like caches, that use cheaper "path()" to
avoid likely performance regressions (on Windows FilePath
comparison is currently case-insenstive, and more expensive).
There should be no difference for local operation with this patch.
Change-Id: I7b35f98a0a6f0bfed4ea0f8f987faf586f7a8f2b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppcodemodelinspectordialog.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelinspectordialog.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 0b5006e6bf..176bd9f4fc 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -33,6 +33,8 @@ #include <numeric> using namespace CPlusPlus; +using namespace Utils; + namespace CMI = CppEditor::CppCodeModelInspector; namespace { @@ -48,11 +50,11 @@ TextEditor::BaseTextEditor *currentEditor() return qobject_cast<TextEditor::BaseTextEditor*>(Core::EditorManager::currentEditor()); } -QString fileInCurrentEditor() +Utils::FilePath fileInCurrentEditor() { if (TextEditor::BaseTextEditor *editor = currentEditor()) - return editor->document()->filePath().toString(); - return QString(); + return editor->document()->filePath(); + return {}; } QSizePolicy sizePolicyWithStretchFactor(int stretchFactor) @@ -435,7 +437,7 @@ public: void configure(const Snapshot &snapshot); void setGlobalSnapshot(const Snapshot &snapshot); - QModelIndex indexForDocument(const QString &filePath); + QModelIndex indexForDocument(const Utils::FilePath &filePath); enum Columns { SymbolCountColumn, SharedColumn, FilePathColumn, ColumnCount }; @@ -465,11 +467,11 @@ void SnapshotModel::setGlobalSnapshot(const Snapshot &snapshot) m_globalSnapshot = snapshot; } -QModelIndex SnapshotModel::indexForDocument(const QString &filePath) +QModelIndex SnapshotModel::indexForDocument(const FilePath &filePath) { for (int i = 0, total = m_documents.size(); i < total; ++i) { const Document::Ptr document = m_documents.at(i); - if (document->fileName() == filePath) + if (document->filePath() == filePath) return index(i, FilePathColumn); } return {}; @@ -493,12 +495,12 @@ QVariant SnapshotModel::data(const QModelIndex &index, int role) const if (column == SymbolCountColumn) { return document->control()->symbolCount(); } else if (column == SharedColumn) { - Document::Ptr globalDocument = m_globalSnapshot.document(document->fileName()); + Document::Ptr globalDocument = m_globalSnapshot.document(document->filePath()); const bool isShared = globalDocument && globalDocument->fingerprint() == document->fingerprint(); return CMI::Utils::toString(isShared); } else if (column == FilePathColumn) { - return QDir::toNativeSeparators(document->fileName()); + return document->filePath().toUserOutput(); } } return QVariant(); @@ -1200,7 +1202,7 @@ public: WorkingCopyModel(QObject *parent); void configure(const WorkingCopy &workingCopy); - QModelIndex indexForFile(const QString &filePath); + QModelIndex indexForFile(const Utils::FilePath &filePath); enum Columns { RevisionColumn, FilePathColumn, ColumnCount }; @@ -1211,11 +1213,11 @@ public: private: struct WorkingCopyEntry { - WorkingCopyEntry(const QString &filePath, const QByteArray &source, unsigned revision) + WorkingCopyEntry(const Utils::FilePath &filePath, const QByteArray &source, unsigned revision) : filePath(filePath), source(source), revision(revision) {} - QString filePath; + Utils::FilePath filePath; QByteArray source; unsigned revision; }; @@ -1232,14 +1234,13 @@ void WorkingCopyModel::configure(const WorkingCopy &workingCopy) emit layoutAboutToBeChanged(); m_workingCopyList.clear(); const WorkingCopy::Table &elements = workingCopy.elements(); - for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) { - m_workingCopyList << WorkingCopyEntry(it.key().toString(), it.value().first, - it.value().second); - } + for (auto it = elements.cbegin(), end = elements.cend(); it != end; ++it) + m_workingCopyList << WorkingCopyEntry(it.key(), it.value().first, it.value().second); + emit layoutChanged(); } -QModelIndex WorkingCopyModel::indexForFile(const QString &filePath) +QModelIndex WorkingCopyModel::indexForFile(const Utils::FilePath &filePath) { for (int i = 0, total = m_workingCopyList.size(); i < total; ++i) { const WorkingCopyEntry entry = m_workingCopyList.at(i); @@ -1267,7 +1268,7 @@ QVariant WorkingCopyModel::data(const QModelIndex &index, int role) const if (column == RevisionColumn) return m_workingCopyList.at(row).revision; else if (column == FilePathColumn) - return m_workingCopyList.at(row).filePath; + return m_workingCopyList.at(row).filePath.toString(); } else if (role == Qt::UserRole) { return m_workingCopyList.at(row).source; } @@ -1659,14 +1660,14 @@ void CppCodeModelInspectorDialog::updateDocumentData(const Document::Ptr &docume // General const KeyValueModel::Table table = { - {QString::fromLatin1("File Path"), QDir::toNativeSeparators(document->fileName())}, + {QString::fromLatin1("File Path"), document->filePath().toUserOutput()}, {QString::fromLatin1("Last Modified"), CMI::Utils::toString(document->lastModified())}, {QString::fromLatin1("Revision"), CMI::Utils::toString(document->revision())}, {QString::fromLatin1("Editor Revision"), CMI::Utils::toString(document->editorRevision())}, {QString::fromLatin1("Check Mode"), CMI::Utils::toString(document->checkMode())}, {QString::fromLatin1("Tokenized"), CMI::Utils::toString(document->isTokenized())}, {QString::fromLatin1("Parsed"), CMI::Utils::toString(document->isParsed())}, - {QString::fromLatin1("Project Parts"), CMI::Utils::partsForFile(document->fileName())} + {QString::fromLatin1("Project Parts"), CMI::Utils::partsForFile(document->filePath())} }; m_docGenericInfoModel->configure(table); resizeColumns<KeyValueModel>(m_ui->docGeneralView); |