OSDN Git Service

It's 2011 now.
[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 (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 #ifndef REWRITEACTION_H
35 #define REWRITEACTION_H
36
37 #include "abstractproperty.h"
38 #include "modelnodepositionstorage.h"
39
40 #include <filemanager/qmlrefactoring.h>
41
42 namespace QmlDesigner {
43 namespace Internal {
44
45 class AddImportRewriteAction;
46 class AddPropertyRewriteAction;
47 class ChangeIdRewriteAction;
48 class ChangePropertyRewriteAction;
49 class ChangeTypeRewriteAction;
50 class RemoveImportRewriteAction;
51 class RemoveNodeRewriteAction;
52 class RemovePropertyRewriteAction;
53 class ReparentNodeRewriteAction;
54 class MoveNodeRewriteAction;
55
56 class RewriteAction
57 {
58 public:
59     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore) = 0;
60     virtual QString info() const = 0;
61
62     virtual AddImportRewriteAction *asAddImportRewriteAction() { return 0; }
63     virtual AddPropertyRewriteAction *asAddPropertyRewriteAction() { return 0; }
64     virtual ChangeIdRewriteAction *asChangeIdRewriteAction() { return 0; }
65     virtual ChangePropertyRewriteAction *asChangePropertyRewriteAction() { return 0; }
66     virtual ChangeTypeRewriteAction *asChangeTypeRewriteAction() { return 0; }
67     virtual RemoveImportRewriteAction * asRemoveImportRewriteAction() { return 0; }
68     virtual RemoveNodeRewriteAction *asRemoveNodeRewriteAction() { return 0; }
69     virtual RemovePropertyRewriteAction *asRemovePropertyRewriteAction() { return 0; }
70     virtual ReparentNodeRewriteAction *asReparentNodeRewriteAction() { return 0; }
71     virtual MoveNodeRewriteAction *asMoveNodeRewriteAction() { return 0; }
72     virtual ~RewriteAction() {}
73
74 protected:
75     RewriteAction()
76     {}
77
78 private:
79     RewriteAction(const RewriteAction &);
80     RewriteAction &operator=(const RewriteAction&);
81 };
82
83 class AddPropertyRewriteAction: public RewriteAction
84 {
85 public:
86     AddPropertyRewriteAction(const AbstractProperty &property, const QString &valueText, QmlDesigner::QmlRefactoring::PropertyType propertyType, const ModelNode &containedModelNode/* = ModelNode()*/):
87             m_property(property), m_valueText(valueText), m_propertyType(propertyType), m_containedModelNode(containedModelNode)
88     {}
89
90     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
91     virtual QString info() const;
92
93     virtual AddPropertyRewriteAction *asAddPropertyRewriteAction() { return this; }
94
95     AbstractProperty property() const
96     { return m_property; }
97
98     QString valueText() const
99     { return m_valueText; }
100
101     QmlDesigner::QmlRefactoring::PropertyType propertyType() const
102     { return m_propertyType; }
103
104     ModelNode containedModelNode() const
105     { return m_containedModelNode; }
106
107 private:
108     AbstractProperty m_property;
109     QString m_valueText;
110     QmlDesigner::QmlRefactoring::PropertyType m_propertyType;
111     ModelNode m_containedModelNode;
112 };
113
114 class ChangeIdRewriteAction: public RewriteAction
115 {
116 public:
117     ChangeIdRewriteAction(const ModelNode &node, const QString &oldId, const QString &newId):
118             m_node(node), m_oldId(oldId), m_newId(newId)
119     {}
120
121     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
122     virtual QString info() const;
123
124     virtual ChangeIdRewriteAction *asChangeIdRewriteAction() { return this; }
125
126     ModelNode node() const
127     { return m_node; }
128
129 private:
130     ModelNode m_node;
131     QString m_oldId;
132     QString m_newId;
133 };
134
135 class ChangePropertyRewriteAction: public RewriteAction
136 {
137 public:
138     ChangePropertyRewriteAction(const AbstractProperty &property, const QString &valueText, QmlDesigner::QmlRefactoring::PropertyType propertyType, const ModelNode &containedModelNode/* = ModelNode()*/):
139             m_property(property), m_valueText(valueText), m_propertyType(propertyType), m_containedModelNode(containedModelNode)
140     {}
141
142     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
143     virtual QString info() const;
144
145     virtual ChangePropertyRewriteAction *asChangePropertyRewriteAction() { return this; }
146
147     AbstractProperty property() const
148     { return m_property; }
149
150     QString valueText() const
151     { return m_valueText; }
152
153     QmlDesigner::QmlRefactoring::PropertyType propertyType() const
154     { return m_propertyType; }
155
156     ModelNode containedModelNode() const
157     { return m_containedModelNode; }
158
159 private:
160     AbstractProperty m_property;
161     QString m_valueText;
162     QmlDesigner::QmlRefactoring::PropertyType m_propertyType;
163     ModelNode m_containedModelNode;
164 };
165
166 class ChangeTypeRewriteAction:public RewriteAction
167 {
168 public:
169     ChangeTypeRewriteAction(const ModelNode &node):
170             m_node(node)
171     {}
172
173     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
174     virtual QString info() const;
175
176     virtual ChangeTypeRewriteAction *asChangeTypeRewriteAction() { return this; }
177
178     ModelNode node() const
179     { return m_node; }
180
181 private:
182     ModelNode m_node;
183 };
184
185 class RemoveNodeRewriteAction: public RewriteAction
186 {
187 public:
188     RemoveNodeRewriteAction(const ModelNode &node):
189             m_node(node)
190     {}
191
192     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
193     virtual QString info() const;
194
195     virtual RemoveNodeRewriteAction *asRemoveNodeRewriteAction() { return this; }
196
197     ModelNode node() const
198     { return m_node; }
199
200 private:
201     ModelNode m_node;
202 };
203
204 class RemovePropertyRewriteAction: public RewriteAction
205 {
206 public:
207     RemovePropertyRewriteAction(const AbstractProperty &property):
208             m_property(property)
209     {}
210
211     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
212     virtual QString info() const;
213
214     virtual RemovePropertyRewriteAction *asRemovePropertyRewriteAction() { return this; }
215
216     AbstractProperty property() const
217     { return m_property; }
218
219 private:
220     AbstractProperty m_property;
221 };
222
223 class ReparentNodeRewriteAction: public RewriteAction
224 {
225 public:
226     ReparentNodeRewriteAction(const ModelNode &node, const AbstractProperty &oldParentProperty, const AbstractProperty &targetProperty, QmlDesigner::QmlRefactoring::PropertyType propertyType):
227             m_node(node), m_oldParentProperty(oldParentProperty), m_targetProperty(targetProperty), m_propertyType(propertyType)
228     {}
229
230     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
231     virtual QString info() const;
232
233     virtual ReparentNodeRewriteAction *asReparentNodeRewriteAction() { return this; }
234
235     ModelNode reparentedNode() const
236     { return m_node; }
237
238     void setOldParentProperty(const AbstractProperty &oldParentProperty)
239     { m_oldParentProperty = oldParentProperty; }
240
241     AbstractProperty oldParentProperty() const
242     { return m_oldParentProperty; }
243
244     AbstractProperty targetProperty() const
245     { return m_targetProperty; }
246
247     QmlDesigner::QmlRefactoring::PropertyType propertyType() const
248     { return m_propertyType; }
249
250 private:
251     ModelNode m_node;
252     AbstractProperty m_oldParentProperty;
253     AbstractProperty m_targetProperty;
254     QmlDesigner::QmlRefactoring::PropertyType m_propertyType;
255 };
256
257 class MoveNodeRewriteAction: public RewriteAction
258 {
259 public:
260     MoveNodeRewriteAction(const ModelNode &movingNode, const ModelNode &newTrailingNode):
261             m_movingNode(movingNode), m_newTrailingNode(newTrailingNode)
262     {}
263
264     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
265     virtual QString info() const;
266
267     virtual MoveNodeRewriteAction *asMoveNodeRewriteAction() { return this; }
268
269 private:
270     ModelNode m_movingNode;
271     ModelNode m_newTrailingNode;
272 };
273
274 class AddImportRewriteAction: public RewriteAction
275 {
276 public:
277     AddImportRewriteAction(const Import &import):
278             m_import(import)
279     {}
280
281     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
282     virtual QString info() const;
283
284     virtual AddImportRewriteAction *asAddImportRewriteAction() { return this; }
285
286     Import import() const { return m_import; }
287
288 private:
289     Import m_import;
290 };
291
292 class RemoveImportRewriteAction: public RewriteAction
293 {
294 public:
295     RemoveImportRewriteAction(const Import &import):
296             m_import(import)
297     {}
298
299     virtual bool execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore);
300     virtual QString info() const;
301
302     virtual RemoveImportRewriteAction *asRemoveImportRewriteAction() { return this; }
303
304     Import import() const { return m_import; }
305
306 private:
307     Import m_import;
308 };
309
310 } // namespace Internal
311 } // namespace QmlDesigner
312
313 #endif // REWRITEACTION_H