Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/reports/pivottable.cpp
Show First 20 Lines • Show All 1530 Lines • ▼ Show 20 Line(s) | 1293 | { | |||
---|---|---|---|---|---|
1531 | 1531 | | |||
1532 | return result; | 1532 | return result; | ||
1533 | } | 1533 | } | ||
1534 | 1534 | | |||
1535 | QString PivotTable::renderBody() const | 1535 | QString PivotTable::renderBody() const | ||
1536 | { | 1536 | { | ||
1537 | DEBUG_ENTER(Q_FUNC_INFO); | 1537 | DEBUG_ENTER(Q_FUNC_INFO); | ||
1538 | 1538 | | |||
1539 | MyMoneyFile* file = MyMoneyFile::instance(); | ||||
1540 | int pricePrecision = 0; | ||||
1541 | int currencyPrecision = 0; | ||||
1542 | int precision = 2; | ||||
1539 | QString colspan = QString(" colspan=\"%1\"").arg(m_numColumns + 1 + (m_config_f.isShowingRowTotals() ? 1 : 0)); | 1543 | QString colspan = QString(" colspan=\"%1\"").arg(m_numColumns + 1 + (m_config_f.isShowingRowTotals() ? 1 : 0)); | ||
1540 | 1544 | | |||
1541 | // | 1545 | // | ||
1542 | // Report Title | 1546 | // Report Title | ||
1543 | // | 1547 | // | ||
1544 | 1548 | | |||
1545 | QString result = QString("<h2 class=\"report\">%1</h2>\n").arg(m_config_f.name()); | 1549 | QString result = QString("<h2 class=\"report\">%1</h2>\n").arg(m_config_f.name()); | ||
1546 | 1550 | | |||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 1622 | if (m_config_f.detailLevel() != MyMoneyReport::eDetailTotal) { | |||
1621 | // | 1625 | // | ||
1622 | 1626 | | |||
1623 | // Need to sort the outergroups. They can't always be sorted by name. So we create a list of | 1627 | // Need to sort the outergroups. They can't always be sorted by name. So we create a list of | ||
1624 | // map iterators, and sort that. Then we'll iterate through the map iterators and use those as | 1628 | // map iterators, and sort that. Then we'll iterate through the map iterators and use those as | ||
1625 | // before. | 1629 | // before. | ||
1626 | // | 1630 | // | ||
1627 | // I hope this doesn't bog the performance of reports, given that we're copying the entire report | 1631 | // I hope this doesn't bog the performance of reports, given that we're copying the entire report | ||
1628 | // data. If this is a perf hit, we could change to storing outergroup pointers, I think. | 1632 | // data. If this is a perf hit, we could change to storing outergroup pointers, I think. | ||
1633 | | ||||
1629 | QList<PivotOuterGroup> outergroups; | 1634 | QList<PivotOuterGroup> outergroups; | ||
1630 | PivotGrid::const_iterator it_outergroup_map = m_grid.begin(); | 1635 | PivotGrid::const_iterator it_outergroup_map = m_grid.begin(); | ||
1631 | while (it_outergroup_map != m_grid.end()) { | 1636 | while (it_outergroup_map != m_grid.end()) { | ||
1632 | outergroups.push_back(it_outergroup_map.value()); | 1637 | outergroups.push_back(it_outergroup_map.value()); | ||
1633 | 1638 | | |||
1634 | // copy the name into the outergroup, because we will now lose any association with | 1639 | // copy the name into the outergroup, because we will now lose any association with | ||
1635 | // the map iterator | 1640 | // the map iterator | ||
1636 | outergroups.back().m_displayName = it_outergroup_map.key(); | 1641 | outergroups.back().m_displayName = it_outergroup_map.key(); | ||
Show All 28 Lines | 1664 | while (it_innergroup != (*it_outergroup).end()) { | |||
1665 | PivotInnerGroup::const_iterator it_row = (*it_innergroup).begin(); | 1670 | PivotInnerGroup::const_iterator it_row = (*it_innergroup).begin(); | ||
1666 | while (it_row != (*it_innergroup).end()) { | 1671 | while (it_row != (*it_innergroup).end()) { | ||
1667 | // | 1672 | // | ||
1668 | // Columns | 1673 | // Columns | ||
1669 | // | 1674 | // | ||
1670 | 1675 | | |||
1671 | QString rowdata; | 1676 | QString rowdata; | ||
1672 | int column = 1; | 1677 | int column = 1; | ||
1678 | pricePrecision = 0; // new row => new account => new precision | ||||
1679 | currencyPrecision = 0; | ||||
1673 | bool isUsed = it_row.value()[eActual][0].isUsed(); | 1680 | bool isUsed = it_row.value()[eActual][0].isUsed(); | ||
1674 | while (column < m_numColumns) { | 1681 | while (column < m_numColumns) { | ||
1675 | QString lb; | 1682 | QString lb; | ||
1676 | if (column != 1) | 1683 | if (column > 1) | ||
1677 | lb = leftborder; | 1684 | lb = leftborder; | ||
1678 | 1685 | | |||
1679 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1686 | foreach (const auto rowType, m_rowTypeList) { | ||
1687 | if (rowType == ePrice) { | ||||
1688 | if (pricePrecision == 0) { | ||||
1689 | if (it_row.key().isInvest()) { | ||||
1690 | pricePrecision = file->currency(it_row.key().currencyId()).pricePrecision(); | ||||
1691 | precision = pricePrecision; | ||||
1692 | } else | ||||
1693 | precision = 2; | ||||
1694 | } else | ||||
1695 | precision = pricePrecision; | ||||
1696 | } else { | ||||
1697 | if (currencyPrecision == 0) { | ||||
1698 | if (it_row.key().isInvest()) // stock account isn't eveluated in currency, so take investment account instead | ||||
1699 | currencyPrecision = MyMoneyMoney::denomToPrec(it_row.key().parent().fraction()); | ||||
1700 | else | ||||
1701 | currencyPrecision = MyMoneyMoney::denomToPrec(it_row.key().fraction()); | ||||
1702 | precision = currencyPrecision; | ||||
1703 | } else | ||||
1704 | precision = currencyPrecision; | ||||
1705 | } | ||||
1680 | rowdata += QString("<td%2>%1</td>") | 1706 | rowdata += QString("<td%2>%1</td>") | ||
1681 | .arg(coloredAmount(it_row.value()[ m_rowTypeList[i] ][column])) | 1707 | .arg(coloredAmount(it_row.value()[rowType][column], QString(), precision)) | ||
1682 | .arg(i == 0 ? lb : QString()); | 1708 | .arg(lb); | ||
1683 | 1709 | lb.clear(); | |||
1684 | isUsed |= it_row.value()[ m_rowTypeList[i] ][column].isUsed(); | 1710 | isUsed |= it_row.value()[rowType][column].isUsed(); | ||
1685 | } | 1711 | } | ||
1686 | 1712 | ++column; | |||
1687 | column++; | | |||
1688 | } | 1713 | } | ||
1689 | 1714 | | |||
1690 | if (m_config_f.isShowingRowTotals()) { | 1715 | if (m_config_f.isShowingRowTotals()) { | ||
1691 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1716 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1692 | rowdata += QString("<td%2>%1</td>") | 1717 | rowdata += QString("<td%2>%1</td>") | ||
1693 | .arg(coloredAmount(it_row.value()[ m_rowTypeList[i] ].m_total)) | 1718 | .arg(coloredAmount(it_row.value()[ m_rowTypeList[i] ].m_total, QString(), precision)) | ||
1694 | .arg(i == 0 ? leftborder : QString()); | 1719 | .arg(i == 0 ? leftborder : QString()); | ||
1695 | } | 1720 | } | ||
1696 | } | 1721 | } | ||
1697 | 1722 | | |||
1698 | // | 1723 | // | ||
1699 | // Row Header | 1724 | // Row Header | ||
1700 | // | 1725 | // | ||
1701 | 1726 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 1792 | if (finishrow) { | |||
1769 | isUsed |= (*it_innergroup).m_total[eActual][0].isUsed(); | 1794 | isUsed |= (*it_innergroup).m_total[eActual][0].isUsed(); | ||
1770 | while (column < m_numColumns) { | 1795 | while (column < m_numColumns) { | ||
1771 | QString lb; | 1796 | QString lb; | ||
1772 | if (column != 1) | 1797 | if (column != 1) | ||
1773 | lb = leftborder; | 1798 | lb = leftborder; | ||
1774 | 1799 | | |||
1775 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1800 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1776 | finalRow += QString("<td%2>%1</td>") | 1801 | finalRow += QString("<td%2>%1</td>") | ||
1777 | .arg(coloredAmount((*it_innergroup).m_total[ m_rowTypeList[i] ][column])) | 1802 | .arg(coloredAmount((*it_innergroup).m_total[ m_rowTypeList[i] ][column], QString(), precision)) | ||
1778 | .arg(i == 0 ? lb : QString()); | 1803 | .arg(i == 0 ? lb : QString()); | ||
1779 | isUsed |= (*it_innergroup).m_total[ m_rowTypeList[i] ][column].isUsed(); | 1804 | isUsed |= (*it_innergroup).m_total[ m_rowTypeList[i] ][column].isUsed(); | ||
1780 | } | 1805 | } | ||
1781 | 1806 | | |||
1782 | column++; | 1807 | column++; | ||
1783 | } | 1808 | } | ||
1784 | 1809 | | |||
1785 | if (m_config_f.isShowingRowTotals()) { | 1810 | if (m_config_f.isShowingRowTotals()) { | ||
1786 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1811 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1787 | finalRow += QString("<td%2>%1</td>") | 1812 | finalRow += QString("<td%2>%1</td>") | ||
1788 | .arg(coloredAmount((*it_innergroup).m_total[ m_rowTypeList[i] ].m_total)) | 1813 | .arg(coloredAmount((*it_innergroup).m_total[ m_rowTypeList[i] ].m_total, QString(), precision)) | ||
1789 | .arg(i == 0 ? leftborder : QString()); | 1814 | .arg(i == 0 ? leftborder : QString()); | ||
1790 | } | 1815 | } | ||
1791 | } | 1816 | } | ||
1792 | 1817 | | |||
1793 | finalRow += "</tr>\n"; | 1818 | finalRow += "</tr>\n"; | ||
1794 | if (isUsed) { | 1819 | if (isUsed) { | ||
1795 | result += finalRow; | 1820 | result += finalRow; | ||
1796 | ++rownum; | 1821 | ++rownum; | ||
Show All 15 Lines | 1835 | if (m_config_f.isShowingColumnTotals()) { | |||
1812 | int column = 1; | 1837 | int column = 1; | ||
1813 | while (column < m_numColumns) { | 1838 | while (column < m_numColumns) { | ||
1814 | QString lb; | 1839 | QString lb; | ||
1815 | if (column != 1) | 1840 | if (column != 1) | ||
1816 | lb = leftborder; | 1841 | lb = leftborder; | ||
1817 | 1842 | | |||
1818 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1843 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1819 | result += QString("<td%2>%1</td>") | 1844 | result += QString("<td%2>%1</td>") | ||
1820 | .arg(coloredAmount((*it_outergroup).m_total[ m_rowTypeList[i] ][column])) | 1845 | .arg(coloredAmount((*it_outergroup).m_total[ m_rowTypeList[i] ][column], QString(), precision)) | ||
1821 | .arg(i == 0 ? lb : QString()); | 1846 | .arg(i == 0 ? lb : QString()); | ||
1822 | } | 1847 | } | ||
1823 | 1848 | | |||
1824 | column++; | 1849 | column++; | ||
1825 | } | 1850 | } | ||
1826 | 1851 | | |||
1827 | if (m_config_f.isShowingRowTotals()) { | 1852 | if (m_config_f.isShowingRowTotals()) { | ||
1828 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1853 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1829 | result += QString("<td%2>%1</td>") | 1854 | result += QString("<td%2>%1</td>") | ||
1830 | .arg(coloredAmount((*it_outergroup).m_total[ m_rowTypeList[i] ].m_total)) | 1855 | .arg(coloredAmount((*it_outergroup).m_total[ m_rowTypeList[i] ].m_total, QString(), precision)) | ||
1831 | .arg(i == 0 ? leftborder : QString()); | 1856 | .arg(i == 0 ? leftborder : QString()); | ||
1832 | } | 1857 | } | ||
1833 | } | 1858 | } | ||
1834 | result += "</tr>\n"; | 1859 | result += "</tr>\n"; | ||
1835 | } | 1860 | } | ||
1836 | 1861 | | |||
1837 | ++it_outergroup; | 1862 | ++it_outergroup; | ||
1838 | 1863 | | |||
Show All 11 Lines | 1872 | if (m_config_f.isShowingColumnTotals()) { | |||
1850 | int totalcolumn = 1; | 1875 | int totalcolumn = 1; | ||
1851 | while (totalcolumn < m_numColumns) { | 1876 | while (totalcolumn < m_numColumns) { | ||
1852 | QString lb; | 1877 | QString lb; | ||
1853 | if (totalcolumn != 1) | 1878 | if (totalcolumn != 1) | ||
1854 | lb = leftborder; | 1879 | lb = leftborder; | ||
1855 | 1880 | | |||
1856 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1881 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1857 | result += QString("<td%2>%1</td>") | 1882 | result += QString("<td%2>%1</td>") | ||
1858 | .arg(coloredAmount(m_grid.m_total[ m_rowTypeList[i] ][totalcolumn])) | 1883 | .arg(coloredAmount(m_grid.m_total[ m_rowTypeList[i] ][totalcolumn], QString(), precision)) | ||
1859 | .arg(i == 0 ? lb : QString()); | 1884 | .arg(i == 0 ? lb : QString()); | ||
1860 | } | 1885 | } | ||
1861 | 1886 | | |||
1862 | totalcolumn++; | 1887 | totalcolumn++; | ||
1863 | } | 1888 | } | ||
1864 | 1889 | | |||
1865 | if (m_config_f.isShowingRowTotals()) { | 1890 | if (m_config_f.isShowingRowTotals()) { | ||
1866 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | 1891 | for (int i = 0; i < m_rowTypeList.size(); ++i) { | ||
1867 | result += QString("<td%2>%1</td>") | 1892 | result += QString("<td%2>%1</td>") | ||
1868 | .arg(coloredAmount(m_grid.m_total[ m_rowTypeList[i] ].m_total)) | 1893 | .arg(coloredAmount(m_grid.m_total[ m_rowTypeList[i] ].m_total, QString(), precision)) | ||
1869 | .arg(i == 0 ? leftborder : QString()); | 1894 | .arg(i == 0 ? leftborder : QString()); | ||
1870 | } | 1895 | } | ||
1871 | } | 1896 | } | ||
1872 | 1897 | | |||
1873 | result += "</tr>\n"; | 1898 | result += "</tr>\n"; | ||
1874 | } | 1899 | } | ||
1875 | 1900 | | |||
1876 | result += QString("<tr class=\"spacer\"><td> </td></tr>\n"); | 1901 | result += QString("<tr class=\"spacer\"><td> </td></tr>\n"); | ||
Show All 11 Lines | 1909 | { | |||
1888 | g.close(); | 1913 | g.close(); | ||
1889 | } | 1914 | } | ||
1890 | 1915 | | |||
1891 | void PivotTable::drawChart(KReportChartView& chartView) const | 1916 | void PivotTable::drawChart(KReportChartView& chartView) const | ||
1892 | { | 1917 | { | ||
1893 | chartView.drawPivotChart(m_grid, m_config_f, m_numColumns, m_columnHeadings, m_rowTypeList, m_columnTypeHeaderList); | 1918 | chartView.drawPivotChart(m_grid, m_config_f, m_numColumns, m_columnHeadings, m_rowTypeList, m_columnTypeHeaderList); | ||
1894 | } | 1919 | } | ||
1895 | 1920 | | |||
1896 | QString PivotTable::coloredAmount(const MyMoneyMoney& amount, const QString& currencySymbol) const | | |||
1897 | { | | |||
1898 | return coloredAmount(amount, currencySymbol, KMyMoneyGlobalSettings::pricePrecision()); | | |||
1899 | } | | |||
1900 | | ||||
1901 | QString PivotTable::coloredAmount(const MyMoneyMoney& amount, const QString& currencySymbol, int prec) const | 1921 | QString PivotTable::coloredAmount(const MyMoneyMoney& amount, const QString& currencySymbol, int prec) const | ||
1902 | { | 1922 | { | ||
1903 | QString result; | 1923 | QString result; | ||
1904 | if (amount.isNegative()) | 1924 | if (amount.isNegative()) | ||
1905 | result += QString("<font color=\"rgb(%1,%2,%3)\">") | 1925 | result += QString("<font color=\"rgb(%1,%2,%3)\">") | ||
1906 | .arg(KMyMoneyGlobalSettings::listNegativeValueColor().red()) | 1926 | .arg(KMyMoneyGlobalSettings::listNegativeValueColor().red()) | ||
1907 | .arg(KMyMoneyGlobalSettings::listNegativeValueColor().green()) | 1927 | .arg(KMyMoneyGlobalSettings::listNegativeValueColor().green()) | ||
1908 | .arg(KMyMoneyGlobalSettings::listNegativeValueColor().blue()); | 1928 | .arg(KMyMoneyGlobalSettings::listNegativeValueColor().blue()); | ||
▲ Show 20 Lines • Show All 388 Lines • Show Last 20 Lines |