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