kandy
commanditem.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qdom.h>
00026
00027 #include <kdebug.h>
00028
00029 #include "atcommand.h"
00030
00031 #include "commanditem.h"
00032
00033 CommandItem::CommandItem(QListView *listView,ATCommand *command)
00034 : QListViewItem(listView)
00035 {
00036 mCommand = command;
00037
00038 setItemText();
00039 }
00040
00041 CommandItem::~CommandItem()
00042 {
00043 }
00044
00045 ATCommand *CommandItem::command()
00046 {
00047 return mCommand;
00048 }
00049
00050 void CommandItem::load(QDomElement *c)
00051 {
00052 mCommand->setCmdName(c->attribute("name","unknown"));
00053 mCommand->setCmdString(c->attribute("string","at"));
00054 mCommand->setHexOutput(c->attribute("hexoutput","n") == "y");
00055
00056 QDomNode n = c->firstChild();
00057 while(!n.isNull()) {
00058 QDomElement e = n.toElement();
00059 if (!e.isNull()) {
00060 ATParameter *p = new ATParameter;
00061 p->setName(e.attribute("name","unnamed"));
00062 p->setValue(e.attribute("value","0"));
00063 p->setUserInput(e.attribute("userinput","n") == "y");
00064
00065 mCommand->addParameter(p);
00066 }
00067 n = n.nextSibling();
00068 }
00069
00070 setItemText();
00071 }
00072
00073 void CommandItem::save(QDomDocument *doc,QDomElement *parent)
00074 {
00075 QDomElement c = doc->createElement("command");
00076 c.setAttribute("name",mCommand->cmdName());
00077 c.setAttribute("string",mCommand->cmdString());
00078 c.setAttribute("hexoutput",mCommand->hexOutput() ? "y" : "n");
00079 parent->appendChild(c);
00080
00081 QPtrList<ATParameter> paras = mCommand->parameters();
00082 for(uint i=0;i<paras.count();++i) {
00083 saveParameter(paras.at(i),doc,&c);
00084 }
00085 }
00086
00087 void CommandItem::saveParameter(ATParameter *p, QDomDocument *doc,
00088 QDomElement *parent)
00089 {
00090 QDomElement e = doc->createElement("parameter");
00091 e.setAttribute("name",p->name());
00092 e.setAttribute("value",p->value());
00093 e.setAttribute("userinput",p->userInput() ? "y" : "n");
00094 parent->appendChild(e);
00095 }
00096
00097 void CommandItem::setItemText()
00098 {
00099 setText(0,mCommand->cmdName());
00100 setText(1,mCommand->cmdString());
00101 setText(2,mCommand->hexOutput() ? "y" : "n");
00102 }
|