1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include <abstractview.h>
38 #include <nodeabstractproperty.h>
39 #include <nodelistproperty.h>
40 #include <variantproperty.h>
41 #include <bindingproperty.h>
44 namespace QmlDesigner {
45 class NodeInstanceView;
47 template <class ViewType>
48 class ForwardView : public AbstractView
51 typedef QWeakPointer<ForwardView> Pointer;
52 typedef typename ViewType::Pointer ViewTypePointer;
54 ForwardView(QObject *parent);
56 void modelAttached(Model *model);
57 void modelAboutToBeDetached(Model *model);
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);
70 void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
71 const QList<ModelNode> &lastSelectedNodeList);
73 void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
75 void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
76 void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
78 void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
80 void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
83 void appendView(ViewType *view);
84 void removeView(ViewType *view);
85 QList<ViewType*> viewList() const;
86 ViewType *firstView() const;
89 QList<ViewTypePointer> m_targetViewList;
92 template <class ViewType>
93 ForwardView<ViewType>::ForwardView(QObject *parent)
94 : AbstractView(parent)
98 template <class ViewType>
99 void ForwardView<ViewType>::modelAttached(Model *model)
101 AbstractView::modelAttached(model);
102 foreach (const ViewTypePointer &view, m_targetViewList)
103 view->modelAttached(model);
106 template <class ViewType>
107 void ForwardView<ViewType>::modelAboutToBeDetached(Model *model)
109 foreach (const ViewTypePointer &view, m_targetViewList)
110 view->modelAboutToBeDetached(model);
112 AbstractView::modelAboutToBeDetached(model);
115 template <class ViewType>
116 void ForwardView<ViewType>::nodeCreated(const ModelNode &createdNode)
118 foreach (const ViewTypePointer &view, m_targetViewList)
119 view->nodeCreated(ModelNode(createdNode, view.data()));
122 template <class ViewType>
123 void ForwardView<ViewType>::nodeAboutToBeRemoved(const ModelNode &removedNode)
125 foreach (const ViewTypePointer &view, m_targetViewList)
126 view->nodeAboutToBeRemoved(ModelNode(removedNode, view.data()));
129 template <class ViewType>
130 void ForwardView<ViewType>::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange)
132 foreach (const ViewTypePointer &view, m_targetViewList)
133 view->nodeRemoved(ModelNode(removedNode, view.data()), NodeAbstractProperty(parentProperty, view.data()), propertyChange);
136 template <class ViewType>
137 void ForwardView<ViewType>::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, PropertyChangeFlags propertyChange)
139 foreach (const ViewTypePointer &view, m_targetViewList)
140 view->nodeReparented(ModelNode(node, view.data()), NodeAbstractProperty(newPropertyParent, view.data()), NodeAbstractProperty(oldPropertyParent, view.data()), propertyChange);
143 template <class ViewType>
144 void ForwardView<ViewType>::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId)
146 foreach (const ViewTypePointer &view, m_targetViewList)
147 view->nodeIdChanged(ModelNode(node, view.data()), newId, oldId);
151 static QList<T> adjustedList(const QList<T>& oldList, AbstractView *view)
155 foreach (const T &item, oldList)
157 newList.append(T(item, view));
163 template <class ViewType>
164 void ForwardView<ViewType>::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList)
166 foreach (const ViewTypePointer &view, m_targetViewList)
167 view->propertiesAboutToBeRemoved(adjustedList(propertyList, view.data()));
170 template <class ViewType>
171 void ForwardView<ViewType>::propertiesRemoved(const QList<AbstractProperty>& propertyList)
173 foreach (const ViewTypePointer &view, m_targetViewList)
174 view->propertiesRemoved(adjustedList(propertyList, view.data()));
177 template <class ViewType>
178 void ForwardView<ViewType>::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange)
180 foreach (const ViewTypePointer &view, m_targetViewList)
181 view->variantPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange);
184 template <class ViewType>
185 void ForwardView<ViewType>::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange)
187 foreach (const ViewTypePointer &view, m_targetViewList)
188 view->bindingPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange);
191 template <class ViewType>
192 void ForwardView<ViewType>::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion)
194 foreach (const ViewTypePointer &view, m_targetViewList)
195 view->rootNodeTypeChanged(type, majorVersion, minorVersion);
198 template <class ViewType>
199 void ForwardView<ViewType>::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
200 const QList<ModelNode> &lastSelectedNodeList)
202 foreach (const ViewTypePointer &view, m_targetViewList)
203 view->selectedNodesChanged(adjustedList(selectedNodeList, view.data()), adjustedList(lastSelectedNodeList, view.data()));
206 template <class ViewType>
207 void ForwardView<ViewType>::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl)
209 AbstractView::fileUrlChanged(oldUrl, newUrl);
211 foreach (const ViewTypePointer &view, m_targetViewList)
212 view->fileUrlChanged(oldUrl, newUrl);
215 template <class ViewType>
216 void ForwardView<ViewType>::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex)
218 foreach (const ViewTypePointer &view, m_targetViewList)
219 view->nodeOrderChanged(NodeListProperty(listProperty, view.data()),
220 ModelNode(movedNode, view.data()), oldIndex);
223 template <class ViewType>
224 void ForwardView<ViewType>::importChanged(const QList<Import> &addedImports, const QList<Import> &removedImports)
226 foreach (const ViewTypePointer &view, m_targetViewList)
227 view->importChanged(addedImport, removedImport);
230 template <class ViewType>
231 void ForwardView<ViewType>::importRemoved(const Import &import)
233 AbstractView::importRemoved(import);
235 foreach (const ViewTypePointer &view, m_targetViewList)
236 view->importRemoved(import);
239 template <class ViewType>
240 void ForwardView<ViewType>::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data)
242 AbstractView::auxiliaryDataChanged(node, name, data);
244 foreach (const ViewTypePointer &view, m_targetViewList)
245 view->auxiliaryDataChanged(ModelNode(node, view.data()), name, data);
248 template <class ViewType>
249 void ForwardView<ViewType>::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList)
251 foreach (const ViewTypePointer &view, m_targetViewList)
252 view->scriptFunctionsChanged(node, scriptFunctionList);
255 template <class ViewType>
256 void ForwardView<ViewType>::appendView(ViewType *view)
258 m_targetViewList.append(view);
261 template <class ViewType>
262 void ForwardView<ViewType>::removeView(ViewType *view)
264 m_targetViewList.append(view);
267 template <class ViewType>
268 QList<ViewType*> ForwardView<ViewType>::viewList() const
270 QList<ViewType*> newList;
272 foreach (const ViewTypePointer &view, m_targetViewList)
273 newList.append(view.data());
278 template <class ViewType>
279 ViewType *ForwardView<ViewType>::firstView() const
281 if (m_targetViewList.isEmpty())
284 return m_targetViewList.first().data();
288 } // namespace QmlDesigner
290 #endif // FORWARDVIEW_H