forked from qt-creator/qt-creator
ScxmlEditor: Inline scxmleditorstack.* into its only user
Also de-Q_OBJECT-ify and drop two unnecessary casts. Change-Id: I8113fc52e96226c3bdd72b36a904775c2fa5f1e6 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -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 <utils/utilsicons.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QStackedWidget>
|
||||
#include <QToolBar>
|
||||
#include <QUndoGroup>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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<ScxmlEditorDocument*>(editor->textDocument()))
|
||||
document->syncXmlFromDesignWidget();
|
||||
}
|
||||
}
|
||||
|
||||
QList<ScxmlTextEditor*> m_editors;
|
||||
};
|
||||
|
||||
class ScxmlTextEditorWidget : public TextEditor::TextEditorWidget
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user