2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-11-29 11:42:58 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-29 11:42:58 +01:00
|
|
|
|
|
|
|
|
#include "qmlprojectrunconfigurationwidget.h"
|
|
|
|
|
#include "qmlprojectrunconfiguration.h"
|
|
|
|
|
#include "qmlproject.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2010-11-29 11:42:58 +01:00
|
|
|
#include <utils/detailswidget.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QStandardItemModel>
|
2010-11-29 11:42:58 +01:00
|
|
|
|
|
|
|
|
using Core::ICore;
|
|
|
|
|
|
|
|
|
|
namespace QmlProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
QmlProjectRunConfigurationWidget::QmlProjectRunConfigurationWidget(QmlProjectRunConfiguration *rc) :
|
|
|
|
|
m_runConfiguration(rc),
|
|
|
|
|
m_fileListCombo(0),
|
2010-12-03 17:04:29 +01:00
|
|
|
m_fileListModel(new QStandardItemModel(this))
|
2010-11-29 11:42:58 +01:00
|
|
|
{
|
2010-11-29 12:50:44 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
2013-04-08 13:18:23 +02:00
|
|
|
layout->setMargin(0);
|
2010-11-29 12:50:44 +01:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Qt Version, Arguments
|
|
|
|
|
//
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
Utils::DetailsWidget *detailsWidget = new Utils::DetailsWidget();
|
|
|
|
|
detailsWidget->setState(Utils::DetailsWidget::NoSummary);
|
|
|
|
|
|
|
|
|
|
QWidget *formWidget = new QWidget(detailsWidget);
|
|
|
|
|
detailsWidget->setWidget(formWidget);
|
|
|
|
|
QFormLayout *form = new QFormLayout(formWidget);
|
|
|
|
|
form->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
|
|
|
|
|
|
|
|
|
m_fileListCombo = new QComboBox;
|
|
|
|
|
m_fileListCombo->setModel(m_fileListModel);
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
connect(m_fileListCombo, SIGNAL(activated(int)), this, SLOT(setMainScript(int)));
|
2010-11-29 11:42:58 +01:00
|
|
|
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(fileListChanged()),
|
|
|
|
|
SLOT(updateFileComboBox()));
|
|
|
|
|
|
|
|
|
|
QLineEdit *qmlViewerArgs = new QLineEdit;
|
|
|
|
|
qmlViewerArgs->setText(rc->m_qmlViewerArgs);
|
|
|
|
|
connect(qmlViewerArgs, SIGNAL(textChanged(QString)), this, SLOT(onViewerArgsChanged()));
|
|
|
|
|
|
|
|
|
|
form->addRow(tr("Arguments:"), qmlViewerArgs);
|
2010-11-29 12:50:44 +01:00
|
|
|
form->addRow(tr("Main QML file:"), m_fileListCombo);
|
|
|
|
|
|
|
|
|
|
layout->addWidget(detailsWidget);
|
|
|
|
|
|
2011-07-28 18:23:01 +02:00
|
|
|
updateFileComboBox();
|
2014-01-16 12:16:25 +01:00
|
|
|
|
|
|
|
|
connect(rc, SIGNAL(scriptSourceChanged()),
|
|
|
|
|
this, SLOT(updateFileComboBox()));
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
|
|
|
|
|
{
|
|
|
|
|
return s1.toLower() < s2.toLower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProjectRunConfigurationWidget::updateFileComboBox()
|
|
|
|
|
{
|
2012-04-24 15:49:09 +02:00
|
|
|
ProjectExplorer::Project *project = m_runConfiguration->target()->project();
|
|
|
|
|
QDir projectDir(project->projectDirectory());
|
2010-11-29 11:42:58 +01:00
|
|
|
|
2012-01-02 11:53:37 +01:00
|
|
|
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);
|
2010-12-03 17:04:29 +01:00
|
|
|
m_fileListModel->clear();
|
2012-11-26 21:24:16 +02:00
|
|
|
m_fileListModel->appendRow(new QStandardItem(QLatin1String(CURRENT_FILE)));
|
2010-12-03 17:04:29 +01:00
|
|
|
QModelIndex currentIndex;
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QStringList sortedFiles = project->files(ProjectExplorer::Project::AllFiles);
|
2010-12-03 17:04:29 +01:00
|
|
|
|
|
|
|
|
// make paths relative to project directory
|
|
|
|
|
QStringList relativeFiles;
|
|
|
|
|
foreach (const QString &fn, sortedFiles) {
|
|
|
|
|
relativeFiles += projectDir.relativeFilePath(fn);
|
|
|
|
|
}
|
|
|
|
|
sortedFiles = relativeFiles;
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
qStableSort(sortedFiles.begin(), sortedFiles.end(), caseInsensitiveLessThan);
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
QString mainScriptPath;
|
|
|
|
|
if (m_runConfiguration->mainScriptSource() != QmlProjectRunConfiguration::FileInEditor)
|
|
|
|
|
mainScriptPath = projectDir.relativeFilePath(m_runConfiguration->mainScript());
|
|
|
|
|
|
2010-11-29 11:42:58 +01:00
|
|
|
foreach (const QString &fn, sortedFiles) {
|
|
|
|
|
QFileInfo fileInfo(fn);
|
|
|
|
|
if (fileInfo.suffix() != QLatin1String("qml"))
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
QStandardItem *item = new QStandardItem(fn);
|
|
|
|
|
m_fileListModel->appendRow(item);
|
2010-11-29 11:42:58 +01:00
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
if (mainScriptPath == fn)
|
|
|
|
|
currentIndex = item->index();
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (currentIndex.isValid())
|
2010-12-03 17:04:29 +01:00
|
|
|
m_fileListCombo->setCurrentIndex(currentIndex.row());
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2010-11-29 11:42:58 +01:00
|
|
|
m_fileListCombo->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-03 17:04:29 +01:00
|
|
|
void QmlProjectRunConfigurationWidget::setMainScript(int index)
|
2010-11-29 11:42:58 +01:00
|
|
|
{
|
2010-12-03 17:04:29 +01:00
|
|
|
if (index == 0) {
|
|
|
|
|
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInEditor);
|
|
|
|
|
} else {
|
|
|
|
|
const QString path = m_fileListModel->data(m_fileListModel->index(index, 0)).toString();
|
2012-01-02 11:53:37 +01:00
|
|
|
m_runConfiguration->setScriptSource(QmlProjectRunConfiguration::FileInSettings, path);
|
2010-12-03 17:04:29 +01:00
|
|
|
}
|
2010-11-29 11:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlProjectRunConfigurationWidget::onViewerArgsChanged()
|
|
|
|
|
{
|
|
|
|
|
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender()))
|
|
|
|
|
m_runConfiguration->m_qmlViewerArgs = lineEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProjectManager
|