void QLCFixtureHead_Test::load() { QBuffer buffer; buffer.open(QIODevice::WriteOnly | QIODevice::Text); QXmlStreamWriter xmlWriter(&buffer); xmlWriter.writeStartElement("Head"); xmlWriter.writeTextElement("Channel", "0"); xmlWriter.writeTextElement("Channel", "1"); xmlWriter.writeTextElement("Channel", "15"); xmlWriter.writeTextElement("Foo", "25"); xmlWriter.writeTextElement("Channel", "42"); xmlWriter.writeEndDocument(); xmlWriter.setDevice(NULL); buffer.close(); buffer.open(QIODevice::ReadOnly | QIODevice::Text); QXmlStreamReader xmlReader(&buffer); xmlReader.readNextStartElement(); QLCFixtureHead head; QVERIFY(head.loadXML(xmlReader)); QCOMPARE(head.channels().size(), 4); QVERIFY(head.channels().contains(0)); QVERIFY(head.channels().contains(1)); QVERIFY(head.channels().contains(15)); QVERIFY(head.channels().contains(42)); }
bool QLCFixtureMode::loadXML(const QDomElement& root) { if (root.tagName() != KXMLQLCFixtureMode) { qWarning() << Q_FUNC_INFO << "Mode tag not found"; return false; } /* Mode name */ QString str = root.attribute(KXMLQLCFixtureModeName); if (str.isEmpty() == true) { qWarning() << Q_FUNC_INFO << "Mode has no name"; return false; } else { setName(str); } /* Subtags */ QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCFixtureModeChannel) { /* Channel */ Q_ASSERT(m_fixtureDef != NULL); str = tag.attribute(KXMLQLCFixtureModeChannelNumber); insertChannel(m_fixtureDef->channel(tag.text()), str.toInt()); } else if (tag.tagName() == KXMLQLCFixtureHead) { /* Head */ QLCFixtureHead head; if (head.loadXML(tag) == true) insertHead(-1, head); } else if (tag.tagName() == KXMLQLCPhysical) { /* Physical */ QLCPhysical physical; physical.loadXML(tag); setPhysical(physical); } else { qWarning() << Q_FUNC_INFO << "Unknown Fixture Mode tag:" << tag.tagName(); } node = node.nextSibling(); } // Cache all head channels cacheHeads(); return true; }
bool QLCFixtureMode::loadXML(QXmlStreamReader &doc) { if (doc.name() != KXMLQLCFixtureMode) { qWarning() << Q_FUNC_INFO << "Mode tag not found"; return false; } /* Mode name */ QString str = doc.attributes().value(KXMLQLCFixtureModeName).toString(); if (str.isEmpty() == true) { qWarning() << Q_FUNC_INFO << "Mode has no name"; return false; } else { setName(str); } /* Subtags */ while (doc.readNextStartElement()) { if (doc.name() == KXMLQLCFixtureModeChannel) { /* Channel */ Q_ASSERT(m_fixtureDef != NULL); str = doc.attributes().value(KXMLQLCFixtureModeChannelNumber).toString(); insertChannel(m_fixtureDef->channel(doc.readElementText()), str.toInt()); } else if (doc.name() == KXMLQLCFixtureHead) { /* Head */ QLCFixtureHead head; if (head.loadXML(doc) == true) insertHead(-1, head); } else if (doc.name() == KXMLQLCPhysical) { /* Physical */ QLCPhysical physical; physical.loadXML(doc); setPhysical(physical); } else { qWarning() << Q_FUNC_INFO << "Unknown Fixture Mode tag:" << doc.name(); doc.skipCurrentElement(); } } // Cache all head channels cacheHeads(); return true; }