void SetJoystick::writeConfig(QXmlStreamWriter *xml) { if (!isSetEmpty()) { xml->writeStartElement("set"); xml->writeAttribute("index", QString::number(index+1)); if (!name.isEmpty()) { xml->writeTextElement("name", name); } for (int i=0; i < getNumberSticks(); i++) { JoyControlStick *stick = getJoyStick(i); stick->writeConfig(xml); } for (int i=0; i < getNumberVDPads(); i++) { VDPad *vdpad = getVDPad(i); if (vdpad) { vdpad->writeConfig(xml); } } for (int i=0; i < getNumberAxes(); i++) { JoyAxis *axis = getJoyAxis(i); if (!axis->isPartControlStick() && axis->hasControlOfButtons()) { axis->writeConfig(xml); } } for (int i=0; i < getNumberHats(); i++) { JoyDPad *dpad = getJoyDPad(i); dpad->writeConfig(xml); } for (int i=0; i < getNumberButtons(); i++) { JoyButton *button = getJoyButton(i); if (button && !button->isPartVDPad()) { button->writeConfig(xml); } } xml->writeEndElement(); } }
void SetJoystick::readConfig(QXmlStreamReader *xml) { if (xml->isStartElement() && xml->name() == "set") { //reset(); xml->readNextStartElement(); while (!xml->atEnd() && (!xml->isEndElement() && xml->name() != "set")) { if (xml->name() == "button" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); JoyButton *button = getJoyButton(index-1); if (button) { button->readConfig(xml); } else { xml->skipCurrentElement(); } } else if (xml->name() == "axis" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); JoyAxis *axis = getJoyAxis(index-1); if (axis) { axis->readConfig(xml); } else { xml->skipCurrentElement(); } } else if (xml->name() == "dpad" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); JoyDPad *dpad = getJoyDPad(index-1); if (dpad) { dpad->readConfig(xml); } else { xml->skipCurrentElement(); } } else if (xml->name() == "stick" && xml->isStartElement()) { int stickIndex = xml->attributes().value("index").toString().toInt(); if (stickIndex > 0) { stickIndex -= 1; JoyControlStick *stick = getJoyStick(stickIndex); if (stick) { stick->readConfig(xml); } else { xml->skipCurrentElement(); } } else { xml->skipCurrentElement(); } } else if (xml->name() == "vdpad" && xml->isStartElement()) { int index = xml->attributes().value("index").toString().toInt(); VDPad *vdpad = getVDPad(index-1); if (vdpad) { vdpad->readConfig(xml); } else { xml->skipCurrentElement(); } } else { // If none of the above, skip the element xml->skipCurrentElement(); } xml->readNextStartElement(); } } }