From a6b1fb94e657daa0b7bc72362377d3308c050cb5 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen <erik.verbruggen@nokia.com> Date: Mon, 8 Feb 2010 14:27:42 +0100 Subject: [PATCH] Moved Creator specific code to a subclas. --- .../integration/designdocumentcontroller.cpp | 6 +- .../designdocumentcontrollerview.cpp | 6 +- src/plugins/qmldesigner/core/core.pri | 2 + .../core/include/plaintexteditmodifier.h | 6 +- .../core/model/basetexteditmodifier.cpp | 60 +++++++++++++++++++ .../core/model/plaintexteditmodifier.cpp | 22 ------- 6 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp diff --git a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp index 08a68a47132..bd0e94a3d25 100644 --- a/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocumentcontroller.cpp @@ -40,7 +40,7 @@ #include <stateseditorwidget.h> #include <formeditorview.h> #include <formeditorwidget.h> -#include <plaintexteditmodifier.h> +#include <basetexteditmodifier.h> #include <componenttextmodifier.h> #include <metainfo.h> #include <invalidargumentexception.h> @@ -92,7 +92,7 @@ public: QWeakPointer<QmlDesigner::Model> masterModel; QWeakPointer<QPlainTextEdit> textEdit; QWeakPointer<RewriterView> rewriterView; - QmlDesigner::PlainTextEditModifier *textModifier; + QmlDesigner::BaseTextEditModifier *textModifier; QmlDesigner::ComponentTextModifier *componentTextModifier; QWeakPointer<SubComponentManager> subComponentManager; QWeakPointer<Internal::ViewLogger> viewLogger; @@ -326,7 +326,7 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit * connect(edit, SIGNAL(modificationChanged(bool)), this, SIGNAL(dirtyStateChanged(bool))); - m_d->textModifier = new PlainTextEditModifier(m_d->textEdit.data()); + m_d->textModifier = new BaseTextEditModifier(m_d->textEdit.data()); m_d->componentTextModifier = 0; diff --git a/src/plugins/qmldesigner/components/integration/designdocumentcontrollerview.cpp b/src/plugins/qmldesigner/components/integration/designdocumentcontrollerview.cpp index 250ae85847c..dc1fe48b2f7 100644 --- a/src/plugins/qmldesigner/components/integration/designdocumentcontrollerview.cpp +++ b/src/plugins/qmldesigner/components/integration/designdocumentcontrollerview.cpp @@ -29,7 +29,7 @@ #include "designdocumentcontrollerview.h" #include <rewriterview.h> -#include <plaintexteditmodifier.h> +#include <basetexteditmodifier.h> #include <metainfo.h> #include <QApplication> @@ -102,7 +102,7 @@ QString DesignDocumentControllerView::toText() const outputModel->setMetaInfo(model()->metaInfo()); QPlainTextEdit textEdit; textEdit.setPlainText("import Qt 4.6; Item {}"); - PlainTextEditModifier modifier(&textEdit); + BaseTextEditModifier modifier(&textEdit); QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0)); rewriterView->setTextModifier(&modifier); @@ -126,7 +126,7 @@ void DesignDocumentControllerView::fromText(QString text) QPlainTextEdit textEdit; QString imports("import Qt 4.6;\n"); textEdit.setPlainText(imports + text); - PlainTextEditModifier modifier(&textEdit); + BaseTextEditModifier modifier(&textEdit); QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0)); rewriterView->setTextModifier(&modifier); diff --git a/src/plugins/qmldesigner/core/core.pri b/src/plugins/qmldesigner/core/core.pri index caadc846138..128696b6746 100644 --- a/src/plugins/qmldesigner/core/core.pri +++ b/src/plugins/qmldesigner/core/core.pri @@ -74,6 +74,7 @@ SOURCES += $$PWD/model/abstractview.cpp \ $$PWD/model/modeltotextmerger.cpp \ $$PWD/model/texttomodelmerger.cpp \ $$PWD/model/plaintexteditmodifier.cpp \ + $$PWD/model/basetexteditmodifier.cpp \ $$PWD/model/componenttextmodifier.cpp \ $$PWD/model/textmodifier.cpp \ $$PWD/model/qmlmodelview.cpp \ @@ -158,6 +159,7 @@ HEADERS += $$PWD/include/corelib_global.h \ $$PWD/model/internalnodeabstractproperty.h \ $$PWD/include/nodeabstractproperty.h \ $$PWD/include/plaintexteditmodifier.h \ + $$PWD/include/basetexteditmodifier.h \ $$PWD/include/componenttextmodifier.h \ $$PWD/include/textmodifier.h \ $$PWD/model/modeltotextmerger.h \ diff --git a/src/plugins/qmldesigner/core/include/plaintexteditmodifier.h b/src/plugins/qmldesigner/core/include/plaintexteditmodifier.h index a7090f9fdad..503b8924642 100644 --- a/src/plugins/qmldesigner/core/include/plaintexteditmodifier.h +++ b/src/plugins/qmldesigner/core/include/plaintexteditmodifier.h @@ -64,7 +64,7 @@ public: virtual void replace(int offset, int length, const QString &replacement); virtual void move(const MoveInfo &moveInfo); - virtual void indent(int offset, int length); + virtual void indent(int offset, int length) = 0; virtual void startGroup(); virtual void flushGroup(); @@ -73,6 +73,10 @@ public: virtual void deactivateChangeSignals(); virtual void reactivateChangeSignals(); +protected: + QPlainTextEdit *plainTextEdit() const + { return m_textEdit; } + private slots: void textEditChanged(); diff --git a/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp b/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp new file mode 100644 index 00000000000..89ac19b73a5 --- /dev/null +++ b/src/plugins/qmldesigner/core/model/basetexteditmodifier.cpp @@ -0,0 +1,60 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "basetexteditmodifier.h" + +#include <texteditor/basetexteditor.h> + +using namespace QmlDesigner; + +BaseTextEditModifier::BaseTextEditModifier(QPlainTextEdit *textEdit): + PlainTextEditModifier(textEdit) +{ +} + +void BaseTextEditModifier::indent(int offset, int length) +{ + if (length == 0 || offset < 0 || offset + length >= text().length()) + return; + +// qDebug() << "PlainTextEditModifier::indent(" << offset << "," << length << ")"; + if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(plainTextEdit())) { +// qDebug() << "**** Doing indentation"; + // find the applicable block: + QTextDocument *doc = bte->document(); + QTextCursor tc(doc); + tc.beginEditBlock(); + tc.setPosition(offset); + tc.setPosition(offset + length, QTextCursor::KeepAnchor); + bte->indentInsertedText(tc); + tc.endEditBlock(); + } else { +// qDebug() << "**** Skipping indentation"; + } +} diff --git a/src/plugins/qmldesigner/core/model/plaintexteditmodifier.cpp b/src/plugins/qmldesigner/core/model/plaintexteditmodifier.cpp index 5ed763a388d..4eb5512da9f 100644 --- a/src/plugins/qmldesigner/core/model/plaintexteditmodifier.cpp +++ b/src/plugins/qmldesigner/core/model/plaintexteditmodifier.cpp @@ -29,7 +29,6 @@ #include "plaintexteditmodifier.h" -#include <texteditor/basetexteditor.h> #include <utils/changeset.h> #include <QtGui/QPlainTextEdit> @@ -113,27 +112,6 @@ void PlainTextEditModifier::move(const MoveInfo &moveInfo) } } -void PlainTextEditModifier::indent(int offset, int length) -{ - if (length == 0 || offset < 0 || offset + length >= text().length()) - return; - -// qDebug() << "PlainTextEditModifier::indent(" << offset << "," << length << ")"; - if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(m_textEdit)) { -// qDebug() << "**** Doing indentation"; - // find the applicable block: - QTextDocument *doc = bte->document(); - QTextCursor tc(doc); - tc.beginEditBlock(); - tc.setPosition(offset); - tc.setPosition(offset + length, QTextCursor::KeepAnchor); - bte->indentInsertedText(tc); - tc.endEditBlock(); - } else { -// qDebug() << "**** Skipping indentation"; - } -} - void PlainTextEditModifier::startGroup() { if (!m_changeSet) -- GitLab