OSDN Git Service

d90dee3b516d66bed734aa89752736cb46667a91
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / include / forwardview.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 FORWARDVIEW_H
35 #define FORWARDVIEW_H
36
37 #include <abstractview.h>
38
39 #include <nodeabstractproperty.h>
40 #include <nodelistproperty.h>
41 #include <variantproperty.h>
42 #include <bindingproperty.h>
43 #include <QtDebug>
44
45 namespace QmlDesigner {
46 class NodeInstanceView;
47
48 template <class ViewType>
49 class ForwardView : public AbstractView
50 {
51 public:
52     typedef QWeakPointer<ForwardView> Pointer;
53     typedef typename ViewType::Pointer ViewTypePointer;
54
55     ForwardView(QObject *parent);
56
57     void modelAttached(Model *model);
58     void modelAboutToBeDetached(Model *model);
59
60     void nodeCreated(const ModelNode &createdNode);
61     void nodeAboutToBeRemoved(const ModelNode &removedNode);
62     void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
63     void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
64     void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
65     void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList);
66     void propertiesRemoved(const QList<AbstractProperty>& propertyList);
67     void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
68     void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
69     void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
70
71     void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
72                               const QList<ModelNode> &lastSelectedNodeList);
73
74     void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
75
76     void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
77     void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
78
79     void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
80
81     void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
82
83 protected:
84     void appendView(ViewType *view);
85     void removeView(ViewType *view);
86     QList<ViewType*> viewList() const;
87     ViewType *firstView() const;
88
89 private:
90     QList<ViewTypePointer> m_targetViewList;
91 };
92
93 template <class ViewType>
94 ForwardView<ViewType>::ForwardView(QObject *parent)
95     : AbstractView(parent)
96 {
97 }
98
99 template <class ViewType>
100 void ForwardView<ViewType>::modelAttached(Model *model)
101 {
102     AbstractView::modelAttached(model);
103     foreach (const ViewTypePointer &view, m_targetViewList)
104         view->modelAttached(model);
105 }
106
107 template <class ViewType>
108 void ForwardView<ViewType>::modelAboutToBeDetached(Model *model)
109 {
110     foreach (const ViewTypePointer &view, m_targetViewList)
111         view->modelAboutToBeDetached(model);
112
113     AbstractView::modelAboutToBeDetached(model);
114 }
115
116 template <class ViewType>
117 void ForwardView<ViewType>::nodeCreated(const ModelNode &createdNode)
118 {
119     foreach (const ViewTypePointer &view, m_targetViewList)
120         view->nodeCreated(ModelNode(createdNode, view.data()));
121 }
122
123 template <class ViewType>
124 void ForwardView<ViewType>::nodeAboutToBeRemoved(const ModelNode &removedNode)
125 {
126     foreach (const ViewTypePointer &view, m_targetViewList)
127         view->nodeAboutToBeRemoved(ModelNode(removedNode, view.data()));
128 }
129
130 template <class ViewType>
131 void ForwardView<ViewType>::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange)
132 {
133     foreach (const ViewTypePointer &view, m_targetViewList)
134         view->nodeRemoved(ModelNode(removedNode, view.data()), NodeAbstractProperty(parentProperty, view.data()), propertyChange);
135 }
136
137 template <class ViewType>
138 void ForwardView<ViewType>::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, PropertyChangeFlags propertyChange)
139 {
140     foreach (const ViewTypePointer &view, m_targetViewList)
141         view->nodeReparented(ModelNode(node, view.data()), NodeAbstractProperty(newPropertyParent, view.data()), NodeAbstractProperty(oldPropertyParent, view.data()), propertyChange);
142 }
143
144 template <class ViewType>
145 void ForwardView<ViewType>::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
146 {
147     foreach (const ViewTypePointer &view, m_targetViewList)
148         view->nodeIdChanged(ModelNode(node, view.data()), newId, oldId);
149 }
150
151 template <class T>
152 static QList<T> adjustedList(const QList<T>& oldList, AbstractView *view)
153 {
154     QList<T> newList;
155
156     foreach (const T &item, oldList)
157     {
158        newList.append(T(item, view));
159     }
160
161     return newList;
162 }
163
164 template <class ViewType>
165 void ForwardView<ViewType>::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
166 {
167     foreach (const ViewTypePointer &view, m_targetViewList)
168         view->propertiesAboutToBeRemoved(adjustedList(propertyList, view.data()));
169 }
170
171 template <class ViewType>
172 void ForwardView<ViewType>::propertiesRemoved(const QList<AbstractProperty>& propertyList)
173 {
174     foreach (const ViewTypePointer &view, m_targetViewList)
175         view->propertiesRemoved(adjustedList(propertyList, view.data()));
176 }
177
178 template <class ViewType>
179 void ForwardView<ViewType>::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange)
180 {
181     foreach (const ViewTypePointer &view, m_targetViewList)
182         view->variantPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange);
183 }
184
185 template <class ViewType>
186 void ForwardView<ViewType>::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange)
187 {
188     foreach (const ViewTypePointer &view, m_targetViewList)
189         view->bindingPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange);
190 }
191
192 template <class ViewType>
193 void ForwardView<ViewType>::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion)
194 {
195     foreach (const ViewTypePointer &view, m_targetViewList)
196         view->rootNodeTypeChanged(type, majorVersion, minorVersion);
197 }
198
199 template <class ViewType>
200 void ForwardView<ViewType>::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
201                           const QList<ModelNode> &lastSelectedNodeList)
202 {
203     foreach (const ViewTypePointer &view, m_targetViewList)
204         view->selectedNodesChanged(adjustedList(selectedNodeList, view.data()), adjustedList(lastSelectedNodeList, view.data()));
205 }
206
207 template <class ViewType>
208 void ForwardView<ViewType>::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl)
209 {
210     AbstractView::fileUrlChanged(oldUrl, newUrl);
211
212     foreach (const ViewTypePointer &view, m_targetViewList)
213         view->fileUrlChanged(oldUrl, newUrl);
214 }
215
216 template <class ViewType>
217 void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
218 {
219     foreach (const ViewTypePointer &view, m_targetViewList)
220         view->nodeOrderChanged(NodeListProperty(listProperty, view.data()),
221                                 ModelNode(movedNode, view.data()), oldIndex);
222 }
223
224 template <class ViewType>
225 void ForwardView<ViewType>::importChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
226 {
227     foreach (const ViewTypePointer &view, m_targetViewList)
228         view->importChanged(addedImport, removedImport);
229 }
230
231 template <class ViewType>
232 void ForwardView<ViewType>::importRemoved(const Import &import)
233 {
234     AbstractView::importRemoved(import);
235
236     foreach (const ViewTypePointer &view, m_targetViewList)
237         view->importRemoved(import);
238 }
239
240 template <class ViewType>
241 void ForwardView<ViewType>::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
242 {
243     AbstractView::auxiliaryDataChanged(node, name, data);
244
245     foreach (const ViewTypePointer &view, m_targetViewList)
246         view->auxiliaryDataChanged(ModelNode(node, view.data()), name, data);
247 }
248
249 template <class ViewType>
250         void ForwardView<ViewType>::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
251 {
252     foreach (const ViewTypePointer &view, m_targetViewList)
253         view->scriptFunctionsChanged(node, scriptFunctionList);
254 }
255
256 template <class ViewType>
257 void ForwardView<ViewType>::appendView(ViewType *view)
258 {
259     m_targetViewList.append(view);
260 }
261
262 template <class ViewType>
263 void ForwardView<ViewType>::removeView(ViewType *view)
264 {
265     m_targetViewList.append(view);
266 }
267
268 template <class ViewType>
269 QList<ViewType*> ForwardView<ViewType>::viewList() const
270 {
271     QList<ViewType*> newList;
272
273     foreach (const ViewTypePointer &view, m_targetViewList)
274         newList.append(view.data());
275
276     return newList;
277 }
278
279 template <class ViewType>
280 ViewType *ForwardView<ViewType>::firstView() const
281 {
282     if (m_targetViewList.isEmpty())
283         return 0;
284
285     return m_targetViewList.first().data();
286 }
287
288
289 } // namespace QmlDesigner
290
291 #endif // FORWARDVIEW_H