예제 #1
0
/*!
  Returns the typed value for \a node, which must be either an
  attribute or an element. The QVariant returned represents the atomic
  value of an attribute or the atomic value contained in an element.

  If the QVariant is returned as a default constructed variant,
  it means that \a node has no typed value.
 */
QVariant FileTree::typedValue(const QXmlNodeModelIndex &node) const
{
    const QFileInfo &fi = toFileInfo(node);

    switch (Type(node.additionalData())) {
    case Directory:
    // deliberate fall through.
    case File:
        return QString();
    case AttributeFileName:
        return fi.fileName();
    case AttributeFilePath:
        return fi.filePath();
    case AttributeSize:
        return fi.size();
    case AttributeMIMEType:
    {
        /* We don't have any MIME detection code currently, so return
         * the most generic one. */
        return QLatin1String("application/octet-stream");
    }
    case AttributeSuffix:
        return fi.suffix();
    }

    Q_ASSERT_X(false, Q_FUNC_INFO, "This line should never be reached.");
    return QString();
}
예제 #2
0
void tst_QXmlNodeModelIndex::constCorrectness() const
{
    const QXmlNodeModelIndex index;
    /* All these functions should be const. */
    index.internalPointer();
    index.data();
    index.additionalData();
    index.isNull();
    index.model();
}
예제 #3
0
void tst_QXmlNodeModelIndex::additionalData() const
{
    /* Check default value. */
    {
        const QXmlNodeModelIndex index;
        QCOMPARE(index.additionalData(), qint64(0));
    }

    // TODO check that the return value for data() is qint64.
}
예제 #4
0
/*!
  This function returns QXmlNodeModelIndex::Element if \a node
  is a directory or a file, and QXmlNodeModelIndex::Attribute
  otherwise.
 */
QXmlNodeModelIndex::NodeKind
FileTree::kind(const QXmlNodeModelIndex &node) const
{
    switch (Type(node.additionalData())) {
    case Directory:
    case File:
        return QXmlNodeModelIndex::Element;
    default:
        return QXmlNodeModelIndex::Attribute;
    }
}
예제 #5
0
/*!
  Returns the attributes of \a element. The caller guarantees
  that \a element is an element in this node model.
 */
QVector<QXmlNodeModelIndex>
FileTree::attributes(const QXmlNodeModelIndex &element) const
{
    QVector<QXmlNodeModelIndex> result;

    /* Both elements has this attribute. */
    const QFileInfo &forElement = toFileInfo(element);
    result.append(toNodeIndex(forElement, AttributeFilePath));
    result.append(toNodeIndex(forElement, AttributeFileName));

    if (Type(element.additionalData() == File)) {
        result.append(toNodeIndex(forElement, AttributeSize));
        result.append(toNodeIndex(forElement, AttributeSuffix));
        //result.append(toNodeIndex(forElement, AttributeMIMEType));
    }
    else {
        Q_ASSERT(element.additionalData() == Directory);
    }

    return result;
}
예제 #6
0
//! [4]
QXmlNodeModelIndex
FileTree::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &nodeIndex) const
{
    const QFileInfo fi(toFileInfo(nodeIndex));
    const Type type = Type(nodeIndex.additionalData());

    if (type != File && type != Directory) {
        Q_ASSERT_X(axis == Parent, Q_FUNC_INFO, "An attribute only has a parent!");
        return toNodeIndex(fi, Directory);
    }

    switch (axis) {
    case Parent:
        return toNodeIndex(QFileInfo(fi.path()), Directory);

    case FirstChild:
    {
        if (type == File) // A file has no children.
            return QXmlNodeModelIndex();
        else {
            Q_ASSERT(type == Directory);
            Q_ASSERT_X(fi.isDir(), Q_FUNC_INFO, "It isn't really a directory!");
            const QDir dir(fi.absoluteFilePath());
            Q_ASSERT(dir.exists());

            const QFileInfoList children(dir.entryInfoList(QStringList(),
                                         m_filterAllowAll,
                                         m_sortFlags));
            if (children.isEmpty())
                return QXmlNodeModelIndex();
            const QFileInfo firstChild(children.first());
            return toNodeIndex(firstChild);
        }
    }

    case PreviousSibling:
        return nextSibling(nodeIndex, fi, -1);

    case NextSibling:
        return nextSibling(nodeIndex, fi, 1);
    }

    Q_ASSERT_X(false, Q_FUNC_INFO, "Don't ever get here!");
    return QXmlNodeModelIndex();
}
예제 #7
0
//! [1]
QObjectXmlModel::QObjectNodeType QObjectXmlModel::toNodeType(const QXmlNodeModelIndex &n)
{
    return QObjectNodeType(n.additionalData() & (15 << 26));
}
예제 #8
0
QMetaProperty QObjectXmlModel::toMetaProperty(const QXmlNodeModelIndex &n)
{
    const int propertyOffset = n.additionalData() & (~QObjectProperty);
    const QObject *const qo = asQObject(n);
    return qo->metaObject()->property(propertyOffset);
}
예제 #9
0
bool QObjectXmlModel::isProperty(const QXmlNodeModelIndex n)
{
    return n.additionalData() & QObjectProperty;
}
예제 #10
0
//! [3]
QXmlName FileTree::name(const QXmlNodeModelIndex &node) const
{
    return m_names.at(node.additionalData());
}