Commit 7828bb81 authored by Friedemann Kleint's avatar Friedemann Kleint

DesignMode/Qt Designer clean-up Part V: Renaming

Re-introduce FormWindowEditor as IEditor used for
Designer. Use SharedTools::WidgetHost directly
for embedding into FormEditorStack, doing the
geometry-changed handling in there as well.
parent 1c893073
......@@ -4,6 +4,15 @@ They are dependent on the CPP editor plugin.
Including cpp.pri in designer.pro enables them and defines
CPP_ENABLED.
Editor
------
The editor shows read-only XML text in a PlainTextEditor and Designer
in Design mode. The switch is done in the currentEditorChanged signal.
To make the text editor work, IEditor needs to aggregate a PlainTextEditable
and delegate some functionality to it, while the isModified()-handling
needs to be done by Designer itself.
Resource handling:
------------------
......
......@@ -64,4 +64,4 @@ SOURCES += formeditorplugin.cpp \
RESOURCES += designer.qrc
OTHER_FILES += Designer.pluginspec Designer.mimetypes.xml
OTHER_FILES += Designer.pluginspec Designer.mimetypes.xml README.txt
......@@ -28,208 +28,26 @@
**************************************************************************/
#include "designerxmleditor.h"
#include "formwindoweditor.h"
#include "designerconstants.h"
#include "resourcehandler.h"
#include "qt_private/formwindowbase_p.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/imode.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/uniqueidmanager.h>
#include <texteditor/basetextdocument.h>
#include <utils/qtcassert.h>
#include <QtDesigner/QDesignerFormWindowInterface>
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QFile>
namespace Designer {
DesignerXmlEditorEditable::DesignerXmlEditorEditable(Internal::DesignerXmlEditor *editor,
QDesignerFormWindowInterface *form,
QObject *parent) :
Core::IEditor(parent),
m_textEditable(editor),
m_file(form)
{
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
m_context << uidm->uniqueIdentifier(QLatin1String(Designer::Constants::K_DESIGNER_XML_EDITOR_ID));
m_context << uidm->uniqueIdentifier(QLatin1String(Designer::Constants::C_DESIGNER_XML_EDITOR));
connect(form, SIGNAL(changed()), this, SIGNAL(changed()));
// Revert to saved/load externally modified files
connect(&m_file, SIGNAL(reload(QString)), this, SLOT(slotOpen(QString)));
}
bool DesignerXmlEditorEditable::createNew(const QString &contents)
{
if (Designer::Constants::Internal::debug)
qDebug() << "DesignerXmlEditorEditable::createNew" << contents.size();
syncXmlEditor(QString());
QDesignerFormWindowInterface *form = m_file.formWindow();
QTC_ASSERT(form, return false);
if (contents.isEmpty())
return false;
form->setContents(contents);
if (form->mainContainer() == 0)
return false;
syncXmlEditor(contents);
m_file.setFileName(QString());
return true;
}
void DesignerXmlEditorEditable::slotOpen(const QString &fileName)
{
open(fileName);
}
bool DesignerXmlEditorEditable::open(const QString &fileName)
{
if (Designer::Constants::Internal::debug)
qDebug() << "DesignerXmlEditorEditable::open" << fileName;
QDesignerFormWindowInterface *form = m_file.formWindow();
QTC_ASSERT(form, return false);
if (fileName.isEmpty()) {
setDisplayName(tr("untitled"));
return true;
}
const QFileInfo fi(fileName);
const QString absfileName = fi.absoluteFilePath();
QFile file(absfileName);
if (!file.open(QIODevice::ReadOnly|QIODevice::Text))
return false;
form->setFileName(absfileName);
const QString contents = QString::fromUtf8(file.readAll());
form->setContents(contents);
file.close();
if (!form->mainContainer())
return false;
form->setDirty(false);
syncXmlEditor(contents);
setDisplayName(fi.fileName());
m_file.setFileName(absfileName);
if (Internal::ResourceHandler *rh = qFindChild<Designer::Internal::ResourceHandler*>(form))
rh->updateResources();
emit changed();
return true;
}
void DesignerXmlEditorEditable::syncXmlEditor()
{
if (Designer::Constants::Internal::debug)
qDebug() << "DesignerXmlEditorEditable::syncXmlEditor" << m_file.fileName();
syncXmlEditor(contents());
}
void DesignerXmlEditorEditable::syncXmlEditor(const QString &contents)
{
m_textEditable.editor()->setPlainText(contents);
m_textEditable.editor()->setReadOnly(true);
}
Core::IFile *DesignerXmlEditorEditable::file()
{
return &m_file;
}
QString DesignerXmlEditorEditable::id() const
{
return QLatin1String(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
}
QString DesignerXmlEditorEditable::displayName() const
{
return m_textEditable.displayName();
}
void DesignerXmlEditorEditable::setDisplayName(const QString &title)
{
m_textEditable.setDisplayName(title);
}
bool DesignerXmlEditorEditable::duplicateSupported() const
{
return false;
}
Core::IEditor *DesignerXmlEditorEditable::duplicate(QWidget *)
{
return 0;
}
QByteArray DesignerXmlEditorEditable::saveState() const
{
return m_textEditable.saveState();
}
bool DesignerXmlEditorEditable::restoreState(const QByteArray &state)
{
return m_textEditable.restoreState(state);
}
QList<int> DesignerXmlEditorEditable::context() const
{
return m_context;
}
QWidget *DesignerXmlEditorEditable::widget()
{
return m_textEditable.widget();
}
bool DesignerXmlEditorEditable::isTemporary() const
{
return false;
}
QWidget *DesignerXmlEditorEditable::toolBar()
{
return 0;
}
QString DesignerXmlEditorEditable::contents() const
{
const qdesigner_internal::FormWindowBase *fw = qobject_cast<const qdesigner_internal::FormWindowBase *>(m_file.formWindow());
QTC_ASSERT(fw, return QString());
return fw->fileContents(); // No warnings about spacers here
}
TextEditor::BaseTextDocument *DesignerXmlEditorEditable::textDocument()
{
return qobject_cast<TextEditor::BaseTextDocument*>(m_textEditable.file());
}
TextEditor::PlainTextEditorEditable *DesignerXmlEditorEditable::textEditable()
{
return &m_textEditable;
}
namespace Internal {
DesignerXmlEditor::DesignerXmlEditor(QDesignerFormWindowInterface *form,
QWidget *parent) :
TextEditor::PlainTextEditor(parent),
m_editable(new DesignerXmlEditorEditable(this, form))
m_designerEditor(new FormWindowEditor(this, form))
{
setReadOnly(true);
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
......@@ -240,12 +58,12 @@ TextEditor::BaseTextEditorEditable *DesignerXmlEditor::createEditableInterface()
{
if (Designer::Constants::Internal::debug)
qDebug() << "DesignerXmlEditor::createEditableInterface()";
return m_editable->textEditable();
return m_designerEditor->textEditable();
}
void DesignerXmlEditor::updateEditorInfoBar(Core::IEditor *editor)
{
if (editor == m_editable) {
if (editor == m_designerEditor) {
Core::EditorManager::instance()->showEditorInfoBar(Constants::INFO_READ_ONLY,
tr("This file can only be edited in Design Mode."),
"Open Designer", this, SLOT(designerModeClicked()));
......@@ -259,9 +77,9 @@ void DesignerXmlEditor::designerModeClicked()
Core::ICore::instance()->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
}
DesignerXmlEditorEditable *DesignerXmlEditor::designerEditable() const
FormWindowEditor *DesignerXmlEditor::designerEditor() const
{
return m_editable;
return m_designerEditor;
}
}
......
......@@ -30,88 +30,24 @@
#ifndef DESIGNERXMLEDITOR_H
#define DESIGNERXMLEDITOR_H
#include "designer_export.h"
#include "formwindowfile.h"
#include <texteditor/plaintexteditor.h>
namespace Core {
class IMode;
}
namespace TextEditor {
class BaseTextDocument;
}
QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
QT_END_NAMESPACE
namespace Designer {
class FormWindowEditor;
namespace Internal {
class DesignerXmlEditor;
}
// The actual Core::IEditor belonging to Qt Designer. It internally embeds
// a TextEditor::PlainTextEditorEditable which is used to make the
// Read-only edit mode XML text editor work and delegates some functionality
// to it. However, the isDirty() handling is delegated to the FormWindowFile,
// which is the Core::IFile used for it.
class DESIGNER_EXPORT DesignerXmlEditorEditable : public Core::IEditor
{
Q_OBJECT
public:
explicit DesignerXmlEditorEditable(Internal::DesignerXmlEditor *editor,
QDesignerFormWindowInterface *form,
QObject *parent = 0);
// IEditor
virtual bool createNew(const QString &contents = QString());
virtual bool open(const QString &fileName = QString());
virtual Core::IFile *file();
virtual QString id() const;
virtual QString displayName() const;
virtual void setDisplayName(const QString &title);
virtual bool duplicateSupported() const;
virtual IEditor *duplicate(QWidget *parent);
virtual QByteArray saveState() const;
virtual bool restoreState(const QByteArray &state);
virtual bool isTemporary() const;
virtual QWidget *toolBar();
// IContext
virtual QList<int> context() const;
virtual QWidget *widget();
// For uic code model support
QString contents() const;
TextEditor::BaseTextDocument *textDocument();
TextEditor::PlainTextEditorEditable *textEditable();
public slots:
void syncXmlEditor();
private slots:
void slotOpen(const QString &fileName);
private:
void syncXmlEditor(const QString &contents);
TextEditor::PlainTextEditorEditable m_textEditable;
Internal::FormWindowFile m_file;
QList<int> m_context;
};
/* A stub-like, read-only text editor which displays UI files as text. Could be used as a
* read/write editor too, but due to lack of XML editor, highlighting and other such
* functionality, editing is disabled.
* Provides an informational title bar containing a button triggering a
* switch to design mode.
* Internally manages DesignerXmlEditorEditable and uses the plain text
* Internally manages a FormWindowEditor and uses the plain text
* editable embedded in it. */
namespace Internal {
class DesignerXmlEditor : public TextEditor::PlainTextEditor
{
......@@ -120,7 +56,7 @@ public:
explicit DesignerXmlEditor(QDesignerFormWindowInterface *form,
QWidget *parent = 0);
DesignerXmlEditorEditable *designerEditable() const;
FormWindowEditor *designerEditor() const;
private slots:
void designerModeClicked();
......@@ -130,7 +66,7 @@ protected:
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
private:
DesignerXmlEditorEditable *m_editable;
FormWindowEditor *m_designerEditor;
};
} // Internal
......
......@@ -30,19 +30,22 @@
#ifndef EDITORDATA_H
#define EDITORDATA_H
namespace SharedTools {
class WidgetHost;
}
namespace Designer {
class FormWindowEditor;
class DesignerXmlEditorEditable;
namespace Internal {
// Associates XML and its form editor
// Associates the XML editor implementing the IEditor and its form widget host
struct EditorData {
EditorData() : xmlEditor(0), formEditor(0) {}
operator bool() const { return xmlEditor != 0; }
EditorData() : formWindowEditor(0), widgetHost(0) {}
operator bool() const { return formWindowEditor != 0; }
DesignerXmlEditorEditable *xmlEditor;
Designer::FormWindowEditor *formEditor;
FormWindowEditor *formWindowEditor;
SharedTools::WidgetHost *widgetHost;
};
} // namespace Internal
......
......@@ -107,7 +107,7 @@ bool EditorWidget::setVisibleEditor(Core::IEditor *xmlEditor)
return m_stack->setVisibleEditor(xmlEditor);
}
Designer::FormWindowEditor *EditorWidget::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const
SharedTools::WidgetHost *EditorWidget::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const
{
return m_stack->formWindowEditorForXmlEditor(xmlEditor);
}
......@@ -117,7 +117,7 @@ EditorData EditorWidget::activeEditor() const
return m_stack->activeEditor();
}
Designer::FormWindowEditor *EditorWidget::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
SharedTools::WidgetHost *EditorWidget::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
{
return m_stack->formWindowEditorForFormWindow(fw);
}
......
......@@ -38,12 +38,14 @@ QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
QT_END_NAMESPACE
namespace SharedTools {
class WidgetHost;
}
namespace Core {
class IEditor;
}
namespace Designer {
class FormWindowEditor;
class DesignerXmlEditorEditable;
namespace Internal {
struct EditorData;
......@@ -64,8 +66,8 @@ public:
void add(const EditorData &d);
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
bool setVisibleEditor(Core::IEditor *xmlEditor);
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
SharedTools::WidgetHost *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
SharedTools::WidgetHost *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
EditorData activeEditor() const;
......
......@@ -74,7 +74,7 @@ Core::IFile *FormEditorFactory::open(const QString &fileName)
Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
{
const EditorData data = FormEditorW::instance()->createEditor(parent);
return data.xmlEditor;
return data.formWindowEditor;
}
QStringList FormEditorFactory::mimeTypes() const
......
......@@ -28,11 +28,12 @@
**************************************************************************/
#include "formeditorstack.h"
#include "designerxmleditor.h"
#include "formwindoweditor.h"
#include "formeditorw.h"
#include "designerconstants.h"
#include <widgethost.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/imode.h>
......@@ -42,8 +43,11 @@
#include <QDesignerFormWindowInterface>
#include <QDesignerFormWindowManagerInterface>
#include <QDesignerFormEditorInterface>
#include <QDesignerPropertyEditorInterface>
#include <QtCore/QDebug>
#include <QtCore/QVariant>
#include <QtCore/QRect>
namespace Designer {
namespace Internal {
......@@ -58,7 +62,7 @@ FormEditorStack::FormEditorStack(QWidget *parent) :
void FormEditorStack::add(const EditorData &data)
{
if (m_designerCore == 0) { // Initialize first time here
m_designerCore = data.formEditor->formWindow()->core();
m_designerCore = data.widgetHost->formWindow()->core();
connect(m_designerCore->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
this, SLOT(updateFormWindowSelectionHandles()));
connect(Core::ModeManager::instance(), SIGNAL(currentModeAboutToChange(Core::IMode*)),
......@@ -66,20 +70,23 @@ void FormEditorStack::add(const EditorData &data)
}
if (Designer::Constants::Internal::debug)
qDebug() << "FormEditorStack::add" << data.xmlEditor << data.formEditor;
qDebug() << "FormEditorStack::add" << data.formWindowEditor << data.widgetHost;
m_formEditors.append(data);
addWidget(data.formEditor);
addWidget(data.widgetHost);
connect(data.widgetHost, SIGNAL(formWindowSizeChanged(int,int)),
this, SLOT(formSizeChanged(int,int)));
if (Designer::Constants::Internal::debug)
qDebug() << "FormEditorStack::add" << data.formEditor;
qDebug() << "FormEditorStack::add" << data.widgetHost;
}
int FormEditorStack::indexOf(const QDesignerFormWindowInterface *fw) const
{
const int count = m_formEditors.size();
for(int i = 0; i < count; ++i)
if (m_formEditors[i].formEditor->formWindow() == fw)
if (m_formEditors[i].widgetHost->formWindow() == fw)
return i;
return -1;
}
......@@ -88,7 +95,7 @@ int FormEditorStack::indexOf(const Core::IEditor *xmlEditor) const
{
const int count = m_formEditors.size();
for(int i = 0; i < count; ++i)
if (m_formEditors[i].xmlEditor == xmlEditor)
if (m_formEditors[i].formWindowEditor == xmlEditor)
return i;
return -1;
}
......@@ -104,10 +111,10 @@ EditorData FormEditorStack::activeEditor() const
return EditorData();
}
Designer::FormWindowEditor *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const
{
const int i = indexOf(fw);
return i != -1 ? m_formEditors[i].formEditor : static_cast<Designer::FormWindowEditor *>(0);
return i != -1 ? m_formEditors[i].widgetHost : static_cast<SharedTools::WidgetHost *>(0);
}
bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor)
......@@ -117,8 +124,8 @@ bool FormEditorStack::removeFormWindowEditor(Core::IEditor *xmlEditor)
const int i = indexOf(xmlEditor);
if (i == -1) // Fail silently as this is invoked for all editors.
return false;
removeWidget(m_formEditors[i].formEditor->widget());
delete m_formEditors[i].formEditor;
removeWidget(m_formEditors[i].widgetHost->widget());
delete m_formEditors[i].widgetHost;
m_formEditors.removeAt(i);
return true;
}
......@@ -142,15 +149,27 @@ void FormEditorStack::updateFormWindowSelectionHandles()
qDebug() << "updateFormWindowSelectionHandles";
QDesignerFormWindowInterface *activeFormWindow = m_designerCore->formWindowManager()->activeFormWindow();
foreach(const EditorData &fdm, m_formEditors) {
const bool active = activeFormWindow == fdm.formEditor->formWindow();
fdm.formEditor->updateFormWindowSelectionHandles(active);
const bool active = activeFormWindow == fdm.widgetHost->formWindow();
fdm.widgetHost->updateFormWindowSelectionHandles(active);
}
}
void FormEditorStack::formSizeChanged(int w, int h)
{
// Handle main container resize.
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO << w << h;
if (const SharedTools::WidgetHost *wh = qobject_cast<const SharedTools::WidgetHost *>(sender())) {
wh->formWindow()->setDirty(true);
static const QString geometry = QLatin1String("geometry");
m_designerCore->propertyEditor()->setPropertyValue(geometry, QRect(0,0,w,h) );
}
}
Designer::FormWindowEditor *FormEditorStack::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const
SharedTools::WidgetHost *FormEditorStack::formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const
{
const int i = indexOf(xmlEditor);
return i != -1 ? m_formEditors.at(i).formEditor : static_cast<Designer::FormWindowEditor *>(0);
return i != -1 ? m_formEditors.at(i).widgetHost : static_cast<SharedTools::WidgetHost *>(0);
}
void FormEditorStack::modeAboutToChange(Core::IMode *m)
......@@ -161,7 +180,7 @@ void FormEditorStack::modeAboutToChange(Core::IMode *m)
// Sync the editor when leaving design mode
if (m && m->id() == QLatin1String(Core::Constants::MODE_DESIGN))
foreach(const EditorData &data, m_formEditors)
data.xmlEditor->syncXmlEditor();
data.formWindowEditor->syncXmlEditor();
}
} // Internal
......
......@@ -47,9 +47,6 @@ namespace Core {
}
namespace Designer {
class FormWindowEditor;
class DesignerXmlEditorEditable;
namespace Internal {
/* FormEditorStack: Maintains a stack of Qt Designer form windows embedded
......@@ -68,14 +65,15 @@ public:
bool removeFormWindowEditor(Core::IEditor *xmlEditor);
bool setVisibleEditor(Core::IEditor *xmlEditor);
Designer::FormWindowEditor *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
Designer::FormWindowEditor *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
SharedTools::WidgetHost *formWindowEditorForXmlEditor(const Core::IEditor *xmlEditor) const;
SharedTools::WidgetHost *formWindowEditorForFormWindow(const QDesignerFormWindowInterface *fw) const;
EditorData activeEditor() const;
private slots:
void updateFormWindowSelectionHandles();
void modeAboutToChange(Core::IMode *);
void formSizeChanged(int w, int h);
private:
inline int indexOf(const QDesignerFormWindowInterface *) const;
......
......@@ -40,6 +40,7 @@
#include "designercontext.h"
#include "editorwidget.h"
#include "resourcehandler.h"
#include <widgethost.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/designmode.h>
......@@ -666,13 +667,13 @@ EditorData FormEditorW::createEditor(QWidget *parent)
ResourceHandler *resourceHandler = new ResourceHandler(form);