diff --git a/src/plugins/qmldesigner/components/texteditor/texteditor.pri b/src/plugins/qmldesigner/components/texteditor/texteditor.pri index b683350cd96..ae66f38eef7 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditor.pri +++ b/src/plugins/qmldesigner/components/texteditor/texteditor.pri @@ -1,4 +1,5 @@ VPATH += $$PWD -SOURCES += texteditorview.cpp -HEADERS += texteditorview.h -#RESOURCES += texteditor.qrc +SOURCES += texteditorview.cpp \ + texteditorwidget.cpp +HEADERS += texteditorview.h \ + texteditorwidget.h diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp index b160aebbc17..8d6d80dfc08 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.cpp @@ -25,6 +25,8 @@ #include "texteditorview.h" +#include "texteditorwidget.h" + #include #include #include @@ -41,48 +43,22 @@ #include #include #include -#include #include namespace QmlDesigner { -class DummyWidget : public QWidget { -public: - DummyWidget(QWidget *parent = nullptr) : QWidget(parent) { - QBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); - } - void showEvent(QShowEvent *event) { - if (m_widget.isNull()) - setWidget(QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate()->widget()); - QWidget::showEvent(event); - } - -private: - void setWidget(QWidget *widget) { - if (m_widget) - m_widget->deleteLater(); - m_widget = widget; - - layout()->addWidget(widget); - } - QPointer m_widget; -}; - - TextEditorView::TextEditorView(QObject *parent) : AbstractView(parent) - , m_dummyWidget(new DummyWidget) + , m_widget(new TextEditorWidget(this)) { // not completely sure that we need this to just call the right help method -> - Internal::TextEditorContext *textEditorContext = new Internal::TextEditorContext(m_dummyWidget); + Internal::TextEditorContext *textEditorContext = new Internal::TextEditorContext(m_widget.get()); Core::ICore::addContextObject(textEditorContext); } TextEditorView::~TextEditorView() { - m_textEditor->deleteLater(); - m_dummyWidget->deleteLater(); + m_widget->deleteLater(); } void TextEditorView::modelAttached(Model *model) @@ -90,6 +66,7 @@ void TextEditorView::modelAttached(Model *model) Q_ASSERT(model); AbstractView::modelAttached(model); + m_widget->setTextEditor(qobject_cast(QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate())); } void TextEditorView::modelAboutToBeDetached(Model *model) @@ -119,15 +96,15 @@ void TextEditorView::nodeReparented(const ModelNode &/*node*/, const NodeAbstrac WidgetInfo TextEditorView::widgetInfo() { - return createWidgetInfo(m_dummyWidget, 0, "TextEditor", WidgetInfo::CentralPane, 0, tr("Text Editor")); + return createWidgetInfo(m_widget.get(), 0, "TextEditor", WidgetInfo::CentralPane, 0, tr("Text Editor")); } QString TextEditorView::contextHelpId() const { - if (m_textEditor) { - QString contextHelpId = m_textEditor->contextHelpId(); + if (m_widget->textEditor()) { + QString contextHelpId = m_widget->textEditor()->contextHelpId(); if (!contextHelpId.isEmpty()) - return m_textEditor->contextHelpId(); + return m_widget->textEditor()->contextHelpId(); } return AbstractView::contextHelpId(); } @@ -206,5 +183,6 @@ void TextEditorView::rewriterEndTransaction() void TextEditorView::instancePropertyChanged(const QList > &/*propertyList*/) { } -} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorview.h b/src/plugins/qmldesigner/components/texteditor/texteditorview.h index fe5587bccb3..2c18f178c1a 100644 --- a/src/plugins/qmldesigner/components/texteditor/texteditorview.h +++ b/src/plugins/qmldesigner/components/texteditor/texteditorview.h @@ -26,12 +26,16 @@ #include +#include + namespace TextEditor { class BaseTextEditor; } namespace Utils { class CrumblePath; } namespace QmlDesigner { +class TextEditorWidget; + class QMLDESIGNERCORE_EXPORT TextEditorView : public AbstractView { Q_OBJECT @@ -84,8 +88,7 @@ public: void deActivateItemCreator(); private: - QPointer m_textEditor; - QWidget *m_dummyWidget = 0; + std::unique_ptr m_widget; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp new file mode 100644 index 00000000000..ad25fab0f4c --- /dev/null +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "texteditorwidget.h" + +#include + +#include + +namespace QmlDesigner { + +TextEditorWidget::TextEditorWidget(TextEditorView *textEditorView) : QWidget() + , m_textEditorView(textEditorView) + +{ + QBoxLayout *layout = new QVBoxLayout(this); + layout->setMargin(0); +} + +void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor) { + m_textEditor.reset(textEditor); + layout()->addWidget(textEditor->widget()); +} + +QString TextEditorWidget::contextHelpId() const +{ + return m_textEditorView->contextHelpId(); +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h new file mode 100644 index 00000000000..5093cfe7ed6 --- /dev/null +++ b/src/plugins/qmldesigner/components/texteditor/texteditorwidget.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ +#pragma once + +#include + +#include + +#include + +namespace QmlDesigner { + +class TextEditorView; + +class TextEditorWidget : public QWidget { + + Q_OBJECT + +public: + TextEditorWidget(TextEditorView *textEditorView); + + void setTextEditor(TextEditor::BaseTextEditor *textEditor); + + TextEditor::BaseTextEditor *textEditor() const + { + return m_textEditor.get(); + } + + QString contextHelpId() const; + +private: + std::unique_ptr m_textEditor; + QPointer m_textEditorView; +}; + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/qmldesignerplugin.qbs b/src/plugins/qmldesigner/qmldesignerplugin.qbs index 9a80c276916..23587235d75 100644 --- a/src/plugins/qmldesigner/qmldesignerplugin.qbs +++ b/src/plugins/qmldesigner/qmldesignerplugin.qbs @@ -400,6 +400,8 @@ Project { "componentcore/qmldesignericonprovider.h", "texteditor/texteditorview.cpp", "texteditor/texteditorview.h", + "texteditor/texteditorwidget.cpp", + "texteditor/texteditorwidget.h", "debugview/debugview.cpp", "debugview/debugview.h", "debugview/debugviewwidget.cpp",