From 68b9966bf208cdcb12f9f2ed34a3dc6e60a19fe4 Mon Sep 17 00:00:00 2001 From: Daniel Teske <daniel.teske@digia.com> Date: Tue, 8 Jan 2013 17:21:18 +0100 Subject: [PATCH] Fix .ui code completion for some cmake projects CMake generates the ui*h file in the directory that corresponds to the CMakeLists.txt. Creator does not have the information whihch CMakeLists.txt file includes the .ui file. This patch adds a crude heuristic that searches for the right CMakeLists.txt. Task-number: QTCREATORBUG-8509 Change-Id: I0f31d9766c6b5988a00ab618026ea052690dd649 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> --- .../cmakeprojectmanager/cmakeproject.cpp | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 94f8b827b4c..a3b9493a624 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -651,16 +651,28 @@ QString CMakeProject::uicCommand() const QString CMakeProject::uiHeaderFile(const QString &uiFile) { - QDir srcDirRoot = QDir(projectDirectory()); - QString relativePath = srcDirRoot.relativeFilePath(uiFile); + QFileInfo fi(uiFile); + Utils::FileName project = Utils::FileName::fromString(projectDirectory()); + Utils::FileName baseDirectory = Utils::FileName::fromString(fi.absolutePath()); + + while (baseDirectory.isChildOf(project)) { + Utils::FileName cmakeListsTxt = baseDirectory; + cmakeListsTxt.appendPath(QLatin1String("CMakeLists.txt")); + if (cmakeListsTxt.toFileInfo().exists()) + break; + QDir dir(baseDirectory.toString()); + dir.cdUp(); + baseDirectory = Utils::FileName::fromString(dir.absolutePath()); + } + + QDir srcDirRoot = QDir(project.toString()); + QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString()); QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory()); QString uiHeaderFilePath = buildDir.absoluteFilePath(relativePath); - - QFileInfo fi(uiHeaderFilePath); - uiHeaderFilePath = fi.absolutePath(); uiHeaderFilePath += QLatin1String("/ui_"); uiHeaderFilePath += fi.completeBaseName(); uiHeaderFilePath += QLatin1String(".h"); + return QDir::cleanPath(uiHeaderFilePath); } -- GitLab