1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | #ifndef Patternist_QObjectNodeModel_H
|
---|
42 | #define Patternist_QObjectNodeModel_H
|
---|
43 |
|
---|
44 | #include <QSimpleXmlNodeModel>
|
---|
45 |
|
---|
46 | QT_BEGIN_HEADER
|
---|
47 | QT_BEGIN_NAMESPACE
|
---|
48 |
|
---|
49 | class QObject;
|
---|
50 | class PropertyToAtomicValue;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * @short Delegates QtCore's QObject into Patternist's QAbstractXmlNodeModel.
|
---|
54 | * known as pre/post numbering.
|
---|
55 | *
|
---|
56 | * QObjectXmlModel sets the toggle on QXmlNodeModelIndex to @c true, if it
|
---|
57 | * represents a property of the QObject. That is, if the QXmlNodeModelIndex is
|
---|
58 | * an attribute.
|
---|
59 | *
|
---|
60 | * @author Frans Englich <[email protected]>
|
---|
61 | */
|
---|
62 | class QObjectXmlModel : public QSimpleXmlNodeModel
|
---|
63 | {
|
---|
64 | public:
|
---|
65 | QObjectXmlModel(QObject *const object, const QXmlNamePool &np);
|
---|
66 |
|
---|
67 | QXmlNodeModelIndex root() const;
|
---|
68 |
|
---|
69 | //! [0]
|
---|
70 | virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &n1, const QXmlNodeModelIndex &n2) const;
|
---|
71 | virtual QXmlName name(const QXmlNodeModelIndex &n) const;
|
---|
72 | virtual QUrl documentUri(const QXmlNodeModelIndex &n) const;
|
---|
73 | virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &n) const;
|
---|
74 | virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const;
|
---|
75 | virtual QVariant typedValue(const QXmlNodeModelIndex &n) const;
|
---|
76 | virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex&) const;
|
---|
77 | virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis, const QXmlNodeModelIndex&) const;
|
---|
78 | //! [0]
|
---|
79 |
|
---|
80 | private:
|
---|
81 | /**
|
---|
82 | * The highest three bits are used to signify whether the node index
|
---|
83 | * is an artificial node.
|
---|
84 | *
|
---|
85 | * @short if QXmlNodeModelIndex::additionalData() has the
|
---|
86 | * QObjectPropery flag set, then the QXmlNodeModelIndex is an
|
---|
87 | * attribute of the QObject element, and the remaining bits form
|
---|
88 | * an offset to the QObject property that the QXmlNodeModelIndex
|
---|
89 | * refers to.
|
---|
90 | *
|
---|
91 | */
|
---|
92 | //! [3]
|
---|
93 | enum QObjectNodeType
|
---|
94 | {
|
---|
95 | IsQObject = 0,
|
---|
96 | QObjectProperty = 1 << 26,
|
---|
97 | MetaObjects = 2 << 26,
|
---|
98 | MetaObject = 3 << 26,
|
---|
99 | MetaObjectClassName = 4 << 26,
|
---|
100 | MetaObjectSuperClass = 5 << 26,
|
---|
101 | QObjectClassName = 6 << 26
|
---|
102 | };
|
---|
103 | //! [3]
|
---|
104 |
|
---|
105 | //! [1]
|
---|
106 | typedef QVector<const QMetaObject *> AllMetaObjects;
|
---|
107 | //! [1]
|
---|
108 | AllMetaObjects allMetaObjects() const;
|
---|
109 |
|
---|
110 | static QObjectNodeType toNodeType(const QXmlNodeModelIndex &n);
|
---|
111 | static bool isTypeSupported(QVariant::Type type);
|
---|
112 | static inline QObject *asQObject(const QXmlNodeModelIndex &n);
|
---|
113 | static inline bool isProperty(const QXmlNodeModelIndex n);
|
---|
114 | static inline QMetaProperty toMetaProperty(const QXmlNodeModelIndex &n);
|
---|
115 | /**
|
---|
116 | * Returns the ancestors of @p n. Does therefore not include
|
---|
117 | * @p n.
|
---|
118 | */
|
---|
119 | inline QXmlNodeModelIndex::List ancestors(const QXmlNodeModelIndex n) const;
|
---|
120 | QXmlNodeModelIndex qObjectSibling(const int pos,
|
---|
121 | const QXmlNodeModelIndex &n) const;
|
---|
122 | QXmlNodeModelIndex metaObjectSibling(const int pos,
|
---|
123 | const QXmlNodeModelIndex &n) const;
|
---|
124 |
|
---|
125 | //! [2]
|
---|
126 | const QUrl m_baseURI;
|
---|
127 | QObject *const m_root;
|
---|
128 | //! [4]
|
---|
129 | const AllMetaObjects m_allMetaObjects;
|
---|
130 | //! [4]
|
---|
131 | //! [2]
|
---|
132 | };
|
---|
133 |
|
---|
134 | QT_END_NAMESPACE
|
---|
135 |
|
---|
136 | QT_END_HEADER
|
---|
137 |
|
---|
138 | #endif
|
---|