OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmldesigner / designercore / include / modelnode.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef DESIGNERNODE_H
34 #define DESIGNERNODE_H
35
36 #include "corelib_global.h"
37 #include <QWeakPointer>
38 #include <QtCore/QList>
39 #include <QtCore/QMetaType>
40 #include <QVariant>
41
42 QT_BEGIN_NAMESPACE
43 class QTextStream;
44 QT_END_NAMESPACE
45
46 namespace QmlDesigner {
47
48 namespace Internal {
49     class InternalNode;
50     class ModelPrivate;
51     class InternalNode;
52     class InternalProperty;
53
54     typedef QSharedPointer<InternalNode> InternalNodePointer;
55     typedef QSharedPointer<InternalProperty> InternalPropertyPointer;
56     typedef QWeakPointer<InternalNode> InternalNodeWeakPointer;
57 }
58 class NodeMetaInfo;
59 class AbstractProperty;
60 class BindingProperty;
61 class VariantProperty;
62 class Model;
63 class AbstractView;
64 class NodeListProperty;
65 class NodeProperty;
66 class NodeAbstractProperty;
67 class ModelNode;
68
69 CORESHARED_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList);
70
71 typedef QList<QPair<QString, QVariant> > PropertyListType;
72
73 class CORESHARED_EXPORT ModelNode
74 {
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;
87
88 public:
89     ModelNode();
90     ModelNode(const Internal::InternalNodePointer &internalNode, Model *model, AbstractView *view);
91     ModelNode(const ModelNode modelNode, AbstractView *view);
92     ModelNode(const ModelNode &other);
93     ~ModelNode();
94
95     ModelNode& operator=(const ModelNode &other);
96     QString type() const;
97     QString simplifiedTypeName() const;
98     int minorVersion() const;
99     int majorVersion() const;
100
101     bool isValid() const;
102     bool isInHierarchy() const;
103
104
105     NodeAbstractProperty parentProperty() const;
106     void setParentProperty(NodeAbstractProperty parent);
107     void setParentProperty(const ModelNode &newParentNode, const QString &propertyName);
108     bool hasParentProperty() const;
109
110     const QList<ModelNode> allDirectSubModelNodes() const;
111     const QList<ModelNode> allSubModelNodes() const;
112     bool hasAnySubModelNodes() const;
113
114     //###
115
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;
122
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;
131
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;
139
140
141     void setScriptFunctions(const QStringList &scriptFunctionList);
142     QStringList scriptFunctions() const;
143
144     //###
145     void destroy();
146
147     QString id() const;
148     QString validId();
149     void setId(const QString &id);
150     static bool isValidId(const QString &id);
151
152     Model *model() const;
153     AbstractView *view() const;
154
155     const NodeMetaInfo metaInfo() const;
156
157     bool isSelected() const;
158     bool isRootNode() const;
159
160     bool isAncestorOf(const ModelNode &node) const;
161     void selectNode();
162     void deselectNode();
163
164     static int variantUserType();
165     QVariant toVariant() const;
166
167     QVariant auxiliaryData(const QString &name) const;
168     void setAuxiliaryData(const QString &name, const QVariant &data);
169     bool hasAuxiliaryData(const QString &name) const;
170
171     qint32 internalId() const;
172
173 private: // functions
174     Internal::InternalNodePointer internalNode() const;
175     QString generateNewId() const;
176
177 private: // variables
178     Internal::InternalNodePointer m_internalNode;
179     QWeakPointer<Model> m_model;
180     QWeakPointer<AbstractView> m_view;
181 };
182
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);
189 }
190
191 Q_DECLARE_METATYPE(QmlDesigner::ModelNode)
192 Q_DECLARE_METATYPE(QList<QmlDesigner::ModelNode>)
193
194 #endif // DESIGNERNODE_H