diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-04 22:38:03 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-04 22:38:03 +0000 |
commit | dadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (patch) | |
tree | 99e72842fe687baea16376a147619b6048d7e441 /kmymoney2/mymoney/mymoneykeyvaluecontainer.cpp | |
download | kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.tar.gz kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.zip |
Added kmymoney
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmymoney2/mymoney/mymoneykeyvaluecontainer.cpp')
-rw-r--r-- | kmymoney2/mymoney/mymoneykeyvaluecontainer.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/kmymoney2/mymoney/mymoneykeyvaluecontainer.cpp b/kmymoney2/mymoney/mymoneykeyvaluecontainer.cpp new file mode 100644 index 0000000..4df855b --- /dev/null +++ b/kmymoney2/mymoney/mymoneykeyvaluecontainer.cpp @@ -0,0 +1,120 @@ +/*************************************************************************** + mymoneykeyvaluecontainer.cpp + ------------------- + begin : Sun Nov 10 2002 + copyright : (C) 2002-2005 by Thomas Baumgart + email : Thomas Baumgart <ipwizard@users.sourceforge.net> + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include <kmymoney/mymoneykeyvaluecontainer.h> +#include <kmymoney/mymoneyexception.h> + +MyMoneyKeyValueContainer::MyMoneyKeyValueContainer() +{ +} + +MyMoneyKeyValueContainer::MyMoneyKeyValueContainer(const QDomElement& node) +{ + if(!node.isNull()) { + if("KEYVALUEPAIRS" != node.tagName()) + throw new MYMONEYEXCEPTION("Node was not KEYVALUEPAIRS"); + + m_kvp.clear(); + + QDomNodeList nodeList = node.elementsByTagName("PAIR"); + for(unsigned int i = 0; i < nodeList.count(); ++i) { + const QDomElement& el(nodeList.item(i).toElement()); + m_kvp[el.attribute("key")] = el.attribute("value"); + } + } +} + +MyMoneyKeyValueContainer::~MyMoneyKeyValueContainer() +{ +} + +const QString& MyMoneyKeyValueContainer::value(const QString& key) const +{ + QMap<QString, QString>::ConstIterator it; + + it = m_kvp.find(key); + if(it != m_kvp.end()) + return (*it); + return QString::null; +} + +void MyMoneyKeyValueContainer::setValue(const QString& key, const QString& value) +{ + m_kvp[key] = value; +} + + +void MyMoneyKeyValueContainer::setPairs(const QMap<QString, QString>& list) +{ + m_kvp = list; +} + +void MyMoneyKeyValueContainer::deletePair(const QString& key) +{ + QMap<QString, QString>::Iterator it; + + it = m_kvp.find(key); + if(it != m_kvp.end()) + m_kvp.remove(it); +} + +void MyMoneyKeyValueContainer::clear(void) +{ + m_kvp.clear(); +} + +bool MyMoneyKeyValueContainer::operator == (const MyMoneyKeyValueContainer& right) const +{ + QMap<QString, QString>::ConstIterator it_a, it_b; + + it_a = m_kvp.begin(); + it_b = right.m_kvp.begin(); + + while(it_a != m_kvp.end() && it_b != right.m_kvp.end()) { + if(it_a.key() != it_b.key() + || (((*it_a).length() != 0 || (*it_b).length() != 0) && *it_a != *it_b)) + return false; + ++it_a; + ++it_b; + } + + return (it_a == m_kvp.end() && it_b == right.m_kvp.end()); +} + +void MyMoneyKeyValueContainer::writeXML(QDomDocument& document, QDomElement& parent) const +{ + if(m_kvp.count() != 0) { + QDomElement el = document.createElement("KEYVALUEPAIRS"); + + QMap<QString, QString>::ConstIterator it; + for(it = m_kvp.begin(); it != m_kvp.end(); ++it) + { + QDomElement pair = document.createElement("PAIR"); + pair.setAttribute("key", it.key()); + pair.setAttribute("value", it.data()); + el.appendChild(pair); + } + + parent.appendChild(el); + } +} |