nodeinstanceview.h 7.21 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

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

52
53
namespace QmlDesigner {

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

class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
68
69
70
71
{
    Q_OBJECT

    friend class NodeInstance;
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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);
    void nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags propertyChange);
89
    void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
90
91
    void fileUrlChanged(const QUrl &oldUrl, const QUrl &newUrl);
    void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId);
92
    void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
93
    void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
Marco Bubke's avatar
Marco Bubke committed
94
    void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
95
    void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
96
    void importAdded(const Import &import);
97
98

    QList<NodeInstance> instances() const;
99
100
    NodeInstance instanceForNode(const ModelNode &node) const ;
    bool hasInstanceForNode(const ModelNode &node) const;
101

102
103
    NodeInstance instanceForId(qint32 id) const;
    bool hasInstanceForId(qint32 id) const;
104
105
106
107
108

    void render(QPainter *painter, const QRectF &target=QRectF(), const QRectF &source=QRect(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);

    QRectF sceneRect() const;

109
    void setBlockUpdates(bool block);
110

111
112
113
114
115
    NodeInstance activeStateInstance() const;

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

116
117
118
    void valuesChanged(const ValuesChangedCommand &command);
    void pixmapChanged(const PixmapChangedCommand &command);
    void informationChanged(const InformationChangedCommand &command);
119
120

private: // functions
121
122
    NodeInstance rootNodeInstance() const;

123
124
    NodeInstance loadNode(const ModelNode &node);

125
126
127
128
129
130
    void loadNodes(const QList<ModelNode> &nodeList);

    void removeAllInstanceNodeRelationships();

    void removeRecursiveChildRelationship(const ModelNode &removedNode);

131
    void insertInstanceRelationships(const NodeInstance &instance);
132
133
134
135
    void removeInstanceNodeRelationship(const ModelNode &node);

    void removeInstanceAndSubInstances(const ModelNode &node);

136
137
138
    void setStateInstance(const NodeInstance &stateInstance);
    void clearStateInstance();

139
    NodeInstanceServerInterface *nodeInstanceServer() const;
140

141
142
143
144
145
146
147
148
149
150
151
152
    CreateSceneCommand createCreateSceneCommand() const;
    ClearSceneCommand createClearSceneCommand() const;
    CreateInstancesCommand createCreateInstancesCommand(const QList<NodeInstance> &instanceList) const;
    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;
153
    AddImportCommand createImportCommand(const Import &import);
154
155
156
157
158
159
160
161

    qint32 generateInstanceId();

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

private slots:
    void restartProcess();
162

163
164
private: //variables
    NodeInstance m_rootNodeInstance;
165
    NodeInstance m_activeStateInstance;
166
167

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

170
    QList<QPair<ModelNode, QString> > m_valuePropertyChangeList;
171

172
173
    QSet<ModelNode> m_renderImageChangeSet;
    QSet<ModelNode> m_informationChangeSet;
174

175
176
177
178
    uint m_blockUpdates;
    QWeakPointer<NodeInstanceServerInterface> m_nodeInstanceServer;
    qint32 m_instanceIdCounter;
;
179
180
};

181
} // namespace ProxyNodeInstanceView
182

183
#endif // NODEINSTANCEVIEW_H