Commit 5d0177ac authored by Alessandro Portale's avatar Alessandro Portale

Merged 'New Qt quick App' and 'Import Qml App' Wizards

The only difference between these wizards was that in the
Import Wizard, the user was able to chose a .qml file.
So, why not merge them. Also, this commit is a nice code
reduction.

The module deployment feature was killed by popular demand.
Apparently, nobody writes or deploys Qml modules, these days.
Let's see when they want to have it back ;)

Task-Number: QTCREATORBUG-2505
Reviewed-by: ck
parent e1aa2935
......@@ -140,8 +140,7 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
MobileAppWizard *mobileWizard = new MobileAppWizard;
addAutoReleasedObject(mobileWizard);
addAutoReleasedObject(new QmlStandaloneAppWizard(QmlStandaloneAppWizard::NewQmlFile));
addAutoReleasedObject(new QmlStandaloneAppWizard(QmlStandaloneAppWizard::ImportQmlFile));
addAutoReleasedObject(new QmlStandaloneAppWizard());
LibraryWizard *libWizard = new LibraryWizard;
addAutoReleasedObject(libWizard);
......
......@@ -52,48 +52,36 @@ class QmlStandaloneAppWizardDialog : public AbstractMobileAppWizardDialog
Q_OBJECT
public:
explicit QmlStandaloneAppWizardDialog(QmlStandaloneAppWizard::WizardType type, QWidget *parent = 0);
explicit QmlStandaloneAppWizardDialog(QWidget *parent = 0);
private:
QmlStandaloneAppWizard::WizardType m_type;
class QmlStandaloneAppWizardSourcesPage *m_qmlSourcesPage;
friend class QmlStandaloneAppWizard;
};
QmlStandaloneAppWizardDialog::QmlStandaloneAppWizardDialog(QmlStandaloneAppWizard::WizardType type,
QWidget *parent)
QmlStandaloneAppWizardDialog::QmlStandaloneAppWizardDialog(QWidget *parent)
: AbstractMobileAppWizardDialog(parent)
, m_type(type)
, m_qmlSourcesPage(0)
{
setWindowTitle(m_type == QmlStandaloneAppWizard::NewQmlFile
? tr("New Qt Quick Application")
: tr("Qt Quick Application from Existing QML Directory"));
setIntroDescription(m_type == QmlStandaloneAppWizard::NewQmlFile
? tr("This wizard generates a Qt Quick application project.")
: tr("This wizard imports an existing QML directory and creates a Qt Quick application project from it."));
if (m_type == QmlStandaloneAppWizard::ImportQmlFile) {
m_qmlSourcesPage = new QmlStandaloneAppWizardSourcesPage;
m_qmlSourcesPage->setMainQmlFileChooserVisible(true);
const int qmlSourcesPagePageId = addPage(m_qmlSourcesPage);
wizardProgress()->item(qmlSourcesPagePageId)->setTitle(tr("QML Sources"));
}
setWindowTitle(tr("New Qt Quick Application"));
setIntroDescription(tr("This wizard generates a Qt Quick application project."));
m_qmlSourcesPage = new QmlStandaloneAppWizardSourcesPage;
const int qmlSourcesPagePageId = addPage(m_qmlSourcesPage);
wizardProgress()->item(qmlSourcesPagePageId)->setTitle(tr("QML Sources"));
}
class QmlStandaloneAppWizardPrivate
{
QmlStandaloneAppWizard::WizardType type;
class QmlStandaloneApp *standaloneApp;
class QmlStandaloneAppWizardDialog *wizardDialog;
friend class QmlStandaloneAppWizard;
};
QmlStandaloneAppWizard::QmlStandaloneAppWizard(WizardType type)
: AbstractMobileAppWizard(parameters(type))
QmlStandaloneAppWizard::QmlStandaloneAppWizard()
: AbstractMobileAppWizard(parameters())
, m_d(new QmlStandaloneAppWizardPrivate)
{
m_d->type = type;
m_d->standaloneApp = new QmlStandaloneApp;
m_d->wizardDialog = 0;
}
......@@ -104,21 +92,13 @@ QmlStandaloneAppWizard::~QmlStandaloneAppWizard()
delete m_d;
}
Core::BaseFileWizardParameters QmlStandaloneAppWizard::parameters(WizardType type)
Core::BaseFileWizardParameters QmlStandaloneAppWizard::parameters()
{
Core::BaseFileWizardParameters parameters(ProjectWizard);
parameters.setIcon(QIcon(QLatin1String(Constants::ICON_QML_STANDALONE)));
parameters.setDisplayName(type == QmlStandaloneAppWizard::NewQmlFile
? tr("Qt Quick Application")
: tr("Import Existing QML Directory"));
parameters.setId(QLatin1String(type == QmlStandaloneAppWizard::NewQmlFile
? "QA.QMLA Application"
: "QA.QMLB Imported Application"));
parameters.setDescription(type == QmlStandaloneAppWizard::NewQmlFile
? tr("Creates a Qt Quick application that you can deploy to mobile devices.")
: tr("Imports an existing QML directory and converts it into a "
"Qt Quick application project. "
"You can deploy the application to mobile devices."));
parameters.setDisplayName(tr("Qt Quick Application"));
parameters.setId(QLatin1String("QA.QMLA Application"));
parameters.setDescription(tr("Creates a Qt Quick application that you can deploy to mobile devices."));
parameters.setCategory(QLatin1String(Constants::QT_APP_WIZARD_CATEGORY));
parameters.setDisplayCategory(QCoreApplication::translate(Constants::QT_APP_WIZARD_TR_SCOPE,
Constants::QT_APP_WIZARD_TR_CATEGORY));
......@@ -127,12 +107,7 @@ Core::BaseFileWizardParameters QmlStandaloneAppWizard::parameters(WizardType typ
AbstractMobileAppWizardDialog *QmlStandaloneAppWizard::createWizardDialogInternal(QWidget *parent) const
{
m_d->wizardDialog = new QmlStandaloneAppWizardDialog(m_d->type, parent);
if (m_d->wizardDialog->m_qmlSourcesPage) {
connect(m_d->wizardDialog->m_qmlSourcesPage,
SIGNAL(externalModulesChanged(QStringList, QStringList)),
SLOT(handleModulesChange(QStringList, QStringList)));
}
m_d->wizardDialog = new QmlStandaloneAppWizardDialog(parent);
const QList<TargetSetupPage::ImportInfo> &qtVersions
= TargetSetupPage::importInfosForKnownQtVersions();
QList<TargetSetupPage::ImportInfo> qmlQtVersions;
......@@ -157,19 +132,16 @@ void QmlStandaloneAppWizard::prepareGenerateFiles(const QWizard *w,
{
Q_UNUSED(errorMessage)
const QmlStandaloneAppWizardDialog *wizard = qobject_cast<const QmlStandaloneAppWizardDialog*>(w);
if (wizard->m_qmlSourcesPage) {
m_d->standaloneApp->setMainQmlFile(wizard->m_qmlSourcesPage->mainQmlFile());
m_d->standaloneApp->setExternalModules(
wizard->m_qmlSourcesPage->moduleUris(),
wizard->m_qmlSourcesPage->moduleImportPaths());
}
const QString mainQmlFile = wizard->m_qmlSourcesPage->mainQmlFile();
if (!mainQmlFile.isEmpty())
m_d->standaloneApp->setMainQmlFile(mainQmlFile);
}
bool QmlStandaloneAppWizard::postGenerateFilesInternal(const Core::GeneratedFiles &l,
QString *errorMessage)
{
const bool success = ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
if (success && m_d->type == QmlStandaloneAppWizard::ImportQmlFile) {
if (success && !m_d->standaloneApp->mainQmlFile().isEmpty()) {
ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, m_d->standaloneApp->mainQmlFile());
Core::EditorManager::instance()->openEditor(m_d->standaloneApp->mainQmlFile(),
QString(), Core::EditorManager::ModeSwitch);
......@@ -177,14 +149,6 @@ bool QmlStandaloneAppWizard::postGenerateFilesInternal(const Core::GeneratedFile
return success;
}
void QmlStandaloneAppWizard::handleModulesChange(const QStringList &uris, const QStringList &paths)
{
Q_ASSERT(m_d->wizardDialog->m_qmlSourcesPage);
QmlStandaloneApp testApp;
testApp.setExternalModules(uris, paths);
m_d->wizardDialog->m_qmlSourcesPage->setModulesError(testApp.error());
}
AbstractMobileApp *QmlStandaloneAppWizard::app() const
{
return m_d->standaloneApp;
......
......@@ -40,19 +40,11 @@ class QmlStandaloneAppWizard : public AbstractMobileAppWizard
Q_OBJECT
public:
enum WizardType {
NewQmlFile,
ImportQmlFile
};
QmlStandaloneAppWizard(WizardType type);
QmlStandaloneAppWizard();
virtual ~QmlStandaloneAppWizard();
private slots:
void handleModulesChange(const QStringList &uris, const QStringList &paths);
private:
static Core::BaseFileWizardParameters parameters(WizardType type);
static Core::BaseFileWizardParameters parameters();
virtual AbstractMobileApp *app() const;
virtual AbstractMobileAppWizardDialog *wizardDialog() const;
......
......@@ -42,7 +42,6 @@ namespace Internal {
class QmlStandaloneAppWizardSourcesPagePrivate
{
Ui::QmlStandaloneAppWizardSourcesPage ui;
bool mainQmlFileChooserVisible;
friend class QmlStandaloneAppWizardSourcesPage;
};
......@@ -54,15 +53,12 @@ QmlStandaloneAppWizardSourcesPage::QmlStandaloneAppWizardSourcesPage(QWidget *pa
m_d->ui.mainQmlFileLineEdit->setExpectedKind(Utils::PathChooser::File);
m_d->ui.mainQmlFileLineEdit->setPromptDialogFilter(QLatin1String("*.qml"));
m_d->ui.mainQmlFileLineEdit->setPromptDialogTitle(tr("Select QML File"));
m_d->ui.addModuleUriButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PLUS)));
m_d->ui.removeModuleUriButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_MINUS)));
m_d->ui.addImportPathButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PLUS)));
m_d->ui.removeImportPathButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_MINUS)));
setMainQmlFileChooserVisible(true);
setModulesError(QString());
connect(m_d->ui.mainQmlFileLineEdit, SIGNAL(changed(QString)), SIGNAL(completeChanged()));
connect(m_d->ui.urisListWidget, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleModulesChanged()));
connect(m_d->ui.importPathsListWidget, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(handleModulesChanged()));
connect(m_d->ui.importExistingQmlRadioButton,
SIGNAL(toggled(bool)), SIGNAL(completeChanged()));
connect(m_d->ui.newQmlRadioButton, SIGNAL(toggled(bool)),
m_d->ui.mainQmlFileLineEdit, SLOT(setDisabled(bool)));
m_d->ui.newQmlRadioButton->setChecked(true);
}
QmlStandaloneAppWizardSourcesPage::~QmlStandaloneAppWizardSourcesPage()
......@@ -72,95 +68,14 @@ QmlStandaloneAppWizardSourcesPage::~QmlStandaloneAppWizardSourcesPage()
QString QmlStandaloneAppWizardSourcesPage::mainQmlFile() const
{
return m_d->ui.mainQmlFileLineEdit->path();
return m_d->ui.importExistingQmlRadioButton->isChecked() ?
m_d->ui.mainQmlFileLineEdit->path() : QString();
}
bool QmlStandaloneAppWizardSourcesPage::isComplete() const
{
return (!m_d->mainQmlFileChooserVisible || m_d->ui.mainQmlFileLineEdit->isValid())
&& m_d->ui.errorLabel->text().isEmpty();
}
void QmlStandaloneAppWizardSourcesPage::setMainQmlFileChooserVisible(bool visible)
{
m_d->mainQmlFileChooserVisible = visible;
m_d->ui.mainQmlFileGroupBox->setVisible(m_d->mainQmlFileChooserVisible);
}
void QmlStandaloneAppWizardSourcesPage::setModulesError(const QString &error)
{
m_d->ui.errorLabel->setText(error);
m_d->ui.errorLabel->setVisible(!error.isEmpty());
}
void QmlStandaloneAppWizardSourcesPage::on_addModuleUriButton_clicked()
{
QListWidgetItem *item = new QListWidgetItem(m_d->ui.urisListWidget);
item->setFlags(item->flags() | Qt::ItemIsEditable);
m_d->ui.urisListWidget->setCurrentItem(item);
m_d->ui.urisListWidget->editItem(item);
}
static bool removeListWidgetItem(QListWidget *list)
{
const int currentRow = list->currentRow();
if (currentRow >= 0) {
list->takeItem(currentRow);
return true;
}
return false;
}
void QmlStandaloneAppWizardSourcesPage::on_removeModuleUriButton_clicked()
{
if (removeListWidgetItem(m_d->ui.urisListWidget))
handleModulesChanged();
}
void QmlStandaloneAppWizardSourcesPage::on_addImportPathButton_clicked()
{
const QString path = QFileDialog::getExistingDirectory(this,
tr("Select an import path for QML modules."), mainQmlFile());
if (!path.isEmpty()) {
QListWidgetItem *item = new QListWidgetItem(QDir::toNativeSeparators(path), m_d->ui.importPathsListWidget);
item->setFlags(item->flags() | Qt::ItemIsEditable);
m_d->ui.importPathsListWidget->setCurrentItem(item);
}
}
void QmlStandaloneAppWizardSourcesPage::on_removeImportPathButton_clicked()
{
if (removeListWidgetItem(m_d->ui.importPathsListWidget))
handleModulesChanged();
}
static inline QStringList ertriesFromListWidget(const QListWidget &listWidget)
{
QStringList result;
for (int i = 0; i < listWidget.count(); ++i) {
const QString text = listWidget.item(i)->text().trimmed();
if (!text.isEmpty())
result.append(text);
}
return result;
}
void QmlStandaloneAppWizardSourcesPage::handleModulesChanged()
{
const QStringList uris = ertriesFromListWidget(*m_d->ui.urisListWidget);
const QStringList paths = ertriesFromListWidget(*m_d->ui.importPathsListWidget);
emit externalModulesChanged(uris, paths);
emit completeChanged();
}
QStringList QmlStandaloneAppWizardSourcesPage::moduleUris() const
{
return ertriesFromListWidget(*m_d->ui.urisListWidget);
}
QStringList QmlStandaloneAppWizardSourcesPage::moduleImportPaths() const
{
return ertriesFromListWidget(*m_d->ui.importPathsListWidget);
return !m_d->ui.importExistingQmlRadioButton->isChecked()
|| m_d->ui.mainQmlFileLineEdit->isValid();
}
} // namespace Internal
......
......@@ -47,20 +47,6 @@ public:
QString mainQmlFile() const;
virtual bool isComplete() const;
void setMainQmlFileChooserVisible(bool visible);
void setModulesError(const QString &error);
QStringList moduleUris() const;
QStringList moduleImportPaths() const;
private slots:
void on_addModuleUriButton_clicked();
void on_removeModuleUriButton_clicked();
void on_addImportPathButton_clicked();
void on_removeImportPathButton_clicked();
void handleModulesChanged();
signals:
void externalModulesChanged(const QStringList &uris, const QStringList &importPaths) const;
private:
class QmlStandaloneAppWizardSourcesPagePrivate *m_d;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>346</height>
<width>605</width>
<height>386</height>
</rect>
</property>
<property name="windowTitle">
......@@ -19,133 +19,62 @@
<property name="title">
<string>Main QML File</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="Utils::PathChooser" name="mainQmlFileLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="qmlModulesGroupBox">
<property name="title">
<string>QML Modules</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="newQmlRadioButton">
<property name="text">
<string>New 'main.qml' file, generated by this wizard.</string>
</property>
<widget class="QWidget" name="layoutWidget1">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" rowspan="3">
<widget class="QListWidget" name="urisListWidget"/>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="addModuleUriButton">
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QToolButton" name="removeModuleUriButton">
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>URIs (e.g. 'org.mydomain.MyQmlModule'):</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0" rowspan="3">
<widget class="QListWidget" name="importPathsListWidget"/>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="addImportPathButton">
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QToolButton" name="removeImportPathButton">
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Import paths:</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QLabel" name="errorLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="importExistingQmlRadioButton">
<property name="text">
<string>Error</string>
<string>Import an existing .qml file</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Utils::PathChooser" name="mainQmlFileLineEdit"/>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Note: All files and directories which reside in the same directory as the Main QML File will be deployed. You can anytime modify the contents of that directory before deploying.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......
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