CppTools: Fix propagating unsaved files

On project loading ExtraCompiler objects are created that might read the
already existing ui_*.h files in the build directory. In this case,
ExtraCompiler::setContent() is called, which will emit a signal about
the modified content.

Now GeneratedCodeModelSupport is a client of this signal and it forwards
the changed contents to the clang code model. However,
GeneratedCodeModelSupport objects might be created later and miss the
initial signal emission, thus leaving the code model unaware of some
unsaved files.

Fix by notifying the code model at construction time of
GeneratedCodeModelSupport.

Change-Id: I7311867ad7f534920357801647bd2d0c82bb4edb
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Nikolai Kosjar
2016-11-17 17:00:01 +01:00
parent 814bf768af
commit b4d6884c25
2 changed files with 4 additions and 8 deletions

View File

@@ -76,7 +76,10 @@ GeneratedCodeModelSupport::GeneratedCodeModelSupport(CppModelManager *modelmanag
QLoggingCategory log("qtc.cpptools.generatedcodemodelsupport");
qCDebug(log) << "ctor GeneratedCodeModelSupport for" << m_generator->source()
<< generatedFile;
init();
connect(m_generator, &ProjectExplorer::ExtraCompiler::contentsChanged,
this, &GeneratedCodeModelSupport::onContentsChanged, Qt::QueuedConnection);
onContentsChanged(generatedFile);
}
GeneratedCodeModelSupport::~GeneratedCodeModelSupport()
@@ -95,12 +98,6 @@ void GeneratedCodeModelSupport::onContentsChanged(const Utils::FileName &file)
}
}
void GeneratedCodeModelSupport::init() const
{
connect(m_generator, &ProjectExplorer::ExtraCompiler::contentsChanged,
this, &GeneratedCodeModelSupport::onContentsChanged, Qt::QueuedConnection);
}
QByteArray GeneratedCodeModelSupport::contents() const
{
return m_generator->content(m_generatedFileName);