1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "nodeinstance.h"
37 #include <modelnode.h>
38 #include "commondefines.h"
42 namespace QmlDesigner {
44 class ProxyNodeInstanceData
47 ProxyNodeInstanceData()
48 : parentInstanceId(-1),
50 isAnchoredBySibling(false),
51 isAnchoredByChildren(false),
58 qint32 parentInstanceId;
64 QTransform sceneTransform;
66 bool isAnchoredBySibling;
67 bool isAnchoredByChildren;
74 QHash<QString, QVariant> propertyValues;
75 QHash<QString, bool> hasBindingForProperty;
76 QHash<QString, bool> hasAnchors;
77 QHash<QString, QString> instanceTypes;
80 QHash<QString, QPair<QString, qint32> > anchors;
83 NodeInstance::NodeInstance()
87 NodeInstance::NodeInstance(ProxyNodeInstanceData *dPointer)
92 NodeInstance NodeInstance::create(const ModelNode &node)
94 ProxyNodeInstanceData *d = new ProxyNodeInstanceData;
98 return NodeInstance(d);
101 NodeInstance::~NodeInstance()
105 NodeInstance::NodeInstance(const NodeInstance &other)
110 NodeInstance &NodeInstance::operator=(const NodeInstance &other)
116 ModelNode NodeInstance::modelNode() const
125 qint32 NodeInstance::instanceId() const
128 return d->modelNode.internalId();
134 bool NodeInstance::isValid() const
136 return instanceId() >= 0 && modelNode().isValid();
139 void NodeInstance::makeInvalid()
142 d->modelNode = ModelNode();
145 QRectF NodeInstance::boundingRect() const
148 return d->boundingRect;
154 bool NodeInstance::hasContent() const
157 return d->hasContent;
163 bool NodeInstance::isAnchoredBySibling() const
166 return d->isAnchoredBySibling;
172 bool NodeInstance::isAnchoredByChildren() const
175 return d->isAnchoredByChildren;
181 bool NodeInstance::isMovable() const
190 bool NodeInstance::isResizable() const
193 return d->isResizable;
199 QTransform NodeInstance::transform() const
207 QTransform NodeInstance::sceneTransform() const
210 return d->sceneTransform;
215 bool NodeInstance::isInPositioner() const
218 return d->isInPositioner;
224 QPointF NodeInstance::position() const
233 QSizeF NodeInstance::size() const
242 int NodeInstance::penWidth() const
251 void NodeInstance::paint(QPainter *painter)
253 if (isValid() && !d->renderImage.isNull())
254 painter->drawImage(boundingRect().topLeft(), d->renderImage);
257 QVariant NodeInstance::property(const QString &name) const
260 return d->propertyValues.value(name);
265 bool NodeInstance::hasBindingForProperty(const QString &name) const
268 return d->hasBindingForProperty.value(name, false);
273 QString NodeInstance::instanceType(const QString &name) const
276 return d->instanceTypes.value(name);
281 qint32 NodeInstance::parentId() const
284 return d->parentInstanceId;
290 bool NodeInstance::hasAnchor(const QString &name) const
293 return d->hasAnchors.value(name, false);
298 QPair<QString, qint32> NodeInstance::anchor(const QString &name) const
301 return d->anchors.value(name, QPair<QString, qint32>(QString(), qint32(-1)));
303 return QPair<QString, qint32>(QString(), -1);
306 void NodeInstance::setProperty(const QString &name, const QVariant &value)
308 d->propertyValues.insert(name, value);
311 void NodeInstance::setRenderImage(const QImage &image)
313 d->renderImage = image;
316 void NodeInstance::setParentId(qint32 instanceId)
318 d->parentInstanceId = instanceId;
321 void NodeInstance::setInformation(InformationName name, const QVariant &information, const QVariant &secondInformation, const QVariant &thirdInformation)
324 case Size: d->size = information.toSizeF(); break;
325 case BoundingRect: d->boundingRect = information.toRectF(); break;
326 case Transform: d->transform = information.value<QTransform>(); break;
327 case PenWidth: d->penWidth = information.toInt(); break;
328 case Position: d->position = information.toPointF(); break;
329 case IsInPositioner: d->isInPositioner = information.toBool(); break;
330 case SceneTransform: d->sceneTransform = information.value<QTransform>(); break;
331 case IsResizable: d->isResizable = information.toBool(); break;
332 case IsMovable: d->isMovable = information.toBool(); break;
333 case IsAnchoredByChildren: d->isAnchoredByChildren = information.toBool(); break;
334 case IsAnchoredBySibling: d->isAnchoredBySibling = information.toBool(); break;
335 case HasContent: d->hasContent = information.toBool(); break;
336 case HasAnchor: d->hasAnchors.insert(information.toString(), secondInformation.toBool());break;
337 case Anchor: d->anchors.insert(information.toString(), qMakePair(secondInformation.toString(), thirdInformation.value<qint32>())); break;
338 case InstanceTypeForProperty: d->instanceTypes.insert(information.toString(), secondInformation.toString()); break;
339 case HasBindingForProperty: d->hasBindingForProperty.insert(information.toString(), secondInformation.toBool()); break;