summaryrefslogtreecommitdiffstats
path: root/kmymoney2/mymoney/mymoneyprice.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
commitdadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (patch)
tree99e72842fe687baea16376a147619b6048d7e441 /kmymoney2/mymoney/mymoneyprice.cpp
downloadkmymoney-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/mymoneyprice.cpp')
-rw-r--r--kmymoney2/mymoney/mymoneyprice.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/kmymoney2/mymoney/mymoneyprice.cpp b/kmymoney2/mymoney/mymoneyprice.cpp
new file mode 100644
index 0000000..b674776
--- /dev/null
+++ b/kmymoney2/mymoney/mymoneyprice.cpp
@@ -0,0 +1,113 @@
+/***************************************************************************
+ mymoneyprice - description
+ -------------------
+ begin : Sun Nov 21 2004
+ copyright : (C) 2000-2004 by Michael Edwardes
+ email : mte@users.sourceforge.net
+ Javier Campos Morales <javi_c@users.sourceforge.net>
+ Felix Rodriguez <frodriguez@users.sourceforge.net>
+ John C <thetacoturtle@users.sourceforge.net>
+ Thomas Baumgart <ipwizard@users.sourceforge.net>
+ Kevin Tambascio <ktambascio@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. *
+ * *
+ ***************************************************************************/
+
+/**
+ * @author Thomas Baumgart
+ */
+
+// ----------------------------------------------------------------------------
+// QT Includes
+
+// ----------------------------------------------------------------------------
+// KDE Includes
+
+// ----------------------------------------------------------------------------
+// Project Includes
+
+#include "mymoneyprice.h"
+#include "mymoneyexception.h"
+
+MyMoneyPrice::MyMoneyPrice() :
+ m_date(QDate())
+{
+}
+
+MyMoneyPrice::MyMoneyPrice(const QString& from, const QString& to, const QDomElement& node)
+{
+ if("PRICE" != node.tagName())
+ throw new MYMONEYEXCEPTION("Node was not PRICE");
+
+ m_fromSecurity = from;
+ m_toSecurity = to;
+
+ m_date = QDate::fromString(node.attribute("date"), Qt::ISODate);
+ m_rate = MyMoneyMoney(node.attribute("price"));
+ m_source = node.attribute("source");
+
+ if(!m_rate.isZero())
+ m_invRate = MyMoneyMoney(1,1) / m_rate;
+ else
+ qDebug("Price with zero value loaded");
+}
+
+MyMoneyPrice::MyMoneyPrice(const QString& from, const QString& to, const QDate& date, const MyMoneyMoney& rate, const QString& source) :
+ m_fromSecurity(from),
+ m_toSecurity(to),
+ m_date(date),
+ m_rate(rate),
+ m_source(source)
+{
+ if(!m_rate.isZero())
+ m_invRate = MyMoneyMoney(1,1) / m_rate;
+ else
+ qDebug("Price with zero value created");
+}
+
+MyMoneyPrice::~MyMoneyPrice()
+{
+}
+
+const MyMoneyMoney MyMoneyPrice::rate(const QString& id) const
+{
+ static MyMoneyMoney dummyPrice(1,1);
+
+ if(!isValid())
+ return dummyPrice;
+
+ if(id.isEmpty() || id == m_toSecurity)
+ return m_rate;
+ if(id == m_fromSecurity)
+ return m_invRate;
+
+ QString msg = QString("Unknown security id %1 for price info %2/%3.").arg(id).arg(m_fromSecurity).arg(m_toSecurity);
+ throw new MYMONEYEXCEPTION(msg);
+}
+
+bool MyMoneyPrice::isValid(void) const
+{
+ return (m_date.isValid() && !m_fromSecurity.isEmpty() && !m_toSecurity.isEmpty());
+}
+
+// Equality operator
+bool MyMoneyPrice::operator == (const MyMoneyPrice &right) const
+{
+ return ((m_date == right.m_date) &&
+ (m_rate == right.m_rate) &&
+ ((m_fromSecurity.length() == 0 && right.m_fromSecurity.length() == 0) || (m_fromSecurity == right.m_fromSecurity)) &&
+ ((m_toSecurity.length() == 0 && right.m_toSecurity.length() == 0) || (m_toSecurity == right.m_toSecurity)) &&
+ ((m_source.length() == 0 && right.m_source.length() == 0) || (m_source == right.m_source)));
+}
+
+bool MyMoneyPrice::hasReferenceTo(const QString& id) const
+{
+ return (id == m_fromSecurity) || (id == m_toSecurity);
+}