From a34b99144829bdeda541e6008b5ba2f2114b1bed Mon Sep 17 00:00:00 2001 From: Ali Kianian Date: Mon, 17 Jul 2023 18:07:19 +0300 Subject: [PATCH] QmlDesigner: Cleanup designer plugin for show/hide designer methods Change-Id: I824ced5f1bf921d7336b3c4fe86ac37060129cd3 Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Marco Bubke --- .../components/toolbar/toolbarbackend.cpp | 36 +++++---- src/plugins/qmldesigner/designmodewidget.cpp | 4 +- src/plugins/qmldesigner/qmldesignerplugin.cpp | 78 ++++++++++--------- src/plugins/qmldesigner/qmldesignerplugin.h | 3 + 4 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp b/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp index c917dfe8a84..99c46b43b33 100644 --- a/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp +++ b/src/plugins/qmldesigner/components/toolbar/toolbarbackend.cpp @@ -132,17 +132,21 @@ void CrumbleBarModel::onCrumblePathElementClicked(int i) WorkspaceModel::WorkspaceModel(QObject *) { - connect(designModeWidget(), &Internal::DesignModeWidget::initialized, this, [this]() { + auto connectDockManager = [this]() -> bool { const auto dockManager = designModeWidget()->dockManager(); + if (!dockManager) + return false; connect(dockManager, &ADS::DockManager::workspaceListChanged, this, [this]() { beginResetModel(); endResetModel(); }); - beginResetModel(); endResetModel(); - }); + return true; + }; + if (!connectDockManager()) + connect(designModeWidget(), &Internal::DesignModeWidget::initialized, this, connectDockManager); } int WorkspaceModel::rowCount(const QModelIndex &) const @@ -288,19 +292,25 @@ ToolBarBackend::ToolBarBackend(QObject *parent) this, &ToolBarBackend::currentStyleChanged); - connect(designModeWidget(), &Internal::DesignModeWidget::initialized, this, [this]() { + auto connectDockManager = [this]() -> bool { const auto dockManager = designModeWidget()->dockManager(); + if (!dockManager) + return false; - connect(dockManager, &ADS::DockManager::workspaceLoaded, this, [this](const QString &) { - emit currentWorkspaceChanged(); - }); - - connect(dockManager, &ADS::DockManager::workspaceListChanged, this, [this]() { - emit currentWorkspaceChanged(); - }); - + connect(dockManager, + &ADS::DockManager::workspaceLoaded, + this, + &ToolBarBackend::currentWorkspaceChanged); + connect(dockManager, + &ADS::DockManager::workspaceListChanged, + this, + &ToolBarBackend::currentWorkspaceChanged); emit currentWorkspaceChanged(); - }); + return true; + }; + + if (!connectDockManager()) + connect(designModeWidget(), &Internal::DesignModeWidget::initialized, this, connectDockManager); auto editorManager = Core::EditorManager::instance(); diff --git a/src/plugins/qmldesigner/designmodewidget.cpp b/src/plugins/qmldesigner/designmodewidget.cpp index 1bb427bd055..aab6aec18ec 100644 --- a/src/plugins/qmldesigner/designmodewidget.cpp +++ b/src/plugins/qmldesigner/designmodewidget.cpp @@ -595,11 +595,9 @@ void DesignModeWidget::initialize() if (m_initStatus == NotInitialized) { m_initStatus = Initializing; setup(); + emit initialized(); } - m_initStatus = Initialized; - - emit initialized(); } } // namespace Internal diff --git a/src/plugins/qmldesigner/qmldesignerplugin.cpp b/src/plugins/qmldesigner/qmldesignerplugin.cpp index e5c02f64875..839ad8b5683 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.cpp +++ b/src/plugins/qmldesigner/qmldesignerplugin.cpp @@ -420,6 +420,38 @@ void QmlDesignerPlugin::integrateIntoQtCreator(QWidget *modeWidget) }); } +void QmlDesignerPlugin::clearDesigner() +{ + if (d->documentManager.hasCurrentDesignDocument()) { + deactivateAutoSynchronization(); + d->mainWidget.saveSettings(); + } +} + +void QmlDesignerPlugin::resetDesignerDocument() +{ + d->shortCutManager.disconnectUndoActions(currentDesignDocument()); + d->documentManager.setCurrentDesignDocument(nullptr); + d->shortCutManager.updateActions(nullptr); + d->shortCutManager.updateUndoActions(nullptr); +} + +void QmlDesignerPlugin::setupDesigner() +{ + d->shortCutManager.disconnectUndoActions(currentDesignDocument()); + d->documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor()); + d->shortCutManager.connectUndoActions(currentDesignDocument()); + + if (d->documentManager.hasCurrentDesignDocument()) { + activateAutoSynchronization(); + d->shortCutManager.updateActions(currentDesignDocument()->textEditor()); + d->viewManager.pushFileOnCrumbleBar(currentDesignDocument()->fileName()); + d->viewManager.setComponentViewToMaster(); + } + + d->shortCutManager.updateUndoActions(currentDesignDocument()); +} + void QmlDesignerPlugin::showDesigner() { QTC_ASSERT(!d->documentManager.hasCurrentDesignDocument(), return); @@ -430,7 +462,8 @@ void QmlDesignerPlugin::showDesigner() const Utils::FilePath fileName = Core::EditorManager::currentEditor()->document()->filePath(); const QStringList allUiQmlFiles = allUiQmlFilesforCurrentProject(fileName); - if (warningsForQmlFilesInsteadOfUiQmlEnabled() && !fileName.endsWith(".ui.qml") && !allUiQmlFiles.isEmpty()) { + if (warningsForQmlFilesInsteadOfUiQmlEnabled() && !fileName.endsWith(".ui.qml") + && !allUiQmlFiles.isEmpty()) { OpenUiQmlFileDialog dialog(&d->mainWidget); dialog.setUiQmlFiles(projectPath(fileName), allUiQmlFiles); dialog.exec(); @@ -442,56 +475,25 @@ void QmlDesignerPlugin::showDesigner() } } - d->shortCutManager.disconnectUndoActions(currentDesignDocument()); - d->documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor()); - d->shortCutManager.connectUndoActions(currentDesignDocument()); - - if (d->documentManager.hasCurrentDesignDocument()) { - activateAutoSynchronization(); - d->shortCutManager.updateActions(currentDesignDocument()->textEditor()); - d->viewManager.pushFileOnCrumbleBar(currentDesignDocument()->fileName()); - } - - d->shortCutManager.updateUndoActions(currentDesignDocument()); + setupDesigner(); m_usageTimer.restart(); } void QmlDesignerPlugin::hideDesigner() { - if (d->documentManager.hasCurrentDesignDocument()) { - deactivateAutoSynchronization(); - d->mainWidget.saveSettings(); - } - - d->shortCutManager.disconnectUndoActions(currentDesignDocument()); - d->documentManager.setCurrentDesignDocument(nullptr); - d->shortCutManager.updateUndoActions(nullptr); + clearDesigner(); + resetDesignerDocument(); emitUsageStatisticsTime(Constants::EVENT_DESIGNMODE_TIME, m_usageTimer.elapsed()); } void QmlDesignerPlugin::changeEditor() { if (d->blockEditorChange) - return; + return; - if (d->documentManager.hasCurrentDesignDocument()) { - deactivateAutoSynchronization(); - d->mainWidget.saveSettings(); - } - - d->shortCutManager.disconnectUndoActions(currentDesignDocument()); - d->documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor()); - d->mainWidget.initialize(); - d->shortCutManager.connectUndoActions(currentDesignDocument()); - - if (d->documentManager.hasCurrentDesignDocument()) { - activateAutoSynchronization(); - d->viewManager.pushFileOnCrumbleBar(currentDesignDocument()->fileName()); - d->viewManager.setComponentViewToMaster(); - } - - d->shortCutManager.updateUndoActions(currentDesignDocument()); + clearDesigner(); + setupDesigner(); } void QmlDesignerPlugin::jumpTextCursorToSelectedModelNode() diff --git a/src/plugins/qmldesigner/qmldesignerplugin.h b/src/plugins/qmldesigner/qmldesignerplugin.h index 455810fa206..e9e8847fbe1 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.h +++ b/src/plugins/qmldesigner/qmldesignerplugin.h @@ -105,6 +105,9 @@ private slots: private: // functions void lauchFeedbackPopupInternal(const QString &identifier); void integrateIntoQtCreator(QWidget *modeWidget); + void clearDesigner(); + void resetDesignerDocument(); + void setupDesigner(); void showDesigner(); void hideDesigner(); void changeEditor();