diff --git a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.cpp b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.cpp index af7e354b3de..614198277e3 100644 --- a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.cpp +++ b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.cpp @@ -87,6 +87,11 @@ QmlStandaloneAppWizardDialog::QmlStandaloneAppWizardDialog(QmlStandaloneAppWizar m_qmlOptionsPage = new QmlStandaloneAppWizardOptionsPage; const int qmlOptionsPagePageId = addPage(m_qmlOptionsPage); wizardProgress()->item(qmlOptionsPagePageId)->setTitle(tr("Qml App options")); + if (m_type == QmlStandaloneAppWizard::NewQmlFile) { + // In case of NewQmlFile, we show that page at the end. Is that useful? Or irritating? + const int qmlSourcesPagePageId = addPage(m_qmlSourcesPage); + wizardProgress()->item(qmlSourcesPagePageId)->setTitle(tr("Qml Sources")); + } } class QmlStandaloneAppWizardPrivate @@ -147,6 +152,8 @@ QWizard *QmlStandaloneAppWizard::createWizardDialog(QWidget *parent, m_d->wizardDialog->m_qmlOptionsPage->setNetworkEnabled(m_d->standaloneApp->networkEnabled()); m_d->wizardDialog->m_qmlOptionsPage->setLoadDummyData(m_d->standaloneApp->loadDummyData()); connect(m_d->wizardDialog, SIGNAL(introPageLeft(QString, QString)), SLOT(useProjectPath(QString, QString))); + connect(m_d->wizardDialog->m_qmlSourcesPage, + SIGNAL(externalModulesChanged(QStringList, QStringList)), SLOT(handleModulesChange(QStringList, QStringList))); foreach (QWizardPage *p, extensionPages) BaseFileWizard::applyExtensionPageShortTitle(m_d->wizardDialog, m_d->wizardDialog->addPage(p)); @@ -169,6 +176,8 @@ Core::GeneratedFiles QmlStandaloneAppWizard::generateFiles(const QWizard *w, m_d->standaloneApp->setNetworkEnabled(wizard->m_qmlOptionsPage->networkEnabled()); if (m_d->type == QmlStandaloneAppWizard::ImportQmlFile) m_d->standaloneApp->setMainQmlFile(wizard->m_qmlSourcesPage->mainQmlFile()); + m_d->standaloneApp->setExternalModules( + wizard->m_qmlSourcesPage->moduleUris(), wizard->m_qmlSourcesPage->moduleImportPaths()); return m_d->standaloneApp->generateFiles(errorMessage); } @@ -189,6 +198,13 @@ void QmlStandaloneAppWizard::useProjectPath(const QString &projectName, const QS m_d->wizardDialog->m_qmlOptionsPage->setSymbianUid(QmlStandaloneApp::symbianUidForPath(projectPath + projectName)); } +void QmlStandaloneAppWizard::handleModulesChange(const QStringList &uris, const QStringList &paths) +{ + QmlStandaloneApp testApp; + testApp.setExternalModules(uris, paths); + m_d->wizardDialog->m_qmlSourcesPage->setModulesError(testApp.error()); +} + } // namespace Internal } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.h b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.h index 91ec63d58b0..f9dee492088 100644 --- a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.h +++ b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizard.h @@ -59,6 +59,7 @@ protected: protected slots: void useProjectPath(const QString &projectName, const QString &projectPath); + void handleModulesChange(const QStringList &uris, const QStringList &paths); private: class QmlStandaloneAppWizardPrivate *m_d; diff --git a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.cpp b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.cpp index 1c5f13b7dff..92ccf4e28ee 100644 --- a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.cpp +++ b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.cpp @@ -30,9 +30,11 @@ #include "qmlstandaloneappwizardpages.h" #include "ui_qmlstandaloneappwizardsourcespage.h" #include "ui_qmlstandaloneappwizardoptionspage.h" +#include #include #include +#include namespace QmlProjectManager { namespace Internal { @@ -40,6 +42,7 @@ namespace Internal { class QmlStandaloneAppWizardSourcesPagePrivate { Ui::QmlStandaloneAppWizardSourcesPage ui; + bool mainQmlFileChooserVisible; friend class QmlStandaloneAppWizardSourcesPage; }; @@ -51,8 +54,15 @@ 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 the main QML file of the application.")); - m_d->ui.qmlModulesGroupBox->setEnabled(false); // TODO: implement modules selection + 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())); } QmlStandaloneAppWizardSourcesPage::~QmlStandaloneAppWizardSourcesPage() @@ -67,12 +77,84 @@ QString QmlStandaloneAppWizardSourcesPage::mainQmlFile() const bool QmlStandaloneAppWizardSourcesPage::isComplete() const { - return m_d->ui.mainQmlFileLineEdit->isValid(); + return (!m_d->mainQmlFileChooserVisible || m_d->ui.mainQmlFileLineEdit->isValid()) + && m_d->ui.errorLabel->text().isEmpty(); } void QmlStandaloneAppWizardSourcesPage::setMainQmlFileChooserVisible(bool visible) { - m_d->ui.mainQmlFileLineEdit->setVisible(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->editItem(item); +} + +void QmlStandaloneAppWizardSourcesPage::on_removeModuleUriButton_clicked() +{ + const int currentRow = m_d->ui.urisListWidget->currentRow(); + if (currentRow >= 0) { + m_d->ui.urisListWidget->takeItem(currentRow); + 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); + } +} + +void QmlStandaloneAppWizardSourcesPage::on_removeImportPathButton_clicked() +{ + const int currentRow = m_d->ui.importPathsListWidget->currentRow(); + if (currentRow >= 0) { + m_d->ui.importPathsListWidget->takeItem(currentRow); + 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); } class QmlStandaloneAppWizardOptionsPagePrivate diff --git a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.h b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.h index 97abf06bc6d..117ead79309 100644 --- a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.h +++ b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardpages.h @@ -48,6 +48,19 @@ 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; diff --git a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardsourcespage.ui b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardsourcespage.ui index 40e67a1e17d..d4def3f9c7a 100644 --- a/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardsourcespage.ui +++ b/src/plugins/qmlprojectmanager/wizards/qmlstandaloneappwizardsourcespage.ui @@ -6,8 +6,8 @@ 0 0 - 408 - 340 + 494 + 346 @@ -31,9 +31,115 @@ Qml Modules - + - + + + Qt::Vertical + + + false + + + + + + + + + + + + + + + + + + - + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 0 + + + + + + + + URIs + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 0 + + + + + + + + Import Paths + + + + + + + + + 75 + true + + + + Error + + + @@ -45,6 +151,11 @@ Utils::PathChooser QLineEdit
utils/pathchooser.h
+ 1 + + editingFinished() + browsingFinished() +