objectnodeinstance.h 6.57 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
47
48
49
class QDeclarativeContext;
class QDeclarativeProperty;
class QDeclarativeContext;
class QDeclarativeBinding;
50
QT_END_NAMESPACE
51
52
53
54
55
56
57
58
59
60
61
62

namespace QmlDesigner {


namespace Internal {

class QmlGraphicsItemNodeInstance;
class GraphicsWidgetNodeInstance;
class GraphicsViewNodeInstance;
class GraphicsSceneNodeInstance;
class ProxyWidgetNodeInstance;
class WidgetNodeInstance;
63
class QDeclarativeViewNodeInstance;
64
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

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);

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

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

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

    virtual bool isTopLevel() const;

    virtual QObject *parent() const;

105
    virtual void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty);
106
107
108
109
110
111
112
113
114

    void setId(const QString &id);

    virtual bool isQmlGraphicsItem() const;
    virtual bool isGraphicsScene() const;
    virtual bool isGraphicsView() const;
    virtual bool isGraphicsWidget() const;
    virtual bool isProxyWidget() const;
    virtual bool isWidget() const;
115
    virtual bool isQDeclarativeView() const;
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    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
130
131
    virtual int penWidth() const;

132
133
134
135
136
137
138
139
140
141
142
143
144
145
    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);
146
    virtual void refreshProperty(const QString &name);
147
    virtual QString instanceType(const QString &name) const;
148
149
150
151
152
153
154
155

    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
156
157
158
    virtual void activateState();
    virtual void deactivateState();

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

    QObject *object() const;

    virtual bool hasContent() const;

166
    QDeclarativeContext *context() const;
167

168
169
170
171
    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);

172
protected:
173
    static QObject* createObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context);
174

175
    void doResetProperty(const QString &propertyName);
176
177
178
179
    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);
180
    void deleteObjectsInList(const QDeclarativeProperty &metaProperty);
181
182

private:
183
    static void refreshBindings(QDeclarativeContext *context);
184
185
186
187

    QHash<QString, QVariant> m_resetValueHash;
    QHash<QString, NodeInstance> m_modelAbstractPropertyHash;
    ModelNode m_modelNode;
Marco Bubke's avatar
Marco Bubke committed
188
    QString m_id;
189
190
191
192

    QWeakPointer<NodeInstanceView> m_nodeInstanceView;
    bool m_deleteHeldInstance;
    QWeakPointer<QObject> m_object;
193
    NodeInstanceMetaObject *m_metaObject;
194
    NodeInstanceSignalSpy m_signalSpy;
195
196
197
198
199
200
201
};


} // namespace Internal
} // namespace QmlDesigner

#endif // ABSTRACTNODEINSTANCE_H