objectnodeinstance.h 6.99 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
30
31
32
33
34
35
36
**
** 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.
**
**************************************************************************/

#ifndef ABSTRACTNODEINSTANCE_H
#define ABSTRACTNODEINSTANCE_H

#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include "modelnode.h"
#include <QSharedPointer>
37
#include <QScopedPointer>
38
39
40
#include <QWeakPointer>
#include <propertymetainfo.h>
#include <nodeinstanceview.h>
41
#include "nodeinstancemetaobject.h"
42
#include "nodeinstancesignalspy.h"
43

44
QT_BEGIN_NAMESPACE
45
class QGraphicsItem;
46
class QDeclarativeContext;
47
class QDeclarativeEngine;
48
49
50
class QDeclarativeProperty;
class QDeclarativeContext;
class QDeclarativeBinding;
51
QT_END_NAMESPACE
52
53
54
55
56
57
58
59
60
61
62
63

namespace QmlDesigner {


namespace Internal {

class QmlGraphicsItemNodeInstance;
class GraphicsWidgetNodeInstance;
class GraphicsViewNodeInstance;
class GraphicsSceneNodeInstance;
class ProxyWidgetNodeInstance;
class WidgetNodeInstance;
64
class QDeclarativeViewNodeInstance;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

class ChildrenChangeEventFilter : public QObject
{
    Q_OBJECT
public:
    ChildrenChangeEventFilter(QObject *parent);


signals:
    void childrenChanged(QObject *object);

protected:
    bool eventFilter(QObject *object, QEvent *event);

};

class ObjectNodeInstance
{
public:
    typedef QSharedPointer<ObjectNodeInstance> Pointer;
    typedef QWeakPointer<ObjectNodeInstance> WeakPointer;
    ObjectNodeInstance(QObject *object);

    virtual ~ObjectNodeInstance();
    void destroy();
    //void setModelNode(const ModelNode &node);

92
    static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped);
93
94
95
96
97

    ModelNode modelNode() const;
    void setModelNode(const ModelNode &node);

    NodeInstanceView *nodeInstanceView() const;
98
    void setNodeInstanceView(NodeInstanceView *view);
99
    virtual void initializePropertyWatcher(const Pointer &objectNodeInstance);
100
101
102
103
104
105
    virtual void paint(QPainter *painter) const;

    virtual bool isTopLevel() const;

    virtual QObject *parent() const;

106
    virtual void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty);
107
108

    void setId(const QString &id);
109
    QString id() const;
110
111
112
113
114
115
116

    virtual bool isQmlGraphicsItem() const;
    virtual bool isGraphicsScene() const;
    virtual bool isGraphicsView() const;
    virtual bool isGraphicsWidget() const;
    virtual bool isProxyWidget() const;
    virtual bool isWidget() const;
117
    virtual bool isQDeclarativeView() const;
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    virtual bool isGraphicsObject() const;
    virtual bool isTransition() const;

    virtual bool equalGraphicsItem(QGraphicsItem *item) const;

    virtual QRectF boundingRect() const;

    virtual QPointF position() const;
    virtual QSizeF size() const;
    virtual QTransform transform() const;
    virtual QTransform customTransform() const;
    virtual QTransform sceneTransform() const;
    virtual double opacity() const;

Marco Bubke's avatar
Marco Bubke committed
132
133
    virtual int penWidth() const;

134
135
136
137
138
139
140
141
142
143
144
145
146
147
    virtual bool hasAnchor(const QString &name) const;
    virtual QPair<QString, NodeInstance> anchor(const QString &name) const;
    virtual bool isAnchoredBy() const;

    virtual double rotation() const;
    virtual double scale() const;
    virtual QList<QGraphicsTransform *> transformations() const;
    virtual QPointF transformOriginPoint() const;
    virtual double zValue() const;

    virtual void setPropertyVariant(const QString &name, const QVariant &value);
    virtual void setPropertyBinding(const QString &name, const QString &expression);
    virtual QVariant property(const QString &name) const;
    virtual void resetProperty(const QString &name);
148
    virtual void refreshProperty(const QString &name);
149
    virtual QString instanceType(const QString &name) const;
150
151
152
153
154
155
156
157

    void createDynamicProperty(const QString &name, const QString &typeName);
    void setDeleteHeldInstance(bool deleteInstance);
    bool deleteHeldInstance() const;

    virtual void updateAnchors();
    virtual void paintUpdate();

Marco Bubke's avatar
Marco Bubke committed
158
159
160
    virtual void activateState();
    virtual void deactivateState();

161
162
163
164
165
166
167
    void populateResetValueHash();
    QVariant resetValue(const QString &propertyName) const;

    QObject *object() const;

    virtual bool hasContent() const;

Thomas Hartmann's avatar
Thomas Hartmann committed
168
169
    bool hasBindingForProperty(const QString &name) const;

170
    QDeclarativeContext *context() const;
171
    QDeclarativeEngine *engine() const;
172

173
174
175
176
    virtual bool updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value);
    virtual bool updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression);
    virtual bool resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue);

177
178
    static void removeAnimationsFromComponents(QObject *object, QObjectList &inspectedObjectList);

179
180
    NodeInstance nodeInstanceParentForObject(QObject *currentObject) const;

181
protected:
182
183
    static QObject *createInstance(const NodeMetaInfo &metaInfo, QDeclarativeContext *parentContext);

184
    static QObject* createObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context);
185

186
    void doResetProperty(const QString &propertyName);
187
188
189
190
    NodeInstance instanceForNode(const ModelNode &node, const QString &fullname);

    void removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty);
    void addToNewProperty(QObject *object, QObject *newParent, const QString &newParentProperty);
191
    void deleteObjectsInList(const QDeclarativeProperty &metaProperty);
192
193

private:
194
    static void refreshBindings(QDeclarativeContext *context);
195
196
197
198

    QHash<QString, QVariant> m_resetValueHash;
    QHash<QString, NodeInstance> m_modelAbstractPropertyHash;
    ModelNode m_modelNode;
Marco Bubke's avatar
Marco Bubke committed
199
    QString m_id;
200
201
202
203

    QWeakPointer<NodeInstanceView> m_nodeInstanceView;
    bool m_deleteHeldInstance;
    QWeakPointer<QObject> m_object;
204
    NodeInstanceMetaObject *m_metaObject;
205
    NodeInstanceSignalSpy m_signalSpy;
206
207
208
209
210
211
212
};


} // namespace Internal
} // namespace QmlDesigner

#endif // ABSTRACTNODEINSTANCE_H