diff --git a/kmymoney/dialogs/kbalancechartdlg.cpp b/kmymoney/dialogs/kbalancechartdlg.cpp index 4ef59627c..61233dbdb 100644 --- a/kmymoney/dialogs/kbalancechartdlg.cpp +++ b/kmymoney/dialogs/kbalancechartdlg.cpp @@ -1,168 +1,168 @@ /*************************************************************************** kbalancechartdlg - description ------------------- begin : Mon Nov 26 2007 copyright : (C) 2007 by Thomas Baumgart email : Thomas Baumgart ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "kbalancechartdlg.h" // ---------------------------------------------------------------------------- // QT Includes #include #include #include #include #include #include #include // ---------------------------------------------------------------------------- // KDE Includes #include #include #include #include // ---------------------------------------------------------------------------- // Project Includes -#include -#include -#include -#include +#include "mymoneyreport.h" +#include "pivottable.h" +#include "kmymoneyglobalsettings.h" +#include "kreportchartview.h" using namespace reports; KBalanceChartDlg::KBalanceChartDlg(const MyMoneyAccount& account, QWidget* parent) : QDialog(parent) { setWindowTitle(i18n("Balance of %1", account.name())); setSizeGripEnabled(true); setModal(true); // restore the last used dialog size winId(); // needs to be called to create the QWindow KConfigGroup grp = KSharedConfig::openConfig()->group("KBalanceChartDlg"); if (grp.isValid()) { KWindowConfig::restoreWindowSize(windowHandle(), grp); } // let the minimum size be 700x500 resize(QSize(700, 500).expandedTo(windowHandle() ? windowHandle()->size() : QSize())); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); //draw the chart and add it to the main layout KReportChartView* chartWidget = drawChart(account); mainLayout->addWidget(chartWidget); // add the buttons QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); mainLayout->addWidget(buttonBox); } KBalanceChartDlg::~KBalanceChartDlg() { // store the last used dialog size KConfigGroup grp = KSharedConfig::openConfig()->group("KBalanceChartDlg"); if (grp.isValid()) { KWindowConfig::saveWindowSize(windowHandle(), grp); } } KReportChartView* KBalanceChartDlg::drawChart(const MyMoneyAccount& account) { MyMoneyReport reportCfg = MyMoneyReport( MyMoneyReport::eAssetLiability, MyMoneyReport::eMonths, MyMoneyTransactionFilter::last3ToNext3Months, MyMoneyReport::eDetailTotal, i18n("%1 Balance History", account.name()), i18n("Generated Report") ); reportCfg.setChartByDefault(true); reportCfg.setChartCHGridLines(false); reportCfg.setChartSVGridLines(false); reportCfg.setChartDataLabels(false); reportCfg.setChartType(MyMoneyReport::eChartLine); reportCfg.setIncludingForecast(true); reportCfg.setIncludingBudgetActuals(true); if (account.accountType() == MyMoneyAccount::Investment) { QStringList::const_iterator it_a; for (it_a = account.accountList().begin(); it_a != account.accountList().end(); ++it_a) reportCfg.addAccount(*it_a); } else reportCfg.addAccount(account.id()); reportCfg.setColumnsAreDays(true); reportCfg.setConvertCurrency(false); reportCfg.setMixedTime(true); reports::PivotTable table(reportCfg); reports::KReportChartView* chartWidget = new reports::KReportChartView(this); table.drawChart(*chartWidget); // add another row for limit bool needRow = false; bool haveMinBalance = false; bool haveMaxCredit = false; MyMoneyMoney minBalance, maxCredit; MyMoneyMoney factor(1, 1); if (account.accountGroup() == MyMoneyAccount::Asset) factor = -factor; - if (account.value("maxCreditEarly").length() > 0) { + if (!account.value("maxCreditEarly").isEmpty()) { needRow = true; haveMaxCredit = true; maxCredit = MyMoneyMoney(account.value("maxCreditEarly")) * factor; } - if (account.value("maxCreditAbsolute").length() > 0) { + if (!account.value("maxCreditAbsolute").isEmpty()) { needRow = true; haveMaxCredit = true; maxCredit = MyMoneyMoney(account.value("maxCreditAbsolute")) * factor; } - if (account.value("minBalanceEarly").length() > 0) { + if (!account.value("minBalanceEarly").isEmpty()) { needRow = true; haveMinBalance = true; minBalance = MyMoneyMoney(account.value("minBalanceEarly")); } - if (account.value("minBalanceAbsolute").length() > 0) { + if (!account.value("minBalanceAbsolute").isEmpty()) { needRow = true; haveMinBalance = true; minBalance = MyMoneyMoney(account.value("minBalanceAbsolute")); } if (needRow) { if (haveMinBalance) { chartWidget->drawLimitLine(minBalance.toDouble()); } if (haveMaxCredit) { chartWidget->drawLimitLine(maxCredit.toDouble()); } } // always draw the y axis zero value line // TODO: port to KF5 - this crashes KChart //chartWidget->drawLimitLine(0); //remove the legend chartWidget->removeLegend(); return chartWidget; }