modelnode.h 7.58 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** 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.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

30 31
#ifndef MODELNODE_H
#define MODELNODE_H
32

33
#include "qmldesignercorelib_global.h"
34
#include <QWeakPointer>
35 36
#include <QList>
#include <QMetaType>
37 38
#include <QVariant>

39
QT_BEGIN_NAMESPACE
40
class QTextStream;
41
QT_END_NAMESPACE
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

namespace QmlDesigner {

namespace Internal {
    class InternalNode;
    class ModelPrivate;
    class InternalNode;
    class InternalProperty;

    typedef QSharedPointer<InternalNode> InternalNodePointer;
    typedef QSharedPointer<InternalProperty> InternalPropertyPointer;
    typedef QWeakPointer<InternalNode> InternalNodeWeakPointer;
}
class NodeMetaInfo;
class AbstractProperty;
class BindingProperty;
class VariantProperty;
59
class SignalHandlerProperty;
60 61 62 63 64 65 66
class Model;
class AbstractView;
class NodeListProperty;
class NodeProperty;
class NodeAbstractProperty;
class ModelNode;

67
QMLDESIGNERCORE_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList);
68

69
typedef QList<QPair<PropertyName, QVariant> > PropertyListType;
70

71
class QMLDESIGNERCORE_EXPORT  ModelNode
72
{
73 74 75 76 77 78
    friend QMLDESIGNERCORE_EXPORT bool operator ==(const ModelNode &firstNode, const ModelNode &secondNode);
    friend QMLDESIGNERCORE_EXPORT bool operator !=(const ModelNode &firstNode, const ModelNode &secondNode);
    friend QMLDESIGNERCORE_EXPORT uint qHash(const ModelNode & node);
    friend QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const ModelNode &modelNode);
    friend QMLDESIGNERCORE_EXPORT bool operator <(const ModelNode &firstNode, const ModelNode &secondNode);
    friend QMLDESIGNERCORE_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList);
79 80 81 82 83 84 85 86
    friend class QmlDesigner::Model;
    friend class QmlDesigner::AbstractView;
    friend class QmlDesigner::NodeListProperty;
    friend class QmlDesigner::Internal::ModelPrivate;
    friend class QmlDesigner::NodeAbstractProperty;
    friend class QmlDesigner::NodeProperty;

public:
87
    enum NodeSourceType {
88 89 90
        NodeWithoutSource = 0,
        NodeWithCustomParserSource = 1,
        NodeWithComponentSource = 2
91 92
    };

93 94 95 96 97 98 99
    ModelNode();
    ModelNode(const Internal::InternalNodePointer &internalNode, Model *model, AbstractView *view);
    ModelNode(const ModelNode modelNode, AbstractView *view);
    ModelNode(const ModelNode &other);
    ~ModelNode();

    ModelNode& operator=(const ModelNode &other);
100 101
    TypeName type() const;
    TypeName simplifiedTypeName() const;
102 103
    int minorVersion() const;
    int majorVersion() const;
104
    int majorQtQuickVersion() const;
105 106 107 108 109 110 111

    bool isValid() const;
    bool isInHierarchy() const;


    NodeAbstractProperty parentProperty() const;
    void setParentProperty(NodeAbstractProperty parent);
112
    void setParentProperty(const ModelNode &newParentNode, const PropertyName &propertyName);
113 114 115 116 117 118 119 120
    bool hasParentProperty() const;

    const QList<ModelNode> allDirectSubModelNodes() const;
    const QList<ModelNode> allSubModelNodes() const;
    bool hasAnySubModelNodes() const;

    //###

121 122 123
    AbstractProperty property(const PropertyName &name) const;
    VariantProperty variantProperty(const PropertyName &name) const;
    BindingProperty bindingProperty(const PropertyName &name) const;
124
    SignalHandlerProperty signalHandlerProperty(const PropertyName &name) const;
125 126 127
    NodeListProperty nodeListProperty(const PropertyName &name) const;
    NodeProperty nodeProperty(const PropertyName &name) const;
    NodeAbstractProperty nodeAbstractProperty(const PropertyName &name) const;
128

129
    void removeProperty(const PropertyName &name); //### also implement in AbstractProperty
130 131 132 133 134 135
    QList<AbstractProperty> properties() const;
    QList<VariantProperty> variantProperties() const;
    QList<NodeAbstractProperty> nodeAbstractProperties() const;
    QList<NodeProperty> nodeProperties() const;
    QList<NodeListProperty> nodeListProperties() const;
    QList<BindingProperty> bindingProperties() const;
136
    PropertyNameList propertyNames() const;
137 138

    bool hasProperties() const;
139 140 141 142 143 144
    bool hasProperty(const PropertyName &name) const;
    bool hasVariantProperty(const PropertyName &name) const;
    bool hasBindingProperty(const PropertyName &name) const;
    bool hasNodeAbstracProperty(const PropertyName &name) const;
    bool hasNodeProperty(const PropertyName &name) const;
    bool hasNodeListProperty(const PropertyName &name) const;
145

Marco Bubke's avatar
Marco Bubke committed
146 147 148 149

    void setScriptFunctions(const QStringList &scriptFunctionList);
    QStringList scriptFunctions() const;

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
    //###
    void destroy();

    QString id() const;
    QString validId();
    void setId(const QString &id);
    static bool isValidId(const QString &id);

    Model *model() const;
    AbstractView *view() const;

    const NodeMetaInfo metaInfo() const;

    bool isSelected() const;
    bool isRootNode() const;

    bool isAncestorOf(const ModelNode &node) const;
    void selectNode();
    void deselectNode();

    static int variantUserType();
    QVariant toVariant() const;

173 174 175 176
    QVariant auxiliaryData(const PropertyName &name) const;
    void setAuxiliaryData(const PropertyName &name, const QVariant &data) const;
    bool hasAuxiliaryData(const PropertyName &name) const;
    QHash<PropertyName, QVariant> auxiliaryData() const;
177

178 179
    qint32 internalId() const;

180 181
    void setNodeSource(const QString&);
    QString nodeSource() const;
182

183 184
    QString convertTypeToImportAlias() const;

185 186
    NodeSourceType nodeSourceType() const;

187 188 189 190 191 192 193 194 195 196
private: // functions
    Internal::InternalNodePointer internalNode() const;
    QString generateNewId() const;

private: // variables
    Internal::InternalNodePointer m_internalNode;
    QWeakPointer<Model> m_model;
    QWeakPointer<AbstractView> m_view;
};

197 198 199 200 201 202
QMLDESIGNERCORE_EXPORT bool operator ==(const ModelNode &firstNode, const ModelNode &secondNode);
QMLDESIGNERCORE_EXPORT bool operator !=(const ModelNode &firstNode, const ModelNode &secondNode);
QMLDESIGNERCORE_EXPORT uint qHash(const ModelNode & node);
QMLDESIGNERCORE_EXPORT bool operator <(const ModelNode &firstNode, const ModelNode &secondNode);
QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const ModelNode &modelNode);
QMLDESIGNERCORE_EXPORT QTextStream& operator<<(QTextStream &stream, const ModelNode &modelNode);
203 204 205 206 207
}

Q_DECLARE_METATYPE(QmlDesigner::ModelNode)
Q_DECLARE_METATYPE(QList<QmlDesigner::ModelNode>)

208
#endif // MODELNODE_H