summaryrefslogtreecommitdiffstats
path: root/kmymoney2/reports/pivotgrid.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/reports/pivotgrid.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/reports/pivotgrid.cpp')
-rw-r--r--kmymoney2/reports/pivotgrid.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/kmymoney2/reports/pivotgrid.cpp b/kmymoney2/reports/pivotgrid.cpp
new file mode 100644
index 0000000..9cdf9b3
--- /dev/null
+++ b/kmymoney2/reports/pivotgrid.cpp
@@ -0,0 +1,161 @@
+/***************************************************************************
+ pivotgrid.cpp
+ -------------------
+ begin : Mon May 17 2004
+ copyright : (C) 2004-2005 by Ace Jones
+ email : <ace.j@hotpop.com>
+ 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
+#include <qlayout.h>
+#include <qdatetime.h>
+#include <qregexp.h>
+#include <qdragobject.h>
+#include <qclipboard.h>
+#include <qapplication.h>
+#include <qprinter.h>
+#include <qpainter.h>
+#include <qfile.h>
+#include <qdom.h>
+
+// ----------------------------------------------------------------------------
+// KDE Includes
+// This is just needed for i18n() and weekStartDay().
+// Once I figure out how to handle i18n
+// without using this macro directly, I'll be freed of KDE dependency. This
+// is a minor problem because we use these terms when rendering to HTML,
+// and a more major problem because we need it to translate account types
+// (e.g. MyMoneyAccount::Checkings) into their text representation. We also
+// use that text representation in the core data structure of the report. (Ace)
+
+#include <kglobal.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kcalendarsystem.h>
+
+// ----------------------------------------------------------------------------
+// Project Includes
+
+#include "pivottable.h"
+#include "reportdebug.h"
+#include "kreportchartview.h"
+#include "../kmymoneyglobalsettings.h"
+
+#include <kmymoney/kmymoneyutils.h>
+
+namespace reports {
+
+ const unsigned PivotOuterGroup::m_kDefaultSortOrder = 100;
+
+ PivotCell::PivotCell(const MyMoneyMoney& value) :
+ MyMoneyMoney(value),
+ m_stockSplit(MyMoneyMoney(1,1))
+ {
+ m_cellUsed |= !value.isZero();
+ }
+
+PivotCell PivotCell::operator += (const PivotCell& right)
+{
+ const MyMoneyMoney& r = static_cast<const MyMoneyMoney&>(right);
+ *this += r;
+ m_postSplit = m_postSplit * right.m_stockSplit;
+ m_stockSplit = m_stockSplit * right.m_stockSplit;
+ m_postSplit += right.m_postSplit;
+ m_cellUsed |= right.m_cellUsed;
+ return *this;
+}
+
+PivotCell PivotCell::operator += (const MyMoneyMoney& value)
+{
+ m_cellUsed |= !value.isZero();
+ if(m_stockSplit != MyMoneyMoney(1,1))
+ m_postSplit += value;
+ else
+ MyMoneyMoney::operator += (value);
+ return *this;
+}
+
+PivotCell PivotCell::stockSplit(const MyMoneyMoney& factor)
+{
+ PivotCell s;
+ s.m_stockSplit = factor;
+ return s;
+}
+
+const QString PivotCell::formatMoney(int fraction, bool showThousandSeparator) const
+{
+ return formatMoney("", MyMoneyMoney::denomToPrec(fraction), showThousandSeparator);
+}
+
+const QString PivotCell::formatMoney(const QString& currency, const int prec, bool showThousandSeparator) const
+{
+ // construct the result
+ MyMoneyMoney res = (*this * m_stockSplit) + m_postSplit;
+ return res.formatMoney(currency, prec, showThousandSeparator);
+}
+
+MyMoneyMoney PivotCell::calculateRunningSum(const MyMoneyMoney& runningSum)
+{
+ MyMoneyMoney::operator += (runningSum);
+ MyMoneyMoney::operator = ((*this * m_stockSplit) + m_postSplit);
+ m_postSplit = MyMoneyMoney(0,1);
+ m_stockSplit = MyMoneyMoney(1,1);
+ return *this;
+}
+
+MyMoneyMoney PivotCell::cellBalance(const MyMoneyMoney& _balance)
+{
+ MyMoneyMoney balance(_balance);
+ balance += *this;
+ balance = (balance * m_stockSplit) + m_postSplit;
+ return balance;
+}
+
+PivotGridRowSet::PivotGridRowSet( unsigned _numcolumns )
+{
+ insert(eActual, PivotGridRow(_numcolumns));
+ insert(eBudget, PivotGridRow(_numcolumns));
+ insert(eBudgetDiff, PivotGridRow(_numcolumns));
+ insert(eForecast, PivotGridRow(_numcolumns));
+ insert(eAverage, PivotGridRow(_numcolumns));
+ insert(ePrice, PivotGridRow(_numcolumns));
+}
+
+PivotGridRowSet PivotGrid::rowSet(QString id)
+{
+
+ //go through the data and get the row that matches the id
+ PivotGrid::iterator it_outergroup = begin();
+ while ( it_outergroup != end() )
+ {
+ PivotOuterGroup::iterator it_innergroup = (*it_outergroup).begin();
+ while ( it_innergroup != (*it_outergroup).end() )
+ {
+ PivotInnerGroup::iterator it_row = (*it_innergroup).begin();
+ while ( it_row != (*it_innergroup).end() )
+ {
+ if(it_row.key().id() == id)
+ return it_row.data();
+
+ ++it_row;
+ }
+ ++it_innergroup;
+ }
+ ++it_outergroup;
+ }
+ return PivotGridRowSet();
+}
+
+} // namespace
+// vim:cin:si:ai:et:ts=2:sw=2: