OSDN Git Service

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