QmlProjectManager: Load QDS landing page content when it is needed

Task-number: QTCREATORBUG-27583
Change-Id: Ib329816f7282b0c6f88d78d62a0c9f34c961e509
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Tapani Mattila
2022-06-01 17:33:39 +03:00
parent 1445e4180f
commit 0b404c9c7a
3 changed files with 95 additions and 45 deletions

View File

@@ -30,6 +30,7 @@
#include <coreplugin/icore.h>
#include <QtQml/QQmlEngine>
#include <QHBoxLayout>
#include <QQuickItem>
namespace QmlProjectManager {
@@ -38,51 +39,76 @@ namespace Internal {
const char QMLRESOURCEPATH[] = "qmldesigner/propertyEditorQmlSources/imports";
const char LANDINGPAGEPATH[] = "qmldesigner/landingpage";
QdsLandingPage::QdsLandingPage(QWidget *parent)
: m_dialog{new QQuickWidget(parent)}
QdsLandingPageWidget::QdsLandingPageWidget(QWidget* parent)
: QWidget(parent)
{
setParent(m_dialog);
setLayout(new QHBoxLayout());
layout()->setContentsMargins(0, 0, 0, 0);
}
QdsLandingPageWidget::~QdsLandingPageWidget()
{
if (m_widget)
m_widget->deleteLater();
}
QQuickWidget *QdsLandingPageWidget::widget()
{
if (!m_widget) {
m_widget = new QQuickWidget();
layout()->addWidget(m_widget);
}
return m_widget;
}
QdsLandingPage::QdsLandingPage(QdsLandingPageWidget *widget, QWidget *parent)
: m_widget{widget->widget()}
{
Q_UNUSED(parent)
setParent(m_widget);
const QString resourcePath = Core::ICore::resourcePath(QMLRESOURCEPATH).toString();
const QString landingPath = Core::ICore::resourcePath(LANDINGPAGEPATH).toString();
qmlRegisterSingletonInstance<QdsLandingPage>("LandingPageApi", 1, 0, "LandingPageApi", this);
QdsLandingPageTheme::setupTheme(m_dialog->engine());
QdsLandingPageTheme::setupTheme(m_widget->engine());
m_dialog->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_dialog->engine()->addImportPath(landingPath + "/imports");
m_dialog->engine()->addImportPath(resourcePath);
m_dialog->setSource(QUrl::fromLocalFile(landingPath + "/main.qml"));
m_widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_widget->engine()->addImportPath(landingPath + "/imports");
m_widget->engine()->addImportPath(resourcePath);
m_widget->setSource(QUrl::fromLocalFile(landingPath + "/main.qml"));
if (m_dialog->rootObject()) { // main.qml only works with Qt6
connect(m_dialog->rootObject(), SIGNAL(openQtc(bool)), this, SIGNAL(openCreator(bool)));
connect(m_dialog->rootObject(), SIGNAL(openQds(bool)), this, SIGNAL(openDesigner(bool)));
connect(m_dialog->rootObject(), SIGNAL(installQds()), this, SIGNAL(installDesigner()));
connect(m_dialog->rootObject(), SIGNAL(generateCmake()), this, SIGNAL(generateCmake()));
connect(m_dialog->rootObject(), SIGNAL(generateProjectFile()), this, SIGNAL(generateProjectFile()));
if (m_widget->rootObject()) { // main.qml only works with Qt6
connect(m_widget->rootObject(), SIGNAL(openQtc(bool)), this, SIGNAL(openCreator(bool)));
connect(m_widget->rootObject(), SIGNAL(openQds(bool)), this, SIGNAL(openDesigner(bool)));
connect(m_widget->rootObject(), SIGNAL(installQds()), this, SIGNAL(installDesigner()));
connect(m_widget->rootObject(), SIGNAL(generateCmake()), this, SIGNAL(generateCmake()));
connect(m_widget->rootObject(), SIGNAL(generateProjectFile()), this, SIGNAL(generateProjectFile()));
}
m_dialog->hide();
m_widget->hide();
}
QWidget* QdsLandingPage::dialog()
QWidget *QdsLandingPage::widget()
{
return m_dialog;
return m_widget;
}
void QdsLandingPage::show()
{
m_dialog->rootObject()->setProperty("qdsInstalled", m_qdsInstalled);
m_dialog->rootObject()->setProperty("projectFileExists", m_projectFileExists);
m_dialog->rootObject()->setProperty("qtVersion", m_qtVersion);
m_dialog->rootObject()->setProperty("qdsVersion", m_qdsVersion);
m_dialog->rootObject()->setProperty("cmakeLists", m_cmakeResources);
m_dialog->rootObject()->setProperty("rememberSelection", Qt::Unchecked);
m_dialog->show();
m_widget->rootObject()->setProperty("qdsInstalled", m_qdsInstalled);
m_widget->rootObject()->setProperty("projectFileExists", m_projectFileExists);
m_widget->rootObject()->setProperty("qtVersion", m_qtVersion);
m_widget->rootObject()->setProperty("qdsVersion", m_qdsVersion);
m_widget->rootObject()->setProperty("cmakeLists", m_cmakeResources);
m_widget->rootObject()->setProperty("rememberSelection", Qt::Unchecked);
m_widget->show();
}
void QdsLandingPage::hide()
{
m_dialog->hide();
m_widget->hide();
}
bool QdsLandingPage::qdsInstalled() const

View File

@@ -42,6 +42,19 @@ public:
DesignModeContext(QWidget *widget) { setWidget(widget); }
};
class QdsLandingPageWidget : public QWidget
{
Q_OBJECT
public:
QdsLandingPageWidget(QWidget* parent = nullptr);
~QdsLandingPageWidget();
QQuickWidget *widget();
private:
QQuickWidget *m_widget = nullptr;
};
class QdsLandingPage : public QObject
{
Q_OBJECT
@@ -53,9 +66,9 @@ public:
Q_PROPERTY(QString qdsVersion MEMBER m_qdsVersion READ qdsVersion WRITE setQdsVersion)
public:
QdsLandingPage(QWidget *parent = nullptr);
QdsLandingPage(QdsLandingPageWidget *widget, QWidget *parent = nullptr);
QWidget *dialog();
QWidget *widget();
void show();
void hide();
@@ -80,7 +93,7 @@ signals:
void generateProjectFile();
private:
QQuickWidget *m_dialog = nullptr;
QQuickWidget *m_widget = nullptr;
bool m_qdsInstalled = false;
bool m_projectFileExists = false;

View File

@@ -117,6 +117,7 @@ public:
{runConfigFactory.runConfigurationId()}};
QPointer<QMessageBox> lastMessageBox;
QdsLandingPage *landingPage = nullptr;
QdsLandingPageWidget *landingPageWidget = nullptr;
};
QmlProjectPlugin::~QmlProjectPlugin()
@@ -125,6 +126,8 @@ QmlProjectPlugin::~QmlProjectPlugin()
d->lastMessageBox->deleteLater();
if (d->landingPage)
d->landingPage->deleteLater();
if (d->landingPageWidget)
d->landingPageWidget->deleteLater();
delete d;
}
@@ -263,8 +266,19 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
d = new QmlProjectPluginPrivate;
if (!qmlDesignerEnabled())
initializeQmlLandingPage();
if (!qmlDesignerEnabled()) {
d->landingPageWidget = new QdsLandingPageWidget();
const QStringList mimeTypes = {QmlJSTools::Constants::QMLUI_MIMETYPE};
auto context = new Internal::DesignModeContext(d->landingPageWidget);
Core::ICore::addContextObject(context);
Core::DesignMode::registerDesignWidget(d->landingPageWidget, mimeTypes, context->context());
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged,
this, &QmlProjectPlugin::editorModeChanged);
}
ProjectManager::registerProjectType<QmlProject>(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
Core::FileIconProvider::registerIconOverlayForSuffix(":/qmlproject/images/qmlproject.png",
@@ -366,23 +380,12 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
void QmlProjectPlugin::initializeQmlLandingPage()
{
d->landingPage = new QdsLandingPage();
d->landingPage = new QdsLandingPage(d->landingPageWidget);
connect(d->landingPage, &QdsLandingPage::openCreator, this, &QmlProjectPlugin::openQtc);
connect(d->landingPage, &QdsLandingPage::openDesigner, this, &QmlProjectPlugin::openQds);
connect(d->landingPage, &QdsLandingPage::installDesigner, this, &QmlProjectPlugin::installQds);
connect(d->landingPage, &QdsLandingPage::generateCmake, this, &QmlProjectPlugin::generateCmake);
connect(d->landingPage, &QdsLandingPage::generateProjectFile, this, &QmlProjectPlugin::generateProjectFile);
auto dialog = d->landingPage->dialog();
const QStringList mimeTypes = {QmlJSTools::Constants::QMLUI_MIMETYPE};
auto context = new Internal::DesignModeContext(dialog);
Core::ICore::addContextObject(context);
Core::DesignMode::registerDesignWidget(dialog, mimeTypes, context->context());
connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged,
this, &QmlProjectPlugin::editorModeChanged);
}
void QmlProjectPlugin::displayQmlLandingPage()
@@ -390,6 +393,9 @@ void QmlProjectPlugin::displayQmlLandingPage()
const QString qtVersionString = ProjectFileContentTools::qtVersion(projectFilePath());
const QString qdsVersionString = ProjectFileContentTools::qdsVersion(projectFilePath());
if (!d->landingPage)
initializeQmlLandingPage();
d->landingPage->setQdsInstalled(qdsInstallationExists());
d->landingPage->setProjectFileExists(projectFilePath().exists());
d->landingPage->setCmakeResources(ProjectFileContentTools::rootCmakeFiles());
@@ -400,7 +406,8 @@ void QmlProjectPlugin::displayQmlLandingPage()
void QmlProjectPlugin::hideQmlLandingPage()
{
d->landingPage->hide();
if (d->landingPage)
d->landingPage->hide();
}
static bool isDesignerMode(Utils::Id mode)
@@ -430,7 +437,9 @@ void QmlProjectPlugin::openQtc(bool permanent)
if (permanent)
setAlwaysOpenWithMode(Core::Constants::MODE_EDIT);
hideQmlLandingPage();
if (d->landingPage)
hideQmlLandingPage();
Core::ModeManager::activateMode(Core::Constants::MODE_EDIT);
}
@@ -439,7 +448,9 @@ void QmlProjectPlugin::openQds(bool permanent)
if (permanent)
setAlwaysOpenWithMode(Core::Constants::MODE_DESIGN);
hideQmlLandingPage();
if (d->landingPage)
hideQmlLandingPage();
auto editor = Core::EditorManager::currentEditor();
if (editor)
openInQDSWithProject(editor->document()->filePath());