diff --git a/src/plugins/designer/designer.pro b/src/plugins/designer/designer.pro index d677181d1dd..809a6e79f74 100644 --- a/src/plugins/designer/designer.pro +++ b/src/plugins/designer/designer.pro @@ -25,8 +25,7 @@ HEADERS += formeditorplugin.h \ formeditorstack.h \ editordata.h \ resourcehandler.h \ - qtdesignerformclasscodegenerator.h \ - designerxmleditorwidget.h + qtdesignerformclasscodegenerator.h SOURCES += formeditorplugin.cpp \ formeditorfactory.cpp \ @@ -44,8 +43,7 @@ SOURCES += formeditorplugin.cpp \ designercontext.cpp \ formeditorstack.cpp \ resourcehandler.cpp \ - qtdesignerformclasscodegenerator.cpp \ - designerxmleditorwidget.cpp + qtdesignerformclasscodegenerator.cpp equals(TEST, 1) { SOURCES += gotoslot_test.cpp diff --git a/src/plugins/designer/designer.qbs b/src/plugins/designer/designer.qbs index 8cef355cf8b..c8fc2fc9464 100644 --- a/src/plugins/designer/designer.qbs +++ b/src/plugins/designer/designer.qbs @@ -31,7 +31,6 @@ QtcPlugin { "designer_export.h", "designerconstants.h", "designercontext.cpp", "designercontext.h", - "designerxmleditorwidget.cpp", "designerxmleditorwidget.h", "editordata.h", "editorwidget.cpp", "editorwidget.h", "formeditorfactory.cpp", "formeditorfactory.h", diff --git a/src/plugins/designer/designerxmleditorwidget.cpp b/src/plugins/designer/designerxmleditorwidget.cpp deleted file mode 100644 index 01b0f4c1567..00000000000 --- a/src/plugins/designer/designerxmleditorwidget.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "designerxmleditorwidget.h" -#include "formwindoweditor.h" - -#include - -#include -#include - -namespace Designer { -namespace Internal { - -DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form) -{ - TextEditor::BaseTextDocumentPtr doc(new FormWindowFile(form)); - setTextDocument(doc); - m_editor = new FormWindowEditor(this); - setupAsPlainEditor(); - setReadOnly(true); - configureMimeType(doc->mimeType()); -} - -FormWindowEditor *DesignerXmlEditorWidget::designerEditor() const -{ - return m_editor; -} - -Internal::FormWindowFile *DesignerXmlEditorWidget::formWindowFile() const -{ - return qobject_cast(textDocument()); -} - -} // namespace Internal -} // namespace Designer - diff --git a/src/plugins/designer/designerxmleditorwidget.h b/src/plugins/designer/designerxmleditorwidget.h deleted file mode 100644 index e1e2c98f877..00000000000 --- a/src/plugins/designer/designerxmleditorwidget.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef DESIGNERXMLEDITORWIDGET_H -#define DESIGNERXMLEDITORWIDGET_H - -#include "formwindowfile.h" - -#include - -#include - -QT_BEGIN_NAMESPACE -class QDesignerFormWindowInterface; -QT_END_NAMESPACE - -namespace Designer { -class FormWindowEditor; - -namespace Internal { - -/* 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 a FormWindowEditor and uses the plain text - * editable embedded in it. */ - -class DesignerXmlEditorWidget : public TextEditor::BaseTextEditorWidget -{ - Q_OBJECT -public: - explicit DesignerXmlEditorWidget(QDesignerFormWindowInterface *form); - - FormWindowEditor *designerEditor() const; - Internal::FormWindowFile *formWindowFile() const; - -private: - FormWindowEditor *m_editor; -}; - -} // Internal -} // Designer - -#endif // DESIGNERXMLEDITORWIDGET_H diff --git a/src/plugins/designer/formeditorfactory.cpp b/src/plugins/designer/formeditorfactory.cpp index cc43bfaf029..a07fed0d4d2 100644 --- a/src/plugins/designer/formeditorfactory.cpp +++ b/src/plugins/designer/formeditorfactory.cpp @@ -31,7 +31,6 @@ #include "formeditorw.h" #include "formwindoweditor.h" #include "editordata.h" -#include "designerxmleditorwidget.h" #include #include diff --git a/src/plugins/designer/formeditorplugin.cpp b/src/plugins/designer/formeditorplugin.cpp index 2988888101a..b7480a85674 100644 --- a/src/plugins/designer/formeditorplugin.cpp +++ b/src/plugins/designer/formeditorplugin.cpp @@ -30,6 +30,7 @@ #include "formeditorplugin.h" #include "formeditorfactory.h" #include "formeditorw.h" +#include "formwindoweditor.h" #include "formwizard.h" #ifdef CPP_ENABLED diff --git a/src/plugins/designer/formeditorstack.cpp b/src/plugins/designer/formeditorstack.cpp index be622befe44..a453d6035a9 100644 --- a/src/plugins/designer/formeditorstack.cpp +++ b/src/plugins/designer/formeditorstack.cpp @@ -30,6 +30,7 @@ #include "formeditorstack.h" #include "formwindoweditor.h" #include "formeditorw.h" +#include "formwindowfile.h" #include @@ -188,7 +189,7 @@ void FormEditorStack::modeAboutToChange(Core::IMode *m) // Sync the editor when entering edit mode if (m && m->id() == Core::Constants::MODE_EDIT) foreach (const EditorData &data, m_formEditors) - data.formWindowEditor->syncXmlEditor(); + data.formWindowEditor->formWindowFile()->syncXmlFromFormWindow(); } } // Internal diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index 47d5e2dca26..de7c4b589a9 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -29,12 +29,12 @@ #include "formeditorw.h" #include "formwindoweditor.h" +#include "formwindowfile.h" #include "settingsmanager.h" #include "settingspage.h" #include "editorwidget.h" #include "editordata.h" #include "qtcreatorintegration.h" -#include "designerxmleditorwidget.h" #include "designercontext.h" #include "resourcehandler.h" #include @@ -104,9 +104,45 @@ using namespace Designer::Constants; namespace Designer { namespace Internal { +/* 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 a FormWindowEditor and uses the plain text + * editable embedded in it. */ +class DesignerXmlEditorWidget : public TextEditor::BaseTextEditorWidget +{ +public: + DesignerXmlEditorWidget() {} + + void finalizeInitialization() + { + setupAsPlainEditor(); + setReadOnly(true); + } +}; + +class FormWindowEditorFactory : public TextEditor::BaseTextEditorFactory +{ +public: + FormWindowEditorFactory() + { + setId(Designer::Constants::K_DESIGNER_XML_EDITOR_ID); + setDocumentCreator([this]() { return new FormWindowFile(m_form); }); + setEditorCreator([]() { return new FormWindowEditor; }); + setEditorWidgetCreator([]() { return new Internal::DesignerXmlEditorWidget; }); + setDuplicatedSupported(false); + } + + QDesignerFormWindowInterface *m_form; +}; + +static FormWindowEditorFactory *m_xmlEditorFactory = 0; + // --------- FormEditorW -FormEditorW *FormEditorW::m_self = 0; +static FormEditorW *m_self = 0; FormEditorW::FormEditorW() : m_formeditor(QDesignerComponents::createFormEditor(0)), @@ -154,6 +190,8 @@ FormEditorW::FormEditorW() : this, SLOT(currentEditorChanged(Core::IEditor*))); connect(m_shortcutMapper, SIGNAL(mapped(QObject*)), this, SLOT(updateShortcut(QObject*))); + + m_xmlEditorFactory = new FormWindowEditorFactory; } FormEditorW::~FormEditorW() @@ -176,6 +214,7 @@ FormEditorW::~FormEditorW() m_settingsPages.clear(); delete m_integration; + delete m_xmlEditorFactory ; m_self = 0; } @@ -633,15 +672,16 @@ EditorData FormEditorW::createEditor() QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0); QTC_ASSERT(form, return data); connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int))); + + m_xmlEditorFactory->m_form = form; ResourceHandler *resourceHandler = new ResourceHandler(form); data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form); - DesignerXmlEditorWidget *xmlEditor = new DesignerXmlEditorWidget(form); - data.formWindowEditor = xmlEditor->designerEditor(); - connect(data.formWindowEditor->document(), SIGNAL(filePathChanged(QString,QString)), + data.formWindowEditor = qobject_cast(m_xmlEditorFactory->createEditor()); + connect(data.formWindowEditor->textDocument(), SIGNAL(filePathChanged(QString,QString)), resourceHandler, SLOT(updateResources())); m_editorWidget->add(data); - m_toolBar->addEditor(xmlEditor->designerEditor()); + m_toolBar->addEditor(data.formWindowEditor); return data; } diff --git a/src/plugins/designer/formeditorw.h b/src/plugins/designer/formeditorw.h index c20fb684b77..2cfc601b89a 100644 --- a/src/plugins/designer/formeditorw.h +++ b/src/plugins/designer/formeditorw.h @@ -158,8 +158,6 @@ private: Core::Id groupId = Core::Id()); QToolBar *createEditorToolBar() const; - static FormEditorW *m_self; - QDesignerFormEditorInterface *m_formeditor; QDesignerIntegrationInterface *m_integration; QDesignerFormWindowManagerInterface *m_fwm; diff --git a/src/plugins/designer/formwindoweditor.cpp b/src/plugins/designer/formwindoweditor.cpp index 39f338b3ca4..4726866daf5 100644 --- a/src/plugins/designer/formwindoweditor.cpp +++ b/src/plugins/designer/formwindoweditor.cpp @@ -31,7 +31,6 @@ #include "formwindowfile.h" #include "designerconstants.h" #include "resourcehandler.h" -#include "designerxmleditorwidget.h" #include #include @@ -45,25 +44,23 @@ namespace Designer { -FormWindowEditor::FormWindowEditor(TextEditor::BaseTextEditorWidget *widget) +FormWindowEditor::FormWindowEditor() { - setWidget(widget); - setDuplicateSupported(false); - setContext(Core::Context(Designer::Constants::K_DESIGNER_XML_EDITOR_ID, - Designer::Constants::C_DESIGNER_XML_EDITOR)); - - // Revert to saved/load externally modified files. - connect(formWindowFile(), SIGNAL(reloadRequested(QString*,QString)), - this, SLOT(slotOpen(QString*,QString)), Qt::DirectConnection); + addContext(Designer::Constants::K_DESIGNER_XML_EDITOR_ID); + addContext(Designer::Constants::C_DESIGNER_XML_EDITOR); } FormWindowEditor::~FormWindowEditor() { } -void FormWindowEditor::slotOpen(QString *errorString, const QString &fileName) +void FormWindowEditor::finalizeInitialization() { - open(errorString, fileName, fileName); + // Revert to saved/load externally modified files. + connect(formWindowFile(), &Internal::FormWindowFile::reloadRequested, + [this](QString *errorString, const QString &fileName) { + open(errorString, fileName, fileName); + }); } bool FormWindowEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) @@ -103,13 +100,6 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const return true; } -void FormWindowEditor::syncXmlEditor() -{ - if (Designer::Constants::Internal::debug) - qDebug() << "FormWindowEditor::syncXmlEditor" << formWindowFile()->filePath(); - formWindowFile()->syncXmlFromFormWindow(); -} - QWidget *FormWindowEditor::toolBar() { return 0; @@ -122,7 +112,7 @@ QString FormWindowEditor::contents() const Internal::FormWindowFile *FormWindowEditor::formWindowFile() const { - return qobject_cast(const_cast(this)->textDocument()); + return qobject_cast(textDocument()); } bool FormWindowEditor::isDesignModePreferred() const diff --git a/src/plugins/designer/formwindoweditor.h b/src/plugins/designer/formwindoweditor.h index 777cda74f54..af0c84d6c7f 100644 --- a/src/plugins/designer/formwindoweditor.h +++ b/src/plugins/designer/formwindoweditor.h @@ -34,15 +34,9 @@ #include #include -QT_BEGIN_NAMESPACE -class QDesignerFormWindowInterface; -QT_END_NAMESPACE - namespace Designer { -namespace Internal { -class FormWindowFile; -} +namespace Internal { class FormWindowFile; } // IEditor that is used for the QDesignerFormWindowInterface // It is a read-only text editor that shows the XML of the form. @@ -55,28 +49,21 @@ class DESIGNER_EXPORT FormWindowEditor : public TextEditor::BaseTextEditor { Q_PROPERTY(QString contents READ contents) Q_OBJECT + public: - explicit FormWindowEditor(TextEditor::BaseTextEditorWidget *widget); - virtual ~FormWindowEditor(); + FormWindowEditor(); + ~FormWindowEditor(); - // IEditor - virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName); - - virtual QWidget *toolBar(); - - virtual bool isDesignModePreferred() const; + void finalizeInitialization(); + bool open(QString *errorString, const QString &fileName, const QString &realFileName); + QWidget *toolBar(); + bool isDesignModePreferred() const; // For uic code model support QString contents() const; // Convenience access. Internal::FormWindowFile *formWindowFile() const; - -public slots: - void syncXmlEditor(); - -private slots: - void slotOpen(QString *errorString, const QString &fileName); }; } // namespace Designer