OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / model / rewriteaction.h
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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef REWRITEACTION_H
34 #define REWRITEACTION_H
35
36 #include "abstractproperty.h"
37 #include "modelnodepositionstorage.h"
38
39 #include <filemanager/qmlrefactoring.h>
40
41 namespace QmlDesigner {
42 namespace Internal {
43
44 class AddImportRewriteAction;
45 class AddPropertyRewriteAction;
46 class ChangeIdRewriteAction;
47 class ChangePropertyRewriteAction;
48 class ChangeTypeRewriteAction;
49 class RemoveImportRewriteAction;
50 class RemoveNodeRewriteAction;
51 class RemovePropertyRewriteAction;
52 class ReparentNodeRewriteAction;
53 class MoveNodeRewriteAction;
54
55 class RewriteAction
56 {
57 public:
58     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore) = 0;
59     virtual QString info() const = 0;
60
61     virtual AddImportRewriteAction *asAddImportRewriteAction() { return 0; }
62     virtual AddPropertyRewriteAction *asAddPropertyRewriteAction() { return 0; }
63     virtual ChangeIdRewriteAction *asChangeIdRewriteAction() { return 0; }
64     virtual ChangePropertyRewriteAction *asChangePropertyRewriteAction() { return 0; }
65     virtual ChangeTypeRewriteAction *asChangeTypeRewriteAction() { return 0; }
66     virtual RemoveImportRewriteAction * asRemoveImportRewriteAction() { return 0; }
67     virtual RemoveNodeRewriteAction *asRemoveNodeRewriteAction() { return 0; }
68     virtual RemovePropertyRewriteAction *asRemovePropertyRewriteAction() { return 0; }
69     virtual ReparentNodeRewriteAction *asReparentNodeRewriteAction() { return 0; }
70     virtual MoveNodeRewriteAction *asMoveNodeRewriteAction() { return 0; }
71     virtual ~RewriteAction() {}
72
73 protected:
74     RewriteAction()
75     {}
76
77 private:
78     RewriteAction(const RewriteAction &);
79     RewriteAction &operator=(const RewriteAction&);
80 };
81
82 class AddPropertyRewriteAction: public RewriteAction
83 {
84 public:
85     AddPropertyRewriteAction(const AbstractProperty &property, const QString &valueText, QmlDesigner::QmlRefactoring::PropertyType propertyType, const ModelNode &containedModelNode/* = ModelNode()*/):
86             m_property(property), m_valueText(valueText), m_propertyType(propertyType), m_containedModelNode(containedModelNode)
87     {}
88
89     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
90     virtual QString info() const;
91
92     virtual AddPropertyRewriteAction *asAddPropertyRewriteAction() { return this; }
93
94     AbstractProperty property() const
95     { return m_property; }
96
97     QString valueText() const
98     { return m_valueText; }
99
100     QmlDesigner::QmlRefactoring::PropertyType propertyType() const
101     { return m_propertyType; }
102
103     ModelNode containedModelNode() const
104     { return m_containedModelNode; }
105
106 private:
107     AbstractProperty m_property;
108     QString m_valueText;
109     QmlDesigner::QmlRefactoring::PropertyType m_propertyType;
110     ModelNode m_containedModelNode;
111 };
112
113 class ChangeIdRewriteAction: public RewriteAction
114 {
115 public:
116     ChangeIdRewriteAction(const ModelNode &node, const QString &oldId, const QString &newId):
117             m_node(node), m_oldId(oldId), m_newId(newId)
118     {}
119
120     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
121     virtual QString info() const;
122
123     virtual ChangeIdRewriteAction *asChangeIdRewriteAction() { return this; }
124
125     ModelNode node() const
126     { return m_node; }
127
128 private:
129     ModelNode m_node;
130     QString m_oldId;
131     QString m_newId;
132 };
133
134 class ChangePropertyRewriteAction: public RewriteAction
135 {
136 public:
137     ChangePropertyRewriteAction(const AbstractProperty &property, const QString &valueText, QmlDesigner::QmlRefactoring::PropertyType propertyType, const ModelNode &containedModelNode/* = ModelNode()*/):
138             m_property(property), m_valueText(valueText), m_propertyType(propertyType), m_containedModelNode(containedModelNode)
139     {}
140
141     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
142     virtual QString info() const;
143
144     virtual ChangePropertyRewriteAction *asChangePropertyRewriteAction() { return this; }
145
146     AbstractProperty property() const
147     { return m_property; }
148
149     QString valueText() const
150     { return m_valueText; }
151
152     QmlDesigner::QmlRefactoring::PropertyType propertyType() const
153     { return m_propertyType; }
154
155     ModelNode containedModelNode() const
156     { return m_containedModelNode; }
157
158 private:
159     AbstractProperty m_property;
160     QString m_valueText;
161     QmlDesigner::QmlRefactoring::PropertyType m_propertyType;
162     ModelNode m_containedModelNode;
163 };
164
165 class ChangeTypeRewriteAction:public RewriteAction
166 {
167 public:
168     ChangeTypeRewriteAction(const ModelNode &node):
169             m_node(node)
170     {}
171
172     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
173     virtual QString info() const;
174
175     virtual ChangeTypeRewriteAction *asChangeTypeRewriteAction() { return this; }
176
177     ModelNode node() const
178     { return m_node; }
179
180 private:
181     ModelNode m_node;
182 };
183
184 class RemoveNodeRewriteAction: public RewriteAction
185 {
186 public:
187     RemoveNodeRewriteAction(const ModelNode &node):
188             m_node(node)
189     {}
190
191     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
192     virtual QString info() const;
193
194     virtual RemoveNodeRewriteAction *asRemoveNodeRewriteAction() { return this; }
195
196     ModelNode node() const
197     { return m_node; }
198
199 private:
200     ModelNode m_node;
201 };
202
203 class RemovePropertyRewriteAction: public RewriteAction
204 {
205 public:
206     RemovePropertyRewriteAction(const AbstractProperty &property):
207             m_property(property)
208     {}
209
210     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
211     virtual QString info() const;
212
213     virtual RemovePropertyRewriteAction *asRemovePropertyRewriteAction() { return this; }
214
215     AbstractProperty property() const
216     { return m_property; }
217
218 private:
219     AbstractProperty m_property;
220 };
221
222 class ReparentNodeRewriteAction: public RewriteAction
223 {
224 public:
225     ReparentNodeRewriteAction(const ModelNode &node, const AbstractProperty &oldParentProperty, const AbstractProperty &targetProperty, QmlDesigner::QmlRefactoring::PropertyType propertyType):
226             m_node(node), m_oldParentProperty(oldParentProperty), m_targetProperty(targetProperty), m_propertyType(propertyType)
227     {}
228
229     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
230     virtual QString info() const;
231
232     virtual ReparentNodeRewriteAction *asReparentNodeRewriteAction() { return this; }
233
234     ModelNode reparentedNode() const
235     { return m_node; }
236
237     void setOldParentProperty(const AbstractProperty &oldParentProperty)
238     { m_oldParentProperty = oldParentProperty; }
239
240     AbstractProperty oldParentProperty() const
241     { return m_oldParentProperty; }
242
243     AbstractProperty targetProperty() const
244     { return m_targetProperty; }
245
246     QmlDesigner::QmlRefactoring::PropertyType propertyType() const
247     { return m_propertyType; }
248
249 private:
250     ModelNode m_node;
251     AbstractProperty m_oldParentProperty;
252     AbstractProperty m_targetProperty;
253     QmlDesigner::QmlRefactoring::PropertyType m_propertyType;
254 };
255
256 class MoveNodeRewriteAction: public RewriteAction
257 {
258 public:
259     MoveNodeRewriteAction(const ModelNode &movingNode, const ModelNode &newTrailingNode):
260             m_movingNode(movingNode), m_newTrailingNode(newTrailingNode)
261     {}
262
263     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
264     virtual QString info() const;
265
266     virtual MoveNodeRewriteAction *asMoveNodeRewriteAction() { return this; }
267
268 private:
269     ModelNode m_movingNode;
270     ModelNode m_newTrailingNode;
271 };
272
273 class AddImportRewriteAction: public RewriteAction
274 {
275 public:
276     AddImportRewriteAction(const Import &import):
277             m_import(import)
278     {}
279
280     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
281     virtual QString info() const;
282
283     virtual AddImportRewriteAction *asAddImportRewriteAction() { return this; }
284
285     Import import() const { return m_import; }
286
287 private:
288     Import m_import;
289 };
290
291 class RemoveImportRewriteAction: public RewriteAction
292 {
293 public:
294     RemoveImportRewriteAction(const Import &import):
295             m_import(import)
296     {}
297
298     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
299     virtual QString info() const;
300
301     virtual RemoveImportRewriteAction *asRemoveImportRewriteAction() { return this; }
302
303     Import import() const { return m_import; }
304
305 private:
306     Import m_import;
307 };
308
309 } // namespace Internal
310 } // namespace QmlDesigner
311
312 #endif // REWRITEACTION_H