diff --git a/src/plugins/scxmleditor/CMakeLists.txt b/src/plugins/scxmleditor/CMakeLists.txt index 85a1c7fc706..de5fe6327af 100644 --- a/src/plugins/scxmleditor/CMakeLists.txt +++ b/src/plugins/scxmleditor/CMakeLists.txt @@ -89,6 +89,5 @@ add_qtc_plugin(ScxmlEditor scxmleditor.cpp scxmleditor.h scxmleditordocument.cpp scxmleditordocument.h scxmleditorplugin.cpp - scxmleditorstack.cpp scxmleditorstack.h scxmltexteditor.cpp scxmltexteditor.h ) diff --git a/src/plugins/scxmleditor/scxmleditor.cpp b/src/plugins/scxmleditor/scxmleditor.cpp index f28965ff28a..9a2320246bd 100644 --- a/src/plugins/scxmleditor/scxmleditor.cpp +++ b/src/plugins/scxmleditor/scxmleditor.cpp @@ -4,7 +4,6 @@ #include "mainwidget.h" #include "scxmleditorconstants.h" #include "scxmleditordocument.h" -#include "scxmleditorstack.h" #include "scxmleditortr.h" #include "scxmltexteditor.h" @@ -32,9 +31,10 @@ #include #include -#include +#include #include #include +#include using namespace Core; using namespace ScxmlEditor::Common; @@ -43,6 +43,68 @@ using namespace Utils; namespace ScxmlEditor::Internal { +class ScxmlEditorStack final : public QStackedWidget +{ +public: + ScxmlEditorStack() { setObjectName("ScxmlEditorStack"); } + + void add(ScxmlTextEditor *editor, QWidget *widget) + { + connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeAboutToChange, + this, &ScxmlEditorStack::modeAboutToChange); + + m_editors.append(editor); + addWidget(widget); + connect(editor, &ScxmlTextEditor::destroyed, + this, &ScxmlEditorStack::removeScxmlTextEditor); + } + + QWidget *widgetForEditor(ScxmlTextEditor *xmlEditor) + { + const int i = m_editors.indexOf(xmlEditor); + QTC_ASSERT(i >= 0, return nullptr); + + return widget(i); + } + + void removeScxmlTextEditor(QObject *xmlEditor) + { + const int i = m_editors.indexOf(xmlEditor); + QTC_ASSERT(i >= 0, return); + + QWidget *widget = this->widget(i); + if (widget) { + removeWidget(widget); + widget->deleteLater(); + } + m_editors.removeAt(i); + } + + bool setVisibleEditor(Core::IEditor *xmlEditor) + { + const int i = m_editors.indexOf(xmlEditor); + QTC_ASSERT(i >= 0, return false); + + if (i != currentIndex()) + setCurrentIndex(i); + + return true; + } + +private: + void modeAboutToChange(Utils::Id m) + { + // Sync the editor when entering edit mode + if (m == Core::Constants::MODE_EDIT) { + for (auto editor: std::as_const(m_editors)) + if (auto document = qobject_cast(editor->textDocument())) + document->syncXmlFromDesignWidget(); + } + } + + QList m_editors; +}; + class ScxmlTextEditorWidget : public TextEditor::TextEditorWidget { public: diff --git a/src/plugins/scxmleditor/scxmleditor.qbs b/src/plugins/scxmleditor/scxmleditor.qbs index b583163579d..06a6773124a 100644 --- a/src/plugins/scxmleditor/scxmleditor.qbs +++ b/src/plugins/scxmleditor/scxmleditor.qbs @@ -24,7 +24,6 @@ QtcPlugin { "scxmleditor.cpp", "scxmleditor.h", "scxmleditordocument.cpp", "scxmleditordocument.h", "scxmleditorplugin.cpp", - "scxmleditorstack.cpp", "scxmleditorstack.h", "scxmltexteditor.cpp", "scxmltexteditor.h", ] diff --git a/src/plugins/scxmleditor/scxmleditorstack.cpp b/src/plugins/scxmleditor/scxmleditorstack.cpp deleted file mode 100644 index d3a739133f3..00000000000 --- a/src/plugins/scxmleditor/scxmleditorstack.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "scxmleditorstack.h" -#include "scxmleditordocument.h" -#include "scxmltexteditor.h" - -#include -#include -#include - -#include - -using namespace ScxmlEditor; -using namespace ScxmlEditor::Internal; - -ScxmlEditorStack::ScxmlEditorStack(QWidget *parent) - : QStackedWidget(parent) -{ - setObjectName("ScxmlEditorStack"); -} - -void ScxmlEditorStack::add(ScxmlTextEditor *editor, QWidget *w) -{ - connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeAboutToChange, - this, &ScxmlEditorStack::modeAboutToChange); - - m_editors.append(editor); - addWidget(w); - connect(editor, &ScxmlTextEditor::destroyed, - this, &ScxmlEditorStack::removeScxmlTextEditor); -} - -void ScxmlEditorStack::removeScxmlTextEditor(QObject *xmlEditor) -{ - const int i = m_editors.indexOf(static_cast(xmlEditor)); - QTC_ASSERT(i >= 0, return); - - QWidget *widget = this->widget(i); - if (widget) { - removeWidget(widget); - widget->deleteLater(); - } - m_editors.removeAt(i); -} - -bool ScxmlEditorStack::setVisibleEditor(Core::IEditor *xmlEditor) -{ - const int i = m_editors.indexOf(static_cast(xmlEditor)); - QTC_ASSERT(i >= 0, return false); - - if (i != currentIndex()) - setCurrentIndex(i); - - return true; -} - -QWidget *ScxmlEditorStack::widgetForEditor(ScxmlTextEditor *xmlEditor) -{ - const int i = m_editors.indexOf(xmlEditor); - QTC_ASSERT(i >= 0, return nullptr); - - return widget(i); -} - -void ScxmlEditorStack::modeAboutToChange(Utils::Id m) -{ - // Sync the editor when entering edit mode - if (m == Core::Constants::MODE_EDIT) { - for (auto editor: std::as_const(m_editors)) - if (auto document = qobject_cast(editor->textDocument())) - document->syncXmlFromDesignWidget(); - } -} diff --git a/src/plugins/scxmleditor/scxmleditorstack.h b/src/plugins/scxmleditor/scxmleditorstack.h deleted file mode 100644 index ecad2324ecc..00000000000 --- a/src/plugins/scxmleditor/scxmleditorstack.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#pragma once - -#include - -#include - -namespace Core { -class IEditor; -class IMode; -} - -namespace ScxmlEditor { - -class ScxmlTextEditor; - -namespace Internal { - -class ScxmlEditorStack : public QStackedWidget { - Q_OBJECT - -public: - ScxmlEditorStack(QWidget *parent = nullptr); - - void add(ScxmlTextEditor *editor, QWidget *widget); - QWidget *widgetForEditor(ScxmlTextEditor *editor); - void removeScxmlTextEditor(QObject*); - bool setVisibleEditor(Core::IEditor *xmlEditor); - -private: - void modeAboutToChange(Utils::Id m); - - QVector m_editors; -}; - -} // namespace Internal -} // namespace ScxmlEditor