nodeinstanceview.h 7.69 KB
Newer Older
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

30
31
#ifndef NODEINSTANCEVIEW_H
#define NODEINSTANCEVIEW_H
32
33
34
35
36
37

#include "corelib_global.h"
#include "abstractview.h"

#include <modelnode.h>
#include <nodeinstance.h>
38
#include <nodeinstanceclientinterface.h>
39

40
#include <QHash>
41
#include <QSet>
42
#include <QWeakPointer>
43
#include <QRectF>
44
#include <QTimer>
45

ck's avatar
ck committed
46
QT_BEGIN_NAMESPACE
47
class QDeclarativeEngine;
48
class QGraphicsView;
49
class QFileSystemWatcher;
50
class QPainter;
ck's avatar
ck committed
51
QT_END_NAMESPACE
52

53
54
namespace QmlDesigner {

55
56
57
58
59
60
61
62
63
64
65
class NodeInstanceServerInterface;
class CreateSceneCommand;
class CreateInstancesCommand;
class ClearSceneCommand;
class ReparentInstancesCommand;
class ChangeFileUrlCommand;
class ChangeValuesCommand;
class ChangeBindingsCommand;
class ChangeIdsCommand;
class RemoveInstancesCommand;
class RemovePropertiesCommand;
66
class AddImportCommand;
67
class CompleteComponentCommand;
68
69

class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
70
71
72
73
{
    Q_OBJECT

    friend class NodeInstance;
74

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
public:
    typedef QWeakPointer<NodeInstanceView> Pointer;

    NodeInstanceView(QObject *parent = 0);
    ~NodeInstanceView();

    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 propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList);
    void propertiesRemoved(const QList<AbstractProperty>& propertyList);
    void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange);
    void bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags propertyChange);
90
    void nodeAboutToBeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
91
    void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
92
    void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
93
94
    void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
    void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
95
    void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
96
    void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
Marco Bubke's avatar
Marco Bubke committed
97
    void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
98
    void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
99
    void instancesCompleted(const QVector<ModelNode> &completedNodeList);
100
    void importAdded(const Import &import);
101
    void importRemoved(const Import &import);
102
103

    QList<NodeInstance> instances() const;
104
105
    NodeInstance instanceForNode(const ModelNode &node) const ;
    bool hasInstanceForNode(const ModelNode &node) const;
106

107
108
    NodeInstance instanceForId(qint32 id) const;
    bool hasInstanceForId(qint32 id) const;
109
110
111

    QRectF sceneRect() const;

112
    void setBlockUpdates(bool block);
113

114
115
116
117
118
    NodeInstance activeStateInstance() const;

    void activateState(const NodeInstance &instance);
    void activateBaseState();

119
120
121
    void valuesChanged(const ValuesChangedCommand &command);
    void pixmapChanged(const PixmapChangedCommand &command);
    void informationChanged(const InformationChangedCommand &command);
122
    void childrenChanged(const ChildrenChangedCommand &command);
123
    void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
124
    void componentCompleted(const ComponentCompletedCommand &command);
125
126

private: // functions
127
128
    NodeInstance rootNodeInstance() const;

129
130
    NodeInstance loadNode(const ModelNode &node);

131
132
133
134
135
136
    void loadNodes(const QList<ModelNode> &nodeList);

    void removeAllInstanceNodeRelationships();

    void removeRecursiveChildRelationship(const ModelNode &removedNode);

137
    void insertInstanceRelationships(const NodeInstance &instance);
138
139
140
141
    void removeInstanceNodeRelationship(const ModelNode &node);

    void removeInstanceAndSubInstances(const ModelNode &node);

142
143
144
    void setStateInstance(const NodeInstance &stateInstance);
    void clearStateInstance();

145
    NodeInstanceServerInterface *nodeInstanceServer() const;
146

147
148
149
    CreateSceneCommand createCreateSceneCommand() const;
    ClearSceneCommand createClearSceneCommand() const;
    CreateInstancesCommand createCreateInstancesCommand(const QList<NodeInstance> &instanceList) const;
150
151
    CompleteComponentCommand createComponentCompleteCommand(const QList<NodeInstance> &instanceList) const;
    ComponentCompletedCommand createComponentCompletedCommand(const QList<NodeInstance> &instanceList) const;
152
153
154
155
156
157
158
159
160
    ReparentInstancesCommand createReparentInstancesCommand(const QList<NodeInstance> &instanceList) const;
    ReparentInstancesCommand createReparentInstancesCommand(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent) const;
    ChangeFileUrlCommand createChangeFileUrlCommand(const QUrl &fileUrl) const;
    ChangeValuesCommand createChangeValueCommand(const QList<VariantProperty> &propertyList) const;
    ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const;
    ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const;
    RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const;
    RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const;
    RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const;
161
    AddImportCommand createImportCommand(const Import &import);
162
163
164
165
166
167

    void resetHorizontalAnchors(const ModelNode &node);
    void resetVerticalAnchors(const ModelNode &node);

private slots:
    void restartProcess();
168
    void restartProcessDelayed();
169

170
171
private: //variables
    NodeInstance m_rootNodeInstance;
172
    NodeInstance m_activeStateInstance;
173
174

    QHash<ModelNode, NodeInstance> m_nodeInstanceHash;
175
    QHash<qint32, NodeInstance> m_idInstanceHash; // This is purely internal. Might contain dangling pointers!
176

177
178
    uint m_blockUpdates;
    QWeakPointer<NodeInstanceServerInterface> m_nodeInstanceServer;
179
    QTimer m_resetTimer;
180
181
};

182
} // namespace ProxyNodeInstanceView
183

184
#endif // NODEINSTANCEVIEW_H