Commit 1e28e759 authored by hjk's avatar hjk

Designer: Use static pattern for FormEditorW singleton

Change-Id: Icf4a0135d9bc8441d468fd77abe29adcee677bb9
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent f70ba993
......@@ -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();
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -30,13 +30,9 @@
#include "formeditorfactory.h"
#include "formeditorw.h"
#include "formwindoweditor.h"
#include "editordata.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/infobar.h>
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/modemanager.h>
#include <QCoreApplication>
#include <QDebug>
......@@ -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 <b>Design</b> 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
......
This diff is collapsed.
......@@ -35,42 +35,18 @@
#include <coreplugin/icontext.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <QMap>
#include <QObject>
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();
inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
EditorData activeEditor() const;
QList<Core::IOptionsPage *> 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<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;
static Core::IEditor *createEditor();
QWidget *m_editorToolBar;
Core::EditorToolBar *m_toolBar;
static QDesignerFormEditorInterface *designerEditor();
static QWidget * const *designerSubWindows();
QMap<Core::Command *, QAction *> m_commandToDesignerAction;
static SharedTools::WidgetHost *activeWidgetHost();
static FormWindowEditor *activeEditor();
static QList<Core::IOptionsPage *> optionsPages();
};
} // namespace Internal
......
......@@ -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"));
......
......@@ -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<FormWindowFile *>(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<Designer::Internal::ResourceHandler*>())
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<Internal::FormWindowFile *>(textDocument());
return qobject_cast<FormWindowFile *>(textDocument());
}
bool FormWindowEditor::isDesignModePreferred() const
......
......@@ -29,6 +29,7 @@
#include "formwindowfile.h"
#include "designerconstants.h"
#include "resourcehandler.h"
#include <utils/qtcassert.h>
......@@ -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
......
......@@ -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<QDesignerFormWindowInterface> m_formWindow;
bool m_isModified;
ResourceHandler *m_resourceHandler;
};
} // namespace Internal
......
......@@ -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());
......
......@@ -76,9 +76,8 @@ static QString msgClassNotFound(const QString &uiClassName, const QList<Document
.arg(uiClassName, files);
}
QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, FormEditorW *parent) :
QDesignerIntegration(core, parent),
m_few(parent)
QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, QObject *parent)
: QDesignerIntegration(core, parent)
{
setResourceFileWatcherBehaviour(ReloadResourceFileSilently);
Feature f = features();
......@@ -103,15 +102,15 @@ void QtCreatorIntegration::slotDesignerHelpRequested(const QString &manual, cons
void QtCreatorIntegration::updateSelection()
{
if (const EditorData ed = m_few->activeEditor())
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<int, Document::Ptr> 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());
......
......@@ -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 &parameterNames,
QString *errorMessage);
FormEditorW *m_few;
};
} // namespace Internal
......
......@@ -84,7 +84,7 @@ QList<Core::IOptionsPage *> SettingsPageProvider::pages() const
m_initialized = true;
FormEditorW::ensureInitStage(FormEditorW::RegisterPlugins);
}
return FormEditorW::instance()->optionsPages();
return FormEditorW::optionsPages();
}
bool SettingsPageProvider::matches(const QString &searchKeyWord) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment