forked from qt-creator/qt-creator
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:
@@ -36,12 +36,12 @@ HEADERS += formeditorplugin.h \
|
||||
formwizarddialog.h \
|
||||
codemodelhelpers.h \
|
||||
designer_export.h \
|
||||
designerxmleditor.h \
|
||||
designercontext.h \
|
||||
formeditorstack.h \
|
||||
editordata.h \
|
||||
resourcehandler.h \
|
||||
qtdesignerformclasscodegenerator.h
|
||||
qtdesignerformclasscodegenerator.h \
|
||||
designerxmleditorwidget.h
|
||||
|
||||
SOURCES += formeditorplugin.cpp \
|
||||
formeditorfactory.cpp \
|
||||
@@ -56,11 +56,11 @@ SOURCES += formeditorplugin.cpp \
|
||||
formtemplatewizardpage.cpp \
|
||||
formwizarddialog.cpp \
|
||||
codemodelhelpers.cpp \
|
||||
designerxmleditor.cpp \
|
||||
designercontext.cpp \
|
||||
formeditorstack.cpp \
|
||||
resourcehandler.cpp \
|
||||
qtdesignerformclasscodegenerator.cpp
|
||||
qtdesignerformclasscodegenerator.cpp \
|
||||
designerxmleditorwidget.cpp
|
||||
|
||||
RESOURCES += designer.qrc
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ QtcPlugin {
|
||||
"designerconstants.h",
|
||||
"designercontext.cpp",
|
||||
"designercontext.h",
|
||||
"designerxmleditor.cpp",
|
||||
"designerxmleditor.h",
|
||||
"designerxmleditorwidget.cpp",
|
||||
"designerxmleditorwidget.h",
|
||||
"editordata.h",
|
||||
"editorwidget.cpp",
|
||||
"editorwidget.h",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "designerxmleditor.h"
|
||||
#include "designerxmleditorwidget.h"
|
||||
#include "formwindoweditor.h"
|
||||
#include "designerconstants.h"
|
||||
|
||||
@@ -37,26 +37,34 @@
|
||||
namespace Designer {
|
||||
namespace Internal {
|
||||
|
||||
DesignerXmlEditor::DesignerXmlEditor(QDesignerFormWindowInterface *form,
|
||||
DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
|
||||
QWidget *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);
|
||||
configure(m_file->mimeType());
|
||||
}
|
||||
|
||||
TextEditor::BaseTextEditor *DesignerXmlEditor::createEditor()
|
||||
TextEditor::BaseTextEditor *DesignerXmlEditorWidget::createEditor()
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "DesignerXmlEditor::createEditableInterface()";
|
||||
return m_designerEditor->textEditor();
|
||||
return m_designerEditor;
|
||||
}
|
||||
|
||||
FormWindowEditor *DesignerXmlEditor::designerEditor() const
|
||||
FormWindowEditor *DesignerXmlEditorWidget::designerEditor() const
|
||||
{
|
||||
return m_designerEditor;
|
||||
}
|
||||
|
||||
Internal::FormWindowFile *DesignerXmlEditorWidget::formWindowFile() const
|
||||
{
|
||||
return m_file.data();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Designer
|
||||
|
||||
@@ -27,11 +27,15 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef DESIGNERXMLEDITOR_H
|
||||
#define DESIGNERXMLEDITOR_H
|
||||
#ifndef DESIGNERXMLEDITORWIDGET_H
|
||||
#define DESIGNERXMLEDITORWIDGET_H
|
||||
|
||||
#include "formwindowfile.h"
|
||||
|
||||
#include <texteditor/plaintexteditor.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDesignerFormWindowInterface;
|
||||
QT_END_NAMESPACE
|
||||
@@ -49,23 +53,25 @@ namespace Internal {
|
||||
* Internally manages a FormWindowEditor and uses the plain text
|
||||
* editable embedded in it. */
|
||||
|
||||
class DesignerXmlEditor : public TextEditor::PlainTextEditorWidget
|
||||
class DesignerXmlEditorWidget : public TextEditor::PlainTextEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DesignerXmlEditor(QDesignerFormWindowInterface *form,
|
||||
explicit DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
|
||||
QWidget *parent = 0);
|
||||
|
||||
FormWindowEditor *designerEditor() const;
|
||||
Internal::FormWindowFile *formWindowFile() const;
|
||||
|
||||
protected:
|
||||
virtual TextEditor::BaseTextEditor *createEditor();
|
||||
|
||||
private:
|
||||
QSharedPointer<Internal::FormWindowFile> m_file;
|
||||
FormWindowEditor *m_designerEditor;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // Designer
|
||||
|
||||
#endif // DESIGNERXMLEDITOR_H
|
||||
#endif // DESIGNERXMLEDITORWIDGET_H
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "formeditorw.h"
|
||||
#include "formwindoweditor.h"
|
||||
#include "editordata.h"
|
||||
#include "designerxmleditor.h"
|
||||
#include "designerxmleditorwidget.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "editorwidget.h"
|
||||
#include "editordata.h"
|
||||
#include "qtcreatorintegration.h"
|
||||
#include "designerxmleditor.h"
|
||||
#include "designerxmleditorwidget.h"
|
||||
#include "designercontext.h"
|
||||
#include "resourcehandler.h"
|
||||
#include <widgethost.h>
|
||||
@@ -710,7 +710,7 @@ EditorData FormEditorW::createEditor(QWidget *parent)
|
||||
qdesigner_internal::FormWindowBase::setupDefaultAction(form);
|
||||
#endif
|
||||
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);
|
||||
data.formWindowEditor = xmlEditor->designerEditor();
|
||||
connect(data.widgetHost, SIGNAL(formWindowSizeChanged(int,int)),
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "formwindowfile.h"
|
||||
#include "designerconstants.h"
|
||||
#include "resourcehandler.h"
|
||||
#include "designerxmleditor.h"
|
||||
#include "designerxmleditorwidget.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <texteditor/basetextdocument.h>
|
||||
@@ -53,27 +53,20 @@ namespace Designer {
|
||||
|
||||
struct FormWindowEditorPrivate
|
||||
{
|
||||
FormWindowEditorPrivate(Internal::DesignerXmlEditor *editor,
|
||||
QDesignerFormWindowInterface *form)
|
||||
: m_textEditor(editor), m_file(form)
|
||||
{}
|
||||
|
||||
TextEditor::PlainTextEditor m_textEditor;
|
||||
Internal::FormWindowFile m_file;
|
||||
Internal::DesignerXmlEditorWidget *m_widget;
|
||||
};
|
||||
|
||||
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditor *editor,
|
||||
QDesignerFormWindowInterface *form,
|
||||
QObject *parent) :
|
||||
Core::IEditor(parent),
|
||||
d(new FormWindowEditorPrivate(editor, form))
|
||||
FormWindowEditor::FormWindowEditor(Internal::DesignerXmlEditorWidget *editor) :
|
||||
TextEditor::PlainTextEditor(editor),
|
||||
d(new FormWindowEditorPrivate)
|
||||
{
|
||||
d->m_widget = editor;
|
||||
setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID,
|
||||
Designer::Constants::C_DESIGNER_XML_EDITOR));
|
||||
setWidget(d->m_textEditor.widget());
|
||||
|
||||
// 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()
|
||||
@@ -88,7 +81,7 @@ bool FormWindowEditor::createNew(const QString &contents)
|
||||
|
||||
syncXmlEditor(QString());
|
||||
|
||||
QDesignerFormWindowInterface *form = d->m_file.formWindow();
|
||||
QDesignerFormWindowInterface *form = d->m_widget->formWindowFile()->formWindow();
|
||||
QTC_ASSERT(form, return false);
|
||||
|
||||
if (contents.isEmpty())
|
||||
@@ -117,8 +110,8 @@ bool FormWindowEditor::createNew(const QString &contents)
|
||||
return false;
|
||||
|
||||
syncXmlEditor(contents);
|
||||
d->m_file.setFilePath(QString());
|
||||
d->m_file.setShouldAutoSave(false);
|
||||
d->m_widget->formWindowFile()->setFilePath(QString());
|
||||
d->m_widget->formWindowFile()->setShouldAutoSave(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -132,7 +125,7 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "FormWindowEditor::open" << fileName;
|
||||
|
||||
QDesignerFormWindowInterface *form = d->m_file.formWindow();
|
||||
QDesignerFormWindowInterface *form = d->m_widget->formWindowFile()->formWindow();
|
||||
QTC_ASSERT(form, return false);
|
||||
|
||||
if (fileName.isEmpty())
|
||||
@@ -142,7 +135,7 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
|
||||
const QString absfileName = fi.absoluteFilePath();
|
||||
|
||||
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;
|
||||
|
||||
form->setFileName(absfileName);
|
||||
@@ -161,8 +154,8 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
|
||||
form->setDirty(fileName != realFileName);
|
||||
syncXmlEditor(contents);
|
||||
|
||||
d->m_file.setFilePath(absfileName);
|
||||
d->m_file.setShouldAutoSave(false);
|
||||
d->m_widget->formWindowFile()->setFilePath(absfileName);
|
||||
d->m_widget->formWindowFile()->setShouldAutoSave(false);
|
||||
|
||||
if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>())
|
||||
rh->updateResources();
|
||||
@@ -173,22 +166,13 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
|
||||
void FormWindowEditor::syncXmlEditor()
|
||||
{
|
||||
if (Designer::Constants::Internal::debug)
|
||||
qDebug() << "FormWindowEditor::syncXmlEditor" << d->m_file.filePath();
|
||||
qDebug() << "FormWindowEditor::syncXmlEditor" << d->m_widget->formWindowFile()->filePath();
|
||||
syncXmlEditor(contents());
|
||||
}
|
||||
|
||||
void FormWindowEditor::syncXmlEditor(const QString &contents)
|
||||
{
|
||||
d->m_textEditor.editorWidget()->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;
|
||||
editorWidget()->document()->setPlainText(contents);
|
||||
}
|
||||
|
||||
Core::Id FormWindowEditor::id() const
|
||||
@@ -196,16 +180,6 @@ Core::Id FormWindowEditor::id() const
|
||||
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()
|
||||
{
|
||||
return 0;
|
||||
@@ -214,27 +188,18 @@ QWidget *FormWindowEditor::toolBar()
|
||||
QString FormWindowEditor::contents() const
|
||||
{
|
||||
#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());
|
||||
return fw->contents();
|
||||
#else
|
||||
// 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());
|
||||
return fw->fileContents();
|
||||
#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
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "designer_export.h"
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <texteditor/plaintexteditor.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDesignerFormWindowInterface;
|
||||
@@ -45,36 +46,30 @@ namespace TextEditor {
|
||||
namespace Designer {
|
||||
|
||||
namespace Internal {
|
||||
class DesignerXmlEditor;
|
||||
class DesignerXmlEditorWidget;
|
||||
}
|
||||
struct FormWindowEditorPrivate;
|
||||
|
||||
// The actual Core::IEditor belonging to Qt Designer. Uses FormWindowFile
|
||||
// as the Core::IDocument to do the isModified() handling,
|
||||
// which needs to be done by Qt Designer.
|
||||
// However, to make the read-only XML text editor work,
|
||||
// a TextEditor::PlainTextEditorEditable (IEditor) is also required.
|
||||
// It is aggregated and some functions are delegated to it.
|
||||
// IEditor that is used for the QDesignerFormWindowInterface
|
||||
// It is a read-only PlainTextEditor that shows the XML of the form.
|
||||
// DesignerXmlEditorWidget is the corresponding PlainTextEditorWidget,
|
||||
// FormWindowFile the corresponding BaseTextDocument.
|
||||
// The content from the QDesignerFormWindowInterface is synced to the
|
||||
// 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_OBJECT
|
||||
public:
|
||||
explicit FormWindowEditor(Internal::DesignerXmlEditor *editor,
|
||||
QDesignerFormWindowInterface *form,
|
||||
QObject *parent = 0);
|
||||
explicit FormWindowEditor(Internal::DesignerXmlEditorWidget *editor);
|
||||
virtual ~FormWindowEditor();
|
||||
|
||||
// IEditor
|
||||
virtual bool createNew(const QString &contents = QString());
|
||||
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName);
|
||||
virtual Core::IDocument *document();
|
||||
virtual Core::Id id() const;
|
||||
|
||||
virtual QByteArray saveState() const;
|
||||
virtual bool restoreState(const QByteArray &state);
|
||||
|
||||
virtual QWidget *toolBar();
|
||||
|
||||
virtual bool isDesignModePreferred() const;
|
||||
@@ -82,9 +77,6 @@ public:
|
||||
// For uic code model support
|
||||
QString contents() const;
|
||||
|
||||
TextEditor::BaseTextDocument *textDocument();
|
||||
TextEditor::PlainTextEditor *textEditor();
|
||||
|
||||
public slots:
|
||||
void syncXmlEditor();
|
||||
|
||||
|
||||
@@ -49,12 +49,12 @@ namespace Designer {
|
||||
namespace Internal {
|
||||
|
||||
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_formWindow(form),
|
||||
m_isModified(false)
|
||||
{
|
||||
setParent(parent);
|
||||
// Designer needs UTF-8 regardless of settings.
|
||||
setCodec(QTextCodec::codecForName("UTF-8"));
|
||||
connect(m_formWindow->core()->formWindowManager(), SIGNAL(formWindowRemoved(QDesignerFormWindowInterface*)),
|
||||
@@ -141,7 +141,7 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
|
||||
emit changed();
|
||||
} else {
|
||||
emit aboutToReload();
|
||||
emit reload(errorString, filePath());
|
||||
emit reloadRequested(errorString, filePath());
|
||||
const bool success = errorString->isEmpty();
|
||||
emit reloadFinished(success);
|
||||
return success;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifndef FORMWINDOWFILE_H
|
||||
#define FORMWINDOWFILE_H
|
||||
|
||||
#include <coreplugin/textdocument.h>
|
||||
#include <texteditor/basetextdocument.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
@@ -42,12 +42,13 @@ QT_END_NAMESPACE
|
||||
namespace Designer {
|
||||
namespace Internal {
|
||||
|
||||
class FormWindowFile : public Core::TextDocument
|
||||
class FormWindowFile : public TextEditor::BaseTextDocument
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FormWindowFile(QDesignerFormWindowInterface *form, QObject *parent = 0);
|
||||
~FormWindowFile() { }
|
||||
|
||||
// IDocument
|
||||
virtual bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||
@@ -68,8 +69,7 @@ public:
|
||||
|
||||
signals:
|
||||
// Internal
|
||||
void reload(QString *errorString, const QString &);
|
||||
void setDisplayName(const QString &);
|
||||
void reloadRequested(QString *errorString, const QString &);
|
||||
|
||||
public slots:
|
||||
void setFilePath(const QString &);
|
||||
|
||||
Reference in New Issue
Block a user