1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef DESIGNERNODE_H
34 #define DESIGNERNODE_H
36 #include "corelib_global.h"
37 #include <QWeakPointer>
38 #include <QtCore/QList>
39 #include <QtCore/QMetaType>
46 namespace QmlDesigner {
52 class InternalProperty;
54 typedef QSharedPointer<InternalNode> InternalNodePointer;
55 typedef QSharedPointer<InternalProperty> InternalPropertyPointer;
56 typedef QWeakPointer<InternalNode> InternalNodeWeakPointer;
59 class AbstractProperty;
60 class BindingProperty;
61 class VariantProperty;
64 class NodeListProperty;
66 class NodeAbstractProperty;
69 CORESHARED_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList);
71 typedef QList<QPair<QString, QVariant> > PropertyListType;
73 class CORESHARED_EXPORT ModelNode
75 friend CORESHARED_EXPORT bool operator ==(const ModelNode &firstNode, const ModelNode &secondNode);
76 friend CORESHARED_EXPORT bool operator !=(const ModelNode &firstNode, const ModelNode &secondNode);
77 friend CORESHARED_EXPORT uint qHash(const ModelNode & node);
78 friend CORESHARED_EXPORT QDebug operator<<(QDebug debug, const ModelNode &modelNode);
79 friend CORESHARED_EXPORT bool operator <(const ModelNode &firstNode, const ModelNode &secondNode);
80 friend CORESHARED_EXPORT QList<Internal::InternalNodePointer> QmlDesigner::toInternalNodeList(const QList<ModelNode> &nodeList);
81 friend class QmlDesigner::Model;
82 friend class QmlDesigner::AbstractView;
83 friend class QmlDesigner::NodeListProperty;
84 friend class QmlDesigner::Internal::ModelPrivate;
85 friend class QmlDesigner::NodeAbstractProperty;
86 friend class QmlDesigner::NodeProperty;
90 ModelNode(const Internal::InternalNodePointer &internalNode, Model *model, AbstractView *view);
91 ModelNode(const ModelNode modelNode, AbstractView *view);
92 ModelNode(const ModelNode &other);
95 ModelNode& operator=(const ModelNode &other);
97 QString simplifiedTypeName() const;
98 int minorVersion() const;
99 int majorVersion() const;
101 bool isValid() const;
102 bool isInHierarchy() const;
105 NodeAbstractProperty parentProperty() const;
106 void setParentProperty(NodeAbstractProperty parent);
107 void setParentProperty(const ModelNode &newParentNode, const QString &propertyName);
108 bool hasParentProperty() const;
110 const QList<ModelNode> allDirectSubModelNodes() const;
111 const QList<ModelNode> allSubModelNodes() const;
112 bool hasAnySubModelNodes() const;
116 AbstractProperty property(const QString &name) const;
117 VariantProperty variantProperty(const QString &name) const;
118 BindingProperty bindingProperty(const QString &name) const;
119 NodeListProperty nodeListProperty(const QString &name) const;
120 NodeProperty nodeProperty(const QString &name) const;
121 NodeAbstractProperty nodeAbstractProperty(const QString &name) const;
123 void removeProperty(const QString &name); //### also implement in AbstractProperty
124 QList<AbstractProperty> properties() const;
125 QList<VariantProperty> variantProperties() const;
126 QList<NodeAbstractProperty> nodeAbstractProperties() const;
127 QList<NodeProperty> nodeProperties() const;
128 QList<NodeListProperty> nodeListProperties() const;
129 QList<BindingProperty> bindingProperties() const;
130 QStringList propertyNames() const;
132 bool hasProperties() const;
133 bool hasProperty(const QString &name) const;
134 bool hasVariantProperty(const QString &name) const;
135 bool hasBindingProperty(const QString &name) const;
136 bool hasNodeAbstracProperty(const QString &name) const;
137 bool hasNodeProperty(const QString &name) const;
138 bool hasNodeListProperty(const QString &name) const;
141 void setScriptFunctions(const QStringList &scriptFunctionList);
142 QStringList scriptFunctions() const;
149 void setId(const QString &id);
150 static bool isValidId(const QString &id);
152 Model *model() const;
153 AbstractView *view() const;
155 const NodeMetaInfo metaInfo() const;
157 bool isSelected() const;
158 bool isRootNode() const;
160 bool isAncestorOf(const ModelNode &node) const;
164 static int variantUserType();
165 QVariant toVariant() const;
167 QVariant auxiliaryData(const QString &name) const;
168 void setAuxiliaryData(const QString &name, const QVariant &data);
169 bool hasAuxiliaryData(const QString &name) const;
171 qint32 internalId() const;
173 private: // functions
174 Internal::InternalNodePointer internalNode() const;
175 QString generateNewId() const;
177 private: // variables
178 Internal::InternalNodePointer m_internalNode;
179 QWeakPointer<Model> m_model;
180 QWeakPointer<AbstractView> m_view;
183 CORESHARED_EXPORT bool operator ==(const ModelNode &firstNode, const ModelNode &secondNode);
184 CORESHARED_EXPORT bool operator !=(const ModelNode &firstNode, const ModelNode &secondNode);
185 CORESHARED_EXPORT uint qHash(const ModelNode & node);
186 CORESHARED_EXPORT bool operator <(const ModelNode &firstNode, const ModelNode &secondNode);
187 CORESHARED_EXPORT QDebug operator<<(QDebug debug, const ModelNode &modelNode);
188 CORESHARED_EXPORT QTextStream& operator<<(QTextStream &stream, const ModelNode &modelNode);
191 Q_DECLARE_METATYPE(QmlDesigner::ModelNode)
192 Q_DECLARE_METATYPE(QList<QmlDesigner::ModelNode>)
194 #endif // DESIGNERNODE_H