//! [5]
QXmlNodeModelIndex QObjectXmlModel::qObjectSibling(const int pos, const QXmlNodeModelIndex &n) const
{
    Q_ASSERT(pos == 1 || pos == -1);
    Q_ASSERT(asQObject(n));

    const QObject *parent = asQObject(n)->parent();
    if (parent) {
        const QList<QObject *> &children = parent->children();
        const int siblingPos = children.indexOf(asQObject(n)) + pos;

        if (siblingPos >= 0 && siblingPos < children.count())
            return createIndex(children.at(siblingPos));
        else
            return QXmlNodeModelIndex();
    }
    else
        return QXmlNodeModelIndex();
}
Пример #2
0
void tst_QXmlItem::copyConstructorFromQXmlNodeModelIndex() const
{
    // TODO copy a valid model index.

    /* Construct from a null QXmlNodeModelIndex. */
    {
        const QXmlItem item((QXmlNodeModelIndex()));
        QVERIFY(item.isNull());
    }
}
Пример #3
0
QXmlNodeModelIndex QObjectXmlModel::metaObjectSibling(const int pos, const QXmlNodeModelIndex &n) const
{
    Q_ASSERT(pos == 1 || pos == -1);
    Q_ASSERT(!n.isNull());

    const int indexOf = m_allMetaObjects.indexOf(static_cast<const QMetaObject *>(n.internalPointer())) + pos;

    if (indexOf >= 0 && indexOf < m_allMetaObjects.count())
        return createIndex(const_cast<QMetaObject *>(m_allMetaObjects.at(indexOf)), MetaObject);
    else
        return QXmlNodeModelIndex();
}
Пример #4
0
QXmlNodeModelIndex LoadingModel::nextFromSimpleAxis(QAbstractXmlNodeModel::SimpleAxis axis,
                                                    const QXmlNodeModelIndex &ni) const
{
    const Node *const internal = toInternal(ni);

    /* Note that a QXmlNodeModelIndex containing a null pointer is not a null node. */
    switch(axis)
    {
        case Parent:
            return internal->parent ? createIndex(internal->parent) : QXmlNodeModelIndex();
        case FirstChild:
            return internal->firstChild ? createIndex(internal->firstChild) : QXmlNodeModelIndex();
        case PreviousSibling:
            return internal->precedingSibling ? createIndex(internal->precedingSibling) : QXmlNodeModelIndex();
        case NextSibling:
            return internal->followingSibling ? createIndex(internal->followingSibling) : QXmlNodeModelIndex();
    }

    Q_ASSERT(false);
    return QXmlNodeModelIndex();
}
Пример #5
0
QXmlNodeModelIndex LoadingModel::nextFromSimpleAxis(QAbstractXmlNodeModel::SimpleAxis axis,
                                                    const QXmlNodeModelIndex &ni) const
{
    const Node *const internal = toInternal(ni);

    /* Note that a QXmlNodeModelIndex containing a null pointer is not a null node. */
    switch(axis)
    {
        case Parent:
            return internal->parent ? createIndex(internal->parent) : QXmlNodeModelIndex();
        case FirstChild:
            return internal->firstChild ? createIndex(internal->firstChild) : QXmlNodeModelIndex();
        case PreviousSibling:
            return internal->precedingSibling ? createIndex(internal->precedingSibling) : QXmlNodeModelIndex();
        case NextSibling:
            return internal->followingSibling ? createIndex(internal->followingSibling) : QXmlNodeModelIndex();
        default:
            qWarning("%s: unknown axis enum value %d", Q_FUNC_INFO, static_cast<int>(axis));
            return QXmlNodeModelIndex();
    }
}
Пример #6
0
void tst_QXmlNodeModelIndex::isNull() const
{
    /* Check default value. */
    {
        const QXmlNodeModelIndex index;
        QVERIFY(index.isNull());
    }

    /* Test default value on a temporary object. */
    {
        QVERIFY(QXmlNodeModelIndex().isNull());
    }
}
Пример #7
0
void tst_QXmlItem::assignmentOperator() const
{
    /* Assign to self. */
    {
        /* With null value. */
        {
            QXmlItem item;
            item = item;
            item = item;
            item = item;
            item = item;
            item = item;
        }

        /* With the same atomic value. */
        {
            QXmlItem item(QVariant(QString::fromLatin1("dummy")));
            item = item;
            item = item;
            item = item;
            item = item;
            item = item;
        }

        /* With the same node. */
        {
            // TODO
        }

        /* With a QXmlItem constructed from a null QVariant. */
        {
            QXmlItem item((QVariant()));
            item = item;
            item = item;
            item = item;
            item = item;
            item = item;
        }

        /* With a QXmlItem constructed from a null QXmlNodeModelIndex. */
        {
            QXmlItem item((QXmlNodeModelIndex()));
            item = item;
            item = item;
            item = item;
            item = item;
            item = item;
        }
    }
}
Пример #8
0
void tst_QXmlNodeModelIndex::copyConstructor() const
{
    /* Check that we can take a const reference. */
    {
        const QXmlNodeModelIndex index;
        const QXmlNodeModelIndex copy(index);
    }

    /* Take a copy of a temporary. */
    {
    	/* The extra paranthesis silences a warning on win32-msvc. */
        const QXmlNodeModelIndex copy((QXmlNodeModelIndex()));
    }
}
//! [0]
QXmlNodeModelIndex MyTreeModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &ni) const
{
    // Convert the QXmlNodeModelIndex to a value that is specific to what we represent.
    const MyValue value = toMyValue(ni);

    switch(axis)
    {
        case Parent:
            return toNodeIndex(value.parent());
        case FirstChild:
        case PreviousSibling:
        case NextSibling:
            // and so on
            ;
    }
    return QXmlNodeModelIndex();
}
Пример #10
0
void tst_QXmlItem::copyConstructor() const
{
    /* Check that we can copy from a const reference. */
    {
        const QXmlItem item;
        const QXmlItem copy(item);
    }

    /* On a QXmlItem constructed from a null QVariant. */
    {
        const QXmlItem item((QVariant()));
        const QXmlItem copy(item);
    }

    /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
    {
        const QXmlItem item((QXmlNodeModelIndex()));
        const QXmlItem copy(item);
    }
}
Пример #11
0
int
main(int argc, char** argv) {
    QCoreApplication app(argc, argv);
    if (argc != 3) return -1;

    QUrl queryUrl = QUrl::fromLocalFile(argv[1]);

    const QXmlNamePool namePool;
    MsoXmlNodeModel model(namePool, argv[2]);
    QXmlNodeModelIndex root = model.root(QXmlNodeModelIndex());

    QXmlQuery query(namePool);
    query.bindVariable("fileTree", root);
    query.setQuery(queryUrl);

    QFile out;
    out.open(stdout, QIODevice::WriteOnly);

    QXmlFormatter serializer(query, &out);
    query.evaluateTo(&serializer);

    return 0;
}
Пример #12
0
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
myInstance = QXmlNodeModelIndex();
//! [0]

//! [1]
QFile queryFile(argv[1]);
QFile chemistryData(argv[2]);
QString moleculeName = argv[3];

QXmlQuery query;
query.setQuery(&queryFile, QUrl::fromLocalFile(queryFile.fileName()));

ChemistryNodeModel myNodeModel(query.namePool(), chemistryData);
QXmlNodeModelIndex startNode = myNodeModel.nodeFor(moleculeName);
query.bindVariable("queryRoot", startNode);

QFile out;
Пример #13
0
//! [2]
QXmlNodeModelIndex QObjectXmlModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &n) const
{
    switch (toNodeType(n))
    {
    case IsQObject:
    {
        switch (axis)
        {
        case Parent:
            return createIndex(asQObject(n)->parent());

        case FirstChild:
        {
            if (!asQObject(n) || asQObject(n)->children().isEmpty())
                return QXmlNodeModelIndex();
            else
                return createIndex(asQObject(n)->children().first());
        }

        case NextSibling:
            return qObjectSibling(1, n);

//! [10]
        case PreviousSibling:
        {
            if (asQObject(n) == m_root)
                return createIndex(qint64(0), MetaObjects);
            else
                return qObjectSibling(-1, n);
        }
//! [10]
        }
        Q_ASSERT(false);
    }

//! [7]
    case QObjectClassName:
    case QObjectProperty:
    {
        Q_ASSERT(axis == Parent);
        return createIndex(asQObject(n));
    }
//! [7]
//! [2]
//! [3]

//! [11]
    case MetaObjects:
    {
        switch (axis)
        {
        case Parent:
            return QXmlNodeModelIndex();
        case PreviousSibling:
            return QXmlNodeModelIndex();
        case NextSibling:
            return root();
        case FirstChild:
        {
            return createIndex(const_cast<QMetaObject*>(m_allMetaObjects.first()),MetaObject);
        }
        }
        Q_ASSERT(false);
    }
//! [11]

    case MetaObject:
    {
        switch (axis)
        {
        case FirstChild:
            return QXmlNodeModelIndex();
        case Parent:
            return createIndex(qint64(0), MetaObjects);
        case PreviousSibling:
            return metaObjectSibling(-1, n);
        case NextSibling:
            return metaObjectSibling(1, n);
        }
    }

    case MetaObjectClassName:
    case MetaObjectSuperClass:
    {
        Q_ASSERT(axis == Parent);
        return createIndex(asQObject(n), MetaObject);
    }
//! [3]
//! [4]
    }

    Q_ASSERT(false);
    return QXmlNodeModelIndex();
}