Designer: Remove some redirections.

Instead of keeping a separate plain text editor and document,
the FormWindowEditor and FormWindowFile are directly derived
from PlainTextEditor and BaseTextDocument respectively.

Change-Id: I4319904dea769ec31900061bc7c3a3c5c22e0e8a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2013-07-15 14:12:05 +02:00
parent 38a44f7e0f
commit 4ba6faec3f
10 changed files with 72 additions and 101 deletions

View File

@@ -36,12 +36,12 @@ HEADERS += formeditorplugin.h \
formwizarddialog.h \ formwizarddialog.h \
codemodelhelpers.h \ codemodelhelpers.h \
designer_export.h \ designer_export.h \
designerxmleditor.h \
designercontext.h \ designercontext.h \
formeditorstack.h \ formeditorstack.h \
editordata.h \ editordata.h \
resourcehandler.h \ resourcehandler.h \
qtdesignerformclasscodegenerator.h qtdesignerformclasscodegenerator.h \
designerxmleditorwidget.h
SOURCES += formeditorplugin.cpp \ SOURCES += formeditorplugin.cpp \
formeditorfactory.cpp \ formeditorfactory.cpp \
@@ -56,11 +56,11 @@ SOURCES += formeditorplugin.cpp \
formtemplatewizardpage.cpp \ formtemplatewizardpage.cpp \
formwizarddialog.cpp \ formwizarddialog.cpp \
codemodelhelpers.cpp \ codemodelhelpers.cpp \
designerxmleditor.cpp \
designercontext.cpp \ designercontext.cpp \
formeditorstack.cpp \ formeditorstack.cpp \
resourcehandler.cpp \ resourcehandler.cpp \
qtdesignerformclasscodegenerator.cpp qtdesignerformclasscodegenerator.cpp \
designerxmleditorwidget.cpp
RESOURCES += designer.qrc RESOURCES += designer.qrc

View File

@@ -28,8 +28,8 @@ QtcPlugin {
"designerconstants.h", "designerconstants.h",
"designercontext.cpp", "designercontext.cpp",
"designercontext.h", "designercontext.h",
"designerxmleditor.cpp", "designerxmleditorwidget.cpp",
"designerxmleditor.h", "designerxmleditorwidget.h",
"editordata.h", "editordata.h",
"editorwidget.cpp", "editorwidget.cpp",
"editorwidget.h", "editorwidget.h",

View File

@@ -27,7 +27,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "designerxmleditor.h" #include "designerxmleditorwidget.h"
#include "formwindoweditor.h" #include "formwindoweditor.h"
#include "designerconstants.h" #include "designerconstants.h"
@@ -37,26 +37,34 @@
namespace Designer { namespace Designer {
namespace Internal { namespace Internal {
DesignerXmlEditor::DesignerXmlEditor(QDesignerFormWindowInterface *form, DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
QWidget *parent) : QWidget *parent) :
TextEditor::PlainTextEditorWidget(parent), TextEditor::PlainTextEditorWidget(parent),
m_designerEditor(new FormWindowEditor(this, form)) m_file(new FormWindowFile(form, this)),
m_designerEditor(new FormWindowEditor(this))
{ {
setBaseTextDocument(m_file);
setReadOnly(true); setReadOnly(true);
configure(m_file->mimeType());
} }
TextEditor::BaseTextEditor *DesignerXmlEditor::createEditor() TextEditor::BaseTextEditor *DesignerXmlEditorWidget::createEditor()
{ {
if (Designer::Constants::Internal::debug) if (Designer::Constants::Internal::debug)
qDebug() << "DesignerXmlEditor::createEditableInterface()"; qDebug() << "DesignerXmlEditor::createEditableInterface()";
return m_designerEditor->textEditor(); return m_designerEditor;
} }
FormWindowEditor *DesignerXmlEditor::designerEditor() const FormWindowEditor *DesignerXmlEditorWidget::designerEditor() const
{ {
return m_designerEditor; return m_designerEditor;
} }
Internal::FormWindowFile *DesignerXmlEditorWidget::formWindowFile() const
{
return m_file.data();
}
} // namespace Internal } // namespace Internal
} // namespace Designer } // namespace Designer

View File

@@ -27,11 +27,15 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef DESIGNERXMLEDITOR_H #ifndef DESIGNERXMLEDITORWIDGET_H
#define DESIGNERXMLEDITOR_H #define DESIGNERXMLEDITORWIDGET_H
#include "formwindowfile.h"
#include <texteditor/plaintexteditor.h> #include <texteditor/plaintexteditor.h>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface; class QDesignerFormWindowInterface;
QT_END_NAMESPACE QT_END_NAMESPACE
@@ -49,23 +53,25 @@ namespace Internal {
* Internally manages a FormWindowEditor and uses the plain text * Internally manages a FormWindowEditor and uses the plain text
* editable embedded in it. */ * editable embedded in it. */
class DesignerXmlEditor : public TextEditor::PlainTextEditorWidget class DesignerXmlEditorWidget : public TextEditor::PlainTextEditorWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DesignerXmlEditor(QDesignerFormWindowInterface *form, explicit DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
QWidget *parent = 0); QWidget *parent = 0);
FormWindowEditor *designerEditor() const; FormWindowEditor *designerEditor() const;
Internal::FormWindowFile *formWindowFile() const;
protected: protected:
virtual TextEditor::BaseTextEditor *createEditor(); virtual TextEditor::BaseTextEditor *createEditor();
private: private:
QSharedPointer<Internal::FormWindowFile> m_file;
FormWindowEditor *m_designerEditor; FormWindowEditor *m_designerEditor;
}; };
} // Internal } // Internal
} // Designer } // Designer
#endif // DESIGNERXMLEDITOR_H #endif // DESIGNERXMLEDITORWIDGET_H

View File

@@ -31,7 +31,7 @@
#include "formeditorw.h" #include "formeditorw.h"
#include "formwindoweditor.h" #include "formwindoweditor.h"
#include "editordata.h" #include "editordata.h"
#include "designerxmleditor.h" #include "designerxmleditorwidget.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>

View File

@@ -34,7 +34,7 @@
#include "editorwidget.h" #include "editorwidget.h"
#include "editordata.h" #include "editordata.h"
#include "qtcreatorintegration.h" #include "qtcreatorintegration.h"
#include "designerxmleditor.h" #include "designerxmleditorwidget.h"
#include "designercontext.h" #include "designercontext.h"
#include "resourcehandler.h" #include "resourcehandler.h"
#include <widgethost.h> #include <widgethost.h>
@@ -710,7 +710,7 @@ EditorData FormEditorW::createEditor(QWidget *parent)
qdesigner_internal::FormWindowBase::setupDefaultAction(form); qdesigner_internal::FormWindowBase::setupDefaultAction(form);
#endif #endif
data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form); data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form);
DesignerXmlEditor *xmlEditor = new DesignerXmlEditor(form, parent); DesignerXmlEditorWidget *xmlEditor = new DesignerXmlEditorWidget(form, parent);
TextEditor::TextEditorSettings::instance()->initializeEditor(xmlEditor); TextEditor::TextEditorSettings::instance()->initializeEditor(xmlEditor);
data.formWindowEditor = xmlEditor->designerEditor(); data.formWindowEditor = xmlEditor->designerEditor();
connect(data.widgetHost, SIGNAL(formWindowSizeChanged(int,int)), connect(data.widgetHost, SIGNAL(formWindowSizeChanged(int,int)),

View File

@@ -31,7 +31,7 @@
#include "formwindowfile.h" #include "formwindowfile.h"
#include "designerconstants.h" #include "designerconstants.h"
#include "resourcehandler.h" #include "resourcehandler.h"
#include "designerxmleditor.h" #include "designerxmleditorwidget.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <texteditor/basetextdocument.h> #include <texteditor/basetextdocument.h>
@@ -53,27 +53,20 @@ namespace Designer {
struct FormWindowEditorPrivate struct FormWindowEditorPrivate
{ {
FormWindowEditorPrivate(Internal::DesignerXmlEditor *editor, Internal::DesignerXmlEditorWidget *m_widget;
QDesignerFormWindowInterface *form)
: m_textEditor(editor), m_file(form)
{}
TextEditor::PlainTextEditor m_textEditor;
Internal::FormWindowFile m_file;
}; };
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditor *editor, FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditorWidget *editor) :
QDesignerFormWindowInterface *form, TextEditor::PlainTextEditor(editor),
QObject *parent) : d(new FormWindowEditorPrivate)
Core::IEditor(parent),
d(new FormWindowEditorPrivate(editor, form))
{ {
d->m_widget = editor;
setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID, setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID,
Designer::Constants::C_DESIGNER_XML_EDITOR)); Designer::Constants::C_DESIGNER_XML_EDITOR));
setWidget(d->m_textEditor.widget());
// Revert to saved/load externally modified files. // Revert to saved/load externally modified files.
connect(&d->m_file, SIGNAL(reload(QString*,QString)), this, SLOT(slotOpen(QString*,QString))); connect(d->m_widget->formWindowFile(), SIGNAL(reloadRequested(QString*,QString)),
this, SLOT(slotOpen(QString*,QString)), Qt::DirectConnection);
} }
FormWindowEditor::~FormWindowEditor() FormWindowEditor::~FormWindowEditor()
@@ -88,7 +81,7 @@ bool FormWindowEditor::createNew(const QString &contents)
syncXmlEditor(QString()); syncXmlEditor(QString());
QDesignerFormWindowInterface *form = d->m_file.formWindow(); QDesignerFormWindowInterface *form = d->m_widget->formWindowFile()->formWindow();
QTC_ASSERT(form, return false); QTC_ASSERT(form, return false);
if (contents.isEmpty()) if (contents.isEmpty())
@@ -117,8 +110,8 @@ bool FormWindowEditor::createNew(const QString &contents)
return false; return false;
syncXmlEditor(contents); syncXmlEditor(contents);
d->m_file.setFilePath(QString()); d->m_widget->formWindowFile()->setFilePath(QString());
d->m_file.setShouldAutoSave(false); d->m_widget->formWindowFile()->setShouldAutoSave(false);
return true; return true;
} }
@@ -132,7 +125,7 @@ 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 = d->m_file.formWindow(); QDesignerFormWindowInterface *form = d->m_widget->formWindowFile()->formWindow();
QTC_ASSERT(form, return false); QTC_ASSERT(form, return false);
if (fileName.isEmpty()) if (fileName.isEmpty())
@@ -142,7 +135,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 (d->m_file.read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess) if (d->m_widget->formWindowFile()->read(absfileName, &contents, errorString) != Utils::TextFileFormat::ReadSuccess)
return false; return false;
form->setFileName(absfileName); form->setFileName(absfileName);
@@ -161,8 +154,8 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
form->setDirty(fileName != realFileName); form->setDirty(fileName != realFileName);
syncXmlEditor(contents); syncXmlEditor(contents);
d->m_file.setFilePath(absfileName); d->m_widget->formWindowFile()->setFilePath(absfileName);
d->m_file.setShouldAutoSave(false); d->m_widget->formWindowFile()->setShouldAutoSave(false);
if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>()) if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>())
rh->updateResources(); rh->updateResources();
@@ -173,22 +166,13 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
void FormWindowEditor::syncXmlEditor() void FormWindowEditor::syncXmlEditor()
{ {
if (Designer::Constants::Internal::debug) if (Designer::Constants::Internal::debug)
qDebug() << "FormWindowEditor::syncXmlEditor" << d->m_file.filePath(); qDebug() << "FormWindowEditor::syncXmlEditor" << d->m_widget->formWindowFile()->filePath();
syncXmlEditor(contents()); syncXmlEditor(contents());
} }
void FormWindowEditor::syncXmlEditor(const QString &contents) void FormWindowEditor::syncXmlEditor(const QString &contents)
{ {
d->m_textEditor.editorWidget()->setPlainText(contents); editorWidget()->document()->setPlainText(contents);
d->m_textEditor.editorWidget()->setReadOnly(true);
d->m_textEditor.document()->setDisplayName(d->m_file.displayName());
static_cast<TextEditor::PlainTextEditorWidget *>
(d->m_textEditor.editorWidget())->configure(document()->mimeType());
}
Core::IDocument *FormWindowEditor::document()
{
return &d->m_file;
} }
Core::Id FormWindowEditor::id() const Core::Id FormWindowEditor::id() const
@@ -196,16 +180,6 @@ Core::Id FormWindowEditor::id() const
return Core::Id(Designer::Constants::K_DESIGNER_XML_EDITOR_ID); return Core::Id(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
} }
QByteArray FormWindowEditor::saveState() const
{
return d->m_textEditor.saveState();
}
bool FormWindowEditor::restoreState(const QByteArray &state)
{
return d->m_textEditor.restoreState(state);
}
QWidget *FormWindowEditor::toolBar() QWidget *FormWindowEditor::toolBar()
{ {
return 0; return 0;
@@ -214,27 +188,18 @@ QWidget *FormWindowEditor::toolBar()
QString FormWindowEditor::contents() const QString FormWindowEditor::contents() const
{ {
#if QT_VERSION >= 0x050000 // TODO: No warnings about spacers here #if QT_VERSION >= 0x050000 // TODO: No warnings about spacers here
const QDesignerFormWindowInterface *fw = d->m_file.formWindow(); const QDesignerFormWindowInterface *fw = d->m_widget->formWindowFile()->formWindow();
QTC_ASSERT(fw, return QString()); QTC_ASSERT(fw, return QString());
return fw->contents(); return fw->contents();
#else #else
// No warnings about spacers here // No warnings about spacers here
const qdesigner_internal::FormWindowBase *fw = qobject_cast<const qdesigner_internal::FormWindowBase *>(d->m_file.formWindow()); const qdesigner_internal::FormWindowBase *fw =
qobject_cast<const qdesigner_internal::FormWindowBase *>(d->m_widget->formWindowFile()->formWindow());
QTC_ASSERT(fw, return QString()); QTC_ASSERT(fw, return QString());
return fw->fileContents(); return fw->fileContents();
#endif #endif
} }
TextEditor::BaseTextDocument *FormWindowEditor::textDocument()
{
return qobject_cast<TextEditor::BaseTextDocument*>(d->m_textEditor.document());
}
TextEditor::PlainTextEditor *FormWindowEditor::textEditor()
{
return &d->m_textEditor;
}
bool FormWindowEditor::isDesignModePreferred() const bool FormWindowEditor::isDesignModePreferred() const
{ {
return true; return true;

View File

@@ -32,6 +32,7 @@
#include "designer_export.h" #include "designer_export.h"
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <texteditor/plaintexteditor.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface; class QDesignerFormWindowInterface;
@@ -45,36 +46,30 @@ namespace TextEditor {
namespace Designer { namespace Designer {
namespace Internal { namespace Internal {
class DesignerXmlEditor; class DesignerXmlEditorWidget;
} }
struct FormWindowEditorPrivate; struct FormWindowEditorPrivate;
// The actual Core::IEditor belonging to Qt Designer. Uses FormWindowFile // IEditor that is used for the QDesignerFormWindowInterface
// as the Core::IDocument to do the isModified() handling, // It is a read-only PlainTextEditor that shows the XML of the form.
// which needs to be done by Qt Designer. // DesignerXmlEditorWidget is the corresponding PlainTextEditorWidget,
// However, to make the read-only XML text editor work, // FormWindowFile the corresponding BaseTextDocument.
// a TextEditor::PlainTextEditorEditable (IEditor) is also required. // The content from the QDesignerFormWindowInterface is synced to the
// It is aggregated and some functions are delegated to it. // content of the XML editor.
class DESIGNER_EXPORT FormWindowEditor : public Core::IEditor class DESIGNER_EXPORT FormWindowEditor : public TextEditor::PlainTextEditor
{ {
Q_PROPERTY(QString contents READ contents) Q_PROPERTY(QString contents READ contents)
Q_OBJECT Q_OBJECT
public: public:
explicit FormWindowEditor(Internal::DesignerXmlEditor *editor, explicit FormWindowEditor(Internal::DesignerXmlEditorWidget *editor);
QDesignerFormWindowInterface *form,
QObject *parent = 0);
virtual ~FormWindowEditor(); virtual ~FormWindowEditor();
// IEditor // IEditor
virtual bool createNew(const QString &contents = QString()); virtual bool createNew(const QString &contents = QString());
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName); virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
virtual Core::IDocument *document();
virtual Core::Id id() const; virtual Core::Id id() const;
virtual QByteArray saveState() const;
virtual bool restoreState(const QByteArray &state);
virtual QWidget *toolBar(); virtual QWidget *toolBar();
virtual bool isDesignModePreferred() const; virtual bool isDesignModePreferred() const;
@@ -82,9 +77,6 @@ public:
// For uic code model support // For uic code model support
QString contents() const; QString contents() const;
TextEditor::BaseTextDocument *textDocument();
TextEditor::PlainTextEditor *textEditor();
public slots: public slots:
void syncXmlEditor(); void syncXmlEditor();

View File

@@ -49,12 +49,12 @@ namespace Designer {
namespace Internal { namespace Internal {
FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent) FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent)
: Core::TextDocument(parent), : m_mimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE)),
m_mimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE)),
m_shouldAutoSave(false), m_shouldAutoSave(false),
m_formWindow(form), m_formWindow(form),
m_isModified(false) m_isModified(false)
{ {
setParent(parent);
// Designer needs UTF-8 regardless of settings. // Designer needs UTF-8 regardless of settings.
setCodec(QTextCodec::codecForName("UTF-8")); setCodec(QTextCodec::codecForName("UTF-8"));
connect(m_formWindow->core()->formWindowManager(), SIGNAL(formWindowRemoved(QDesignerFormWindowInterface*)), connect(m_formWindow->core()->formWindowManager(), SIGNAL(formWindowRemoved(QDesignerFormWindowInterface*)),
@@ -141,7 +141,7 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
emit changed(); emit changed();
} else { } else {
emit aboutToReload(); emit aboutToReload();
emit reload(errorString, filePath()); emit reloadRequested(errorString, filePath());
const bool success = errorString->isEmpty(); const bool success = errorString->isEmpty();
emit reloadFinished(success); emit reloadFinished(success);
return success; return success;

View File

@@ -30,7 +30,7 @@
#ifndef FORMWINDOWFILE_H #ifndef FORMWINDOWFILE_H
#define FORMWINDOWFILE_H #define FORMWINDOWFILE_H
#include <coreplugin/textdocument.h> #include <texteditor/basetextdocument.h>
#include <QPointer> #include <QPointer>
@@ -42,12 +42,13 @@ QT_END_NAMESPACE
namespace Designer { namespace Designer {
namespace Internal { namespace Internal {
class FormWindowFile : public Core::TextDocument class FormWindowFile : public TextEditor::BaseTextDocument
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent = 0); explicit FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent = 0);
~FormWindowFile() { }
// IDocument // IDocument
virtual bool save(QString *errorString, const QString &fileName, bool autoSave); virtual bool save(QString *errorString, const QString &fileName, bool autoSave);
@@ -68,8 +69,7 @@ public:
signals: signals:
// Internal // Internal
void reload(QString *errorString, const QString &); void reloadRequested(QString *errorString, const QString &);
void setDisplayName(const QString &);
public slots: public slots:
void setFilePath(const QString &); void setFilePath(const QString &);