QmlProject: Make sure 'mainFile: "xxx"' is always respected

Prevent user from overriding the file to launch through the run configuration
dialog. The old logic was broken (main file was always the editor), and
arbitrary files can now be previewed conveniently with
Tools->External->Qt Quick->Preview.

Task-number: QTCREATORBUG-6683
Change-Id: Icee1d11e5063ca634e835bb57ffc77bf973ee93f
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
Kai Koehne
2012-01-02 11:53:37 +01:00
parent ed7b5c9c75
commit c158ae1337
3 changed files with 23 additions and 45 deletions

View File

@@ -179,16 +179,21 @@ void QmlProjectRunConfigurationWidget::updateFileComboBox()
QmlProject *project = m_runConfiguration->qmlTarget()->qmlProject();
QDir projectDir = project->projectDir();
if (m_runConfiguration->mainScriptSource() == QmlProjectRunConfiguration::FileInProjectFile) {
const QString mainScriptInFilePath
= projectDir.relativeFilePath(m_runConfiguration->mainScript());
m_fileListModel->clear();
m_fileListModel->appendRow(new QStandardItem(mainScriptInFilePath));
m_fileListCombo->setEnabled(false);
return;
}
m_fileListCombo->setEnabled(true);
m_fileListModel->clear();
m_fileListModel->appendRow(new QStandardItem(CURRENT_FILE));
QModelIndex currentIndex;
QModelIndex fileInQmlProjectIndex;
const QString mainScriptInFilePath = projectDir.absoluteFilePath(project->mainFile());
QStringList sortedFiles = project->files();
if (!sortedFiles.contains(mainScriptInFilePath))
sortedFiles += mainScriptInFilePath;
// make paths relative to project directory
QStringList relativeFiles;
@@ -213,9 +218,6 @@ void QmlProjectRunConfigurationWidget::updateFileComboBox()
if (mainScriptPath == fn)
currentIndex = item->index();
if (mainScriptInFilePath == fn)
fileInQmlProjectIndex = item->index();
}
if (currentIndex.isValid()) {
@@ -223,27 +225,15 @@ void QmlProjectRunConfigurationWidget::updateFileComboBox()
} else {
m_fileListCombo->setCurrentIndex(0);
}
if (fileInQmlProjectIndex.isValid()) {
QFont font;
font.setBold(true);
m_fileListModel->setData(fileInQmlProjectIndex, font, Qt::FontRole);
}
}
void QmlProjectRunConfigurationWidget::setMainScript(int index)
{
QmlProject *project = m_runConfiguration->qmlTarget()->qmlProject();
QDir projectDir = project->projectDir();
if (index == 0) {
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInEditor);
} else {
const QString path = m_fileListModel->data(m_fileListModel->index(index, 0)).toString();
if (projectDir.relativeFilePath(project->mainFile()) == path) {
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInProjectFile);
} else {
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
}
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
}
}