|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
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 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef Patternist_QObjectNodeModel_H |
|
43 #define Patternist_QObjectNodeModel_H |
|
44 |
|
45 #include <QSimpleXmlNodeModel> |
|
46 |
|
47 QT_BEGIN_HEADER |
|
48 QT_BEGIN_NAMESPACE |
|
49 |
|
50 class QObject; |
|
51 class PropertyToAtomicValue; |
|
52 |
|
53 /** |
|
54 * @short Delegates QtCore's QObject into Patternist's QAbstractXmlNodeModel. |
|
55 * known as pre/post numbering. |
|
56 * |
|
57 * QObjectXmlModel sets the toggle on QXmlNodeModelIndex to @c true, if it |
|
58 * represents a property of the QObject. That is, if the QXmlNodeModelIndex is |
|
59 * an attribute. |
|
60 * |
|
61 * @author Frans Englich <frans.englich@nokia.com> |
|
62 */ |
|
63 class QObjectXmlModel : public QSimpleXmlNodeModel |
|
64 { |
|
65 public: |
|
66 QObjectXmlModel(QObject *const object, const QXmlNamePool &np); |
|
67 |
|
68 QXmlNodeModelIndex root() const; |
|
69 |
|
70 //! [0] |
|
71 virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &n1, const QXmlNodeModelIndex &n2) const; |
|
72 virtual QXmlName name(const QXmlNodeModelIndex &n) const; |
|
73 virtual QUrl documentUri(const QXmlNodeModelIndex &n) const; |
|
74 virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &n) const; |
|
75 virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const; |
|
76 virtual QVariant typedValue(const QXmlNodeModelIndex &n) const; |
|
77 virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex&) const; |
|
78 virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis, const QXmlNodeModelIndex&) const; |
|
79 //! [0] |
|
80 |
|
81 private: |
|
82 /** |
|
83 * The highest three bits are used to signify whether the node index |
|
84 * is an artificial node. |
|
85 * |
|
86 * @short if QXmlNodeModelIndex::additionalData() has the |
|
87 * QObjectPropery flag set, then the QXmlNodeModelIndex is an |
|
88 * attribute of the QObject element, and the remaining bits form |
|
89 * an offset to the QObject property that the QXmlNodeModelIndex |
|
90 * refers to. |
|
91 * |
|
92 */ |
|
93 //! [3] |
|
94 enum QObjectNodeType |
|
95 { |
|
96 IsQObject = 0, |
|
97 QObjectProperty = 1 << 26, |
|
98 MetaObjects = 2 << 26, |
|
99 MetaObject = 3 << 26, |
|
100 MetaObjectClassName = 4 << 26, |
|
101 MetaObjectSuperClass = 5 << 26, |
|
102 QObjectClassName = 6 << 26 |
|
103 }; |
|
104 //! [3] |
|
105 |
|
106 //! [1] |
|
107 typedef QVector<const QMetaObject *> AllMetaObjects; |
|
108 //! [1] |
|
109 AllMetaObjects allMetaObjects() const; |
|
110 |
|
111 static QObjectNodeType toNodeType(const QXmlNodeModelIndex &n); |
|
112 static bool isTypeSupported(QVariant::Type type); |
|
113 static inline QObject *asQObject(const QXmlNodeModelIndex &n); |
|
114 static inline bool isProperty(const QXmlNodeModelIndex n); |
|
115 static inline QMetaProperty toMetaProperty(const QXmlNodeModelIndex &n); |
|
116 /** |
|
117 * Returns the ancestors of @p n. Does therefore not include |
|
118 * @p n. |
|
119 */ |
|
120 inline QXmlNodeModelIndex::List ancestors(const QXmlNodeModelIndex n) const; |
|
121 QXmlNodeModelIndex qObjectSibling(const int pos, |
|
122 const QXmlNodeModelIndex &n) const; |
|
123 QXmlNodeModelIndex metaObjectSibling(const int pos, |
|
124 const QXmlNodeModelIndex &n) const; |
|
125 |
|
126 //! [2] |
|
127 const QUrl m_baseURI; |
|
128 QObject *const m_root; |
|
129 //! [4] |
|
130 const AllMetaObjects m_allMetaObjects; |
|
131 //! [4] |
|
132 //! [2] |
|
133 }; |
|
134 |
|
135 QT_END_NAMESPACE |
|
136 |
|
137 QT_END_HEADER |
|
138 |
|
139 #endif |