1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the examples of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** You may use this file under the terms of the BSD license as follows: 10 ** 11 ** "Redistribution and use in source and binary forms, with or without 12 ** modification, are permitted provided that the following conditions are 13 ** met: 14 ** * Redistributions of source code must retain the above copyright 15 ** notice, this list of conditions and the following disclaimer. 16 ** * Redistributions in binary form must reproduce the above copyright 17 ** notice, this list of conditions and the following disclaimer in 18 ** the documentation and/or other materials provided with the 19 ** distribution. 20 ** * Neither the name of The Qt Company Ltd nor the names of its 21 ** contributors may be used to endorse or promote products derived 22 ** from this software without specific prior written permission. 23 ** 24 ** 25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 ** 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 <frans.englich@nokia.com> 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 139