/************************************************************************** ** ** This file is part of Qt Creator ** ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). ** ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** No Commercial Usage ** ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage ** ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** **************************************************************************/ #ifndef FORWARDVIEW_H #define FORWARDVIEW_H #include #include #include #include #include #include namespace QmlDesigner { class NodeInstanceView; template class ForwardView : public AbstractView { public: typedef QWeakPointer Pointer; typedef typename ViewType::Pointer ViewTypePointer; ForwardView(QObject *parent); void modelAttached(Model *model); void modelAboutToBeDetached(Model *model); void nodeCreated(const ModelNode &createdNode); void nodeAboutToBeRemoved(const ModelNode &removedNode); void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange); void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange); void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId); void propertiesAboutToBeRemoved(const QList& propertyList); void propertiesRemoved(const QList& propertyList); void variantPropertiesChanged(const QList& propertyList, PropertyChangeFlags propertyChange); void bindingPropertiesChanged(const QList& propertyList, PropertyChangeFlags propertyChange); void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion); void selectedNodesChanged(const QList &selectedNodeList, const QList &lastSelectedNodeList); void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl); void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex); void importAdded(const Import &import); void importRemoved(const Import &import); void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data); void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList); protected: void appendView(ViewType *view); void removeView(ViewType *view); QList viewList() const; ViewType *firstView() const; private: QList m_targetViewList; }; template ForwardView::ForwardView(QObject *parent) : AbstractView(parent) { } template void ForwardView::modelAttached(Model *model) { AbstractView::modelAttached(model); foreach (const ViewTypePointer &view, m_targetViewList) view->modelAttached(model); } template void ForwardView::modelAboutToBeDetached(Model *model) { foreach (const ViewTypePointer &view, m_targetViewList) view->modelAboutToBeDetached(model); AbstractView::modelAboutToBeDetached(model); } template void ForwardView::nodeCreated(const ModelNode &createdNode) { foreach (const ViewTypePointer &view, m_targetViewList) view->nodeCreated(ModelNode(createdNode, view.data())); } template void ForwardView::nodeAboutToBeRemoved(const ModelNode &removedNode) { foreach (const ViewTypePointer &view, m_targetViewList) view->nodeAboutToBeRemoved(ModelNode(removedNode, view.data())); } template void ForwardView::nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange) { foreach (const ViewTypePointer &view, m_targetViewList) view->nodeRemoved(ModelNode(removedNode, view.data()), NodeAbstractProperty(parentProperty, view.data()), propertyChange); } template void ForwardView::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, PropertyChangeFlags propertyChange) { foreach (const ViewTypePointer &view, m_targetViewList) view->nodeReparented(ModelNode(node, view.data()), NodeAbstractProperty(newPropertyParent, view.data()), NodeAbstractProperty(oldPropertyParent, view.data()), propertyChange); } template void ForwardView::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId) { foreach (const ViewTypePointer &view, m_targetViewList) view->nodeIdChanged(ModelNode(node, view.data()), newId, oldId); } template static QList adjustedList(const QList& oldList, AbstractView *view) { QList newList; foreach (const T &item, oldList) { newList.append(T(item, view)); } return newList; } template void ForwardView::propertiesAboutToBeRemoved(const QList& propertyList) { foreach (const ViewTypePointer &view, m_targetViewList) view->propertiesAboutToBeRemoved(adjustedList(propertyList, view.data())); } template void ForwardView::propertiesRemoved(const QList& propertyList) { foreach (const ViewTypePointer &view, m_targetViewList) view->propertiesRemoved(adjustedList(propertyList, view.data())); } template void ForwardView::variantPropertiesChanged(const QList& propertyList, PropertyChangeFlags propertyChange) { foreach (const ViewTypePointer &view, m_targetViewList) view->variantPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange); } template void ForwardView::bindingPropertiesChanged(const QList& propertyList, PropertyChangeFlags propertyChange) { foreach (const ViewTypePointer &view, m_targetViewList) view->bindingPropertiesChanged(adjustedList(propertyList, view.data()), propertyChange); } template void ForwardView::rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion) { foreach (const ViewTypePointer &view, m_targetViewList) view->rootNodeTypeChanged(type, majorVersion, minorVersion); } template void ForwardView::selectedNodesChanged(const QList &selectedNodeList, const QList &lastSelectedNodeList) { foreach (const ViewTypePointer &view, m_targetViewList) view->selectedNodesChanged(adjustedList(selectedNodeList, view.data()), adjustedList(lastSelectedNodeList, view.data())); } template void ForwardView::fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl) { AbstractView::fileUrlChanged(oldUrl, newUrl); foreach (const ViewTypePointer &view, m_targetViewList) view->fileUrlChanged(oldUrl, newUrl); } template void ForwardView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex) { foreach (const ViewTypePointer &view, m_targetViewList) view->nodeOrderChanged(NodeListProperty(listProperty, view.data()), ModelNode(movedNode, view.data()), oldIndex); } template void ForwardView::importAdded(const Import &import) { AbstractView::importAdded(import); foreach (const ViewTypePointer &view, m_targetViewList) view->importAdded(import); } template void ForwardView::importRemoved(const Import &import) { AbstractView::importRemoved(import); foreach (const ViewTypePointer &view, m_targetViewList) view->importRemoved(import); } template void ForwardView::auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data) { AbstractView::auxiliaryDataChanged(node, name, data); foreach (const ViewTypePointer &view, m_targetViewList) view->auxiliaryDataChanged(ModelNode(node, view.data()), name, data); } template void ForwardView::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList) { foreach (const ViewTypePointer &view, m_targetViewList) view->scriptFunctionsChanged(node, scriptFunctionList); } template void ForwardView::appendView(ViewType *view) { m_targetViewList.append(view); } template void ForwardView::removeView(ViewType *view) { m_targetViewList.append(view); } template QList ForwardView::viewList() const { QList newList; foreach (const ViewTypePointer &view, m_targetViewList) newList.append(view.data()); return newList; } template ViewType *ForwardView::firstView() const { if (m_targetViewList.isEmpty()) return 0; return m_targetViewList.first().data(); } } // namespace QmlDesigner #endif // FORWARDVIEW_H