Introduce method to access the project directory

... use it.

Reviewed-by: dt
This commit is contained in:
Tobias Hunger
2010-03-25 13:19:27 +01:00
parent 3a15c8c3c5
commit 1ca8cb2397
18 changed files with 36 additions and 39 deletions

View File

@@ -93,7 +93,7 @@ QString CMakeBuildConfiguration::buildDirectory() const
{ {
QString buildDirectory = m_buildDirectory; QString buildDirectory = m_buildDirectory;
if (buildDirectory.isEmpty()) if (buildDirectory.isEmpty())
buildDirectory = cmakeTarget()->cmakeProject()->sourceDirectory() + "/qtcreator-build"; buildDirectory = target()->project()->projectDirectory() + "/qtcreator-build";
return buildDirectory; return buildDirectory;
} }
@@ -221,7 +221,7 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer:
cleanMakeStep->setClean(true); cleanMakeStep->setClean(true);
CMakeOpenProjectWizard copw(cmtarget->cmakeProject()->projectManager(), CMakeOpenProjectWizard copw(cmtarget->cmakeProject()->projectManager(),
cmtarget->cmakeProject()->sourceDirectory(), cmtarget->project()->projectDirectory(),
bc->buildDirectory(), bc->buildDirectory(),
bc->environment()); bc->environment());
if (copw.exec() != QDialog::Accepted) { if (copw.exec() != QDialog::Accepted) {

View File

@@ -156,11 +156,6 @@ void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QStri
parseCMakeLists(); parseCMakeLists();
} }
QString CMakeProject::sourceDirectory() const
{
return QFileInfo(m_fileName).absolutePath();
}
bool CMakeProject::parseCMakeLists() bool CMakeProject::parseCMakeLists()
{ {
if (!activeTarget() || if (!activeTarget() ||
@@ -198,7 +193,7 @@ bool CMakeProject::parseCMakeLists()
projectFiles.insert(node->path()); projectFiles.insert(node->path());
} else { } else {
// Manually add the CMakeLists.txt file // Manually add the CMakeLists.txt file
QString cmakeListTxt = sourceDirectory() + "/CMakeLists.txt"; QString cmakeListTxt = projectDirectory() + "/CMakeLists.txt";
fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, false)); fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, false));
projectFiles.insert(cmakeListTxt); projectFiles.insert(cmakeListTxt);
} }
@@ -240,7 +235,7 @@ bool CMakeProject::parseCMakeLists()
allIncludePaths.append(headerPath.path()); allIncludePaths.append(headerPath.path());
} }
// This explicitly adds -I. to the include paths // This explicitly adds -I. to the include paths
allIncludePaths.append(sourceDirectory()); allIncludePaths.append(projectDirectory());
allIncludePaths.append(cbpparser.includeFiles()); allIncludePaths.append(cbpparser.includeFiles());
CppTools::CppModelManagerInterface *modelmanager = CppTools::CppModelManagerInterface *modelmanager =
@@ -479,7 +474,7 @@ bool CMakeProject::fromMap(const QVariantMap &map)
// Ask the user for where he wants to build it // Ask the user for where he wants to build it
// and the cmake command line // and the cmake command line
CMakeOpenProjectWizard copw(m_manager, sourceDirectory(), ProjectExplorer::Environment::systemEnvironment()); CMakeOpenProjectWizard copw(m_manager, projectDirectory(), ProjectExplorer::Environment::systemEnvironment());
if (copw.exec() != QDialog::Accepted) if (copw.exec() != QDialog::Accepted)
return false; return false;
@@ -641,7 +636,7 @@ void CMakeBuildSettingsWidget::init(BuildConfiguration *bc)
{ {
m_buildConfiguration = static_cast<CMakeBuildConfiguration *>(bc); m_buildConfiguration = static_cast<CMakeBuildConfiguration *>(bc);
m_pathLineEdit->setText(m_buildConfiguration->buildDirectory()); m_pathLineEdit->setText(m_buildConfiguration->buildDirectory());
if (m_buildConfiguration->buildDirectory() == m_project->sourceDirectory()) if (m_buildConfiguration->buildDirectory() == m_project->projectDirectory())
m_changeButton->setEnabled(false); m_changeButton->setEnabled(false);
else else
m_changeButton->setEnabled(true); m_changeButton->setEnabled(true);
@@ -650,7 +645,7 @@ void CMakeBuildSettingsWidget::init(BuildConfiguration *bc)
void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog() void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog()
{ {
CMakeOpenProjectWizard copw(m_project->projectManager(), CMakeOpenProjectWizard copw(m_project->projectManager(),
m_project->sourceDirectory(), m_project->projectDirectory(),
m_buildConfiguration->buildDirectory(), m_buildConfiguration->buildDirectory(),
m_buildConfiguration->environment()); m_buildConfiguration->environment());
if (copw.exec() == QDialog::Accepted) { if (copw.exec() == QDialog::Accepted) {

View File

@@ -97,8 +97,6 @@ public:
CMakeBuildTarget buildTargetForTitle(const QString &title); CMakeBuildTarget buildTargetForTitle(const QString &title);
QString sourceDirectory() const;
bool parseCMakeLists(); bool parseCMakeLists();
signals: signals:

View File

@@ -77,7 +77,7 @@ QVariantMap GenericBuildConfiguration::toMap() const
bool GenericBuildConfiguration::fromMap(const QVariantMap &map) bool GenericBuildConfiguration::fromMap(const QVariantMap &map)
{ {
m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY)).toString(); m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY), target()->project()->projectDirectory()).toString();
return BuildConfiguration::fromMap(map); return BuildConfiguration::fromMap(map);
} }
@@ -90,8 +90,7 @@ ProjectExplorer::Environment GenericBuildConfiguration::environment() const
QString GenericBuildConfiguration::buildDirectory() const QString GenericBuildConfiguration::buildDirectory() const
{ {
// Convert to absolute path when necessary // Convert to absolute path when necessary
const QFileInfo projectFile(target()->project()->file()->fileName()); const QDir projectDir(target()->project()->projectDirectory());
const QDir projectDir(projectFile.path());
return projectDir.absoluteFilePath(m_buildDirectory); return projectDir.absoluteFilePath(m_buildDirectory);
} }

View File

@@ -141,8 +141,7 @@ GenericTarget *GenericTargetFactory::create(ProjectExplorer::Project *parent, co
makeStep->setBuildTarget("all", /* on = */ true); makeStep->setBuildTarget("all", /* on = */ true);
const QFileInfo fileInfo(genericproject->file()->fileName()); bc->setBuildDirectory(genericproject->projectDirectory());
bc->setBuildDirectory(fileInfo.absolutePath());
t->addBuildConfiguration(bc); t->addBuildConfiguration(bc);

View File

@@ -227,6 +227,12 @@ QVariantMap Project::toMap() const
return map; return map;
} }
QString Project::projectDirectory() const
{
QFileInfo info(file()->fileName());
return info.absoluteDir().path();
}
bool Project::fromMap(const QVariantMap &map) bool Project::fromMap(const QVariantMap &map)
{ {
if (map.contains(QLatin1String(EDITOR_SETTINGS_KEY))) { if (map.contains(QLatin1String(EDITOR_SETTINGS_KEY))) {

View File

@@ -128,6 +128,9 @@ public:
// creating new BuilConfigurations. // creating new BuilConfigurations.
virtual QVariantMap toMap() const; virtual QVariantMap toMap() const;
// The directory that holds the project file. This includes the absolute path.
QString projectDirectory() const;
signals: signals:
void fileListChanged(); void fileListChanged();

View File

@@ -912,8 +912,7 @@ void ProjectExplorerPlugin::newProject()
QString defaultLocation; QString defaultLocation;
if (currentProject()) { if (currentProject()) {
const QFileInfo file(currentProject()->file()->fileName()); QDir dir(currentProject()->projectDirectory());
QDir dir = file.dir();
dir.cdUp(); dir.cdUp();
defaultLocation = dir.absolutePath(); defaultLocation = dir.absolutePath();
} }

View File

@@ -146,7 +146,7 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
Qt4BuildConfiguration *qt4bc = project->activeTarget()->activeBuildConfiguration(); Qt4BuildConfiguration *qt4bc = project->activeTarget()->activeBuildConfiguration();
const QtVersion *qtVersion = qt4bc->qtVersion(); const QtVersion *qtVersion = qt4bc->qtVersion();
data->binary = (qtVersion->*commandAccessor)(); data->binary = (qtVersion->*commandAccessor)();
data->workingDirectory = QFileInfo(project->file()->fileName()).absolutePath(); data->workingDirectory = project->projectDirectory();
} else { } else {
data->workingDirectory.clear(); data->workingDirectory.clear();
data->binary = Utils::SynchronousProcess::locateBinary(fallbackBinary); data->binary = Utils::SynchronousProcess::locateBinary(fallbackBinary);

View File

@@ -53,7 +53,7 @@ ProjectLoadWizard::ProjectLoadWizard(Qt4Project *project, QWidget *parent, Qt::W
{ {
setWindowTitle(tr("Import existing build settings")); setWindowTitle(tr("Import existing build settings"));
QtVersionManager * vm = QtVersionManager::instance(); QtVersionManager * vm = QtVersionManager::instance();
QString directory = QFileInfo(project->file()->fileName()).absolutePath(); QString directory = project->projectDirectory();
QString importVersion = QtVersionManager::findQMakeBinaryFromMakefile(directory); QString importVersion = QtVersionManager::findQMakeBinaryFromMakefile(directory);
if (!importVersion.isNull()) { if (!importVersion.isNull()) {

View File

@@ -164,8 +164,7 @@ QVariantMap MaemoRunConfiguration::toMap() const
map.insert(SimulatorPathKey, m_simulatorPath); map.insert(SimulatorPathKey, m_simulatorPath);
const QDir &dir = QFileInfo(qt4Target()->qt4Project()->file()->fileName()) const QDir dir = QDir(target()->project()->projectDirectory());
.absoluteDir();
map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath)); map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath));
return map; return map;
@@ -196,8 +195,7 @@ bool MaemoRunConfiguration::fromMap(const QVariantMap &map)
m_simulatorPath = map.value(SimulatorPathKey).toString(); m_simulatorPath = map.value(SimulatorPathKey).toString();
const QDir &dir = QFileInfo(qt4Target()->qt4Project()->file()->fileName()) const QDir dir = QDir(target()->project()->projectDirectory());
.absoluteDir();
m_proFilePath = dir.filePath(map.value(ProFileKey).toString()); m_proFilePath = dir.filePath(map.value(ProFileKey).toString());
return true; return true;
@@ -405,7 +403,7 @@ void MaemoRunConfiguration::updateSimulatorInformation() const
"simulator image.").arg(m_simulatorPath); "simulator image.").arg(m_simulatorPath);
} }
QDir dir(m_simulatorPath); QDir dir = QDir(m_simulatorPath);
if (!m_simulatorPath.isEmpty() && dir.exists(m_simulatorPath)) { if (!m_simulatorPath.isEmpty() && dir.exists(m_simulatorPath)) {
const QStringList &files = dir.entryList(QDir::Files | QDir::NoSymLinks const QStringList &files = dir.entryList(QDir::Files | QDir::NoSymLinks
| QDir::NoDotAndDotDot); | QDir::NoDotAndDotDot);

View File

@@ -201,7 +201,7 @@ QWidget *S60DeviceRunConfiguration::configurationWidget()
QVariantMap S60DeviceRunConfiguration::toMap() const QVariantMap S60DeviceRunConfiguration::toMap() const
{ {
QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir(); const QDir projectDir = QDir(target()->project()->projectDirectory());
map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath)); map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath));
map.insert(QLatin1String(SIGNING_MODE_KEY), (int)m_signingMode); map.insert(QLatin1String(SIGNING_MODE_KEY), (int)m_signingMode);
@@ -215,7 +215,7 @@ QVariantMap S60DeviceRunConfiguration::toMap() const
bool S60DeviceRunConfiguration::fromMap(const QVariantMap &map) bool S60DeviceRunConfiguration::fromMap(const QVariantMap &map)
{ {
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir(); const QDir projectDir = QDir(target()->project()->projectDirectory());
m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString()); m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString());
m_signingMode = static_cast<SigningMode>(map.value(QLatin1String(SIGNING_MODE_KEY)).toInt()); m_signingMode = static_cast<SigningMode>(map.value(QLatin1String(SIGNING_MODE_KEY)).toInt());

View File

@@ -134,14 +134,14 @@ QWidget *S60EmulatorRunConfiguration::configurationWidget()
QVariantMap S60EmulatorRunConfiguration::toMap() const QVariantMap S60EmulatorRunConfiguration::toMap() const
{ {
QVariantMap map(ProjectExplorer::RunConfiguration::toMap()); QVariantMap map(ProjectExplorer::RunConfiguration::toMap());
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir(); const QDir projectDir = QDir(target()->project()->projectDirectory());
map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath)); map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath));
return map; return map;
} }
bool S60EmulatorRunConfiguration::fromMap(const QVariantMap &map) bool S60EmulatorRunConfiguration::fromMap(const QVariantMap &map)
{ {
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir(); const QDir projectDir = QDir(target()->project()->projectDirectory());
m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString()); m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString());
return RunConfiguration::fromMap(map); return RunConfiguration::fromMap(map);

View File

@@ -190,7 +190,7 @@ QString Qt4BuildConfiguration::buildDirectory() const
if (m_shadowBuild) if (m_shadowBuild)
workingDirectory = m_buildDirectory; workingDirectory = m_buildDirectory;
if (workingDirectory.isEmpty()) if (workingDirectory.isEmpty())
workingDirectory = QFileInfo(target()->project()->file()->fileName()).absolutePath(); workingDirectory = target()->project()->projectDirectory();
return workingDirectory; return workingDirectory;
} }

View File

@@ -1128,7 +1128,7 @@ void Qt4Project::notifyChanged(const QString &name)
// // adjust the build directory of the sub-project. // // adjust the build directory of the sub-project.
// if (project()->file()->fileName().startsWith(qtSourceDir) && qtSourceDir != currentQtDir) { // if (project()->file()->fileName().startsWith(qtSourceDir) && qtSourceDir != currentQtDir) {
// project()->setValue(buildConfiguration, "useShadowBuild", true); // project()->setValue(buildConfiguration, "useShadowBuild", true);
// QString buildDir = QFileInfo(project()->file()->fileName()).absolutePath(); // QString buildDir = project()->projectDirectory();
// buildDir.replace(qtSourceDir, currentQtDir); // buildDir.replace(qtSourceDir, currentQtDir);
// project()->setValue(buildConfiguration, "buildDirectory", buildDir); // project()->setValue(buildConfiguration, "buildDirectory", buildDir);
// project()->setValue(buildConfiguration, "autoShadowBuild", true); // project()->setValue(buildConfiguration, "autoShadowBuild", true);

View File

@@ -249,7 +249,7 @@ void Qt4ProjectConfigWidget::buildDirectoryChanged()
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed() void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
{ {
QString initialDirectory = QFileInfo(m_buildConfiguration->target()->project()->file()->fileName()).absolutePath(); QString initialDirectory = m_buildConfiguration->target()->project()->projectDirectory();
if (!initialDirectory.isEmpty()) if (!initialDirectory.isEmpty())
m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory); m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
} }
@@ -320,7 +320,7 @@ void Qt4ProjectConfigWidget::updateImportLabel()
} }
QString sourceDirectory = QString sourceDirectory =
QFileInfo(m_buildConfiguration->qt4Target()->qt4Project()->file()->fileName()).absolutePath(); m_buildConfiguration->target()->project()->projectDirectory();
if (!sourceDirectory.endsWith('/')) if (!sourceDirectory.endsWith('/'))
sourceDirectory.append('/'); sourceDirectory.append('/');
bool invalidBuildDirectory = m_buildConfiguration->shadowBuild() bool invalidBuildDirectory = m_buildConfiguration->shadowBuild()

View File

@@ -446,7 +446,7 @@ QWidget *Qt4RunConfiguration::configurationWidget()
QVariantMap Qt4RunConfiguration::toMap() const QVariantMap Qt4RunConfiguration::toMap() const
{ {
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir(); const QDir projectDir = QDir(target()->project()->projectDirectory());
QVariantMap map(LocalApplicationRunConfiguration::toMap()); QVariantMap map(LocalApplicationRunConfiguration::toMap());
map.insert(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY), m_commandLineArguments); map.insert(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY), m_commandLineArguments);
map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath)); map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath));
@@ -462,7 +462,7 @@ QVariantMap Qt4RunConfiguration::toMap() const
bool Qt4RunConfiguration::fromMap(const QVariantMap &map) bool Qt4RunConfiguration::fromMap(const QVariantMap &map)
{ {
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir(); const QDir projectDir = QDir(target()->project()->projectDirectory());
m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toStringList(); m_commandLineArguments = map.value(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY)).toStringList();
m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString()); m_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString());
m_userSetName = map.value(QLatin1String(USER_SET_NAME_KEY), false).toBool(); m_userSetName = map.value(QLatin1String(USER_SET_NAME_KEY), false).toBool();

View File

@@ -197,7 +197,7 @@ void StateListener::slotStateChanged()
// Check for project, find the control // Check for project, find the control
Core::IVersionControl *projectControl = 0; Core::IVersionControl *projectControl = 0;
if (const ProjectExplorer::Project *currentProject = pe->currentProject()) { if (const ProjectExplorer::Project *currentProject = pe->currentProject()) {
state.currentProjectPath = QFileInfo(currentProject->file()->fileName()).absolutePath(); state.currentProjectPath = currentProject->projectDirectory();
state.currentProjectName = currentProject->displayName(); state.currentProjectName = currentProject->displayName();
projectControl = vcsManager->findVersionControlForDirectory(state.currentProjectPath, projectControl = vcsManager->findVersionControlForDirectory(state.currentProjectPath,
&state.currentProjectTopLevel); &state.currentProjectTopLevel);