CppTools: Add sourceFilePath to AbstractEditorSupport

Provide the source path to track a generated file source. You can for
example get the modified time stamp for the source file and use it for the
generated file content.

Task-number: QTCREATORBUG-21876
Change-Id: Ia422e128c5cb7a3dce88960f126152c2f65afb41
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Marco Bubke
2019-01-23 13:14:50 +01:00
parent 2e19352177
commit f5c3007058
10 changed files with 24 additions and 8 deletions

View File

@@ -293,6 +293,7 @@ void ClangModelManagerSupport::onCppDocumentContentsChangedOnUnsavedFile()
} }
void ClangModelManagerSupport::onAbstractEditorSupportContentsUpdated(const QString &filePath, void ClangModelManagerSupport::onAbstractEditorSupportContentsUpdated(const QString &filePath,
const QString &,
const QByteArray &content) const QByteArray &content)
{ {
QTC_ASSERT(!filePath.isEmpty(), return); QTC_ASSERT(!filePath.isEmpty(), return);

View File

@@ -94,7 +94,9 @@ private:
void onCppDocumentReloadFinishedOnUnsavedFile(bool success); void onCppDocumentReloadFinishedOnUnsavedFile(bool success);
void onCppDocumentContentsChangedOnUnsavedFile(); void onCppDocumentContentsChangedOnUnsavedFile();
void onAbstractEditorSupportContentsUpdated(const QString &filePath, const QByteArray &content); void onAbstractEditorSupportContentsUpdated(const QString &filePath,
const QString &sourceFilePath,
const QByteArray &content);
void onAbstractEditorSupportRemoved(const QString &filePath); void onAbstractEditorSupportRemoved(const QString &filePath);
void onTextMarkContextMenuRequested(TextEditor::TextEditorWidget *widget, void onTextMarkContextMenuRequested(TextEditor::TextEditorWidget *widget,

View File

@@ -103,9 +103,11 @@ private:
[&] (const QStringList &projectPartIds) { projectPartsRemoved(projectPartIds); }); [&] (const QStringList &projectPartIds) { projectPartsRemoved(projectPartIds); });
QObject::connect(Internal::cppModelManager(), QObject::connect(Internal::cppModelManager(),
&CppTools::CppModelManager::abstractEditorSupportContentsUpdated, &CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
[&] (const QString &filePath, const QByteArray &contents) { [&](const QString &filePath,
abstractEditorUpdated(filePath, contents); const QString &,
}); const QByteArray &contents) {
abstractEditorUpdated(filePath, contents);
});
QObject::connect(Internal::cppModelManager(), QObject::connect(Internal::cppModelManager(),
&CppTools::CppModelManager::abstractEditorSupportRemoved, &CppTools::CppModelManager::abstractEditorSupportRemoved,
[&] (const QString &filePath) { abstractEditorRemoved(filePath); }); [&] (const QString &filePath) { abstractEditorRemoved(filePath); });

View File

@@ -84,7 +84,7 @@ void QtCreatorRefactoringProjectUpdater::connectToCppModelManager()
QObject::connect(cppModelManager(), QObject::connect(cppModelManager(),
&CppTools::CppModelManager::abstractEditorSupportContentsUpdated, &CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
[&] (const QString &filePath, const QByteArray &contents) { [&] (const QString &filePath, const QString &, const QByteArray &contents) {
abstractEditorUpdated(filePath, contents); abstractEditorUpdated(filePath, contents);
}); });

View File

@@ -54,7 +54,7 @@ void AbstractEditorSupport::updateDocument()
void AbstractEditorSupport::notifyAboutUpdatedContents() const void AbstractEditorSupport::notifyAboutUpdatedContents() const
{ {
m_modelmanager->emitAbstractEditorSupportContentsUpdated(fileName(), contents()); m_modelmanager->emitAbstractEditorSupportContentsUpdated(fileName(), sourceFileName(), contents());
} }
QString AbstractEditorSupport::licenseTemplate(const QString &file, const QString &className) QString AbstractEditorSupport::licenseTemplate(const QString &file, const QString &className)

View File

@@ -43,6 +43,7 @@ public:
/// \returns the contents, encoded as UTF-8 /// \returns the contents, encoded as UTF-8
virtual QByteArray contents() const = 0; virtual QByteArray contents() const = 0;
virtual QString fileName() const = 0; virtual QString fileName() const = 0;
virtual QString sourceFileName() const = 0;
void updateDocument(); void updateDocument();
void notifyAboutUpdatedContents() const; void notifyAboutUpdatedContents() const;

View File

@@ -1188,9 +1188,10 @@ void CppModelManager::emitDocumentUpdated(Document::Ptr doc)
} }
void CppModelManager::emitAbstractEditorSupportContentsUpdated(const QString &filePath, void CppModelManager::emitAbstractEditorSupportContentsUpdated(const QString &filePath,
const QString &sourcePath,
const QByteArray &contents) const QByteArray &contents)
{ {
emit abstractEditorSupportContentsUpdated(filePath, contents); emit abstractEditorSupportContentsUpdated(filePath, sourcePath, contents);
} }
void CppModelManager::emitAbstractEditorSupportRemoved(const QString &filePath) void CppModelManager::emitAbstractEditorSupportRemoved(const QString &filePath)

View File

@@ -137,6 +137,7 @@ public:
void emitDocumentUpdated(Document::Ptr doc); void emitDocumentUpdated(Document::Ptr doc);
void emitAbstractEditorSupportContentsUpdated(const QString &filePath, void emitAbstractEditorSupportContentsUpdated(const QString &filePath,
const QString &sourcePath,
const QByteArray &contents); const QByteArray &contents);
void emitAbstractEditorSupportRemoved(const QString &filePath); void emitAbstractEditorSupportRemoved(const QString &filePath);
@@ -243,7 +244,9 @@ signals:
void gcFinished(); // Needed for tests. void gcFinished(); // Needed for tests.
void abstractEditorSupportContentsUpdated(const QString &filePath, const QByteArray &contents); void abstractEditorSupportContentsUpdated(const QString &filePath,
const QString &sourcePath,
const QByteArray &contents);
void abstractEditorSupportRemoved(const QString &filePath); void abstractEditorSupportRemoved(const QString &filePath);
public slots: public slots:

View File

@@ -108,6 +108,11 @@ QString GeneratedCodeModelSupport::fileName() const
return m_generatedFileName.toString(); return m_generatedFileName.toString();
} }
QString GeneratedCodeModelSupport::sourceFileName() const
{
return m_generator->source().toString();
}
void GeneratedCodeModelSupport::update(const QList<ProjectExplorer::ExtraCompiler *> &generators) void GeneratedCodeModelSupport::update(const QList<ProjectExplorer::ExtraCompiler *> &generators)
{ {
static QObjectCache extraCompilerCache; static QObjectCache extraCompilerCache;

View File

@@ -54,6 +54,7 @@ public:
/// \returns the contents encoded in UTF-8. /// \returns the contents encoded in UTF-8.
QByteArray contents() const override; QByteArray contents() const override;
QString fileName() const override; // The generated file QString fileName() const override; // The generated file
QString sourceFileName() const override;
static void update(const QList<ProjectExplorer::ExtraCompiler *> &generators); static void update(const QList<ProjectExplorer::ExtraCompiler *> &generators);