1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include <abstractview.h>
39 #include <nodeabstractproperty.h>
40 #include <nodelistproperty.h>
41 #include <variantproperty.h>
42 #include <bindingproperty.h>
45 namespace QmlDesigner {
46 class NodeInstanceView;
48 template <class ViewType>
49 class ForwardView : public AbstractView
52 typedef QWeakPointer<ForwardView> Pointer;
53 typedef typename ViewType::Pointer ViewTypePointer;
55 ForwardView(QObject *parent);
57 void modelAttached(Model *model);
58 void modelAboutToBeDetached(Model *model);
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);
71 void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
72 const QList<ModelNode> &lastSelectedNodeList);
74 void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
76 void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
77 void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
79 void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
81 void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
84 void appendView(ViewType *view);
85 void removeView(ViewType *view);
86 QList<ViewType*> viewList() const;
87 ViewType *firstView() const;
90 QList<ViewTypePointer> m_targetViewList;
93 template <class ViewType>
94 ForwardView<ViewType>::ForwardView(QObject *parent)
95 : AbstractView(parent)
99 template <class ViewType>
100 void ForwardView<ViewType>::modelAttached(Model *model)
102 AbstractView::modelAttached(model);
103 foreach (const ViewTypePointer &view, m_targetViewList)
104 view->modelAttached(model);
107 template <class ViewType>
108 void ForwardView<ViewType>::modelAboutToBeDetached(Model *model)
110 foreach (const ViewTypePointer &view, m_targetViewList)
111 view->modelAboutToBeDetached(model);
113 AbstractView::modelAboutToBeDetached(model);
116 template <class ViewType>
117 void ForwardView<ViewType>::nodeCreated(const ModelNode &createdNode)
119 foreach (const ViewTypePointer &view, m_targetViewList)
120 view->nodeCreated(ModelNode(createdNode, view.data()));
123 template <class ViewType>
124 void ForwardView<ViewType>::nodeAboutToBeRemoved(const ModelNode &removedNode)
126 foreach (const ViewTypePointer &view, m_targetViewList)
127 view->nodeAboutToBeRemoved(ModelNode(removedNode, view.data()));
130 template <class ViewType>
131 void ForwardView<ViewType>::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange)
133 foreach (const ViewTypePointer &view, m_targetViewList)
134 view->nodeRemoved(ModelNode(removedNode, view.data()), NodeAbstractProperty(parentProperty, view.data()), propertyChange);
137 template <class ViewType>
138 void ForwardView<ViewType>::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, PropertyChangeFlags propertyChange)
140 foreach (const ViewTypePointer &view, m_targetViewList)
141 view->nodeReparented(ModelNode(node, view.data()), NodeAbstractProperty(newPropertyParent, view.data()), NodeAbstractProperty(oldPropertyParent, view.data()), propertyChange);
144 template <class ViewType>
145 void ForwardView<ViewType>::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
147 foreach (const ViewTypePointer &view, m_targetViewList)
148 view->nodeIdChanged(ModelNode(node, view.data()), newId, oldId);
152 static QList<T> adjustedList(const QList<T>& oldList, AbstractView *view)
156 foreach (const T &item, oldList)
158 newList.append(T(item, view));
164 template <class ViewType>
165 void ForwardView<ViewType>::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
167 foreach (const ViewTypePointer &view, m_targetViewList)
168 view->propertiesAboutToBeRemoved(adjustedList(propertyList, view.data()));
171 template <class ViewType>
172 void ForwardView<ViewType>::propertiesRemoved(const QList<AbstractProperty>& propertyList)
174 foreach (const ViewTypePointer &view, m_targetViewList)
175 view->propertiesRemoved(adjustedList(propertyList, view.data()));
178 template <class ViewType>
179 void ForwardView<ViewType>::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange)
181 foreach (const ViewTypePointer &view, m_targetViewList)
182 view->variantPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange);
185 template <class ViewType>
186 void ForwardView<ViewType>::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange)
188 foreach (const ViewTypePointer &view, m_targetViewList)
189 view->bindingPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange);
192 template <class ViewType>
193 void ForwardView<ViewType>::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion)
195 foreach (const ViewTypePointer &view, m_targetViewList)
196 view->rootNodeTypeChanged(type, majorVersion, minorVersion);
199 template <class ViewType>
200 void ForwardView<ViewType>::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
201 const QList<ModelNode> &lastSelectedNodeList)
203 foreach (const ViewTypePointer &view, m_targetViewList)
204 view->selectedNodesChanged(adjustedList(selectedNodeList, view.data()), adjustedList(lastSelectedNodeList, view.data()));
207 template <class ViewType>
208 void ForwardView<ViewType>::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl)
210 AbstractView::fileUrlChanged(oldUrl, newUrl);
212 foreach (const ViewTypePointer &view, m_targetViewList)
213 view->fileUrlChanged(oldUrl, newUrl);
216 template <class ViewType>
217 void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
219 foreach (const ViewTypePointer &view, m_targetViewList)
220 view->nodeOrderChanged(NodeListProperty(listProperty, view.data()),
221 ModelNode(movedNode, view.data()), oldIndex);
224 template <class ViewType>
225 void ForwardView<ViewType>::importChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
227 foreach (const ViewTypePointer &view, m_targetViewList)
228 view->importChanged(addedImport, removedImport);
231 template <class ViewType>
232 void ForwardView<ViewType>::importRemoved(const Import &import)
234 AbstractView::importRemoved(import);
236 foreach (const ViewTypePointer &view, m_targetViewList)
237 view->importRemoved(import);
240 template <class ViewType>
241 void ForwardView<ViewType>::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
243 AbstractView::auxiliaryDataChanged(node, name, data);
245 foreach (const ViewTypePointer &view, m_targetViewList)
246 view->auxiliaryDataChanged(ModelNode(node, view.data()), name, data);
249 template <class ViewType>
250 void ForwardView<ViewType>::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
252 foreach (const ViewTypePointer &view, m_targetViewList)
253 view->scriptFunctionsChanged(node, scriptFunctionList);
256 template <class ViewType>
257 void ForwardView<ViewType>::appendView(ViewType *view)
259 m_targetViewList.append(view);
262 template <class ViewType>
263 void ForwardView<ViewType>::removeView(ViewType *view)
265 m_targetViewList.append(view);
268 template <class ViewType>
269 QList<ViewType*> ForwardView<ViewType>::viewList() const
271 QList<ViewType*> newList;
273 foreach (const ViewTypePointer &view, m_targetViewList)
274 newList.append(view.data());
279 template <class ViewType>
280 ViewType *ForwardView<ViewType>::firstView() const
282 if (m_targetViewList.isEmpty())
285 return m_targetViewList.first().data();
289 } // namespace QmlDesigner
291 #endif // FORWARDVIEW_H