OSDN Git Service

bb277d2aa61748ab6960760aa906fb9562789ba0
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / include / nodeinstanceview.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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef NODEINSTANCEVIEW_H
35 #define NODEINSTANCEVIEW_H
36
37 #include "corelib_global.h"
38 #include "abstractview.h"
39
40 #include <modelnode.h>
41 #include <nodeinstance.h>
42 #include <nodeinstanceclientinterface.h>
43 #include <nodeinstanceserverinterface.h>
44
45 #include <QHash>
46 #include <QSet>
47 #include <QImage>
48 #include <QWeakPointer>
49 #include <QRectF>
50 #include <QTime>
51
52 QT_BEGIN_NAMESPACE
53 class QDeclarativeEngine;
54 class QGraphicsView;
55 class QFileSystemWatcher;
56 class QPainter;
57 QT_END_NAMESPACE
58
59 namespace QmlDesigner {
60
61 class NodeInstanceServerInterface;
62 class CreateSceneCommand;
63 class CreateInstancesCommand;
64 class ClearSceneCommand;
65 class ReparentInstancesCommand;
66 class ChangeFileUrlCommand;
67 class ChangeValuesCommand;
68 class ChangeBindingsCommand;
69 class ChangeIdsCommand;
70 class RemoveInstancesCommand;
71 class RemovePropertiesCommand;
72 class AddImportCommand;
73 class CompleteComponentCommand;
74
75 class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
76 {
77     Q_OBJECT
78
79     friend class NodeInstance;
80
81 public:
82     typedef QWeakPointer<NodeInstanceView> Pointer;
83
84     explicit NodeInstanceView(QObject *parent = 0, NodeInstanceServerInterface::RunModus runModus = NodeInstanceServerInterface::NormalModus);
85     ~NodeInstanceView();
86
87     void modelAttached(Model *model);
88     void modelAboutToBeDetached(Model *model);
89     void nodeCreated(const ModelNode &createdNode);
90     void nodeAboutToBeRemoved(const ModelNode &removedNode);
91     void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
92     void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList);
93     void propertiesRemoved(const QList<AbstractProperty>& propertyList);
94     void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
95     void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
96     void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
97     void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
98     void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
99     void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
100     void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
101     void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
102     void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
103     void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
104     void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
105     void instancesCompleted(const QVector<ModelNode> &completedNodeList);
106     void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
107     void instanceInformationsChange(const QVector<ModelNode> &nodeList);
108     void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
109     void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
110     void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
111     void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
112     void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
113
114     void rewriterBeginTransaction();
115     void rewriterEndTransaction();
116
117     void actualStateChanged(const ModelNode &node);
118
119     QList<NodeInstance> instances() const;
120     NodeInstance instanceForNode(const ModelNode &node) const ;
121     bool hasInstanceForNode(const ModelNode &node) const;
122
123     NodeInstance instanceForId(qint32 id);
124     bool hasInstanceForId(qint32 id);
125
126     QRectF sceneRect() const;
127
128     NodeInstance activeStateInstance() const;
129
130     void activateState(const NodeInstance &instance);
131     void activateBaseState();
132
133     void valuesChanged(const ValuesChangedCommand &command);
134     void pixmapChanged(const PixmapChangedCommand &command);
135     void informationChanged(const InformationChangedCommand &command);
136     void childrenChanged(const ChildrenChangedCommand &command);
137     void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
138     void componentCompleted(const ComponentCompletedCommand &command);
139
140     QImage statePreviewImage(const ModelNode &stateNode) const;
141
142 private: // functions
143     NodeInstance rootNodeInstance() const;
144
145     NodeInstance loadNode(const ModelNode &node);
146
147     void removeAllInstanceNodeRelationships();
148
149     void removeRecursiveChildRelationship(const ModelNode &removedNode);
150
151     void insertInstanceRelationships(const NodeInstance &instance);
152     void removeInstanceNodeRelationship(const ModelNode &node);
153
154     void removeInstanceAndSubInstances(const ModelNode &node);
155
156     void setStateInstance(const NodeInstance &stateInstance);
157     void clearStateInstance();
158
159     NodeInstanceServerInterface *nodeInstanceServer() const;
160
161     CreateSceneCommand createCreateSceneCommand();
162     ClearSceneCommand createClearSceneCommand() const;
163     CreateInstancesCommand createCreateInstancesCommand(const QList<NodeInstance> &instanceList) const;
164     CompleteComponentCommand createComponentCompleteCommand(const QList<NodeInstance> &instanceList) const;
165     ComponentCompletedCommand createComponentCompletedCommand(const QList<NodeInstance> &instanceList) const;
166     ReparentInstancesCommand createReparentInstancesCommand(const QList<NodeInstance> &instanceList) const;
167     ReparentInstancesCommand createReparentInstancesCommand(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent) const;
168     ChangeFileUrlCommand createChangeFileUrlCommand(const QUrl &fileUrl) const;
169     ChangeValuesCommand createChangeValueCommand(const QList<VariantProperty> &propertyList) const;
170     ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const;
171     ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const;
172     RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const;
173     RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const;
174     RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const;
175     AddImportCommand createImportCommand(const Import &import);
176
177     void resetHorizontalAnchors(const ModelNode &node);
178     void resetVerticalAnchors(const ModelNode &node);
179
180     void restartProcess();
181
182 private slots:
183     void handleChrash();
184
185 private: //variables
186     NodeInstance m_rootNodeInstance;
187     NodeInstance m_activeStateInstance;
188
189     QHash<ModelNode, NodeInstance> m_nodeInstanceHash;
190     QHash<ModelNode, QImage> m_statePreviewImage;
191
192     uint m_blockUpdates;
193     QWeakPointer<NodeInstanceServerInterface> m_nodeInstanceServer;
194     QImage m_baseStatePreviewImage;
195     QTime m_lastCrashTime;
196     NodeInstanceServerInterface::RunModus m_runModus;
197 };
198
199 } // namespace ProxyNodeInstanceView
200
201 #endif // NODEINSTANCEVIEW_H