Designer: Use a BaseTextEditorFactory to create the Xml editor

Change-Id: Iac80f6ef017a7c5acf1ed89ac0ece83c6a67abec
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-09-03 12:38:51 +02:00
parent afd56bd8ad
commit 88eb60d331
11 changed files with 69 additions and 191 deletions

View File

@@ -25,8 +25,7 @@ HEADERS += formeditorplugin.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 \
@@ -44,8 +43,7 @@ SOURCES += formeditorplugin.cpp \
designercontext.cpp \ designercontext.cpp \
formeditorstack.cpp \ formeditorstack.cpp \
resourcehandler.cpp \ resourcehandler.cpp \
qtdesignerformclasscodegenerator.cpp \ qtdesignerformclasscodegenerator.cpp
designerxmleditorwidget.cpp
equals(TEST, 1) { equals(TEST, 1) {
SOURCES += gotoslot_test.cpp SOURCES += gotoslot_test.cpp

View File

@@ -31,7 +31,6 @@ QtcPlugin {
"designer_export.h", "designer_export.h",
"designerconstants.h", "designerconstants.h",
"designercontext.cpp", "designercontext.h", "designercontext.cpp", "designercontext.h",
"designerxmleditorwidget.cpp", "designerxmleditorwidget.h",
"editordata.h", "editordata.h",
"editorwidget.cpp", "editorwidget.h", "editorwidget.cpp", "editorwidget.h",
"formeditorfactory.cpp", "formeditorfactory.h", "formeditorfactory.cpp", "formeditorfactory.h",

View File

@@ -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 <utils/qtcassert.h>
#include <QDesignerFormWindowInterface>
#include <QDebug>
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<FormWindowFile *>(textDocument());
}
} // namespace Internal
} // namespace Designer

View File

@@ -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 <texteditor/basetexteditor.h>
#include <QSharedPointer>
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

View File

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

View File

@@ -30,6 +30,7 @@
#include "formeditorplugin.h" #include "formeditorplugin.h"
#include "formeditorfactory.h" #include "formeditorfactory.h"
#include "formeditorw.h" #include "formeditorw.h"
#include "formwindoweditor.h"
#include "formwizard.h" #include "formwizard.h"
#ifdef CPP_ENABLED #ifdef CPP_ENABLED

View File

@@ -30,6 +30,7 @@
#include "formeditorstack.h" #include "formeditorstack.h"
#include "formwindoweditor.h" #include "formwindoweditor.h"
#include "formeditorw.h" #include "formeditorw.h"
#include "formwindowfile.h"
#include <widgethost.h> #include <widgethost.h>
@@ -188,7 +189,7 @@ void FormEditorStack::modeAboutToChange(Core::IMode *m)
// Sync the editor when entering edit mode // Sync the editor when entering edit mode
if (m && m->id() == Core::Constants::MODE_EDIT) if (m && m->id() == Core::Constants::MODE_EDIT)
foreach (const EditorData &data, m_formEditors) foreach (const EditorData &data, m_formEditors)
data.formWindowEditor->syncXmlEditor(); data.formWindowEditor->formWindowFile()->syncXmlFromFormWindow();
} }
} // Internal } // Internal

View File

@@ -29,12 +29,12 @@
#include "formeditorw.h" #include "formeditorw.h"
#include "formwindoweditor.h" #include "formwindoweditor.h"
#include "formwindowfile.h"
#include "settingsmanager.h" #include "settingsmanager.h"
#include "settingspage.h" #include "settingspage.h"
#include "editorwidget.h" #include "editorwidget.h"
#include "editordata.h" #include "editordata.h"
#include "qtcreatorintegration.h" #include "qtcreatorintegration.h"
#include "designerxmleditorwidget.h"
#include "designercontext.h" #include "designercontext.h"
#include "resourcehandler.h" #include "resourcehandler.h"
#include <widgethost.h> #include <widgethost.h>
@@ -104,9 +104,45 @@ using namespace Designer::Constants;
namespace Designer { namespace Designer {
namespace Internal { 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 *FormEditorW::m_self = 0; static FormEditorW *m_self = 0;
FormEditorW::FormEditorW() : FormEditorW::FormEditorW() :
m_formeditor(QDesignerComponents::createFormEditor(0)), m_formeditor(QDesignerComponents::createFormEditor(0)),
@@ -154,6 +190,8 @@ FormEditorW::FormEditorW() :
this, SLOT(currentEditorChanged(Core::IEditor*))); this, SLOT(currentEditorChanged(Core::IEditor*)));
connect(m_shortcutMapper, SIGNAL(mapped(QObject*)), connect(m_shortcutMapper, SIGNAL(mapped(QObject*)),
this, SLOT(updateShortcut(QObject*))); this, SLOT(updateShortcut(QObject*)));
m_xmlEditorFactory = new FormWindowEditorFactory;
} }
FormEditorW::~FormEditorW() FormEditorW::~FormEditorW()
@@ -176,6 +214,7 @@ FormEditorW::~FormEditorW()
m_settingsPages.clear(); m_settingsPages.clear();
delete m_integration; delete m_integration;
delete m_xmlEditorFactory ;
m_self = 0; m_self = 0;
} }
@@ -633,15 +672,16 @@ EditorData FormEditorW::createEditor()
QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0); QDesignerFormWindowInterface *form = m_fwm->createFormWindow(0);
QTC_ASSERT(form, return data); QTC_ASSERT(form, return data);
connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int))); connect(form, SIGNAL(toolChanged(int)), this, SLOT(toolChanged(int)));
m_xmlEditorFactory->m_form = form;
ResourceHandler *resourceHandler = new ResourceHandler(form); ResourceHandler *resourceHandler = new ResourceHandler(form);
data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form); data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form);
DesignerXmlEditorWidget *xmlEditor = new DesignerXmlEditorWidget(form); data.formWindowEditor = qobject_cast<FormWindowEditor *>(m_xmlEditorFactory->createEditor());
data.formWindowEditor = xmlEditor->designerEditor(); connect(data.formWindowEditor->textDocument(), SIGNAL(filePathChanged(QString,QString)),
connect(data.formWindowEditor->document(), SIGNAL(filePathChanged(QString,QString)),
resourceHandler, SLOT(updateResources())); resourceHandler, SLOT(updateResources()));
m_editorWidget->add(data); m_editorWidget->add(data);
m_toolBar->addEditor(xmlEditor->designerEditor()); m_toolBar->addEditor(data.formWindowEditor);
return data; return data;
} }

View File

@@ -158,8 +158,6 @@ private:
Core::Id groupId = Core::Id()); Core::Id groupId = Core::Id());
QToolBar *createEditorToolBar() const; QToolBar *createEditorToolBar() const;
static FormEditorW *m_self;
QDesignerFormEditorInterface *m_formeditor; QDesignerFormEditorInterface *m_formeditor;
QDesignerIntegrationInterface *m_integration; QDesignerIntegrationInterface *m_integration;
QDesignerFormWindowManagerInterface *m_fwm; QDesignerFormWindowManagerInterface *m_fwm;

View File

@@ -31,7 +31,6 @@
#include "formwindowfile.h" #include "formwindowfile.h"
#include "designerconstants.h" #include "designerconstants.h"
#include "resourcehandler.h" #include "resourcehandler.h"
#include "designerxmleditorwidget.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <texteditor/basetextdocument.h> #include <texteditor/basetextdocument.h>
@@ -45,25 +44,23 @@
namespace Designer { namespace Designer {
FormWindowEditor::FormWindowEditor(TextEditor::BaseTextEditorWidget *widget) FormWindowEditor::FormWindowEditor()
{ {
setWidget(widget); addContext(Designer::Constants::K_DESIGNER_XML_EDITOR_ID);
setDuplicateSupported(false); addContext(Designer::Constants::C_DESIGNER_XML_EDITOR);
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);
} }
FormWindowEditor::~FormWindowEditor() 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) 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; return true;
} }
void FormWindowEditor::syncXmlEditor()
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormWindowEditor::syncXmlEditor" << formWindowFile()->filePath();
formWindowFile()->syncXmlFromFormWindow();
}
QWidget *FormWindowEditor::toolBar() QWidget *FormWindowEditor::toolBar()
{ {
return 0; return 0;
@@ -122,7 +112,7 @@ QString FormWindowEditor::contents() const
Internal::FormWindowFile *FormWindowEditor::formWindowFile() const Internal::FormWindowFile *FormWindowEditor::formWindowFile() const
{ {
return qobject_cast<Internal::FormWindowFile *>(const_cast<FormWindowEditor *>(this)->textDocument()); return qobject_cast<Internal::FormWindowFile *>(textDocument());
} }
bool FormWindowEditor::isDesignModePreferred() const bool FormWindowEditor::isDesignModePreferred() const

View File

@@ -34,15 +34,9 @@
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
QT_END_NAMESPACE
namespace Designer { namespace Designer {
namespace Internal { namespace Internal { class FormWindowFile; }
class FormWindowFile;
}
// IEditor that is used for the QDesignerFormWindowInterface // IEditor that is used for the QDesignerFormWindowInterface
// It is a read-only text editor that shows the XML of the form. // 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_PROPERTY(QString contents READ contents)
Q_OBJECT Q_OBJECT
public: public:
explicit FormWindowEditor(TextEditor::BaseTextEditorWidget *widget); FormWindowEditor();
virtual ~FormWindowEditor(); ~FormWindowEditor();
// IEditor void finalizeInitialization();
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName); bool open(QString *errorString, const QString &fileName, const QString &realFileName);
QWidget *toolBar();
virtual QWidget *toolBar(); bool isDesignModePreferred() const;
virtual bool isDesignModePreferred() const;
// For uic code model support // For uic code model support
QString contents() const; QString contents() const;
// Convenience access. // Convenience access.
Internal::FormWindowFile *formWindowFile() const; Internal::FormWindowFile *formWindowFile() const;
public slots:
void syncXmlEditor();
private slots:
void slotOpen(QString *errorString, const QString &fileName);
}; };
} // namespace Designer } // namespace Designer