diff --git a/src/plugins/designer/designercontext.cpp b/src/plugins/designer/designercontext.cpp index 0ea7808bc06..001c40cab79 100644 --- a/src/plugins/designer/designercontext.cpp +++ b/src/plugins/designer/designercontext.cpp @@ -51,7 +51,7 @@ DesignerContext::DesignerContext(const Core::Context &context, QString DesignerContext::contextHelpId() const { - const QDesignerFormEditorInterface *core = FormEditorW::instance()->designerEditor(); + const QDesignerFormEditorInterface *core = FormEditorW::designerEditor(); return core->integration()->contextHelpId(); } diff --git a/src/plugins/designer/editorwidget.cpp b/src/plugins/designer/editorwidget.cpp index 41506b18be5..c2dfa92bab5 100644 --- a/src/plugins/designer/editorwidget.cpp +++ b/src/plugins/designer/editorwidget.cpp @@ -99,9 +99,12 @@ QDockWidget* const* EditorWidget::designerDockWidgets() const return m_designerDockWidgets; } -void EditorWidget::add(const EditorData &d) +void EditorWidget::add(SharedTools::WidgetHost *widgetHost, FormWindowEditor *formWindowEditor) { - m_stack->add(d); + EditorData data; + data.formWindowEditor = formWindowEditor; + data.widgetHost = widgetHost; + m_stack->add(data); } void EditorWidget::removeFormWindowEditor(Core::IEditor *xmlEditor) diff --git a/src/plugins/designer/editorwidget.h b/src/plugins/designer/editorwidget.h index bb8d10167df..7bae38c2b73 100644 --- a/src/plugins/designer/editorwidget.h +++ b/src/plugins/designer/editorwidget.h @@ -42,6 +42,9 @@ namespace SharedTools { class WidgetHost; } namespace Core { class IEditor; } namespace Designer { + +class FormWindowEditor; + namespace Internal { class EditorData; @@ -59,7 +62,7 @@ public: QDockWidget* const* designerDockWidgets() const; // Form editor stack API - void add(const EditorData &d); + void add(SharedTools::WidgetHost *widgetHost, FormWindowEditor *formWindowEditor); void removeFormWindowEditor(Core::IEditor *xmlEditor); bool setVisibleEditor(Core::IEditor *xmlEditor); SharedTools::WidgetHost *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const; diff --git a/src/plugins/designer/formeditorfactory.cpp b/src/plugins/designer/formeditorfactory.cpp index 1a8435dafb9..763b543dff7 100644 --- a/src/plugins/designer/formeditorfactory.cpp +++ b/src/plugins/designer/formeditorfactory.cpp @@ -30,13 +30,9 @@ #include "formeditorfactory.h" #include "formeditorw.h" #include "formwindoweditor.h" -#include "editordata.h" #include -#include -#include #include -#include #include #include @@ -48,25 +44,17 @@ namespace Designer { namespace Internal { FormEditorFactory::FormEditorFactory() - : Core::IEditorFactory(Core::ICore::instance()) { setId(K_DESIGNER_XML_EDITOR_ID); setDisplayName(qApp->translate("Designer", C_DESIGNER_XML_DISPLAY_NAME)); addMimeType(FORM_MIMETYPE); - Core::FileIconProvider::registerIconOverlayForSuffix(":/formeditor/images/qt_ui.png", "ui"); + FileIconProvider::registerIconOverlayForSuffix(":/formeditor/images/qt_ui.png", "ui"); } -Core::IEditor *FormEditorFactory::createEditor() +IEditor *FormEditorFactory::createEditor() { - const EditorData data = FormEditorW::instance()->createEditor(); - if (data.formWindowEditor) { - Core::InfoBarEntry info(Core::Id(Constants::INFO_READ_ONLY), - tr("This file can only be edited in Design mode.")); - info.setCustomButtonInfo(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); }); - data.formWindowEditor->document()->infoBar()->addInfo(info); - } - return data.formWindowEditor; + return FormEditorW::createEditor(); } } // namespace Internal diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index de7c4b589a9..45199b0527c 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -36,16 +36,17 @@ #include "editordata.h" #include "qtcreatorintegration.h" #include "designercontext.h" -#include "resourcehandler.h" #include #include #include #include #include +#include #include #include #include +#include #include #include #include @@ -129,33 +130,116 @@ public: FormWindowEditorFactory() { setId(Designer::Constants::K_DESIGNER_XML_EDITOR_ID); - setDocumentCreator([this]() { return new FormWindowFile(m_form); }); setEditorCreator([]() { return new FormWindowEditor; }); setEditorWidgetCreator([]() { return new Internal::DesignerXmlEditorWidget; }); setDuplicatedSupported(false); } - QDesignerFormWindowInterface *m_form; + FormWindowEditor *create(QDesignerFormWindowInterface *form) + { + setDocumentCreator([form]() { return new FormWindowFile(form); }); + return qobject_cast(createEditor()); + } }; -static FormWindowEditorFactory *m_xmlEditorFactory = 0; - // --------- FormEditorW -static FormEditorW *m_self = 0; +class FormEditorData +{ +public: + Q_DECLARE_TR_FUNCTIONS(FormEditorW) -FormEditorW::FormEditorW() : +public: + FormEditorData(); + ~FormEditorData(); + + void activateEditMode(int id); + void toolChanged(int); + void print(); + void setPreviewMenuEnabled(bool e); + void updateShortcut(QObject *command); + + void fullInit(); + + void saveSettings(QSettings *s); + + void initDesignerSubWindows(); + + void setupActions(); + void setupViewActions(); + void addDockViewAction(Core::ActionContainer *viewMenu, + int index, + const Core::Context &context, + const QString &title, Core::Id id); + + Core::ActionContainer *createPreviewStyleMenu(QActionGroup *actionGroup); + + void critical(const QString &errorMessage); + void bindShortcut(Core::Command *command, QAction *action); + QAction *createEditModeAction(QActionGroup *ag, + const Core::Context &context, + Core::ActionContainer *medit, + const QString &actionName, + Core::Id id, + int toolNumber, + const QString &iconName = QString(), + const QString &keySequence = QString()); + Core::Command *addToolAction(QAction *a, + const Core::Context &context, Core::Id id, + Core::ActionContainer *c1, const QString &keySequence = QString(), + Core::Id groupId = Core::Id()); + QToolBar *createEditorToolBar() const; + Core::IEditor *createEditor(); + +public: + QDesignerFormEditorInterface *m_formeditor; + QDesignerIntegrationInterface *m_integration; + QDesignerFormWindowManagerInterface *m_fwm; + FormEditorW::InitializationStage m_initStage; + + QWidget *m_designerSubWindows[Designer::Constants::DesignerSubWindowCount]; + + QAction *m_lockAction; + QAction *m_resetLayoutAction; + + QList m_settingsPages; + QActionGroup *m_actionGroupEditMode; + QAction *m_actionPrint; + QAction *m_actionPreview; + QActionGroup *m_actionGroupPreviewInStyle; + QMenu *m_previewInStyleMenu; + QAction *m_actionAboutPlugins; + QSignalMapper m_shortcutMapper; + + DesignerContext *m_context; + Core::Context m_contexts; + + QList m_toolActionIds; + QWidget *m_modeWidget; + EditorWidget *m_editorWidget; + Core::DesignMode *m_designMode; + + QWidget *m_editorToolBar; + Core::EditorToolBar *m_toolBar; + + QMap m_commandToDesignerAction; + FormWindowEditorFactory *m_xmlEditorFactory = 0; +}; + +static FormEditorData *d = 0; +static FormEditorW *m_instance = 0; + +FormEditorData::FormEditorData() : m_formeditor(QDesignerComponents::createFormEditor(0)), m_integration(0), m_fwm(0), - m_initStage(RegisterPlugins), + m_initStage(FormEditorW::RegisterPlugins), m_actionGroupEditMode(0), m_actionPrint(0), m_actionPreview(0), m_actionGroupPreviewInStyle(0), m_previewInStyleMenu(0), m_actionAboutPlugins(0), - m_shortcutMapper(new QSignalMapper(this)), m_context(0), m_modeWidget(0), m_editorWidget(0), @@ -165,8 +249,8 @@ FormEditorW::FormEditorW() : { if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO; - QTC_ASSERT(!m_self, return); - m_self = this; + QTC_ASSERT(!d, return); + d = this; qFill(m_designerSubWindows, m_designerSubWindows + Designer::Constants::DesignerSubWindowCount, static_cast(0)); @@ -186,19 +270,32 @@ FormEditorW::FormEditorW() : m_settingsPages.append(settingsPage); } - connect(EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)), - this, SLOT(currentEditorChanged(Core::IEditor*))); - connect(m_shortcutMapper, SIGNAL(mapped(QObject*)), - this, SLOT(updateShortcut(QObject*))); + QObject::connect(EditorManager::instance(), &EditorManager::currentEditorChanged, [this](IEditor *editor) { + if (Designer::Constants::Internal::debug) + qDebug() << Q_FUNC_INFO << editor << " of " << m_fwm->formWindowCount(); + + if (editor && editor->document()->id() == Constants::K_DESIGNER_XML_EDITOR_ID) { + FormWindowEditor *xmlEditor = qobject_cast(editor); + QTC_ASSERT(xmlEditor, return); + FormEditorW::ensureInitStage(FormEditorW::FullyInitialized); + SharedTools::WidgetHost *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor); + QTC_ASSERT(fw, return); + m_editorWidget->setVisibleEditor(xmlEditor); + m_fwm->setActiveFormWindow(fw->formWindow()); + } + }); + + QObject::connect(&m_shortcutMapper, static_cast(&QSignalMapper::mapped), + [this](QObject *ob) { updateShortcut(ob); }); m_xmlEditorFactory = new FormWindowEditorFactory; } -FormEditorW::~FormEditorW() +FormEditorData::~FormEditorData() { if (m_context) ICore::removeContextObject(m_context); - if (m_initStage == FullyInitialized) { + if (m_initStage == FormEditorW::FullyInitialized) { QSettings *s = ICore::settings(); s->beginGroup(QLatin1String(settingsGroupC)); m_editorWidget->saveSettings(s); @@ -215,11 +312,11 @@ FormEditorW::~FormEditorW() delete m_integration; delete m_xmlEditorFactory ; - m_self = 0; + d = 0; } // Add an actioon to toggle the view state of a dock window -void FormEditorW::addDockViewAction(ActionContainer *viewMenu, +void FormEditorData::addDockViewAction(ActionContainer *viewMenu, int index, const Context &context, const QString &title, Id id) { @@ -231,7 +328,7 @@ void FormEditorW::addDockViewAction(ActionContainer *viewMenu, } } -void FormEditorW::setupViewActions() +void FormEditorData::setupViewActions() { // Populate "View" menu of form editor menu ActionContainer *viewMenu = ActionManager::actionContainer(Core::Constants::M_WINDOW_VIEWS); @@ -256,27 +353,30 @@ void FormEditorW::setupViewActions() cmd->setAttribute(Command::CA_Hide); cmd = addToolAction(m_editorWidget->resetLayoutAction(), m_contexts, "FormEditor.ResetToDefaultLayout", viewMenu); - connect(m_editorWidget, SIGNAL(resetLayout()), m_editorWidget, SLOT(resetToDefaultLayout())); + + QObject::connect(m_editorWidget, &EditorWidget::resetLayout, + m_editorWidget, &EditorWidget::resetToDefaultLayout); + cmd->setAttribute(Command::CA_Hide); } -void FormEditorW::fullInit() +void FormEditorData::fullInit() { - QTC_ASSERT(m_initStage == RegisterPlugins, return); + QTC_ASSERT(m_initStage == FormEditorW::RegisterPlugins, return); QTime *initTime = 0; if (Designer::Constants::Internal::debug) { initTime = new QTime; initTime->start(); } - QDesignerComponents::createTaskMenu(m_formeditor, parent()); - QDesignerComponents::initializePlugins(designerEditor()); + QDesignerComponents::createTaskMenu(m_formeditor, m_instance); + QDesignerComponents::initializePlugins(m_formeditor); QDesignerComponents::initializeResources(); initDesignerSubWindows(); - m_integration = new QtCreatorIntegration(m_formeditor, this); + m_integration = new QtCreatorIntegration(m_formeditor, m_instance); m_formeditor->setIntegration(m_integration); // Connect Qt Designer help request to HelpManager. - connect(m_integration, SIGNAL(creatorHelpRequested(QUrl)), + QObject::connect(m_integration, SIGNAL(creatorHelpRequested(QUrl)), HelpManager::instance(), SLOT(handleHelpRequest(QUrl))); /** @@ -299,10 +399,13 @@ void FormEditorW::fullInit() delete initTime; } - connect(EditorManager::instance(), SIGNAL(editorsClosed(QList)), - SLOT(closeFormEditorsForXmlEditors(QList))); + QObject::connect(EditorManager::instance(), &EditorManager::editorsClosed, [this] (QList editors) { + foreach (IEditor *editor, editors) + m_editorWidget->removeFormWindowEditor(editor); + }); + // Nest toolbar and editor widget - m_editorWidget = new EditorWidget(this); + m_editorWidget = new EditorWidget(m_instance); QSettings *settings = ICore::settings(); settings->beginGroup(QLatin1String(settingsGroupC)); m_editorWidget->restoreSettings(settings); @@ -333,17 +436,17 @@ void FormEditorW::fullInit() Context designerContexts = m_contexts; designerContexts.add(Core::Constants::C_EDITORMANAGER); - m_context = new DesignerContext(designerContexts, m_modeWidget, this); + m_context = new DesignerContext(designerContexts, m_modeWidget, m_instance); ICore::addContextObject(m_context); m_designMode->registerDesignWidget(m_modeWidget, QStringList(QLatin1String(FORM_MIMETYPE)), m_contexts); setupViewActions(); - m_initStage = FullyInitialized; + m_initStage = FormEditorW::FullyInitialized; } -void FormEditorW::initDesignerSubWindows() +void FormEditorData::initDesignerSubWindows() { qFill(m_designerSubWindows, m_designerSubWindows + Designer::Constants::DesignerSubWindowCount, static_cast(0)); @@ -375,38 +478,44 @@ void FormEditorW::initDesignerSubWindows() ae->setObjectName(QLatin1String("ActionEditor")); m_formeditor->setActionEditor(ae); m_designerSubWindows[ActionEditorSubWindow] = ae; + m_initStage = FormEditorW::SubwindowsInitialized; } -QList FormEditorW::optionsPages() const +QList FormEditorW::optionsPages() { - return m_settingsPages; + return d->m_settingsPages; } void FormEditorW::ensureInitStage(InitializationStage s) { if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << s; - if (!m_self) - m_self = new FormEditorW; - if (m_self->m_initStage >= s) + if (!d) { + m_instance = new FormEditorW; + d = new FormEditorData; + } + if (d->m_initStage >= s) return; QApplication::setOverrideCursor(Qt::WaitCursor); - m_self->fullInit(); + d->fullInit(); QApplication::restoreOverrideCursor(); } -FormEditorW *FormEditorW::instance() -{ - ensureInitStage(FullyInitialized); - return m_self; -} - void FormEditorW::deleteInstance() { - delete m_self; + delete d; + d = 0; + delete m_instance; + m_instance = 0; } -void FormEditorW::setupActions() +IEditor *FormEditorW::createEditor() +{ + ensureInitStage(FullyInitialized); + return d->createEditor(); +} + +void FormEditorData::setupActions() { //menus ActionContainer *medit = ActionManager::actionContainer(Core::Constants::M_EDIT); @@ -420,9 +529,9 @@ void FormEditorW::setupActions() bindShortcut(ActionManager::registerAction(m_fwm->actionPaste(), Core::Constants::PASTE, m_contexts), m_fwm->actionPaste()); bindShortcut(ActionManager::registerAction(m_fwm->actionSelectAll(), Core::Constants::SELECTALL, m_contexts), m_fwm->actionSelectAll()); - m_actionPrint = new QAction(this); + m_actionPrint = new QAction(m_instance); bindShortcut(ActionManager::registerAction(m_actionPrint, Core::Constants::PRINT, m_contexts), m_actionPrint); - connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(print())); + QObject::connect(m_actionPrint, &QAction::triggered, [this]() { print(); }); //'delete' action. Do not set a shortcut as Designer handles // the 'Delete' key by event filter. Setting a shortcut triggers @@ -433,9 +542,10 @@ void FormEditorW::setupActions() command->setAttribute(Command::CA_Hide); medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE); - m_actionGroupEditMode = new QActionGroup(this); + m_actionGroupEditMode = new QActionGroup(m_instance); m_actionGroupEditMode->setExclusive(true); - connect(m_actionGroupEditMode, SIGNAL(triggered(QAction*)), this, SLOT(activateEditMode(QAction*))); + QObject::connect(m_actionGroupEditMode, &QActionGroup::triggered, + [this](QAction *a) { activateEditMode(a->data().toInt()); }); medit->addSeparator(m_contexts, Core::Constants::G_EDIT_OTHER); @@ -531,18 +641,23 @@ void FormEditorW::setupActions() QString(), Core::Constants::G_DEFAULT_THREE); mformtools->addSeparator(m_contexts, Core::Constants::G_DEFAULT_THREE); - m_actionAboutPlugins = new QAction(tr("About Qt Designer Plugins..."), this); + m_actionAboutPlugins = new QAction(tr("About Qt Designer Plugins..."), m_instance); m_actionAboutPlugins->setMenuRole(QAction::NoRole); addToolAction(m_actionAboutPlugins, m_contexts, "FormEditor.AboutPlugins", mformtools, QString(), Core::Constants::G_DEFAULT_THREE); - connect(m_actionAboutPlugins, SIGNAL(triggered()), m_fwm, SLOT(showPluginDialog())); + QObject::connect(m_actionAboutPlugins, &QAction::triggered, + m_fwm, &QDesignerFormWindowManagerInterface::showPluginDialog); m_actionAboutPlugins->setEnabled(false); // FWM - connect(m_fwm, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)), this, SLOT(activeFormWindowChanged(QDesignerFormWindowInterface*))); + QObject::connect(m_fwm, &QDesignerFormWindowManagerInterface::activeFormWindowChanged, + [this] (QDesignerFormWindowInterface *afw) { + m_fwm->closeAllPreviews(); + setPreviewMenuEnabled(afw != 0); + }); } -QToolBar *FormEditorW::createEditorToolBar() const +QToolBar *FormEditorData::createEditorToolBar() const { QToolBar *editorToolBar = new QToolBar; const QList::const_iterator cend = m_toolActionIds.constEnd(); @@ -559,7 +674,7 @@ QToolBar *FormEditorW::createEditorToolBar() const return editorToolBar; } -ActionContainer *FormEditorW::createPreviewStyleMenu(QActionGroup *actionGroup) +ActionContainer *FormEditorData::createPreviewStyleMenu(QActionGroup *actionGroup) { const QString menuId = QLatin1String(M_FORMEDITOR_PREVIEW); ActionContainer *menuPreviewStyle = ActionManager::createMenu(M_FORMEDITOR_PREVIEW); @@ -595,36 +710,36 @@ ActionContainer *FormEditorW::createPreviewStyleMenu(QActionGroup *actionGroup) return menuPreviewStyle; } -void FormEditorW::setPreviewMenuEnabled(bool e) +void FormEditorData::setPreviewMenuEnabled(bool e) { m_actionPreview->setEnabled(e); m_previewInStyleMenu->setEnabled(e); } -void FormEditorW::saveSettings(QSettings *s) +void FormEditorData::saveSettings(QSettings *s) { s->beginGroup(QLatin1String(settingsGroupC)); m_editorWidget->saveSettings(s); s->endGroup(); } -void FormEditorW::critical(const QString &errorMessage) +void FormEditorData::critical(const QString &errorMessage) { QMessageBox::critical(ICore::mainWindow(), tr("Designer"), errorMessage); } // Apply the command shortcut to the action and connects to the command's keySequenceChanged signal -void FormEditorW::bindShortcut(Command *command, QAction *action) +void FormEditorData::bindShortcut(Command *command, QAction *action) { m_commandToDesignerAction.insert(command, action); - connect(command, SIGNAL(keySequenceChanged()), - m_shortcutMapper, SLOT(map())); - m_shortcutMapper->setMapping(command, command); + QObject::connect(command, SIGNAL(keySequenceChanged()), + &m_shortcutMapper, SLOT(map())); + m_shortcutMapper.setMapping(command, command); updateShortcut(command); } // Create an action to activate a designer tool -QAction *FormEditorW::createEditModeAction(QActionGroup *ag, +QAction *FormEditorData::createEditModeAction(QActionGroup *ag, const Context &context, ActionContainer *medit, const QString &actionName, @@ -649,9 +764,9 @@ QAction *FormEditorW::createEditModeAction(QActionGroup *ag, } // Create a tool action -Command *FormEditorW::addToolAction(QAction *a, const Context &context, Id id, - ActionContainer *c1, const QString &keySequence, - Core::Id groupId) +Command *FormEditorData::addToolAction(QAction *a, const Context &context, Id id, + ActionContainer *c1, const QString &keySequence, + Core::Id groupId) { Command *command = ActionManager::registerAction(a, id, context); if (!keySequence.isEmpty()) @@ -662,31 +777,60 @@ Command *FormEditorW::addToolAction(QAction *a, const Context &context, Id id, return command; } -EditorData FormEditorW::createEditor() +Core::IEditor *FormEditorData::createEditor() { if (Designer::Constants::Internal::debug) qDebug() << "FormEditorW::createEditor"; // Create and associate form and text editor. - EditorData data; m_fwm->closeAllPreviews(); QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0); - QTC_ASSERT(form, return data); - connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int))); + QTC_ASSERT(form, return 0); + QObject::connect(form, &QDesignerFormWindowInterface::toolChanged, [this] (int i) { toolChanged(i); }); - m_xmlEditorFactory->m_form = form; - ResourceHandler *resourceHandler = new ResourceHandler(form); - data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form); - data.formWindowEditor = qobject_cast(m_xmlEditorFactory->createEditor()); - connect(data.formWindowEditor->textDocument(), SIGNAL(filePathChanged(QString,QString)), - resourceHandler, SLOT(updateResources())); - m_editorWidget->add(data); + SharedTools::WidgetHost *widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form); + FormWindowEditor *formWindowEditor = m_xmlEditorFactory->create(form); - m_toolBar->addEditor(data.formWindowEditor); + m_editorWidget->add(widgetHost, formWindowEditor); + m_toolBar->addEditor(formWindowEditor); - return data; + if (formWindowEditor) { + Core::InfoBarEntry info(Core::Id(Constants::INFO_READ_ONLY), + tr("This file can only be edited in Design mode.")); + info.setCustomButtonInfo(tr("Switch Mode"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); }); + formWindowEditor->document()->infoBar()->addInfo(info); + } + return formWindowEditor; } -void FormEditorW::updateShortcut(QObject *command) +QDesignerFormEditorInterface *FormEditorW::designerEditor() +{ + ensureInitStage(FullyInitialized); + return d->m_formeditor; +} + +QWidget * const *FormEditorW::designerSubWindows() +{ + ensureInitStage(SubwindowsInitialized); + return d->m_designerSubWindows; +} + +SharedTools::WidgetHost *FormEditorW::activeWidgetHost() +{ + ensureInitStage(FullyInitialized); + if (d->m_editorWidget) + return d->m_editorWidget->activeEditor().widgetHost; + return 0; +} + +FormWindowEditor *FormEditorW::activeEditor() +{ + ensureInitStage(FullyInitialized); + if (d->m_editorWidget) + return d->m_editorWidget->activeEditor().formWindowEditor; + return 0; +} + +void FormEditorData::updateShortcut(QObject *command) { Command *c = qobject_cast(command); if (!c) @@ -697,51 +841,14 @@ void FormEditorW::updateShortcut(QObject *command) a->setShortcut(c->action()->shortcut()); } -void FormEditorW::currentEditorChanged(IEditor *editor) -{ - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << editor << " of " << m_fwm->formWindowCount(); - - if (editor && editor->document()->id() == Constants::K_DESIGNER_XML_EDITOR_ID) { - FormWindowEditor *xmlEditor = qobject_cast(editor); - QTC_ASSERT(xmlEditor, return); - ensureInitStage(FullyInitialized); - SharedTools::WidgetHost *fw = m_editorWidget->formWindowEditorForXmlEditor(xmlEditor); - QTC_ASSERT(fw, return); - m_editorWidget->setVisibleEditor(xmlEditor); - m_fwm->setActiveFormWindow(fw->formWindow()); - } -} - -void FormEditorW::activeFormWindowChanged(QDesignerFormWindowInterface *afw) -{ - if (Designer::Constants::Internal::debug) - qDebug() << Q_FUNC_INFO << afw << " of " << m_fwm->formWindowCount(); - - m_fwm->closeAllPreviews(); - setPreviewMenuEnabled(afw != 0); -} - -EditorData FormEditorW::activeEditor() const -{ - if (m_editorWidget) - return m_editorWidget->activeEditor(); - return EditorData(); -} - -void FormEditorW::activateEditMode(int id) +void FormEditorData::activateEditMode(int id) { if (const int count = m_fwm->formWindowCount()) for (int i = 0; i < count; i++) m_fwm->formWindow(i)->setCurrentTool(id); } -void FormEditorW::activateEditMode(QAction* a) -{ - activateEditMode(a->data().toInt()); -} - -void FormEditorW::toolChanged(int t) +void FormEditorData::toolChanged(int t) { typedef QList ActionList; if (const QAction *currentAction = m_actionGroupEditMode->checkedAction()) @@ -756,13 +863,7 @@ void FormEditorW::toolChanged(int t) } } -void FormEditorW::closeFormEditorsForXmlEditors(QList editors) -{ - foreach (IEditor *editor, editors) - m_editorWidget->removeFormWindowEditor(editor); -} - -void FormEditorW::print() +void FormEditorData::print() { // Printing code courtesy of designer_actions.cpp QDesignerFormWindowInterface *fw = m_fwm->activeFormWindow(); diff --git a/src/plugins/designer/formeditorw.h b/src/plugins/designer/formeditorw.h index 2cfc601b89a..b55291435f9 100644 --- a/src/plugins/designer/formeditorw.h +++ b/src/plugins/designer/formeditorw.h @@ -35,42 +35,18 @@ #include #include -#include -#include - QT_BEGIN_NAMESPACE - -class QDesignerIntegrationInterface; class QDesignerFormEditorInterface; -class QDesignerFormWindowInterface; -class QDesignerFormWindowManagerInterface; - -class QAction; -class QActionGroup; -class QMenu; -class QSignalMapper; -class QSettings; -class QToolBar; - QT_END_NAMESPACE -namespace Core { -class ActionManager; -class ActionContainer; -class Command; -class IEditor; -class Id; -class DesignMode; -class EditorToolBar; -} +namespace Core { class IEditor; } +namespace SharedTools { class WidgetHost; } namespace Designer { -namespace Internal { -class EditorData; -class EditorWidget; -class SettingsPage; -class DesignerContext; +class FormWindowEditor; + +namespace Internal { /** FormEditorW is a singleton that stores the Designer CoreInterface and * performs centralized operations. The instance() function will return an @@ -88,107 +64,29 @@ class DesignerContext; * in Design mode. */ class FormEditorW : public QObject { - Q_OBJECT public: enum InitializationStage { // Register Creator plugins (settings pages, actions) RegisterPlugins, + // Subwindows of the designer are initialized + SubwindowsInitialized, // Fully initialized for handling editor requests FullyInitialized }; - virtual ~FormEditorW(); - // Create an instance and initialize up to stage s static void ensureInitStage(InitializationStage s); - // Returns fully initialized instance - static FormEditorW *instance(); // Deletes an existing instance if there is one. static void deleteInstance(); - EditorData createEditor(); + static Core::IEditor *createEditor(); - inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; } - inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; } + static QDesignerFormEditorInterface *designerEditor(); + static QWidget * const *designerSubWindows(); - EditorData activeEditor() const; - QList optionsPages() const; - -private slots: - void activateEditMode(int id); - void activateEditMode(QAction*); - void activeFormWindowChanged(QDesignerFormWindowInterface *); - void currentEditorChanged(Core::IEditor *editor); - void toolChanged(int); - void print(); - void setPreviewMenuEnabled(bool e); - void updateShortcut(QObject *command); - void closeFormEditorsForXmlEditors(QList editors); - -private: - FormEditorW(); - void fullInit(); - - void saveSettings(QSettings *s); - - void initDesignerSubWindows(); - - void setupActions(); - void setupViewActions(); - void addDockViewAction(Core::ActionContainer *viewMenu, - int index, - const Core::Context &context, - const QString &title, Core::Id id); - - Core::ActionContainer *createPreviewStyleMenu(QActionGroup *actionGroup); - - void critical(const QString &errorMessage); - void bindShortcut(Core::Command *command, QAction *action); - QAction *createEditModeAction(QActionGroup *ag, - const Core::Context &context, - Core::ActionContainer *medit, - const QString &actionName, - Core::Id id, - int toolNumber, - const QString &iconName = QString(), - const QString &keySequence = QString()); - Core::Command *addToolAction(QAction *a, - const Core::Context &context, Core::Id id, - Core::ActionContainer *c1, const QString &keySequence = QString(), - Core::Id groupId = Core::Id()); - QToolBar *createEditorToolBar() const; - - QDesignerFormEditorInterface *m_formeditor; - QDesignerIntegrationInterface *m_integration; - QDesignerFormWindowManagerInterface *m_fwm; - InitializationStage m_initStage; - - QWidget *m_designerSubWindows[Designer::Constants::DesignerSubWindowCount]; - - QAction *m_lockAction; - QAction *m_resetLayoutAction; - - QList m_settingsPages; - QActionGroup *m_actionGroupEditMode; - QAction *m_actionPrint; - QAction *m_actionPreview; - QActionGroup *m_actionGroupPreviewInStyle; - QMenu *m_previewInStyleMenu; - QAction *m_actionAboutPlugins; - QSignalMapper *m_shortcutMapper; - - DesignerContext *m_context; - Core::Context m_contexts; - - QList m_toolActionIds; - QWidget *m_modeWidget; - EditorWidget *m_editorWidget; - Core::DesignMode *m_designMode; - - QWidget *m_editorToolBar; - Core::EditorToolBar *m_toolBar; - - QMap m_commandToDesignerAction; + static SharedTools::WidgetHost *activeWidgetHost(); + static FormWindowEditor *activeEditor(); + static QList optionsPages(); }; } // namespace Internal diff --git a/src/plugins/designer/formtemplatewizardpage.cpp b/src/plugins/designer/formtemplatewizardpage.cpp index d52d41d1309..63f2cdd6146 100644 --- a/src/plugins/designer/formtemplatewizardpage.cpp +++ b/src/plugins/designer/formtemplatewizardpage.cpp @@ -51,7 +51,7 @@ namespace Internal { FormTemplateWizardPage::FormTemplateWizardPage(QWidget * parent) : QWizardPage(parent), - m_newFormWidget(QDesignerNewFormWidgetInterface::createNewFormWidget(FormEditorW::instance()->designerEditor())), + m_newFormWidget(QDesignerNewFormWidgetInterface::createNewFormWidget(FormEditorW::designerEditor())), m_templateSelected(m_newFormWidget->hasCurrentTemplate()) { setTitle(tr("Choose a Form Template")); diff --git a/src/plugins/designer/formwindoweditor.cpp b/src/plugins/designer/formwindoweditor.cpp index 4726866daf5..be12d55b194 100644 --- a/src/plugins/designer/formwindoweditor.cpp +++ b/src/plugins/designer/formwindoweditor.cpp @@ -44,6 +44,8 @@ namespace Designer { +using namespace Internal; + FormWindowEditor::FormWindowEditor() { addContext(Designer::Constants::K_DESIGNER_XML_EDITOR_ID); @@ -57,7 +59,7 @@ FormWindowEditor::~FormWindowEditor() void FormWindowEditor::finalizeInitialization() { // Revert to saved/load externally modified files. - connect(formWindowFile(), &Internal::FormWindowFile::reloadRequested, + connect(formWindowFile(), &FormWindowFile::reloadRequested, [this](QString *errorString, const QString &fileName) { open(errorString, fileName, fileName); }); @@ -68,7 +70,8 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const if (Designer::Constants::Internal::debug) qDebug() << "FormWindowEditor::open" << fileName; - QDesignerFormWindowInterface *form = formWindowFile()->formWindow(); + auto document = qobject_cast(textDocument()); + QDesignerFormWindowInterface *form = document->formWindow(); QTC_ASSERT(form, return false); if (fileName.isEmpty()) @@ -78,7 +81,7 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const const QString absfileName = fi.absoluteFilePath(); QString contents; - if (formWindowFile()->read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess) + if (document->read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess) return false; form->setFileName(absfileName); @@ -90,12 +93,10 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const return false; form->setDirty(fileName != realFileName); - formWindowFile()->syncXmlFromFormWindow(); - formWindowFile()->setFilePath(absfileName); - formWindowFile()->setShouldAutoSave(false); - - if (Internal::ResourceHandler *rh = form->findChild()) - rh->updateResources(true); + document->syncXmlFromFormWindow(); + document->setFilePath(absfileName); + document->setShouldAutoSave(false); + document->resourceHandler()->updateResources(true); return true; } @@ -110,9 +111,9 @@ QString FormWindowEditor::contents() const return formWindowFile()->formWindowContents(); } -Internal::FormWindowFile *FormWindowEditor::formWindowFile() const +FormWindowFile *FormWindowEditor::formWindowFile() const { - return qobject_cast(textDocument()); + return qobject_cast(textDocument()); } bool FormWindowEditor::isDesignModePreferred() const diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index 26fe21d5891..4485acd0adc 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -29,6 +29,7 @@ #include "formwindowfile.h" #include "designerconstants.h" +#include "resourcehandler.h" #include @@ -60,6 +61,10 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare connect(m_formWindow->commandHistory(), SIGNAL(indexChanged(int)), this, SLOT(setShouldAutoSave())); connect(m_formWindow, SIGNAL(changed()), SLOT(updateIsModified())); + + m_resourceHandler = new ResourceHandler(form); + connect(this, SIGNAL(filePathChanged(QString,QString)), + m_resourceHandler, SLOT(updateResources())); } bool FormWindowFile::save(QString *errorString, const QString &name, bool autoSave) @@ -217,6 +222,11 @@ QString FormWindowFile::formWindowContents() const return m_formWindow->contents(); } +ResourceHandler *FormWindowFile::resourceHandler() const +{ + return m_resourceHandler; +} + void FormWindowFile::slotFormWindowRemoved(QDesignerFormWindowInterface *w) { // Release formwindow as soon as the FormWindowManager removes diff --git a/src/plugins/designer/formwindowfile.h b/src/plugins/designer/formwindowfile.h index 52060dd7493..5cde87bf630 100644 --- a/src/plugins/designer/formwindowfile.h +++ b/src/plugins/designer/formwindowfile.h @@ -41,6 +41,8 @@ QT_END_NAMESPACE namespace Designer { namespace Internal { +class ResourceHandler; + class FormWindowFile : public TextEditor::BaseTextDocument { Q_OBJECT @@ -67,6 +69,7 @@ public: QDesignerFormWindowInterface *formWindow() const; void syncXmlFromFormWindow(); QString formWindowContents() const; + ResourceHandler *resourceHandler() const; signals: // Internal @@ -87,6 +90,7 @@ private: // to deleting the WidgetHost which owns it. QPointer m_formWindow; bool m_isModified; + ResourceHandler *m_resourceHandler; }; } // namespace Internal diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp index 7814af028d3..edf5db07aef 100644 --- a/src/plugins/designer/gotoslot_test.cpp +++ b/src/plugins/designer/gotoslot_test.cpp @@ -172,8 +172,7 @@ public: waitForFilesInGlobalSnapshot(QStringList() << cppFile << hFile); // Execute "Go To Slot" - FormEditorW *few = FormEditorW::instance(); - QDesignerIntegrationInterface *integration = few->designerEditor()->integration(); + QDesignerIntegrationInterface *integration = FormEditorW::designerEditor()->integration(); QVERIFY(integration); integration->emitNavigateToSlot(QLatin1String("pushButton"), QLatin1String("clicked()"), QStringList()); diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index d00064ba3a5..3699fff1b1d 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -76,9 +76,8 @@ static QString msgClassNotFound(const QString &uiClassName, const QListactiveEditor()) - ed.widgetHost->updateFormWindowSelectionHandles(true); + if (SharedTools::WidgetHost *host = FormEditorW::activeWidgetHost()) + host->updateFormWindowSelectionHandles(true); QDesignerIntegration::updateSelection(); } QWidget *QtCreatorIntegration::containerWindow(QWidget * /*widget*/) const { - if (const EditorData ed = m_few->activeEditor()) - return ed.widgetHost->integrationContainer(); + if (SharedTools::WidgetHost *host = FormEditorW::activeWidgetHost()) + return host->integrationContainer(); return 0; } @@ -467,7 +466,7 @@ void QtCreatorIntegration::slotNavigateToSlot(const QString &objectName, const Q { QString errorMessage; if (!navigateToSlot(objectName, signalSignature, parameterNames, &errorMessage) && !errorMessage.isEmpty()) - QMessageBox::warning(m_few->designerEditor()->topLevel(), tr("Error finding/adding a slot."), errorMessage); + QMessageBox::warning(FormEditorW::designerEditor()->topLevel(), tr("Error finding/adding a slot."), errorMessage); } // Build name of the class as generated by uic, insert Ui namespace @@ -510,9 +509,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, { typedef QMap DocumentMap; - const EditorData ed = m_few->activeEditor(); - QTC_ASSERT(ed, return false); - const QString currentUiFile = ed.formWindowEditor->document()->filePath(); + const QString currentUiFile = FormEditorW::activeEditor()->document()->filePath(); #if 0 return Designer::Internal::navigateToSlot(currentUiFile, objectName, signalSignature, parameterNames, errorMessage); #endif @@ -566,7 +563,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, return false; } - QDesignerFormWindowInterface *fwi = ed.widgetHost->formWindow(); + QDesignerFormWindowInterface *fwi = FormEditorW::activeWidgetHost()->formWindow(); const QString uiClass = uiClassName(fwi->mainContainer()->objectName()); diff --git a/src/plugins/designer/qtcreatorintegration.h b/src/plugins/designer/qtcreatorintegration.h index 57489e4eec2..579c9610308 100644 --- a/src/plugins/designer/qtcreatorintegration.h +++ b/src/plugins/designer/qtcreatorintegration.h @@ -38,13 +38,12 @@ QT_FORWARD_DECLARE_CLASS(QUrl) namespace Designer { namespace Internal { -class FormEditorW; - class QtCreatorIntegration : public QDesignerIntegration { Q_OBJECT + public: - explicit QtCreatorIntegration(QDesignerFormEditorInterface *core, FormEditorW *parent = 0); + explicit QtCreatorIntegration(QDesignerFormEditorInterface *core, QObject *parent = 0); QWidget *containerWindow(QWidget *widget) const; @@ -66,7 +65,6 @@ private: const QString &signalSignature, const QStringList ¶meterNames, QString *errorMessage); - FormEditorW *m_few; }; } // namespace Internal diff --git a/src/plugins/designer/settingspage.cpp b/src/plugins/designer/settingspage.cpp index ef471f08080..b6606e1c24e 100644 --- a/src/plugins/designer/settingspage.cpp +++ b/src/plugins/designer/settingspage.cpp @@ -84,7 +84,7 @@ QList SettingsPageProvider::pages() const m_initialized = true; FormEditorW::ensureInitStage(FormEditorW::RegisterPlugins); } - return FormEditorW::instance()->optionsPages(); + return FormEditorW::optionsPages(); } bool SettingsPageProvider::matches(const QString &searchKeyWord) const