ModelEditor: Improve component model creation

Ignore include files that only includes one file with the same name.

Change-Id: I1cac46511b44fec2aa1b3f9b4a6ae644d4ed5e9a
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Jochen Becher
2018-01-12 23:12:29 +01:00
parent d226c84cca
commit 67f14eb32d
2 changed files with 41 additions and 11 deletions

View File

@@ -161,6 +161,16 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen
if (document) { if (document) {
foreach (const CPlusPlus::Document::Include &include, document->resolvedIncludes()) { foreach (const CPlusPlus::Document::Include &include, document->resolvedIncludes()) {
QString includeFilePath = include.resolvedFileName(); QString includeFilePath = include.resolvedFileName();
// replace proxy header with real one
CPlusPlus::Document::Ptr includeDocument = snapshot.document(includeFilePath);
if (includeDocument) {
QList<CPlusPlus::Document::Include> includes = includeDocument->resolvedIncludes();
if (includes.count() == 1 &&
QFileInfo(includes.at(0).resolvedFileName()).fileName() == QFileInfo(includeFilePath).fileName())
{
includeFilePath = includes.at(0).resolvedFileName();
}
}
qmt::MComponent *includeComponent = findComponentFromFilePath(includeFilePath); qmt::MComponent *includeComponent = findComponentFromFilePath(includeFilePath);
if (includeComponent && includeComponent != component) { if (includeComponent && includeComponent != component) {
// add dependency between components // add dependency between components
@@ -390,7 +400,8 @@ void ComponentViewController::createComponentModel(const QString &filePath,
const QString &anchorFolder) const QString &anchorFolder)
{ {
d->diagramSceneController->modelController()->startResetModel(); d->diagramSceneController->modelController()->startResetModel();
doCreateComponentModel(filePath, diagram, anchorFolder); doCreateComponentModel(filePath, diagram, anchorFolder, false);
doCreateComponentModel(filePath, diagram, anchorFolder, true);
d->diagramSceneController->modelController()->finishResetModel(true); d->diagramSceneController->modelController()->finishResetModel(true);
} }
@@ -404,7 +415,8 @@ void ComponentViewController::updateIncludeDependencies(qmt::MPackage *rootPacka
d->diagramSceneController->modelController()->finishResetModel(true); d->diagramSceneController->modelController()->finishResetModel(true);
} }
void ComponentViewController::doCreateComponentModel(const QString &filePath, qmt::MDiagram *diagram, const QString &anchorFolder) void ComponentViewController::doCreateComponentModel(const QString &filePath, qmt::MDiagram *diagram,
const QString &anchorFolder, bool scanHeaders)
{ {
for (const QString &fileName : QDir(filePath).entryList(QDir::Files)) { for (const QString &fileName : QDir(filePath).entryList(QDir::Files)) {
QString file = filePath + "/" + fileName; QString file = filePath + "/" + fileName;
@@ -413,18 +425,20 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm
bool isSource = false; bool isSource = false;
CppTools::ProjectFile::Kind kind = CppTools::ProjectFile::classify(file); CppTools::ProjectFile::Kind kind = CppTools::ProjectFile::classify(file);
switch (kind) { switch (kind) {
case CppTools::ProjectFile::AmbiguousHeader:
case CppTools::ProjectFile::CHeader:
case CppTools::ProjectFile::CSource: case CppTools::ProjectFile::CSource:
case CppTools::ProjectFile::CXXHeader:
case CppTools::ProjectFile::CXXSource: case CppTools::ProjectFile::CXXSource:
case CppTools::ProjectFile::ObjCSource: case CppTools::ProjectFile::ObjCSource:
case CppTools::ProjectFile::ObjCHeader:
case CppTools::ProjectFile::ObjCXXSource: case CppTools::ProjectFile::ObjCXXSource:
case CppTools::ProjectFile::ObjCXXHeader:
case CppTools::ProjectFile::CudaSource: case CppTools::ProjectFile::CudaSource:
case CppTools::ProjectFile::OpenCLSource: case CppTools::ProjectFile::OpenCLSource:
isSource = true; isSource = !scanHeaders;
break;
case CppTools::ProjectFile::AmbiguousHeader:
case CppTools::ProjectFile::CHeader:
case CppTools::ProjectFile::CXXHeader:
case CppTools::ProjectFile::ObjCHeader:
case CppTools::ProjectFile::ObjCXXHeader:
isSource = scanHeaders && !isProxyHeader(file);
break; break;
case CppTools::ProjectFile::Unclassified: case CppTools::ProjectFile::Unclassified:
case CppTools::ProjectFile::Unsupported: case CppTools::ProjectFile::Unsupported:
@@ -450,9 +464,24 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm
} }
for (const QString &fileName : QDir(filePath).entryList(QDir::Dirs|QDir::NoDotAndDotDot)) { for (const QString &fileName : QDir(filePath).entryList(QDir::Dirs|QDir::NoDotAndDotDot)) {
QString file = filePath + "/" + fileName; QString file = filePath + "/" + fileName;
doCreateComponentModel(file, diagram, anchorFolder); doCreateComponentModel(file, diagram, anchorFolder, scanHeaders);
} }
} }
bool ComponentViewController::isProxyHeader(const QString &file) const
{
CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance();
CPlusPlus::Snapshot snapshot = cppModelManager->snapshot();
CPlusPlus::Document::Ptr document = snapshot.document(file);
if (document) {
QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
if (includes.count() != 1)
return false;
return QFileInfo(includes.at(0).resolvedFileName()).fileName() == QFileInfo(file).fileName();
}
return false;
}
} // namespace Internal } // namespace Internal
} // namespace ModelEditor } // namespace ModelEditor

View File

@@ -58,8 +58,9 @@ public:
void updateIncludeDependencies(qmt::MPackage *rootPackage); void updateIncludeDependencies(qmt::MPackage *rootPackage);
private: private:
void doCreateComponentModel(const QString &filePath, void doCreateComponentModel(const QString &filePath, qmt::MDiagram *diagram,
qmt::MDiagram *diagram, const QString &anchorFolder); const QString &anchorFolder, bool scanHeaders);
bool isProxyHeader(const QString &file) const;
ComponentViewControllerPrivate *d; ComponentViewControllerPrivate *d;
}; };