QmlDesigner: Cleanup designer plugin for show/hide designer methods

Change-Id: I824ced5f1bf921d7336b3c4fe86ac37060129cd3
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ali Kianian
2023-07-17 18:07:19 +03:00
parent 2322313baf
commit a34b991448
4 changed files with 67 additions and 54 deletions

View File

@@ -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();

View File

@@ -595,11 +595,9 @@ void DesignModeWidget::initialize()
if (m_initStatus == NotInitialized) {
m_initStatus = Initializing;
setup();
emit initialized();
}
m_initStatus = Initialized;
emit initialized();
}
} // namespace Internal

View File

@@ -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()

View File

@@ -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();