itemlibraryinfo.h 4.27 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
** 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
12
13
14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16
17
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
18
19
20
21
22
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25

26
27
#ifndef ITEMLIBRARYINFO_H
#define ITEMLIBRARYINFO_H
28

29
#include "qmldesignercorelib_global.h"
30
31

#include "propertycontainer.h"
32
#include <QPointer>
33
34
35
36
37

namespace QmlDesigner {

namespace Internal {

38
class ItemLibraryEntryData;
39
class MetaInfoPrivate;
40
41
}

42
class ItemLibraryEntry;
43

44
45
QMLDESIGNERCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const ItemLibraryEntry &itemLibraryEntry);
QMLDESIGNERCORE_EXPORT QDataStream& operator>>(QDataStream& stream, ItemLibraryEntry &itemLibraryEntry);
46
QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const ItemLibraryEntry &itemLibraryEntry);
47

48
class QMLDESIGNERCORE_EXPORT ItemLibraryEntry
49
{
50
51
    //friend class QmlDesigner::MetaInfo;
    //friend class QmlDesigner::Internal::MetaInfoParser;
52
53
    friend QMLDESIGNERCORE_EXPORT QDataStream& operator<<(QDataStream& stream, const ItemLibraryEntry &itemLibraryEntry);
    friend QMLDESIGNERCORE_EXPORT QDataStream& operator>>(QDataStream& stream, ItemLibraryEntry &itemLibraryEntry);
54
    friend QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const ItemLibraryEntry &itemLibraryEntry);
hjk's avatar
hjk committed
55

56
public:
57
58
    ItemLibraryEntry();
    ~ItemLibraryEntry();
59
60

    QString name() const;
61
    TypeName typeName() const;
62
63
    QIcon typeIcon() const;
    QString libraryEntryIconPath() const;
64
65
66
67
    int majorVersion() const;
    int minorVersion() const;
    QString category() const;
    QIcon dragIcon() const;
68
    QString qmlPath() const;
69
    QString qmlSource() const;
70
    QString requiredImport() const;
71

72
73
    ItemLibraryEntry(const ItemLibraryEntry &other);
    ItemLibraryEntry& operator=(const ItemLibraryEntry &other);
74
75
76
77
78

    typedef QmlDesigner::PropertyContainer Property;

    QList<Property> properties() const;

79
    void setType(const TypeName &typeName, int majorVersion = -1, int minorVersion = -1);
80
    void setName(const QString &name);
81
    void setLibraryEntryIconPath(const QString &libraryEntryIconPath);
82
    void addProperty(const Property &p);
83
    void addProperty(PropertyName &name, QString &type, QVariant &value);
84
    void setTypeIcon(const QIcon &typeIcon);
85
    void setCategory(const QString &category);
86
    void setQmlPath(const QString &qml);
87
    void setRequiredImport(const QString &requiredImport);
88

89
private:
90
    QExplicitlySharedDataPointer<Internal::ItemLibraryEntryData> m_data;
91
92
};

93
class QMLDESIGNERCORE_EXPORT ItemLibraryInfo : public QObject
94
{
95
    Q_OBJECT
hjk's avatar
hjk committed
96

97
98
99
100
    friend class Internal::MetaInfoPrivate;
public:

    QList<ItemLibraryEntry> entries() const;
101
    QList<ItemLibraryEntry> entriesForType(const QString &typeName, int majorVersion, int minorVersion) const;
102
103
    ItemLibraryEntry entry(const QString &name) const;

104
    void addEntry(const ItemLibraryEntry &entry, bool overwriteDuplicate = false);
105
    bool containsEntry(const ItemLibraryEntry &entry);
106
    void clearEntries();
107

108
109
110
signals:
    void entriesChanged();

111
private: // functions
112
    ItemLibraryInfo(QObject *parent = 0);
113
114
115
116
    void setBaseInfo(ItemLibraryInfo *m_baseInfo);

private: // variables
    QHash<QString, ItemLibraryEntry> m_nameToEntryHash;
117
    QPointer<ItemLibraryInfo> m_baseInfo;
118
119
120
};

} // namespace QmlDesigner
121

122
123
Q_DECLARE_METATYPE(QmlDesigner::ItemLibraryEntry)

124
#endif // ITEMLIBRARYINFO_H