QDomDocument* DomManager
::writeDom(MapContainer<QString,QString> outputMap
) {
int writeCounter = 0;
QDomElement root
= writeDomDoc
->createElement
(CommonDomProtocol
::QSTR_DOC);
writeDomDoc->appendChild(root);
QDomElement elementAction
= writeDomDoc
->createElement
(CommonDomProtocol
::QSTR_API);
elementAction.setAttribute(CommonDomProtocol::QSTR_ACTION,
outputMap[CommonDomProtocol::QSTR_ACTION]);
root.appendChild(elementAction);
QMapIterator<QString,QString> i(outputMap.getMap());
while (i.hasNext())
{
i.next();
if(i.key() != CommonDomProtocol::QSTR_ACTION)
{
writeCounter += 1;
toStr.setNum(writeCounter);
QString str
= CommonDomProtocol
::QSTR_PARAM;
str.append(toStr);
QDomElement elementParam
= writeDomDoc
->createElement
(str
);
elementParam.setAttribute(CommonDomProtocol::QSTR_TYPE, i.key());
elementParam.setAttribute(CommonDomProtocol::QSTR_VALUE, i.value());
root.appendChild(elementParam);
}
}
return writeDomDoc;
}
MapContainer<QString,QString> DomManager
::readDom(QDomDocument *readDomDoc
){
int readCounter = 1;
inputMap.removeAllItems(); // CLEAR THE MAP
while(!node.isNull())
{
toStr.setNum(readCounter);
QString str
= CommonDomProtocol
::QSTR_PARAM;
str.append(toStr);
if(!element.isNull())
{
if(element.tagName() == CommonDomProtocol::QSTR_API)
{
inputMap.addTo(CommonDomProtocol::QSTR_ACTION,
element.attribute(CommonDomProtocol::QSTR_ACTION,
CommonDomProtocol::QSTR_GET_ATTRIBUTE));
}
else if(element.tagName() == str)
{
inputMap.addTo(element.attribute(CommonDomProtocol::QSTR_TYPE,
CommonDomProtocol::QSTR_GET_ATTRIBUTE),
element.attribute(CommonDomProtocol::QSTR_VALUE,
CommonDomProtocol::QSTR_GET_ATTRIBUTE));
readCounter += 1;
}
}
node = node.nextSibling();
}
delete readDomDoc;
return inputMap;
}
QDomDocument* DomManager::writeDom(MapContainer<QString,QString> outputMap)
{
int writeCounter = 0;
QDomDocument *writeDomDoc = new QDomDocument(CommonDomProtocol::QSTR_HMI);
QDomElement root = writeDomDoc->createElement(CommonDomProtocol::QSTR_DOC);
writeDomDoc->appendChild(root);
QDomElement elementAction = writeDomDoc->createElement(CommonDomProtocol::QSTR_API);
elementAction.setAttribute(CommonDomProtocol::QSTR_ACTION,
outputMap[CommonDomProtocol::QSTR_ACTION]);
root.appendChild(elementAction);
QMapIterator<QString,QString> i(outputMap.getMap());
while (i.hasNext())
{
i.next();
if(i.key() != CommonDomProtocol::QSTR_ACTION)
{
writeCounter += 1;
QString toStr;
toStr.setNum(writeCounter);
QString str = CommonDomProtocol::QSTR_PARAM;
str.append(toStr);
QDomElement elementParam = writeDomDoc->createElement(str);
elementParam.setAttribute(CommonDomProtocol::QSTR_TYPE, i.key());
elementParam.setAttribute(CommonDomProtocol::QSTR_VALUE, i.value());
root.appendChild(elementParam);
}
}
return writeDomDoc;
}
MapContainer<QString,QString> DomManager::readDom(QDomDocument *readDomDoc)
{
int readCounter = 1;
inputMap.removeAllItems(); // CLEAR THE MAP
QDomElement docElem = readDomDoc->documentElement();
QDomNode node = docElem.firstChild();
while(!node.isNull())
{
QString toStr;
toStr.setNum(readCounter);
QString str = CommonDomProtocol::QSTR_PARAM;
str.append(toStr);
QDomElement element = node.toElement();
if(!element.isNull())
{
if(element.tagName() == CommonDomProtocol::QSTR_API)
{
inputMap.addTo(CommonDomProtocol::QSTR_ACTION,
element.attribute(CommonDomProtocol::QSTR_ACTION,
CommonDomProtocol::QSTR_GET_ATTRIBUTE));
}
else if(element.tagName() == str)
{
inputMap.addTo(element.attribute(CommonDomProtocol::QSTR_TYPE,
CommonDomProtocol::QSTR_GET_ATTRIBUTE),
element.attribute(CommonDomProtocol::QSTR_VALUE,
CommonDomProtocol::QSTR_GET_ATTRIBUTE));
readCounter += 1;
}
}
node = node.nextSibling();
}
delete readDomDoc;
return inputMap;
}
To copy to clipboard, switch view to plain text mode
Bookmarks