Commit 8678af32 authored by Alessandro Portale's avatar Alessandro Portale

Refacoring. Saner Api for QtQuickApp.

Now using an explicit Mode (generated, imported) instead of empty
or set filename convention. Just like in Html5App.
parent 8eb0bb75
......@@ -98,7 +98,9 @@ QmlCppPlugin::QmlCppPlugin(const QString &name, const QFileInfo &path,
{
}
QtQuickApp::QtQuickApp() : AbstractMobileApp()
QtQuickApp::QtQuickApp()
: AbstractMobileApp()
, m_mainQmlMode(ModeGenerate)
{
}
......@@ -107,18 +109,20 @@ QtQuickApp::~QtQuickApp()
clearModulesAndPlugins();
}
void QtQuickApp::setMainQmlFile(const QString &qmlFile)
void QtQuickApp::setMainQml(Mode mode, const QString &file)
{
m_mainQmlFile.setFile(qmlFile);
Q_ASSERT(mode != ModeGenerate || file.isEmpty());
m_mainQmlMode = mode;
m_mainQmlFile.setFile(file);
}
QString QtQuickApp::mainQmlFile() const
QtQuickApp::Mode QtQuickApp::mainQmlMode() const
{
return path(MainQml);
return m_mainQmlMode;
}
bool QtQuickApp::setExternalModules(const QStringList &uris,
const QStringList &importPaths)
const QStringList &importPaths)
{
clearModulesAndPlugins();
m_importPaths.clear();
......@@ -161,19 +165,20 @@ bool QtQuickApp::setExternalModules(const QStringList &uris,
QString QtQuickApp::pathExtended(int fileType) const
{
QString cleanProjectName = projectName().replace(QLatin1Char('-'), QString());
const bool importQmlFile = m_mainQmlMode == ModeImport;
const QString qmlSubDir = QLatin1String("qml/")
+ (useExistingMainQml() ? m_mainQmlFile.dir().dirName() : cleanProjectName)
+ QLatin1Char('/');
+ (importQmlFile ? m_mainQmlFile.dir().dirName() : cleanProjectName)
+ QLatin1Char('/');
const QString appViewerTargetSubDir = appViewerOriginsSubDir;
const QString mainQml = QLatin1String("main.qml");
const QString pathBase = outputPathBase();
const QDir appProFilePath(pathBase);
switch (fileType) {
case MainQml: return useExistingMainQml() ? m_mainQmlFile.canonicalFilePath()
: pathBase + qmlSubDir + mainQml;
case MainQmlDeployed: return useExistingMainQml() ? qmlSubDir + m_mainQmlFile.fileName()
: QString(qmlSubDir + mainQml);
case MainQml: return importQmlFile ? m_mainQmlFile.canonicalFilePath()
: pathBase + qmlSubDir + mainQml;
case MainQmlDeployed: return importQmlFile ? qmlSubDir + m_mainQmlFile.fileName()
: QString(qmlSubDir + mainQml);
case MainQmlOrigin: return originsRoot() + QLatin1String("qml/app/") + mainQml;
case AppViewerPri: return pathBase + appViewerTargetSubDir + appViewerPriFileName;
case AppViewerPriOrigin: return originsRoot() + appViewerOriginsSubDir + appViewerPriFileName;
......@@ -182,8 +187,8 @@ QString QtQuickApp::pathExtended(int fileType) const
case AppViewerH: return pathBase + appViewerTargetSubDir + appViewerHFileName;
case AppViewerHOrigin: return originsRoot() + appViewerOriginsSubDir + appViewerHFileName;
case QmlDir: return pathBase + qmlSubDir;
case QmlDirProFileRelative: return useExistingMainQml() ? appProFilePath.relativeFilePath(m_mainQmlFile.canonicalPath())
: QString(qmlSubDir).remove(qmlSubDir.length() - 1, 1);
case QmlDirProFileRelative: return importQmlFile ? appProFilePath.relativeFilePath(m_mainQmlFile.canonicalPath())
: QString(qmlSubDir).remove(qmlSubDir.length() - 1, 1);
case ModulesDir: return QLatin1String("modules");
default: qFatal("QtQuickApp::pathExtended() needs more work");
}
......
......@@ -107,11 +107,16 @@ public:
ModulesDir
};
enum Mode {
ModeGenerate,
ModeImport
};
QtQuickApp();
virtual ~QtQuickApp();
void setMainQmlFile(const QString &qmlFile);
QString mainQmlFile() const;
void setMainQml(Mode mode, const QString &file = QString());
Mode mainQmlMode() const;
bool setExternalModules(const QStringList &uris, const QStringList &importPaths);
#ifndef CREATORLESSTEST
......@@ -145,6 +150,7 @@ private:
void clearModulesAndPlugins();
QFileInfo m_mainQmlFile;
Mode m_mainQmlMode;
QStringList m_importPaths;
QList <QmlModule*> m_modules;
QList <QmlCppPlugin*> m_cppPlugins;
......
......@@ -144,18 +144,22 @@ void QtQuickAppWizard::prepareGenerateFiles(const QWizard *w,
{
Q_UNUSED(errorMessage)
const QtQuickAppWizardDialog *wizard = qobject_cast<const QtQuickAppWizardDialog*>(w);
const QString mainQmlFile = wizard->m_qmlSourcesPage->mainQmlFile();
m_d->app->setMainQmlFile(mainQmlFile);
if (wizard->m_qmlSourcesPage->mainQmlMode() == QtQuickApp::ModeGenerate) {
m_d->app->setMainQml(QtQuickApp::ModeGenerate);
} else {
const QString mainQmlFile = wizard->m_qmlSourcesPage->mainQmlFile();
m_d->app->setMainQml(QtQuickApp::ModeImport, mainQmlFile);
}
}
bool QtQuickAppWizard::postGenerateFilesInternal(const Core::GeneratedFiles &l,
QString *errorMessage)
{
const bool success = ProjectExplorer::CustomProjectWizard::postGenerateOpen(l, errorMessage);
if (success && !m_d->app->mainQmlFile().isEmpty()) {
ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, m_d->app->mainQmlFile());
Core::EditorManager::instance()->openEditor(m_d->app->mainQmlFile(),
QString(), Core::EditorManager::ModeSwitch);
const QString mainQmlFile = m_d->app->path(QtQuickApp::MainQml);
if (success && !mainQmlFile.isEmpty()) {
ProjectExplorer::ProjectExplorerPlugin::instance()->setCurrentFile(0, mainQmlFile);
Core::EditorManager::instance()->openEditor(mainQmlFile, QString(), Core::EditorManager::ModeSwitch);
}
return success;
}
......
......@@ -54,15 +54,15 @@ QtQuickAppWizardSourcesPage::QtQuickAppWizardSourcesPage(QWidget *parent)
, m_d(new QtQuickAppWizardSourcesPagePrivate)
{
m_d->ui.setupUi(this);
m_d->ui.mainQmlFileLineEdit->setExpectedKind(Utils::PathChooser::File);
m_d->ui.mainQmlFileLineEdit->setPromptDialogFilter(QLatin1String("*.qml"));
m_d->ui.mainQmlFileLineEdit->setPromptDialogTitle(tr("Select QML File"));
connect(m_d->ui.mainQmlFileLineEdit, SIGNAL(changed(QString)), SIGNAL(completeChanged()));
connect(m_d->ui.importExistingQmlRadioButton,
m_d->ui.importLineEdit->setExpectedKind(Utils::PathChooser::File);
m_d->ui.importLineEdit->setPromptDialogFilter(QLatin1String("*.qml"));
m_d->ui.importLineEdit->setPromptDialogTitle(tr("Select QML File"));
connect(m_d->ui.importLineEdit, SIGNAL(changed(QString)), SIGNAL(completeChanged()));
connect(m_d->ui.importRadioButton,
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);
connect(m_d->ui.generateRadioButton, SIGNAL(toggled(bool)),
m_d->ui.importLineEdit, SLOT(setDisabled(bool)));
m_d->ui.generateRadioButton->setChecked(true);
}
QtQuickAppWizardSourcesPage::~QtQuickAppWizardSourcesPage()
......@@ -70,16 +70,22 @@ QtQuickAppWizardSourcesPage::~QtQuickAppWizardSourcesPage()
delete m_d;
}
QtQuickApp::Mode QtQuickAppWizardSourcesPage::mainQmlMode() const
{
return m_d->ui.generateRadioButton->isChecked() ? QtQuickApp::ModeGenerate
: QtQuickApp::ModeImport;
}
QString QtQuickAppWizardSourcesPage::mainQmlFile() const
{
return m_d->ui.importExistingQmlRadioButton->isChecked() ?
m_d->ui.mainQmlFileLineEdit->path() : QString();
return mainQmlMode() == QtQuickApp::ModeImport ?
m_d->ui.importLineEdit->path() : QString();
}
bool QtQuickAppWizardSourcesPage::isComplete() const
{
return !m_d->ui.importExistingQmlRadioButton->isChecked()
|| m_d->ui.mainQmlFileLineEdit->isValid();
return mainQmlMode() != QtQuickApp::ModeImport
|| m_d->ui.importLineEdit->isValid();
}
} // namespace Internal
......
......@@ -35,6 +35,7 @@
#define QTQUICKAPPWIZARDPAGES_H
#include <QtGui/QWizardPage>
#include "qtquickapp.h"
namespace Qt4ProjectManager {
namespace Internal {
......@@ -48,6 +49,7 @@ public:
explicit QtQuickAppWizardSourcesPage(QWidget *parent = 0);
virtual ~QtQuickAppWizardSourcesPage();
QtQuickApp::Mode mainQmlMode() const;
QString mainQmlFile() const;
virtual bool isComplete() const;
......
......@@ -21,21 +21,21 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QRadioButton" name="newQmlRadioButton">
<widget class="QRadioButton" name="generateRadioButton">
<property name="text">
<string>Generate a main.qml file</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="importExistingQmlRadioButton">
<widget class="QRadioButton" name="importRadioButton">
<property name="text">
<string>Import an existing .qml file</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Utils::PathChooser" name="mainQmlFileLineEdit"/>
<widget class="Utils::PathChooser" name="importLineEdit"/>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer">
......
......@@ -18,7 +18,7 @@ bool QtQuickApp::generateFiles(QString *errorMessage) const
{
return writeFile(generateFile(QtQuickAppGeneratedFileInfo::MainCppFile, errorMessage), path(MainCpp))
&& writeFile(generateFile(QtQuickAppGeneratedFileInfo::AppProFile, errorMessage), path(AppPro))
&& (useExistingMainQml() ? true : writeFile(generateFile(QtQuickAppGeneratedFileInfo::MainQmlFile, errorMessage), path(MainQml)))
&& (m_mainQmlMode != ModeImport ? true : writeFile(generateFile(QtQuickAppGeneratedFileInfo::MainQmlFile, errorMessage), path(MainQml)))
&& writeFile(generateFile(QtQuickAppGeneratedFileInfo::AppViewerPriFile, errorMessage), path(AppViewerPri))
&& writeFile(generateFile(QtQuickAppGeneratedFileInfo::AppViewerCppFile, errorMessage), path(AppViewerCpp))
&& writeFile(generateFile(QtQuickAppGeneratedFileInfo::AppViewerHFile, errorMessage), path(AppViewerH))
......
......@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
QtQuickApp sAppImport01;
sAppImport01.setProjectPath(projectPath);
sAppImport01.setProjectName(QLatin1String("qml_imported_scenario_01"));
sAppImport01.setMainQmlFile(QLatin1String("../appwizards/qmlimportscenario_01/myqmlapp.qml"));
sAppImport01.setMainQml(QtQuickApp::ModeImport, QLatin1String("../appwizards/qmlimportscenario_01/myqmlapp.qml"));
if (!sAppImport01.generateFiles(&errorMessage))
return 1;
}
......@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
QtQuickApp sAppImport02;
sAppImport02.setProjectPath(projectPath);
sAppImport02.setProjectName(QLatin1String("qml_imported_scenario_02"));
sAppImport02.setMainQmlFile(rootPath + QLatin1String("subfolder1/myqmlapp.qml"));
sAppImport02.setMainQml(QtQuickApp::ModeImport, rootPath + QLatin1String("subfolder1/myqmlapp.qml"));
QStringList moduleNames;
moduleNames.append(QLatin1String("no.trolltech.QmlModule01"));
moduleNames.append(QLatin1String("com.nokia.QmlModule02"));
......
import Qt 4.7
import "qmlproject01"
import "qmlproject02"
import QtQuick 1.0
Rectangle {
width: 200
height: 200
color: "#ddddff"
width: 360
height: 360
Text {
id: title
text: "main"
text: "Hello World"
anchors.centerIn: parent
}
Column {
MouseArea {
anchors.fill: parent
anchors.margins: title.height + 2
QmlProject01 {
height: parent.height / 2
width: parent.width
}
QmlProject02 {
height: parent.height / 2
width: parent.width
onClicked: {
Qt.quit();
}
}
}
import Qt 4.7
import no.trolltech.QmlModule01 1.0
import com.nokia.QmlModule02 1.0
import QtQuick 1.0
Rectangle {
width: 200
height: 200
color: "#ddddff"
width: 360
height: 360
Text {
id: title
text: "main"
text: "Hello World"
anchors.centerIn: parent
}
Column {
MouseArea {
anchors.fill: parent
anchors.margins: title.height + 2
QmlComponent01 {
height: parent.height / 2
width: parent.width
}
QmlComponent02 {
height: parent.height / 2
width: parent.width
onClicked: {
Qt.quit();
}
}
}
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