1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
* This file is part of the xTuple ERP: PostBooks Edition, a free and
* open source Enterprise Resource Planning software suite,
* Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
#include "csvatlas.h"
#include <QDomElement>
#include <QDomNodeList>
#include <QDomDocument>
#include <QList>
CSVAtlas::CSVAtlas()
{
}
CSVAtlas::CSVAtlas(const QDomElement & elem)
{
QDomNodeList nList = elem.childNodes();
for(int n = 0; n < nList.count(); ++n)
{
QDomElement elemThis = nList.item(n).toElement();
if(elemThis.tagName() == "Description")
setDescription(elemThis.text());
else if(elemThis.tagName() == "CSVMap")
{
CSVMap map(elemThis);
_maps.append(map);
}
else
{
// ERROR
}
}
}
CSVAtlas::~CSVAtlas()
{
}
QDomElement CSVAtlas::createElement(QDomDocument & doc)
{
QDomElement elem = doc.createElement("CSVAtlas");
if(!_description.isEmpty())
{
QDomElement desc = doc.createElement("Description");
desc.appendChild(doc.createTextNode(_description));
elem.appendChild(desc);
}
for(int i = 0; i < _maps.size(); i++)
{
// tmp required because appendChild expects a const CSVMap
CSVMap tmp = _maps.at(i);
elem.appendChild(tmp.createElement(doc));
}
return elem;
}
void CSVAtlas::setDescription(const QString & desc)
{
_description = desc;
}
void CSVAtlas::setMap(const CSVMap & m)
{
for(int i = 0; i < _maps.count(); ++i)
{
if(_maps[i].name() == m.name())
{
_maps[i] = m;
return;
}
}
_maps.append(m);
}
bool CSVAtlas::removeMap(const QString & name)
{
for (int i = 0; i < _maps.size(); i++)
{
if(_maps.at(i).name() == name)
{
_maps.removeAt(i);
return TRUE;
}
}
return FALSE;
}
CSVMap CSVAtlas::map(const QString & name) const
{
for (int i = 0; i < _maps.size(); i++)
{
if(_maps.at(i).name() == name)
return _maps.at(i);
}
return CSVMap();
}
QStringList CSVAtlas::mapList() const
{
QStringList list;
for (int i = 0; i < _maps.size(); i++)
list.append(_maps.at(i).name());
return list;
}
|