aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-11-23 18:05:46 +0100
committerhjk <hjk@qt.io>2022-11-28 14:02:05 +0000
commit196e73fa163ff463570e9ab0e28ac04b4df9c69a (patch)
tree053107c4dd998caed19ea1059127fe1dcfccca7c /src/plugins/cppeditor
parentf68db427ef763b995f9e4fa3f1dbf2c9b90ad943 (diff)
CppEditor: Convert AbstractEditorSupport interface to FilePath
Change-Id: I47439e154bc28d40e112b7eef46fa1f57a8b3fce Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r--src/plugins/cppeditor/abstracteditorsupport.cpp16
-rw-r--r--src/plugins/cppeditor/abstracteditorsupport.h13
-rw-r--r--src/plugins/cppeditor/cppeditordocument.cpp2
-rw-r--r--src/plugins/cppeditor/cppmodelmanager.cpp15
-rw-r--r--src/plugins/cppeditor/editordocumenthandle.h7
-rw-r--r--src/plugins/cppeditor/generatedcodemodelsupport.cpp36
-rw-r--r--src/plugins/cppeditor/generatedcodemodelsupport.h16
7 files changed, 54 insertions, 51 deletions
diff --git a/src/plugins/cppeditor/abstracteditorsupport.cpp b/src/plugins/cppeditor/abstracteditorsupport.cpp
index 14f800f794..32d141cbae 100644
--- a/src/plugins/cppeditor/abstracteditorsupport.cpp
+++ b/src/plugins/cppeditor/abstracteditorsupport.cpp
@@ -11,6 +11,8 @@
#include <utils/macroexpander.h>
#include <utils/templateengine.h>
+using namespace Utils;
+
namespace CppEditor {
AbstractEditorSupport::AbstractEditorSupport(CppModelManager *modelmanager, QObject *parent) :
@@ -27,22 +29,23 @@ AbstractEditorSupport::~AbstractEditorSupport()
void AbstractEditorSupport::updateDocument()
{
++m_revision;
- m_modelmanager->updateSourceFiles(QSet<QString>{fileName()});
+ m_modelmanager->updateSourceFiles(QSet<QString>{filePath().toString()});
}
void AbstractEditorSupport::notifyAboutUpdatedContents() const
{
- m_modelmanager->emitAbstractEditorSupportContentsUpdated(fileName(), sourceFileName(), contents());
+ m_modelmanager->emitAbstractEditorSupportContentsUpdated(
+ filePath().toString(), sourceFilePath().toString(), contents());
}
-QString AbstractEditorSupport::licenseTemplate(const QString &file, const QString &className)
+QString AbstractEditorSupport::licenseTemplate(const FilePath &filePath, const QString &className)
{
const QString license = Internal::CppFileSettings::licenseTemplate();
Utils::MacroExpander expander;
expander.registerVariable("Cpp:License:FileName", tr("The file name."),
- [file]() { return Utils::FilePath::fromString(file).fileName(); });
+ [filePath] { return filePath.fileName(); });
expander.registerVariable("Cpp:License:ClassName", tr("The class name."),
- [className]() { return className; });
+ [className] { return className; });
return Utils::TemplateEngine::processText(&expander, license, nullptr);
}
@@ -52,5 +55,4 @@ bool AbstractEditorSupport::usePragmaOnce()
return Internal::CppEditorPlugin::usePragmaOnce();
}
-} // namespace CppEditor
-
+} // CppEditor
diff --git a/src/plugins/cppeditor/abstracteditorsupport.h b/src/plugins/cppeditor/abstracteditorsupport.h
index 0a7e633c3d..e5ec8eafc4 100644
--- a/src/plugins/cppeditor/abstracteditorsupport.h
+++ b/src/plugins/cppeditor/abstracteditorsupport.h
@@ -5,29 +5,32 @@
#include "cppeditor_global.h"
-#include <QString>
+#include <utils/filepath.h>
+
#include <QObject>
namespace CppEditor {
+
class CppModelManager;
class CPPEDITOR_EXPORT AbstractEditorSupport : public QObject
{
Q_OBJECT
+
public:
explicit AbstractEditorSupport(CppModelManager *modelmanager, QObject *parent = nullptr);
~AbstractEditorSupport() override;
/// \returns the contents, encoded as UTF-8
virtual QByteArray contents() const = 0;
- virtual QString fileName() const = 0;
- virtual QString sourceFileName() const = 0;
+ virtual Utils::FilePath filePath() const = 0;
+ virtual Utils::FilePath sourceFilePath() const = 0;
void updateDocument();
void notifyAboutUpdatedContents() const;
unsigned revision() const { return m_revision; }
- static QString licenseTemplate(const QString &file = QString(), const QString &className = QString());
+ static QString licenseTemplate(const Utils::FilePath &filePath = {}, const QString &className = {});
static bool usePragmaOnce();
private:
@@ -35,4 +38,4 @@ private:
unsigned m_revision;
};
-} // namespace CppEditor
+} // CppEditor
diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp
index a60cd9660a..0d3d6a634f 100644
--- a/src/plugins/cppeditor/cppeditordocument.cpp
+++ b/src/plugins/cppeditor/cppeditordocument.cpp
@@ -63,7 +63,7 @@ public:
mm()->unregisterCppEditorDocument(m_registrationFilePath);
}
- QString filePath() const override { return m_cppEditorDocument->filePath().toString(); }
+ FilePath filePath() const override { return m_cppEditorDocument->filePath(); }
QByteArray contents() const override { return m_cppEditorDocument->contentsText(); }
unsigned revision() const override { return m_cppEditorDocument->contentsRevision(); }
diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp
index 42798d3a00..a768af9073 100644
--- a/src/plugins/cppeditor/cppmodelmanager.cpp
+++ b/src/plugins/cppeditor/cppmodelmanager.cpp
@@ -1128,12 +1128,12 @@ BaseEditorDocumentProcessor *CppModelManager::cppEditorDocumentProcessor(const Q
void CppModelManager::registerCppEditorDocument(CppEditorDocumentHandle *editorDocument)
{
QTC_ASSERT(editorDocument, return);
- const QString filePath = editorDocument->filePath();
+ const FilePath filePath = editorDocument->filePath();
QTC_ASSERT(!filePath.isEmpty(), return);
QMutexLocker locker(&d->m_cppEditorDocumentsMutex);
- QTC_ASSERT(d->m_cppEditorDocuments.value(filePath, 0) == 0, return);
- d->m_cppEditorDocuments.insert(filePath, editorDocument);
+ QTC_ASSERT(d->m_cppEditorDocuments.value(filePath.toString(), 0) == 0, return);
+ d->m_cppEditorDocuments.insert(filePath.toString(), editorDocument);
}
void CppModelManager::unregisterCppEditorDocument(const QString &filePath)
@@ -1204,7 +1204,7 @@ WorkingCopy CppModelManager::buildWorkingCopyList()
}
for (AbstractEditorSupport *es : std::as_const(d->m_extraEditorSupports))
- workingCopy.insert(es->fileName(), es->contents(), es->revision());
+ workingCopy.insert(es->filePath(), es->contents(), es->revision());
// Add the project configuration file
QByteArray conf = codeModelConfiguration();
@@ -1922,21 +1922,22 @@ void CppModelManager::GC()
return;
// Collect files of opened editors and editor supports (e.g. ui code model)
- QStringList filesInEditorSupports;
+ FilePaths filesInEditorSupports;
const QList<CppEditorDocumentHandle *> editorDocuments = cppEditorDocuments();
for (const CppEditorDocumentHandle *editorDocument : editorDocuments)
filesInEditorSupports << editorDocument->filePath();
const QSet<AbstractEditorSupport *> abstractEditorSupportList = abstractEditorSupports();
for (AbstractEditorSupport *abstractEditorSupport : abstractEditorSupportList)
- filesInEditorSupports << abstractEditorSupport->fileName();
+ filesInEditorSupports << abstractEditorSupport->filePath();
Snapshot currentSnapshot = snapshot();
QSet<Utils::FilePath> reachableFiles;
// The configuration file is part of the project files, which is just fine.
// If single files are open, without any project, then there is no need to
// keep the configuration file around.
- FilePaths todo = transform(filesInEditorSupports + projectFiles(), &FilePath::fromString);
+ FilePaths todo = filesInEditorSupports;
+ todo += transform(projectFiles(), &FilePath::fromString);
// Collect all files that are reachable from the project files
while (!todo.isEmpty()) {
diff --git a/src/plugins/cppeditor/editordocumenthandle.h b/src/plugins/cppeditor/editordocumenthandle.h
index 2e4384bede..fdb8da28f6 100644
--- a/src/plugins/cppeditor/editordocumenthandle.h
+++ b/src/plugins/cppeditor/editordocumenthandle.h
@@ -6,9 +6,10 @@
#include "cppeditor_global.h"
#include "senddocumenttracker.h"
-#include <QString>
+namespace Utils { class FilePath; }
namespace CppEditor {
+
class BaseEditorDocumentProcessor;
class CPPEDITOR_EXPORT CppEditorDocumentHandle
@@ -25,7 +26,7 @@ public:
void setRefreshReason(const RefreshReason &refreshReason);
// For the Working Copy
- virtual QString filePath() const = 0;
+ virtual Utils::FilePath filePath() const = 0;
virtual QByteArray contents() const = 0;
virtual unsigned revision() const = 0;
@@ -41,4 +42,4 @@ private:
RefreshReason m_refreshReason = None;
};
-} // namespace CppEditor
+} // CppEditor
diff --git a/src/plugins/cppeditor/generatedcodemodelsupport.cpp b/src/plugins/cppeditor/generatedcodemodelsupport.cpp
index 5b4cb36fbb..3a85ab963c 100644
--- a/src/plugins/cppeditor/generatedcodemodelsupport.cpp
+++ b/src/plugins/cppeditor/generatedcodemodelsupport.cpp
@@ -7,12 +7,15 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/idocument.h>
+
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildmanager.h>
+#include <projectexplorer/extracompiler.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
+
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
@@ -22,6 +25,7 @@
using namespace ProjectExplorer;
using namespace CPlusPlus;
+using namespace Utils;
namespace CppEditor {
@@ -46,16 +50,16 @@ private:
};
GeneratedCodeModelSupport::GeneratedCodeModelSupport(CppModelManager *modelmanager,
- ProjectExplorer::ExtraCompiler *generator,
- const Utils::FilePath &generatedFile) :
- AbstractEditorSupport(modelmanager, generator), m_generatedFileName(generatedFile),
+ ExtraCompiler *generator,
+ const FilePath &generatedFile) :
+ AbstractEditorSupport(modelmanager, generator), m_generatedFilePath(generatedFile),
m_generator(generator)
{
QLoggingCategory log("qtc.cppeditor.generatedcodemodelsupport", QtWarningMsg);
qCDebug(log) << "ctor GeneratedCodeModelSupport for" << m_generator->source()
<< generatedFile;
- connect(m_generator, &ProjectExplorer::ExtraCompiler::contentsChanged,
+ connect(m_generator, &ExtraCompiler::contentsChanged,
this, &GeneratedCodeModelSupport::onContentsChanged, Qt::QueuedConnection);
onContentsChanged(generatedFile);
}
@@ -63,14 +67,14 @@ GeneratedCodeModelSupport::GeneratedCodeModelSupport(CppModelManager *modelmanag
GeneratedCodeModelSupport::~GeneratedCodeModelSupport()
{
CppModelManager::instance()->emitAbstractEditorSupportRemoved(
- m_generatedFileName.toString());
+ m_generatedFilePath.toString());
QLoggingCategory log("qtc.cppeditor.generatedcodemodelsupport", QtWarningMsg);
- qCDebug(log) << "dtor ~generatedcodemodelsupport for" << m_generatedFileName;
+ qCDebug(log) << "dtor ~generatedcodemodelsupport for" << m_generatedFilePath;
}
-void GeneratedCodeModelSupport::onContentsChanged(const Utils::FilePath &file)
+void GeneratedCodeModelSupport::onContentsChanged(const FilePath &file)
{
- if (file == m_generatedFileName) {
+ if (file == m_generatedFilePath) {
notifyAboutUpdatedContents();
updateDocument();
}
@@ -78,20 +82,20 @@ void GeneratedCodeModelSupport::onContentsChanged(const Utils::FilePath &file)
QByteArray GeneratedCodeModelSupport::contents() const
{
- return m_generator->content(m_generatedFileName);
+ return m_generator->content(m_generatedFilePath);
}
-QString GeneratedCodeModelSupport::fileName() const
+FilePath GeneratedCodeModelSupport::filePath() const
{
- return m_generatedFileName.toString();
+ return m_generatedFilePath;
}
-QString GeneratedCodeModelSupport::sourceFileName() const
+FilePath GeneratedCodeModelSupport::sourceFilePath() const
{
- return m_generator->source().toString();
+ return m_generator->source();
}
-void GeneratedCodeModelSupport::update(const QList<ProjectExplorer::ExtraCompiler *> &generators)
+void GeneratedCodeModelSupport::update(const QList<ExtraCompiler *> &generators)
{
static QObjectCache extraCompilerCache;
@@ -102,10 +106,10 @@ void GeneratedCodeModelSupport::update(const QList<ProjectExplorer::ExtraCompile
continue;
extraCompilerCache.insert(generator);
- generator->forEachTarget([mm, generator](const Utils::FilePath &generatedFile) {
+ generator->forEachTarget([mm, generator](const FilePath &generatedFile) {
new GeneratedCodeModelSupport(mm, generator, generatedFile);
});
}
}
-} // namespace CppEditor
+} // CppEditor
diff --git a/src/plugins/cppeditor/generatedcodemodelsupport.h b/src/plugins/cppeditor/generatedcodemodelsupport.h
index dc4d362e2b..0c2d9097a6 100644
--- a/src/plugins/cppeditor/generatedcodemodelsupport.h
+++ b/src/plugins/cppeditor/generatedcodemodelsupport.h
@@ -6,15 +6,7 @@
#include "cppeditor_global.h"
#include "abstracteditorsupport.h"
-#include <projectexplorer/projectnodes.h>
-#include <projectexplorer/extracompiler.h>
-
-#include <QDateTime>
-#include <QHash>
-#include <QSet>
-
-namespace Core { class IEditor; }
-namespace ProjectExplorer { class Project; }
+namespace ProjectExplorer { class ExtraCompiler; }
namespace CppEditor {
@@ -30,14 +22,14 @@ public:
/// \returns the contents encoded in UTF-8.
QByteArray contents() const override;
- QString fileName() const override; // The generated file
- QString sourceFileName() const override;
+ Utils::FilePath filePath() const override; // The generated file
+ Utils::FilePath sourceFilePath() const override;
static void update(const QList<ProjectExplorer::ExtraCompiler *> &generators);
private:
void onContentsChanged(const Utils::FilePath &file);
- Utils::FilePath m_generatedFileName;
+ Utils::FilePath m_generatedFilePath;
ProjectExplorer::ExtraCompiler *m_generator;
};