OSDN Git Service

2f3bb0ccdbd1b3d525efe9e0d1dbff9e5bad3034
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / model / componenttextmodifier.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "componenttextmodifier.h"
35
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)
42 {
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()));
45
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 &)));
48 }
49
50 ComponentTextModifier::~ComponentTextModifier()
51 {
52 }
53
54 void ComponentTextModifier::replace(int offset, int length, const QString& replacement)
55 {
56     m_originalModifier->replace(offset, length, replacement);
57 }
58
59 void ComponentTextModifier::move(const MoveInfo &moveInfo)
60 {
61     m_originalModifier->move(moveInfo);
62 }
63
64 void ComponentTextModifier::indent(int offset, int length)
65 {
66     m_originalModifier->indent(offset, length);
67 }
68
69 int ComponentTextModifier::indentDepth() const
70 {
71     return m_originalModifier->indentDepth();
72 }
73
74 void ComponentTextModifier::startGroup()
75 {
76     m_originalModifier->startGroup();
77 }
78
79 void ComponentTextModifier::flushGroup()
80 {
81     m_originalModifier->flushGroup();
82 }
83
84 void ComponentTextModifier::commitGroup()
85 {
86     m_originalModifier->commitGroup();
87 }
88
89 QTextDocument *ComponentTextModifier::textDocument() const
90 {
91     return m_originalModifier->textDocument();
92 }
93
94 QString ComponentTextModifier::text() const
95 {
96     QString txt(m_originalModifier->text());
97
98     const int leader = m_componentStartOffset - m_rootStartOffset;
99     txt.replace(m_rootStartOffset, leader, QString(leader, ' '));
100
101     const int textLength = txt.size();
102     const int trailer = textLength - m_componentEndOffset;
103     txt.replace(m_componentEndOffset, trailer, QString(trailer, ' '));
104
105     return txt;
106 }
107
108 QTextCursor ComponentTextModifier::textCursor() const
109 {
110     return m_originalModifier->textCursor();
111 }
112
113 void ComponentTextModifier::deactivateChangeSignals()
114 {
115     m_originalModifier->deactivateChangeSignals();
116 }
117
118 void ComponentTextModifier::reactivateChangeSignals()
119 {
120     m_originalModifier->reactivateChangeSignals();
121 }
122
123 void ComponentTextModifier::contentsChange(int position, int charsRemoved, int charsAdded)
124 {
125     const int diff = charsAdded - charsRemoved;
126
127     if (position < m_rootStartOffset) {
128         m_rootStartOffset += diff;
129     }
130
131     if (position < m_componentStartOffset) {
132         m_componentStartOffset += diff;
133     }
134
135     if (position < m_componentEndOffset) {
136         m_componentEndOffset += diff;
137     }
138 }
139
140 QmlJS::Snapshot ComponentTextModifier::getSnapshot() const
141 { return m_originalModifier->getSnapshot(); }
142
143 QStringList ComponentTextModifier::importPaths() const
144 { return m_originalModifier->importPaths(); }