nodeinstance.h 6.85 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
37
38
39
**
** 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 NODEINSTANCE_H
#define NODEINSTANCE_H

#include "corelib_global.h"
#include <QSharedPointer>
#include <QHash>
#include <QRectF>
#include <propertymetainfo.h>
#include <qmlanchors.h>

40
QT_BEGIN_NAMESPACE
41
42
class QPainter;
class QStyleOptionGraphicsItem;
43
class QDeclarativeContext;
44
45
class QGraphicsItem;
class QGraphicsTransform;
46
QT_END_NAMESPACE
47
48
49
50
51
52
53
54
55
56
57
58
59
60

namespace QmlDesigner {

class ModelNode;
class NodeInstanceView;
class Preview;
class NodeMetaInfo;
class NodeState;
class WidgetQueryView;


namespace Internal {
    class ObjectNodeInstance;
    class QmlGraphicsItemNodeInstance;
61
    class QmlPropertyChangesNodeInstance;
62
    class GraphicsObjectNodeInstance;
63
    class QmlStateNodeInstance;
64
65
66
67
68
69
70
71
72
73
74
75
}

class CORESHARED_EXPORT NodeInstance
{
    friend class CORESHARED_EXPORT QmlDesigner::WidgetQueryView;
    friend CORESHARED_EXPORT class Preview;
    friend CORESHARED_EXPORT class NodeInstanceView;
    friend class QHash<ModelNode, NodeInstance>;
    friend CORESHARED_EXPORT uint qHash(const NodeInstance &instance);
    friend CORESHARED_EXPORT bool operator==(const NodeInstance &first, const NodeInstance &second);
    friend CORESHARED_EXPORT class NodeMetaInfo;
    friend class QmlDesigner::Internal::QmlGraphicsItemNodeInstance;
76
    friend class QmlDesigner::Internal::GraphicsObjectNodeInstance;
77
    friend class QmlDesigner::Internal::ObjectNodeInstance;
78
79
80
    friend class QmlDesigner::Internal::QmlPropertyChangesNodeInstance;
    friend class QmlDesigner::Internal::QmlStateNodeInstance;

81
82
83
84
85
86
87
88
89
90
91
public:
    NodeInstance();
    ~NodeInstance();
    NodeInstance(const NodeInstance &other);
    NodeInstance& operator=(const NodeInstance &other);

    void paint(QPainter *painter) const;

    NodeInstance parent() const;
    bool hasParent() const;
    ModelNode modelNode() const;
92

93
94
95
96
97
98
99
100
101

    bool isTopLevel() const;

    bool isQmlGraphicsItem() const;
    bool isGraphicsScene() const;
    bool isGraphicsView() const;
    bool isGraphicsWidget() const;
    bool isProxyWidget() const;
    bool isWidget() const;
102
    bool isQDeclarativeView() const;
103
104
    bool isGraphicsObject() const;
    bool isTransition() const;
105
    bool isPositioner() const;
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

    bool equalGraphicsItem(QGraphicsItem *item) const;

    QRectF boundingRect() const;
    QPointF position() const;
    QSizeF size() const;
    QTransform transform() const;
    QTransform customTransform() const;
    QTransform sceneTransform() const;
    double rotation() const;
    double scale() const;
    QList<QGraphicsTransform *> transformations() const;
    QPointF transformOriginPoint() const;
    double zValue() const;

    double opacity() const;
    QVariant property(const QString &name) const;
    QVariant defaultValue(const QString &name) const;
124
    QString instanceType(const QString &name) const;
125

Thomas Hartmann's avatar
Thomas Hartmann committed
126
127
    bool hasBindingForProperty(const QString &name) const;

128
129
130
    bool isValid() const;
    void makeInvalid();
    bool hasContent() const;
131
132
133
    bool isResizable() const;
    bool isMovable() const;
    bool isInPositioner() const;
134

135
    bool isWrappingThisObject(QObject *object) const;
136

137
    QVariant resetVariant(const QString &name) const;
138
139

    bool hasAnchor(const QString &name) const;
140
141
    bool isAnchoredBySibling() const;
    bool isAnchoredByChildren() const;
142
143
    QPair<QString, NodeInstance> anchor(const QString &name) const;

Marco Bubke's avatar
Marco Bubke committed
144
145
    int penWidth() const;

146
147
    static void registerDeclarativeTypes();

148
149
    void doComponentComplete();

150
151
    QString id() const;

152
#ifdef QTCREATOR_TEST
153
    QObject* testHandle() const;
154
    Internal::ObjectNodeInstance* internalInstance() const;
155
#endif
156
157
158
private: // functions
    NodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance);

159
160
161
162
163
164
165
166
167
    void setModelNode(const ModelNode &node);

    void setPropertyVariant(const QString &name, const QVariant &value);
    void setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value);

    void setPropertyBinding(const QString &name, const QString &expression);
    void setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression);

    void resetProperty(const QString &name);
168
    void refreshProperty(const QString &name);
169
170
171
172
173
174
175
176
177

    void activateState();
    void deactivateState();
    void refreshState();

    bool updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value);
    bool updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression);
    bool resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue);

178
    static NodeInstance create(NodeInstanceView *nodeInstanceView, const ModelNode &node, QObject *objectToBeWrapped);
179
    static NodeInstance create(NodeInstanceView *nodeInstanceView, const NodeMetaInfo &metaInfo, QDeclarativeContext *context);
180
181
182
183
184
185
186

    void setDeleteHeldInstance(bool deleteInstance);
    void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty);


    void setId(const QString &id);

187
    static QSharedPointer<Internal::ObjectNodeInstance> createInstance(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped);
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    QSharedPointer<Internal::QmlGraphicsItemNodeInstance> qmlGraphicsItemNodeInstance() const;

    void paintUpdate();


    QObject *internalObject() const; // should be not used outside of the nodeinstances!!!!

private: // variables
    QSharedPointer<Internal::ObjectNodeInstance> m_nodeInstance;
};

CORESHARED_EXPORT uint qHash(const NodeInstance &instance);
CORESHARED_EXPORT bool operator==(const NodeInstance &first, const NodeInstance &second);
}

Q_DECLARE_METATYPE(QmlDesigner::NodeInstance);

#endif // NODEINSTANCE_H