File indexing completed on 2024-06-23 05:02:16
0001 /* 0002 SPDX-FileCopyrightText: 2005-2006 Ace Jones <acejones@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2005-2018 Thomas Baumgart <tbaumgart@kde.org> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <pivotgrid.h> 0008 0009 // ---------------------------------------------------------------------------- 0010 // QT Includes 0011 0012 // ---------------------------------------------------------------------------- 0013 // KDE Includes 0014 0015 // ---------------------------------------------------------------------------- 0016 // Project Includes 0017 0018 namespace reports 0019 { 0020 0021 const unsigned PivotOuterGroup::m_kDefaultSortOrder = 100; 0022 0023 PivotCell::PivotCell(const MyMoneyMoney& value) : 0024 MyMoneyMoney(value), 0025 m_stockSplit(MyMoneyMoney::ONE), 0026 m_cellUsed(!value.isZero()) 0027 { 0028 } 0029 0030 PivotCell::~PivotCell() 0031 { 0032 } 0033 0034 PivotCell PivotCell::operator += (const PivotCell& right) 0035 { 0036 const MyMoneyMoney& r = static_cast<const MyMoneyMoney&>(right); 0037 *this += r; 0038 m_postSplit = m_postSplit * right.m_stockSplit; 0039 m_stockSplit = m_stockSplit * right.m_stockSplit; 0040 m_postSplit += right.m_postSplit; 0041 m_cellUsed |= right.m_cellUsed; 0042 return *this; 0043 } 0044 0045 PivotCell PivotCell::operator += (const MyMoneyMoney& value) 0046 { 0047 m_cellUsed |= !value.isZero(); 0048 if (m_stockSplit != MyMoneyMoney::ONE) 0049 m_postSplit += value; 0050 else 0051 MyMoneyMoney::operator += (value); 0052 return *this; 0053 } 0054 0055 PivotCell PivotCell::stockSplit(const MyMoneyMoney& factor) 0056 { 0057 PivotCell s; 0058 s.m_stockSplit = factor; 0059 return s; 0060 } 0061 0062 const QString PivotCell::formatMoney(int fraction, bool showThousandSeparator) const 0063 { 0064 return formatMoney("", MyMoneyMoney::denomToPrec(fraction), showThousandSeparator); 0065 } 0066 0067 const QString PivotCell::formatMoney(const QString& currency, const int prec, bool showThousandSeparator) const 0068 { 0069 // construct the result 0070 MyMoneyMoney res = (*this * m_stockSplit) + m_postSplit; 0071 return res.formatMoney(currency, prec, showThousandSeparator); 0072 } 0073 0074 MyMoneyMoney PivotCell::calculateRunningSum(const MyMoneyMoney& runningSum) 0075 { 0076 MyMoneyMoney::operator += (runningSum); 0077 MyMoneyMoney::operator = ((*this * m_stockSplit) + m_postSplit); 0078 m_postSplit = MyMoneyMoney(); 0079 m_stockSplit = MyMoneyMoney::ONE; 0080 return *this; 0081 } 0082 0083 MyMoneyMoney PivotCell::cellBalance(const MyMoneyMoney& _balance) 0084 { 0085 MyMoneyMoney balance(_balance); 0086 balance += *this; 0087 balance = (balance * m_stockSplit) + m_postSplit; 0088 return balance; 0089 } 0090 0091 PivotGridRowSet::PivotGridRowSet(unsigned _numcolumns) 0092 { 0093 insert(eActual, PivotGridRow(_numcolumns)); 0094 insert(eBudget, PivotGridRow(_numcolumns)); 0095 insert(eBudgetDiff, PivotGridRow(_numcolumns)); 0096 insert(eForecast, PivotGridRow(_numcolumns)); 0097 insert(eAverage, PivotGridRow(_numcolumns)); 0098 insert(ePrice, PivotGridRow(_numcolumns)); 0099 } 0100 0101 PivotGridRowSet PivotGrid::rowSet(QString id) 0102 { 0103 0104 //go through the data and get the row that matches the id 0105 PivotGrid::iterator it_outergroup = begin(); 0106 while (it_outergroup != end()) { 0107 PivotOuterGroup::iterator it_innergroup = (*it_outergroup).begin(); 0108 while (it_innergroup != (*it_outergroup).end()) { 0109 PivotInnerGroup::iterator it_row = (*it_innergroup).begin(); 0110 while (it_row != (*it_innergroup).end()) { 0111 if (it_row.key().id() == id) 0112 return it_row.value(); 0113 0114 ++it_row; 0115 } 0116 ++it_innergroup; 0117 } 0118 ++it_outergroup; 0119 } 0120 return PivotGridRowSet(); 0121 } 0122 0123 } // namespace