1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "componenttextmodifier.h"
36 using namespace QmlDesigner;
37 ComponentTextModifier::ComponentTextModifier(TextModifier *originalModifier, int componentStartOffset, int componentEndOffset, int rootStartOffset) :
38 m_originalModifier(originalModifier),
39 m_componentStartOffset(componentStartOffset),
40 m_componentEndOffset(componentEndOffset),
41 m_rootStartOffset(rootStartOffset)
43 connect(m_originalModifier->textDocument(), SIGNAL(contentsChange(int,int,int)), this, SLOT(contentsChange(int,int,int)));
44 connect(m_originalModifier, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
46 connect(m_originalModifier, SIGNAL(replaced(int, int, int)), this, SIGNAL(replaced(int, int, int)));
47 connect(m_originalModifier, SIGNAL(moved(const TextModifier::MoveInfo &)), this, SIGNAL(moved(const TextModifier::MoveInfo &)));
50 ComponentTextModifier::~ComponentTextModifier()
54 void ComponentTextModifier::replace(int offset, int length, const QString& replacement)
56 m_originalModifier->replace(offset, length, replacement);
59 void ComponentTextModifier::move(const MoveInfo &moveInfo)
61 m_originalModifier->move(moveInfo);
64 void ComponentTextModifier::indent(int offset, int length)
66 m_originalModifier->indent(offset, length);
69 int ComponentTextModifier::indentDepth() const
71 return m_originalModifier->indentDepth();
74 void ComponentTextModifier::startGroup()
76 m_originalModifier->startGroup();
79 void ComponentTextModifier::flushGroup()
81 m_originalModifier->flushGroup();
84 void ComponentTextModifier::commitGroup()
86 m_originalModifier->commitGroup();
89 QTextDocument *ComponentTextModifier::textDocument() const
91 return m_originalModifier->textDocument();
94 QString ComponentTextModifier::text() const
96 QString txt(m_originalModifier->text());
98 const int leader = m_componentStartOffset - m_rootStartOffset;
99 txt.replace(m_rootStartOffset, leader, QString(leader, ' '));
101 const int textLength = txt.size();
102 const int trailer = textLength - m_componentEndOffset;
103 txt.replace(m_componentEndOffset, trailer, QString(trailer, ' '));
108 QTextCursor ComponentTextModifier::textCursor() const
110 return m_originalModifier->textCursor();
113 void ComponentTextModifier::deactivateChangeSignals()
115 m_originalModifier->deactivateChangeSignals();
118 void ComponentTextModifier::reactivateChangeSignals()
120 m_originalModifier->reactivateChangeSignals();
123 void ComponentTextModifier::contentsChange(int position, int charsRemoved, int charsAdded)
125 const int diff = charsAdded - charsRemoved;
127 if (position < m_rootStartOffset) {
128 m_rootStartOffset += diff;
131 if (position < m_componentStartOffset) {
132 m_componentStartOffset += diff;
135 if (position < m_componentEndOffset) {
136 m_componentEndOffset += diff;
140 QmlJS::Snapshot ComponentTextModifier::getSnapshot() const
141 { return m_originalModifier->getSnapshot(); }
143 QStringList ComponentTextModifier::importPaths() const
144 { return m_originalModifier->importPaths(); }