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 **************************************************************************/
33 #ifndef NODEINSTANCEVIEW_H
34 #define NODEINSTANCEVIEW_H
36 #include "corelib_global.h"
37 #include "abstractview.h"
39 #include <modelnode.h>
40 #include <nodeinstance.h>
41 #include <nodeinstanceclientinterface.h>
42 #include <nodeinstanceserverinterface.h>
47 #include <QWeakPointer>
52 class QDeclarativeEngine;
54 class QFileSystemWatcher;
58 namespace QmlDesigner {
60 class NodeInstanceServerInterface;
61 class CreateSceneCommand;
62 class CreateInstancesCommand;
63 class ClearSceneCommand;
64 class ReparentInstancesCommand;
65 class ChangeFileUrlCommand;
66 class ChangeValuesCommand;
67 class ChangeBindingsCommand;
68 class ChangeIdsCommand;
69 class RemoveInstancesCommand;
70 class RemovePropertiesCommand;
71 class AddImportCommand;
72 class CompleteComponentCommand;
74 class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
78 friend class NodeInstance;
81 typedef QWeakPointer<NodeInstanceView> Pointer;
83 explicit NodeInstanceView(QObject *parent = 0, NodeInstanceServerInterface::RunModus runModus = NodeInstanceServerInterface::NormalModus);
86 void modelAttached(Model *model);
87 void modelAboutToBeDetached(Model *model);
88 void nodeCreated(const ModelNode &createdNode);
89 void nodeAboutToBeRemoved(const ModelNode &removedNode);
90 void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
91 void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList);
92 void propertiesRemoved(const QList<AbstractProperty>& propertyList);
93 void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
94 void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
95 void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
96 void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
97 void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
98 void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
99 void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
100 void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
101 void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
102 void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
103 void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
104 void instancesCompleted(const QVector<ModelNode> &completedNodeList);
105 void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
106 void instanceInformationsChange(const QVector<ModelNode> &nodeList);
107 void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
108 void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
109 void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
110 void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
111 void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
113 void rewriterBeginTransaction();
114 void rewriterEndTransaction();
116 void actualStateChanged(const ModelNode &node);
118 QList<NodeInstance> instances() const;
119 NodeInstance instanceForNode(const ModelNode &node) const ;
120 bool hasInstanceForNode(const ModelNode &node) const;
122 NodeInstance instanceForId(qint32 id);
123 bool hasInstanceForId(qint32 id);
125 QRectF sceneRect() const;
127 NodeInstance activeStateInstance() const;
129 void activateState(const NodeInstance &instance);
130 void activateBaseState();
132 void valuesChanged(const ValuesChangedCommand &command);
133 void pixmapChanged(const PixmapChangedCommand &command);
134 void informationChanged(const InformationChangedCommand &command);
135 void childrenChanged(const ChildrenChangedCommand &command);
136 void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
137 void componentCompleted(const ComponentCompletedCommand &command);
139 QImage statePreviewImage(const ModelNode &stateNode) const;
141 private: // functions
142 NodeInstance rootNodeInstance() const;
144 NodeInstance loadNode(const ModelNode &node);
146 void removeAllInstanceNodeRelationships();
148 void removeRecursiveChildRelationship(const ModelNode &removedNode);
150 void insertInstanceRelationships(const NodeInstance &instance);
151 void removeInstanceNodeRelationship(const ModelNode &node);
153 void removeInstanceAndSubInstances(const ModelNode &node);
155 void setStateInstance(const NodeInstance &stateInstance);
156 void clearStateInstance();
158 NodeInstanceServerInterface *nodeInstanceServer() const;
160 CreateSceneCommand createCreateSceneCommand();
161 ClearSceneCommand createClearSceneCommand() const;
162 CreateInstancesCommand createCreateInstancesCommand(const QList<NodeInstance> &instanceList) const;
163 CompleteComponentCommand createComponentCompleteCommand(const QList<NodeInstance> &instanceList) const;
164 ComponentCompletedCommand createComponentCompletedCommand(const QList<NodeInstance> &instanceList) const;
165 ReparentInstancesCommand createReparentInstancesCommand(const QList<NodeInstance> &instanceList) const;
166 ReparentInstancesCommand createReparentInstancesCommand(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent) const;
167 ChangeFileUrlCommand createChangeFileUrlCommand(const QUrl &fileUrl) const;
168 ChangeValuesCommand createChangeValueCommand(const QList<VariantProperty> &propertyList) const;
169 ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const;
170 ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const;
171 RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const;
172 RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const;
173 RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const;
174 AddImportCommand createImportCommand(const Import &import);
176 void resetHorizontalAnchors(const ModelNode &node);
177 void resetVerticalAnchors(const ModelNode &node);
179 void restartProcess();
185 NodeInstance m_rootNodeInstance;
186 NodeInstance m_activeStateInstance;
188 QHash<ModelNode, NodeInstance> m_nodeInstanceHash;
189 QHash<ModelNode, QImage> m_statePreviewImage;
192 QWeakPointer<NodeInstanceServerInterface> m_nodeInstanceServer;
193 QImage m_baseStatePreviewImage;
194 QTime m_lastCrashTime;
195 NodeInstanceServerInterface::RunModus m_runModus;
198 } // namespace ProxyNodeInstanceView
200 #endif // NODEINSTANCEVIEW_H