forked from qt-creator/qt-creator
QmlDesigner: Refactoring TextEditorView
* Using smart pointers * Renaming DummyWidget to TextEditorWidget * Moving TextEditorWidget to separate file Change-Id: Idbe0e50f976bf39beac8632d4254d6d9a5afd5b2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
VPATH += $$PWD
|
VPATH += $$PWD
|
||||||
SOURCES += texteditorview.cpp
|
SOURCES += texteditorview.cpp \
|
||||||
HEADERS += texteditorview.h
|
texteditorwidget.cpp
|
||||||
#RESOURCES += texteditor.qrc
|
HEADERS += texteditorview.h \
|
||||||
|
texteditorwidget.h
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "texteditorview.h"
|
#include "texteditorview.h"
|
||||||
|
|
||||||
|
#include "texteditorwidget.h"
|
||||||
|
|
||||||
#include <designmodecontext.h>
|
#include <designmodecontext.h>
|
||||||
#include <designdocument.h>
|
#include <designdocument.h>
|
||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
@@ -41,48 +43,22 @@
|
|||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
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<QWidget> m_widget;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
TextEditorView::TextEditorView(QObject *parent)
|
TextEditorView::TextEditorView(QObject *parent)
|
||||||
: AbstractView(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 ->
|
// 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);
|
Core::ICore::addContextObject(textEditorContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditorView::~TextEditorView()
|
TextEditorView::~TextEditorView()
|
||||||
{
|
{
|
||||||
m_textEditor->deleteLater();
|
m_widget->deleteLater();
|
||||||
m_dummyWidget->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorView::modelAttached(Model *model)
|
void TextEditorView::modelAttached(Model *model)
|
||||||
@@ -90,6 +66,7 @@ void TextEditorView::modelAttached(Model *model)
|
|||||||
Q_ASSERT(model);
|
Q_ASSERT(model);
|
||||||
|
|
||||||
AbstractView::modelAttached(model);
|
AbstractView::modelAttached(model);
|
||||||
|
m_widget->setTextEditor(qobject_cast<TextEditor::BaseTextEditor*>(QmlDesignerPlugin::instance()->currentDesignDocument()->textEditor()->duplicate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorView::modelAboutToBeDetached(Model *model)
|
void TextEditorView::modelAboutToBeDetached(Model *model)
|
||||||
@@ -119,15 +96,15 @@ void TextEditorView::nodeReparented(const ModelNode &/*node*/, const NodeAbstrac
|
|||||||
|
|
||||||
WidgetInfo TextEditorView::widgetInfo()
|
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
|
QString TextEditorView::contextHelpId() const
|
||||||
{
|
{
|
||||||
if (m_textEditor) {
|
if (m_widget->textEditor()) {
|
||||||
QString contextHelpId = m_textEditor->contextHelpId();
|
QString contextHelpId = m_widget->textEditor()->contextHelpId();
|
||||||
if (!contextHelpId.isEmpty())
|
if (!contextHelpId.isEmpty())
|
||||||
return m_textEditor->contextHelpId();
|
return m_widget->textEditor()->contextHelpId();
|
||||||
}
|
}
|
||||||
return AbstractView::contextHelpId();
|
return AbstractView::contextHelpId();
|
||||||
}
|
}
|
||||||
@@ -206,5 +183,6 @@ void TextEditorView::rewriterEndTransaction()
|
|||||||
void TextEditorView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &/*propertyList*/)
|
void TextEditorView::instancePropertyChanged(const QList<QPair<ModelNode, PropertyName> > &/*propertyList*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
} // namespace QmlDesigner
|
||||||
|
|
||||||
|
@@ -26,12 +26,16 @@
|
|||||||
|
|
||||||
#include <abstractview.h>
|
#include <abstractview.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
namespace TextEditor { class BaseTextEditor; }
|
||||||
|
|
||||||
namespace Utils { class CrumblePath; }
|
namespace Utils { class CrumblePath; }
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class TextEditorWidget;
|
||||||
|
|
||||||
class QMLDESIGNERCORE_EXPORT TextEditorView : public AbstractView
|
class QMLDESIGNERCORE_EXPORT TextEditorView : public AbstractView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -84,8 +88,7 @@ public:
|
|||||||
void deActivateItemCreator();
|
void deActivateItemCreator();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<TextEditor::BaseTextEditor> m_textEditor;
|
std::unique_ptr<TextEditorWidget> m_widget;
|
||||||
QWidget *m_dummyWidget = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -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 <texteditorview.h>
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
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
|
@@ -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 <texteditor/texteditor.h>
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
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<TextEditor::BaseTextEditor> m_textEditor;
|
||||||
|
QPointer<TextEditorView> m_textEditorView;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QmlDesigner
|
@@ -400,6 +400,8 @@ Project {
|
|||||||
"componentcore/qmldesignericonprovider.h",
|
"componentcore/qmldesignericonprovider.h",
|
||||||
"texteditor/texteditorview.cpp",
|
"texteditor/texteditorview.cpp",
|
||||||
"texteditor/texteditorview.h",
|
"texteditor/texteditorview.h",
|
||||||
|
"texteditor/texteditorwidget.cpp",
|
||||||
|
"texteditor/texteditorwidget.h",
|
||||||
"debugview/debugview.cpp",
|
"debugview/debugview.cpp",
|
||||||
"debugview/debugview.h",
|
"debugview/debugview.h",
|
||||||
"debugview/debugviewwidget.cpp",
|
"debugview/debugviewwidget.cpp",
|
||||||
|
Reference in New Issue
Block a user