Commit 1ca8cb23 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Introduce method to access the project directory

... use it.

Reviewed-by: dt
parent 3a15c8c3
......@@ -93,7 +93,7 @@ QString CMakeBuildConfiguration::buildDirectory() const
{
QString buildDirectory = m_buildDirectory;
if (buildDirectory.isEmpty())
buildDirectory = cmakeTarget()->cmakeProject()->sourceDirectory() + "/qtcreator-build";
buildDirectory = target()->project()->projectDirectory() + "/qtcreator-build";
return buildDirectory;
}
......@@ -221,7 +221,7 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer:
cleanMakeStep->setClean(true);
CMakeOpenProjectWizard copw(cmtarget->cmakeProject()->projectManager(),
cmtarget->cmakeProject()->sourceDirectory(),
cmtarget->project()->projectDirectory(),
bc->buildDirectory(),
bc->environment());
if (copw.exec() != QDialog::Accepted) {
......
......@@ -156,11 +156,6 @@ void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QStri
parseCMakeLists();
}
QString CMakeProject::sourceDirectory() const
{
return QFileInfo(m_fileName).absolutePath();
}
bool CMakeProject::parseCMakeLists()
{
if (!activeTarget() ||
......@@ -198,7 +193,7 @@ bool CMakeProject::parseCMakeLists()
projectFiles.insert(node->path());
} else {
// 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));
projectFiles.insert(cmakeListTxt);
}
......@@ -240,7 +235,7 @@ bool CMakeProject::parseCMakeLists()
allIncludePaths.append(headerPath.path());
}
// This explicitly adds -I. to the include paths
allIncludePaths.append(sourceDirectory());
allIncludePaths.append(projectDirectory());
allIncludePaths.append(cbpparser.includeFiles());
CppTools::CppModelManagerInterface *modelmanager =
......@@ -479,7 +474,7 @@ bool CMakeProject::fromMap(const QVariantMap &map)
// Ask the user for where he wants to build it
// 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)
return false;
......@@ -641,7 +636,7 @@ void CMakeBuildSettingsWidget::init(BuildConfiguration *bc)
{
m_buildConfiguration = static_cast<CMakeBuildConfiguration *>(bc);
m_pathLineEdit->setText(m_buildConfiguration->buildDirectory());
if (m_buildConfiguration->buildDirectory() == m_project->sourceDirectory())
if (m_buildConfiguration->buildDirectory() == m_project->projectDirectory())
m_changeButton->setEnabled(false);
else
m_changeButton->setEnabled(true);
......@@ -650,7 +645,7 @@ void CMakeBuildSettingsWidget::init(BuildConfiguration *bc)
void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog()
{
CMakeOpenProjectWizard copw(m_project->projectManager(),
m_project->sourceDirectory(),
m_project->projectDirectory(),
m_buildConfiguration->buildDirectory(),
m_buildConfiguration->environment());
if (copw.exec() == QDialog::Accepted) {
......
......@@ -97,8 +97,6 @@ public:
CMakeBuildTarget buildTargetForTitle(const QString &title);
QString sourceDirectory() const;
bool parseCMakeLists();
signals:
......
......@@ -77,7 +77,7 @@ QVariantMap GenericBuildConfiguration::toMap() const
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);
}
......@@ -90,8 +90,7 @@ ProjectExplorer::Environment GenericBuildConfiguration::environment() const
QString GenericBuildConfiguration::buildDirectory() const
{
// Convert to absolute path when necessary
const QFileInfo projectFile(target()->project()->file()->fileName());
const QDir projectDir(projectFile.path());
const QDir projectDir(target()->project()->projectDirectory());
return projectDir.absoluteFilePath(m_buildDirectory);
}
......
......@@ -141,8 +141,7 @@ GenericTarget *GenericTargetFactory::create(ProjectExplorer::Project *parent, co
makeStep->setBuildTarget("all", /* on = */ true);
const QFileInfo fileInfo(genericproject->file()->fileName());
bc->setBuildDirectory(fileInfo.absolutePath());
bc->setBuildDirectory(genericproject->projectDirectory());
t->addBuildConfiguration(bc);
......
......@@ -227,6 +227,12 @@ QVariantMap Project::toMap() const
return map;
}
QString Project::projectDirectory() const
{
QFileInfo info(file()->fileName());
return info.absoluteDir().path();
}
bool Project::fromMap(const QVariantMap &map)
{
if (map.contains(QLatin1String(EDITOR_SETTINGS_KEY))) {
......
......@@ -128,6 +128,9 @@ public:
// creating new BuilConfigurations.
virtual QVariantMap toMap() const;
// The directory that holds the project file. This includes the absolute path.
QString projectDirectory() const;
signals:
void fileListChanged();
......
......@@ -912,8 +912,7 @@ void ProjectExplorerPlugin::newProject()
QString defaultLocation;
if (currentProject()) {
const QFileInfo file(currentProject()->file()->fileName());
QDir dir = file.dir();
QDir dir(currentProject()->projectDirectory());
dir.cdUp();
defaultLocation = dir.absolutePath();
}
......
......@@ -146,7 +146,7 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
Qt4BuildConfiguration *qt4bc = project->activeTarget()->activeBuildConfiguration();
const QtVersion *qtVersion = qt4bc->qtVersion();
data->binary = (qtVersion->*commandAccessor)();
data->workingDirectory = QFileInfo(project->file()->fileName()).absolutePath();
data->workingDirectory = project->projectDirectory();
} else {
data->workingDirectory.clear();
data->binary = Utils::SynchronousProcess::locateBinary(fallbackBinary);
......
......@@ -53,7 +53,7 @@ ProjectLoadWizard::ProjectLoadWizard(Qt4Project *project, QWidget *parent, Qt::W
{
setWindowTitle(tr("Import existing build settings"));
QtVersionManager * vm = QtVersionManager::instance();
QString directory = QFileInfo(project->file()->fileName()).absolutePath();
QString directory = project->projectDirectory();
QString importVersion = QtVersionManager::findQMakeBinaryFromMakefile(directory);
if (!importVersion.isNull()) {
......
......@@ -164,8 +164,7 @@ QVariantMap MaemoRunConfiguration::toMap() const
map.insert(SimulatorPathKey, m_simulatorPath);
const QDir &dir = QFileInfo(qt4Target()->qt4Project()->file()->fileName())
.absoluteDir();
const QDir dir = QDir(target()->project()->projectDirectory());
map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath));
return map;
......@@ -196,8 +195,7 @@ bool MaemoRunConfiguration::fromMap(const QVariantMap &map)
m_simulatorPath = map.value(SimulatorPathKey).toString();
const QDir &dir = QFileInfo(qt4Target()->qt4Project()->file()->fileName())
.absoluteDir();
const QDir dir = QDir(target()->project()->projectDirectory());
m_proFilePath = dir.filePath(map.value(ProFileKey).toString());
return true;
......@@ -405,7 +403,7 @@ void MaemoRunConfiguration::updateSimulatorInformation() const
"simulator image.").arg(m_simulatorPath);
}
QDir dir(m_simulatorPath);
QDir dir = QDir(m_simulatorPath);
if (!m_simulatorPath.isEmpty() && dir.exists(m_simulatorPath)) {
const QStringList &files = dir.entryList(QDir::Files | QDir::NoSymLinks
| QDir::NoDotAndDotDot);
......
......@@ -201,7 +201,7 @@ QWidget *S60DeviceRunConfiguration::configurationWidget()
QVariantMap S60DeviceRunConfiguration::toMap() const
{
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(SIGNING_MODE_KEY), (int)m_signingMode);
......@@ -215,7 +215,7 @@ QVariantMap S60DeviceRunConfiguration::toMap() const
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_signingMode = static_cast<SigningMode>(map.value(QLatin1String(SIGNING_MODE_KEY)).toInt());
......
......@@ -134,14 +134,14 @@ QWidget *S60EmulatorRunConfiguration::configurationWidget()
QVariantMap S60EmulatorRunConfiguration::toMap() const
{
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));
return 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());
return RunConfiguration::fromMap(map);
......
......@@ -190,7 +190,7 @@ QString Qt4BuildConfiguration::buildDirectory() const
if (m_shadowBuild)
workingDirectory = m_buildDirectory;
if (workingDirectory.isEmpty())
workingDirectory = QFileInfo(target()->project()->file()->fileName()).absolutePath();
workingDirectory = target()->project()->projectDirectory();
return workingDirectory;
}
......
......@@ -1128,7 +1128,7 @@ void Qt4Project::notifyChanged(const QString &name)
// // adjust the build directory of the sub-project.
// if (project()->file()->fileName().startsWith(qtSourceDir) && qtSourceDir != currentQtDir) {
// project()->setValue(buildConfiguration, "useShadowBuild", true);
// QString buildDir = QFileInfo(project()->file()->fileName()).absolutePath();
// QString buildDir = project()->projectDirectory();
// buildDir.replace(qtSourceDir, currentQtDir);
// project()->setValue(buildConfiguration, "buildDirectory", buildDir);
// project()->setValue(buildConfiguration, "autoShadowBuild", true);
......
......@@ -249,7 +249,7 @@ void Qt4ProjectConfigWidget::buildDirectoryChanged()
void Qt4ProjectConfigWidget::onBeforeBeforeShadowBuildDirBrowsed()
{
QString initialDirectory = QFileInfo(m_buildConfiguration->target()->project()->file()->fileName()).absolutePath();
QString initialDirectory = m_buildConfiguration->target()->project()->projectDirectory();
if (!initialDirectory.isEmpty())
m_ui->shadowBuildDirEdit->setInitialBrowsePathBackup(initialDirectory);
}
......@@ -320,7 +320,7 @@ void Qt4ProjectConfigWidget::updateImportLabel()
}
QString sourceDirectory =
QFileInfo(m_buildConfiguration->qt4Target()->qt4Project()->file()->fileName()).absolutePath();
m_buildConfiguration->target()->project()->projectDirectory();
if (!sourceDirectory.endsWith('/'))
sourceDirectory.append('/');
bool invalidBuildDirectory = m_buildConfiguration->shadowBuild()
......
......@@ -446,7 +446,7 @@ QWidget *Qt4RunConfiguration::configurationWidget()
QVariantMap Qt4RunConfiguration::toMap() const
{
const QDir projectDir = QFileInfo(target()->project()->file()->fileName()).absoluteDir();
const QDir projectDir = QDir(target()->project()->projectDirectory());
QVariantMap map(LocalApplicationRunConfiguration::toMap());
map.insert(QLatin1String(COMMAND_LINE_ARGUMENTS_KEY), m_commandLineArguments);
map.insert(QLatin1String(PRO_FILE_KEY), projectDir.relativeFilePath(m_proFilePath));
......@@ -462,7 +462,7 @@ QVariantMap Qt4RunConfiguration::toMap() const
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_proFilePath = projectDir.filePath(map.value(QLatin1String(PRO_FILE_KEY)).toString());
m_userSetName = map.value(QLatin1String(USER_SET_NAME_KEY), false).toBool();
......
......@@ -197,7 +197,7 @@ void StateListener::slotStateChanged()
// Check for project, find the control
Core::IVersionControl *projectControl = 0;
if (const ProjectExplorer::Project *currentProject = pe->currentProject()) {
state.currentProjectPath = QFileInfo(currentProject->file()->fileName()).absolutePath();
state.currentProjectPath = currentProject->projectDirectory();
state.currentProjectName = currentProject->displayName();
projectControl = vcsManager->findVersionControlForDirectory(state.currentProjectPath,
&state.currentProjectTopLevel);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment