Beispiel #1
0
bool QLCChannel::loadXML(const QDomElement& root)
{
    if (root.tagName() != KXMLQLCChannel)
    {
        qWarning() << "Channel node not found.";
        return false;
    }

    /* Get channel name */
    QString str = root.attribute(KXMLQLCChannelName);
    if (str.isEmpty() == true)
        return false;
    setName(str);

    /* Subtags */
    QDomNode node = root.firstChild();
    while (node.isNull() == false)
    {
        QDomElement tag = node.toElement();
        if (tag.tagName() == KXMLQLCCapability)
        {
            /* Create a new capability and attempt to load it */
            QLCCapability* cap = new QLCCapability();
            if (cap->loadXML(tag) == true)
            {
                /* Loading succeeded */
                if (addCapability(cap) == false)
                {
                    /* Value overlaps with existing value */
                    delete cap;
                }
            }
            else
            {
                /* Loading failed */
                delete cap;
            }
        }
        else if (tag.tagName() == KXMLQLCChannelGroup)
        {
            str = tag.attribute(KXMLQLCChannelGroupByte);
            setControlByte(ControlByte(str.toInt()));
            setGroup(stringToGroup(tag.text()));
        }
        else if (tag.tagName() == KXMLQLCChannelColour)
        {
            setColour(stringToColour(tag.text()));
        }
        else
        {
            qWarning() << Q_FUNC_INFO << "Unknown Channel tag: " << tag.tagName();
        }

        node = node.nextSibling();
    }

    return true;
}
void QLCCapability_Test::loadNoMax()
{
    QDomDocument doc;

    QDomElement root = doc.createElement("Capability");
    doc.appendChild(root);

    root.setAttribute("Min", 13);

    QDomText name = doc.createTextNode("Test1");
    root.appendChild(name);

    QLCCapability cap;
    QVERIFY(cap.loadXML(root) == false);
    QVERIFY(cap.name().isEmpty());
    QVERIFY(cap.min() == 0);
    QVERIFY(cap.max() == UCHAR_MAX);
}
void QLCCapability_Test::load()
{
    QDomDocument doc;

    QDomElement root = doc.createElement("Capability");
    doc.appendChild(root);

    root.setAttribute("Min", 13);
    root.setAttribute("Max", 19);

    QDomText name = doc.createTextNode("Test1");
    root.appendChild(name);

    QLCCapability cap;
    QVERIFY(cap.loadXML(root) == true);
    QVERIFY(cap.name() == "Test1");
    QVERIFY(cap.min() == 13);
    QVERIFY(cap.max() == 19);
}
Beispiel #4
0
bool QLCChannel::loadXML(const QDomElement* root)
{
    QDomNode node;
    QDomElement tag;
    QString str;

    Q_ASSERT(root != NULL);

    if (root->tagName() != KXMLQLCChannel)
    {
        qWarning() << "Channel node not found.";
        return false;
    }

    /* Get channel name */
    str = root->attribute(KXMLQLCChannelName);
    if (str == QString::null)
        return false;
    else
        setName(str);

    /* Subtags */
    node = root->firstChild();
    while (node.isNull() == false)
    {
        tag = node.toElement();

        if (tag.tagName() == KXMLQLCCapability)
        {
            /* Create a new capability and attempt to load it */
            QLCCapability* cap = new QLCCapability();
            if (cap->loadXML(&tag) == true)
            {
                /* Loading succeeded */
                if (addCapability(cap) == false)
                {
                    /* Value overlaps with existing value */
                    delete cap;
                }
            }
            else
            {
                /* Loading failed */
                delete cap;
            }
        }
        else if (tag.tagName() == KXMLQLCChannelGroup)
        {
            str = tag.attribute(KXMLQLCChannelGroupByte);
            setControlByte(str.toInt());
            setGroup(tag.text());
        }
        else
        {
            qDebug() << "Unknown Channel tag: " << tag.tagName();
        }

        node = node.nextSibling();
    }

    return true;
}