1 /***************************************************************************
2 kreportsview_p.h - description
3 -------------------
4 begin : Sat Mar 27 2004
5 copyright : (C) 2000-2004 by Michael Edwardes
6 email : mte@users.sourceforge.net
7 Javier Campos Morales <javi_c@users.sourceforge.net>
8 Felix Rodriguez <frodriguez@users.sourceforge.net>
9 John C <thetacoturtle@users.sourceforge.net>
10 Thomas Baumgart <ipwizard@users.sourceforge.net>
11 Kevin Tambascio <ktambascio@users.sourceforge.net>
12 Ace Jones <ace.j@hotpop.com>
13 (C) 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
14 2018 Michael Kiefer <Michael-Kiefer@web.de>
15 ***************************************************************************/
16
17 /***************************************************************************
18 * *
19 * This program is free software; you can redistribute it and/or modify *
20 * it under the terms of the GNU General Public License as published by *
21 * the Free Software Foundation; either version 2 of the License, or *
22 * (at your option) any later version. *
23 * *
24 ***************************************************************************/
25
26 #ifndef KREPORTSVIEW_P_H
27 #define KREPORTSVIEW_P_H
28
29 #include "kreportsview.h"
30
31 // ----------------------------------------------------------------------------
32 // QT Includes
33
34 #include <QTreeWidget>
35 #include <QTreeWidgetItem>
36 #include <QFile>
37 #include <QTimer>
38 #include <QClipboard>
39 #include <QList>
40 #include <QVBoxLayout>
41 #include <QMimeData>
42 #include <QIcon>
43 #include <QUrlQuery>
44 #include <QFileInfo>
45 #include <QFileDialog>
46 #include <QLocale>
47 #include <QTextCodec>
48 #include <QMenu>
49 #include <QPointer>
50 #include <QWheelEvent>
51 #ifdef ENABLE_WEBENGINE
52 #include <QWebEngineView>
53 #else
54 #include <KWebView>
55 #endif
56
57 // ----------------------------------------------------------------------------
58 // KDE Includes
59
60 #include <KMessageBox>
61 #include <KLocalizedString>
62 #include <KChartAbstractCoordinatePlane>
63
64 // ----------------------------------------------------------------------------
65 // Project Includes
66
67 #include "ui_reportcontrol.h"
68
69 #include "kmymoneyviewbase_p.h"
70 #include "kreportconfigurationfilterdlg.h"
71 #include "mymoneyfile.h"
72 #include "mymoneyreport.h"
73 #include "mymoneyexception.h"
74 #include "kmymoneysettings.h"
75 #include "querytable.h"
76 #include "objectinfotable.h"
77 #include "icons/icons.h"
78 #include <kmymoneywebpage.h>
79 #include "tocitem.h"
80 #include "tocitemgroup.h"
81 #include "tocitemreport.h"
82 #include "kreportchartview.h"
83 #include "pivottable.h"
84 #include "reporttable.h"
85 #include "reportcontrolimpl.h"
86 #include "mymoneyenums.h"
87 #include "kmm_printer.h"
88
89 using namespace reports;
90 using namespace eMyMoney;
91 using namespace Icons;
92
93 #define VIEW_LEDGER "ledger"
94 #define VIEW_SCHEDULE "schedule"
95 #define VIEW_WELCOME "welcome"
96 #define VIEW_HOME "home"
97 #define VIEW_REPORTS "reports"
98
99 /**
100 * Helper class for KReportView.
101 *
102 * This is the widget which displays a single report in the TabWidget that comprises this view.
103 *
104 * @author Ace Jones
105 */
106
107 class KReportTab: public QWidget
108 {
109 private:
110 #ifdef ENABLE_WEBENGINE
111 QWebEngineView *m_tableView;
112 #else
113 KWebView *m_tableView;
114 #endif
115 reports::KReportChartView *m_chartView;
116 ReportControl *m_control;
117 QVBoxLayout *m_layout;
118 MyMoneyReport m_report;
119 bool m_deleteMe;
120 bool m_chartEnabled;
121 bool m_showingChart;
122 bool m_needReload;
123 bool m_isChartViewValid;
124 bool m_isTableViewValid;
125 QPointer<reports::ReportTable> m_table;
126
127 /**
128 * Users character set encoding.
129 */
130 QByteArray m_encoding;
131
132 public:
133 KReportTab(QTabWidget* parent, const MyMoneyReport& report, const KReportsView *eventHandler);
134 ~KReportTab();
report()135 const MyMoneyReport& report() const {
136 return m_report;
137 }
138 void print();
139 void toggleChart();
140 /**
141 * Updates information about plotted chart in report's data
142 */
143 void updateDataRange();
144 void copyToClipboard();
145 void saveAs(const QString& filename, bool includeCSS = false);
146 void updateReport();
147 QString createTable(const QString& links = QString());
control()148 const ReportControl* control() const {
149 return m_control;
150 }
isReadyToDelete()151 bool isReadyToDelete() const {
152 return m_deleteMe;
153 }
setReadyToDelete(bool f)154 void setReadyToDelete(bool f) {
155 m_deleteMe = f;
156 }
modifyReport(const MyMoneyReport & report)157 void modifyReport(const MyMoneyReport& report) {
158 m_report = report;
159 }
160 void showEvent(QShowEvent * event) final override;
161 void loadTab();
162
163 protected:
164 void wheelEvent(QWheelEvent *event) override;
165
166 };
167
168 /**
169 * Helper class for KReportView.
170 *
171 * This is a named list of reports, which will be one section
172 * in the list of default reports
173 *
174 * @author Ace Jones
175 */
176 class ReportGroup: public QList<MyMoneyReport>
177 {
178 private:
179 QString m_name; ///< the title of the group in non-translated form
180 QString m_title; ///< the title of the group in i18n-ed form
181 public:
ReportGroup()182 ReportGroup() {}
ReportGroup(const QString & name,const QString & title)183 ReportGroup(const QString& name, const QString& title): m_name(name), m_title(title) {}
name()184 const QString& name() const {
185 return m_name;
186 }
title()187 const QString& title() const {
188 return m_title;
189 }
190 };
191
192 /**
193 * KReportTab Implementation
194 */
KReportTab(QTabWidget * parent,const MyMoneyReport & report,const KReportsView * eventHandler)195 KReportTab::KReportTab(QTabWidget* parent, const MyMoneyReport& report, const KReportsView* eventHandler):
196 QWidget(parent),
197 #ifdef ENABLE_WEBENGINE
198 m_tableView(new QWebEngineView(this)),
199 #else
200 m_tableView(new KWebView(this)),
201 #endif
202 m_chartView(new KReportChartView(this)),
203 m_control(new ReportControl(this)),
204 m_layout(new QVBoxLayout(this)),
205 m_report(report),
206 m_deleteMe(false),
207 m_chartEnabled(false),
208 m_showingChart(report.isChartByDefault()),
209 m_needReload(true),
210 m_isChartViewValid(false),
211 m_isTableViewValid(false),
212 m_table(0)
213 {
214 m_layout->setSpacing(6);
215 m_tableView->setPage(new MyQWebEnginePage(m_tableView));
216 m_tableView->setZoomFactor(KMyMoneySettings::zoomFactor());
217
218 //set button icons
219 m_control->ui->buttonChart->setIcon(Icons::get(Icon::OfficeChartLine));
220 m_control->ui->buttonClose->setIcon(Icons::get(Icon::DocumentClose));
221 m_control->ui->buttonConfigure->setIcon(Icons::get(Icon::Configure));
222 m_control->ui->buttonCopy->setIcon(Icons::get(Icon::EditCopy));
223 m_control->ui->buttonDelete->setIcon(Icons::get(Icon::EditDelete));
224 m_control->ui->buttonExport->setIcon(Icons::get(Icon::DocumentExport));
225 m_control->ui->buttonNew->setIcon(Icons::get(Icon::DocumentNew));
226
227 m_chartView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
228 m_chartView->hide();
229 m_tableView->hide();
230 m_layout->addWidget(m_control);
231 m_layout->addWidget(m_tableView);
232 m_layout->addWidget(m_chartView);
233 m_layout->setStretch(1, 10);
234 m_layout->setStretch(2, 10);
235
236 connect(m_control->ui->buttonChart, &QAbstractButton::clicked,
237 eventHandler, &KReportsView::slotToggleChart);
238
239 connect(m_control->ui->buttonConfigure, &QAbstractButton::clicked,
240 eventHandler, &KReportsView::slotConfigure);
241
242 connect(m_control->ui->buttonNew, &QAbstractButton::clicked,
243 eventHandler, &KReportsView::slotDuplicate);
244
245 connect(m_control->ui->buttonCopy, &QAbstractButton::clicked,
246 eventHandler, &KReportsView::slotCopyView);
247
248 connect(m_control->ui->buttonExport, &QAbstractButton::clicked,
249 eventHandler, &KReportsView::slotSaveView);
250
251 connect(m_control->ui->buttonDelete, &QAbstractButton::clicked,
252 eventHandler, &KReportsView::slotDelete);
253
254 connect(m_control->ui->buttonClose, &QAbstractButton::clicked,
255 eventHandler, &KReportsView::slotCloseCurrent);
256
257 #ifdef ENABLE_WEBENGINE
258 connect(m_tableView->page(), &QWebEnginePage::urlChanged,
259 eventHandler, &KReportsView::slotOpenUrl);
260 #else
261 m_tableView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
262 connect(m_tableView->page(), &KWebPage::linkClicked,
263 eventHandler, &KReportsView::slotOpenUrl);
264 #endif
265
266 // if this is a default report, then you can't delete it!
267 if (report.id().isEmpty())
268 m_control->ui->buttonDelete->setEnabled(false);
269
270 int tabNr = parent->addTab(this,
271 Icons::get(Icon::Report),
272 report.name());
273 parent->setTabEnabled(tabNr, true);
274 parent->setCurrentIndex(tabNr);
275
276 // get users character set encoding
277 m_encoding = QTextCodec::codecForLocale()->name();
278 }
279
~KReportTab()280 KReportTab::~KReportTab()
281 {
282 delete m_table;
283 }
284
285
wheelEvent(QWheelEvent * event)286 void KReportTab::wheelEvent(QWheelEvent* event)
287 {
288 // Zoom text on Ctrl + Scroll
289 if (event->modifiers() & Qt::CTRL) {
290 if (!m_showingChart) {
291 qreal factor = m_tableView->zoomFactor();
292 if (event->delta() > 0)
293 factor += 0.1;
294 else if (event->delta() < 0)
295 factor -= 0.1;
296 m_tableView->setZoomFactor(factor);
297 event->accept();
298 return;
299 }
300 }
301 }
302
303
print()304 void KReportTab::print()
305 {
306 if (m_tableView) {
307 auto printer = KMyMoneyPrinter::startPrint();
308 if (printer != nullptr) {
309 if (m_showingChart) {
310 QPainter painter(printer);
311 m_chartView->paint(&painter, painter.window());
312 QFont font = painter.font();
313 font.setPointSizeF(font.pointSizeF() * 0.8);
314 painter.setFont(font);
315 QLocale locale;
316 painter.drawText(0, 0, QDate::currentDate().toString(locale.dateFormat(QLocale::ShortFormat)));
317
318 /// @todo extract url from KMyMoneyApp
319 QUrl file;
320 if (file.isValid()) {
321 painter.drawText(0, painter.window().height(), file.toLocalFile());
322 }
323 } else {
324 #ifdef ENABLE_WEBENGINE
325 m_tableView->page()->print(printer, [=] (bool) {});
326 #else
327 m_tableView->print(printer);
328 #endif
329 }
330 }
331 }
332 }
333
copyToClipboard()334 void KReportTab::copyToClipboard()
335 {
336 QMimeData* pMimeData = new QMimeData();
337 pMimeData->setHtml(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name(), true));
338 QApplication::clipboard()->setMimeData(pMimeData);
339 }
340
saveAs(const QString & filename,bool includeCSS)341 void KReportTab::saveAs(const QString& filename, bool includeCSS)
342 {
343 QFile file(filename);
344
345 if (file.open(QIODevice::WriteOnly)) {
346 if (QFileInfo(filename).suffix().toLower() == QLatin1String("csv")) {
347 QTextStream(&file) << m_table->renderReport(QLatin1String("csv"), m_encoding, QString());
348 } else {
349 QString table =
350 m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name(), includeCSS);
351 QTextStream stream(&file);
352 stream << table;
353 }
354 file.close();
355 }
356 }
357
loadTab()358 void KReportTab::loadTab()
359 {
360 m_needReload = true;
361 if (isVisible()) {
362 m_needReload = false;
363 updateReport();
364 }
365 }
366
showEvent(QShowEvent * event)367 void KReportTab::showEvent(QShowEvent * event)
368 {
369 if (m_needReload) {
370 m_needReload = false;
371 updateReport();
372 }
373 QWidget::showEvent(event);
374 }
375
updateReport()376 void KReportTab::updateReport()
377 {
378 m_isChartViewValid = false;
379 m_isTableViewValid = false;
380 // reload the report from the engine. It might have
381 // been changed by the user
382
383 try {
384 // Don't try to reload default reports from the engine
385 if (!m_report.id().isEmpty())
386 m_report = MyMoneyFile::instance()->report(m_report.id());
387 } catch (const MyMoneyException &) {
388 }
389
390 delete m_table;
391 m_table = 0;
392
393 if (m_report.reportType() == eMyMoney::Report::ReportType::PivotTable) {
394 m_table = new PivotTable(m_report);
395 m_chartEnabled = true;
396 } else if (m_report.reportType() == eMyMoney::Report::ReportType::QueryTable) {
397 m_table = new QueryTable(m_report);
398 m_chartEnabled = false;
399 } else if (m_report.reportType() == eMyMoney::Report::ReportType::InfoTable) {
400 m_table = new ObjectInfoTable(m_report);
401 m_chartEnabled = false;
402 }
403
404 m_control->ui->buttonChart->setEnabled(m_chartEnabled);
405
406 m_showingChart = !m_showingChart;
407 toggleChart();
408 }
409
toggleChart()410 void KReportTab::toggleChart()
411 {
412 // for now it will just SHOW the chart. In the future it actually has to toggle it.
413
414 if (m_showingChart) {
415 if (!m_isTableViewValid) {
416 m_tableView->setHtml(m_table->renderReport(QLatin1String("html"), m_encoding, m_report.name()),
417 QUrl("file://")); // workaround for access permission to css file
418 }
419 m_isTableViewValid = true;
420 m_tableView->show();
421 m_chartView->hide();
422
423 m_control->ui->buttonChart->setText(i18n("Chart"));
424 m_control->ui->buttonChart->setToolTip(i18n("Show the chart version of this report"));
425 m_control->ui->buttonChart->setIcon(Icons::get(Icon::OfficeChartLine));
426 } else {
427 if (!m_isChartViewValid)
428 m_table->drawChart(*m_chartView);
429 m_isChartViewValid = true;
430 m_tableView->hide();
431 m_chartView->show();
432
433 m_control->ui->buttonChart->setText(i18n("Report"));
434 m_control->ui->buttonChart->setToolTip(i18n("Show the report version of this chart"));
435 m_control->ui->buttonChart->setIcon(Icons::get(Icon::Report));
436 }
437 m_showingChart = ! m_showingChart;
438 }
439
updateDataRange()440 void KReportTab::updateDataRange()
441 {
442 QList<DataDimension> grids = m_chartView->coordinatePlane()->gridDimensionsList(); // get dimensions of plotted graph
443 if (grids.isEmpty())
444 return;
445 QChar separator = locale().groupSeparator();
446 QChar decimalPoint = locale().decimalPoint();
447 int precision = m_report.yLabelsPrecision();
448 QList<QPair<QString, qreal>> dims; // create list of dimension values in string and qreal
449
450 // get qreal values
451 dims.append(qMakePair(QString(), grids.at(1).start));
452 dims.append(qMakePair(QString(), grids.at(1).end));
453 dims.append(qMakePair(QString(), grids.at(1).stepWidth));
454 dims.append(qMakePair(QString(), grids.at(1).subStepWidth));
455
456 // convert qreal values to string variables
457 for (int i = 0; i < 4; ++i) {
458 if (i > 2)
459 ++precision;
460 if (precision == 0)
461 dims[i].first = locale().toString(qRound(dims.at(i).second));
462 else
463 dims[i].first = locale().toString(dims.at(i).second, 'f', precision).remove(separator).remove(QRegularExpression("0+$")).remove(QRegularExpression("\\" + decimalPoint + "$"));
464 }
465
466 // save string variables in report's data
467 m_report.setDataRangeStart(dims.at(0).first);
468 m_report.setDataRangeEnd(dims.at(1).first);
469 m_report.setDataMajorTick(dims.at(2).first);
470 m_report.setDataMinorTick(dims.at(3).first);
471 }
472
473 class KReportsViewPrivate : public KMyMoneyViewBasePrivate
474 {
Q_DECLARE_PUBLIC(KReportsView)475 Q_DECLARE_PUBLIC(KReportsView)
476
477 public:
478 explicit KReportsViewPrivate(KReportsView *qq):
479 q_ptr(qq),
480 m_needLoad(true),
481 m_reportListView(nullptr),
482 m_reportTabWidget(nullptr),
483 m_listTab(nullptr),
484 m_listTabLayout(nullptr),
485 m_tocTreeWidget(nullptr),
486 m_columnsAlreadyAdjusted(false)
487 {
488 }
489
~KReportsViewPrivate()490 ~KReportsViewPrivate()
491 {
492 }
493
init()494 void init()
495 {
496 Q_Q(KReportsView);
497 m_needLoad = false;
498 auto vbox = new QVBoxLayout(q);
499 q->setLayout(vbox);
500 vbox->setSpacing(6);
501 vbox->setMargin(0);
502
503
504 // build reports toc
505
506 setColumnsAlreadyAdjusted(false);
507
508 m_reportTabWidget = new QTabWidget(q);
509 vbox->addWidget(m_reportTabWidget);
510 m_reportTabWidget->setTabsClosable(true);
511
512 m_listTab = new QWidget(m_reportTabWidget);
513 m_listTabLayout = new QVBoxLayout(m_listTab);
514 m_listTabLayout->setSpacing(6);
515
516 m_tocTreeWidget = new QTreeWidget(m_listTab);
517
518 // report-group items have only 1 column (name of group),
519 // report items have 2 columns (report name and comment)
520 m_tocTreeWidget->setColumnCount(2);
521
522 // headers
523 QStringList headers;
524 headers << i18n("Reports") << i18n("Comment");
525 m_tocTreeWidget->setHeaderLabels(headers);
526
527 m_tocTreeWidget->setAlternatingRowColors(true);
528 m_tocTreeWidget->setSortingEnabled(true);
529 m_tocTreeWidget->sortByColumn(0, Qt::AscendingOrder);
530
531 // for report group items:
532 // doubleclick toggles the expand-state,
533 m_tocTreeWidget->setExpandsOnDoubleClick(false);
534
535 m_tocTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
536
537 m_tocTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
538
539 m_listTabLayout->addWidget(m_tocTreeWidget);
540 m_reportTabWidget->addTab(m_listTab, i18n("Reports"));
541
542 q->connect(m_reportTabWidget, &QTabWidget::tabCloseRequested,
543 q, &KReportsView::slotClose);
544
545 q->connect(m_tocTreeWidget, &QTreeWidget::itemDoubleClicked,
546 q, &KReportsView::slotItemDoubleClicked);
547
548 q->connect(m_tocTreeWidget, &QWidget::customContextMenuRequested,
549 q, &KReportsView::slotListContextMenu);
550
551 q->connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, q, &KReportsView::refresh);
552 }
553
restoreTocExpandState(QMap<QString,bool> & expandStates)554 void restoreTocExpandState(QMap<QString, bool>& expandStates)
555 {
556 for (auto i = 0; i < m_tocTreeWidget->topLevelItemCount(); ++i) {
557 QTreeWidgetItem* item = m_tocTreeWidget->topLevelItem(i);
558
559 if (item) {
560 QString itemLabel = item->text(0);
561
562 if (expandStates.contains(itemLabel)) {
563 item->setExpanded(expandStates[itemLabel]);
564 } else {
565 item->setExpanded(false);
566 }
567 }
568 }
569 }
570
571 /**
572 * Display a dialog to confirm report deletion
573 */
deleteReportDialog(const QString & reportName)574 int deleteReportDialog(const QString &reportName)
575 {
576 Q_Q(KReportsView);
577 return KMessageBox::warningContinueCancel(q,
578 i18n("<qt>Are you sure you want to delete report <b>%1</b>? There is no way to recover it.</qt>",
579 reportName), i18n("Delete Report?"));
580 }
581
addReportTab(const MyMoneyReport & report)582 void addReportTab(const MyMoneyReport& report)
583 {
584 Q_Q(KReportsView);
585 new KReportTab(m_reportTabWidget, report, q);
586 }
587
loadView()588 void loadView()
589 {
590 // remember the id of the current selected item
591 QTreeWidgetItem* item = m_tocTreeWidget->currentItem();
592 QString selectedItem = (item) ? item->text(0) : QString();
593
594 // save expand states of all top-level items
595 QMap<QString, bool> expandStates;
596 for (int i = 0; i < m_tocTreeWidget->topLevelItemCount(); ++i) {
597 item = m_tocTreeWidget->topLevelItem(i);
598
599 if (item) {
600 QString itemLabel = item->text(0);
601
602 if (item->isExpanded()) {
603 expandStates.insert(itemLabel, true);
604 } else {
605 expandStates.insert(itemLabel, false);
606 }
607 }
608 }
609
610 // find the item visible on top
611 QTreeWidgetItem* visibleTopItem = m_tocTreeWidget->itemAt(0, 0);
612
613 // text of column 0 identifies the item visible on top
614 QString visibleTopItemText;
615
616 bool visibleTopItemFound = true;
617 if (visibleTopItem == NULL) {
618 visibleTopItemFound = false;
619 } else {
620 // this assumes, that all item-texts in column 0 are unique,
621 // no matter, whether the item is a report- or a group-item
622 visibleTopItemText = visibleTopItem->text(0);
623 }
624
625 // turn off updates to avoid flickering during reload
626 //m_reportListView->setUpdatesEnabled(false);
627
628 //
629 // Rebuild the list page
630 //
631 m_tocTreeWidget->clear();
632
633 // Default Reports
634 QList<ReportGroup> defaultreports;
635 defaultReports(defaultreports);
636
637 QList<ReportGroup>::const_iterator it_group = defaultreports.constBegin();
638
639 // the item to be set as current item
640 QTreeWidgetItem* currentItem = 0L;
641
642 // group number, this will be used as sort key for reportgroup items
643 // we have:
644 // 1st some default groups
645 // 2nd a chart group
646 // 3rd maybe a favorite group
647 // 4th maybe an orphan group (for old reports)
648 int defaultGroupNo = 1;
649 int chartGroupNo = defaultreports.size() + 1;
650
651 // group for diagrams
652 QString groupName = I18N_NOOP("Charts");
653
654 TocItemGroup* chartTocItemGroup =
655 new TocItemGroup(m_tocTreeWidget, chartGroupNo,
656 i18n(groupName.toLatin1().data()));
657
658 m_allTocItemGroups.insert(groupName, chartTocItemGroup);
659
660 while (it_group != defaultreports.constEnd()) {
661 groupName = (*it_group).name();
662
663 TocItemGroup* defaultTocItemGroup =
664 new TocItemGroup(m_tocTreeWidget, defaultGroupNo++,
665 i18n(groupName.toLatin1().data()));
666
667 m_allTocItemGroups.insert(groupName, defaultTocItemGroup);
668
669 if (groupName == selectedItem) {
670 currentItem = defaultTocItemGroup;
671 }
672
673 QList<MyMoneyReport>::const_iterator it_report = (*it_group).begin();
674 while (it_report != (*it_group).end()) {
675 MyMoneyReport report = *it_report;
676 report.setGroup(groupName);
677
678 TocItemReport* reportTocItemReport =
679 new TocItemReport(defaultTocItemGroup, report);
680
681 if (report.name() == selectedItem) {
682 currentItem = reportTocItemReport;
683 }
684
685 // ALSO place it into the Charts list if it's displayed as a chart by default
686 if (report.isChartByDefault()) {
687 new TocItemReport(chartTocItemGroup, report);
688 }
689
690 ++it_report;
691 }
692
693 ++it_group;
694 }
695
696 // group for custom (favorite) reports
697 int favoriteGroupNo = chartGroupNo + 1;
698
699 groupName = I18N_NOOP("Favorite Reports");
700
701 TocItemGroup* favoriteTocItemGroup =
702 new TocItemGroup(m_tocTreeWidget, favoriteGroupNo,
703 i18n(groupName.toLatin1().data()));
704
705 m_allTocItemGroups.insert(groupName, favoriteTocItemGroup);
706
707 TocItemGroup* orphanTocItemGroup = 0;
708
709 QList<MyMoneyReport> customreports = MyMoneyFile::instance()->reportList();
710 QList<MyMoneyReport>::const_iterator it_report = customreports.constBegin();
711 while (it_report != customreports.constEnd()) {
712
713 MyMoneyReport report = *it_report;
714
715 groupName = (*it_report).group();
716
717 // If this report is in a known group, place it there
718 // KReportGroupListItem* groupnode = groupitems[(*it_report).group()];
719 TocItemGroup* groupNode = m_allTocItemGroups[groupName];
720
721 if (groupNode) {
722 new TocItemReport(groupNode, report);
723 } else {
724 // otherwise, place it in the orphanage
725 if (!orphanTocItemGroup) {
726
727 // group for orphaned reports
728 int orphanGroupNo = favoriteGroupNo + 1;
729
730 groupName = I18N_NOOP("Old Customized Reports");
731
732 orphanTocItemGroup =
733 new TocItemGroup(m_tocTreeWidget, orphanGroupNo,
734 i18n(groupName.toLatin1().data()));
735 m_allTocItemGroups.insert(groupName, orphanTocItemGroup);
736 }
737 new TocItemReport(orphanTocItemGroup, report);
738 }
739
740 // ALSO place it into the Favorites list if it's a favorite
741 if ((*it_report).isFavorite()) {
742 new TocItemReport(favoriteTocItemGroup, report);
743 }
744
745 // ALSO place it into the Charts list if it's displayed as a chart by default
746 if ((*it_report).isChartByDefault()) {
747 new TocItemReport(chartTocItemGroup, report);
748 }
749
750 ++it_report;
751 }
752
753 //
754 // Go through the tabs to set their update flag or delete them if needed
755 //
756
757 int index = 1;
758 while (index < m_reportTabWidget->count()) {
759 // TODO: Find some way of detecting the file is closed and kill these tabs!!
760 if (auto tab = dynamic_cast<KReportTab*>(m_reportTabWidget->widget(index))) {
761 if (tab->isReadyToDelete() /* || ! reports.count() */) {
762 delete tab;
763 --index;
764 } else {
765 tab->loadTab();
766 }
767 }
768 ++index;
769 }
770
771 if (visibleTopItemFound) {
772 // try to find the visibleTopItem that we had at the start of this method
773
774 // intentionally not using 'Qt::MatchCaseSensitive' here
775 // to avoid 'item not found' if someone corrected a typo only
776 QList<QTreeWidgetItem*> visibleTopItemList =
777 m_tocTreeWidget->findItems(visibleTopItemText,
778 Qt::MatchFixedString |
779 Qt::MatchRecursive);
780
781 if (visibleTopItemList.isEmpty()) {
782 // the item could not be found, it was deleted or renamed
783 visibleTopItemFound = false;
784 } else {
785 visibleTopItem = visibleTopItemList.at(0);
786 if (visibleTopItem == NULL) {
787 visibleTopItemFound = false;
788 }
789 }
790 }
791
792 // adjust column widths,
793 // but only the first time when the view is loaded,
794 // maybe the user sets other column widths later,
795 // so don't disturb him
796 if (columnsAlreadyAdjusted()) {
797
798 // restore expand states of all top-level items
799 restoreTocExpandState(expandStates);
800
801 // restore current item
802 m_tocTreeWidget->setCurrentItem(currentItem);
803
804 // try to scroll to the item visible on top
805 // when this method started
806 if (visibleTopItemFound) {
807 m_tocTreeWidget->scrollToItem(visibleTopItem);
808 } else {
809 m_tocTreeWidget->scrollToTop();
810 }
811 return;
812 }
813
814 // avoid flickering
815 m_tocTreeWidget->setUpdatesEnabled(false);
816
817 // expand all top-level items
818 m_tocTreeWidget->expandAll();
819
820 // resize columns
821 m_tocTreeWidget->resizeColumnToContents(0);
822 m_tocTreeWidget->resizeColumnToContents(1);
823
824 // restore expand states of all top-level items
825 restoreTocExpandState(expandStates);
826
827 // restore current item
828 m_tocTreeWidget->setCurrentItem(currentItem);
829
830 // try to scroll to the item visible on top
831 // when this method started
832 if (visibleTopItemFound) {
833 m_tocTreeWidget->scrollToItem(visibleTopItem);
834 } else {
835 m_tocTreeWidget->scrollToTop();
836 }
837
838 setColumnsAlreadyAdjusted(true);
839
840 m_tocTreeWidget->setUpdatesEnabled(true);
841 }
842
defaultReports(QList<ReportGroup> & groups)843 void defaultReports(QList<ReportGroup>& groups)
844 {
845 {
846 ReportGroup list("Income and Expenses", i18n("Income and Expenses"));
847
848 list.push_back(MyMoneyReport(
849 eMyMoney::Report::RowType::ExpenseIncome,
850 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
851 TransactionFilter::Date::CurrentMonth,
852 eMyMoney::Report::DetailLevel::All,
853 i18n("Income and Expenses This Month"),
854 i18n("Default Report")
855 ));
856 list.push_back(MyMoneyReport(
857 eMyMoney::Report::RowType::ExpenseIncome,
858 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
859 TransactionFilter::Date::YearToDate,
860 eMyMoney::Report::DetailLevel::All,
861 i18n("Income and Expenses This Year"),
862 i18n("Default Report")
863 ));
864 list.push_back(MyMoneyReport(
865 eMyMoney::Report::RowType::ExpenseIncome,
866 static_cast<unsigned>(eMyMoney::Report::ColumnType::Years),
867 TransactionFilter::Date::All,
868 eMyMoney::Report::DetailLevel::All,
869 i18n("Income and Expenses By Year"),
870 i18n("Default Report")
871 ));
872
873 list.push_back(MyMoneyReport(
874 eMyMoney::Report::RowType::ExpenseIncome,
875 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
876 TransactionFilter::Date::Last12Months,
877 eMyMoney::Report::DetailLevel::Top,
878 i18n("Income and Expenses Graph"),
879 i18n("Default Report")
880 ));
881 list.back().setChartByDefault(true);
882 list.back().setChartType(eMyMoney::Report::ChartType::Line);
883 list.back().setChartDataLabels(false);
884
885 list.push_back(MyMoneyReport(
886 eMyMoney::Report::RowType::ExpenseIncome,
887 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
888 TransactionFilter::Date::Last12Months,
889 eMyMoney::Report::DetailLevel::Top,
890 i18n("Income and Expenses Bar Graph"),
891 i18n("Default Report")
892 ));
893 list.back().setChartByDefault(true);
894 list.back().setChartType(eMyMoney::Report::ChartType::StackedBar);
895 list.back().setChartDataLabels(false);
896 list.back().setNegExpenses(true);
897
898 list.push_back(MyMoneyReport(
899 eMyMoney::Report::RowType::ExpenseIncome,
900 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
901 TransactionFilter::Date::YearToDate,
902 eMyMoney::Report::DetailLevel::Group,
903 i18n("Income and Expenses Pie Chart"),
904 i18n("Default Report")
905 ));
906 list.back().setChartByDefault(true);
907 list.back().setChartType(eMyMoney::Report::ChartType::Pie);
908 list.back().setShowingRowTotals(false);
909
910 groups.push_back(list);
911 }
912 {
913 ReportGroup list("Net Worth", i18n("Net Worth"));
914
915 list.push_back(MyMoneyReport(
916 eMyMoney::Report::RowType::AssetLiability,
917 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
918 TransactionFilter::Date::YearToDate,
919 eMyMoney::Report::DetailLevel::Top,
920 i18n("Net Worth By Month"),
921 i18n("Default Report")
922 ));
923 list.push_back(MyMoneyReport(
924 eMyMoney::Report::RowType::AssetLiability,
925 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
926 TransactionFilter::Date::Today,
927 eMyMoney::Report::DetailLevel::Top,
928 i18n("Net Worth Today"),
929 i18n("Default Report")
930 ));
931 list.push_back(MyMoneyReport(
932 eMyMoney::Report::RowType::AssetLiability,
933 static_cast<unsigned>(eMyMoney::Report::ColumnType::Years),
934 TransactionFilter::Date::All,
935 eMyMoney::Report::DetailLevel::Top,
936 i18n("Net Worth By Year"),
937 i18n("Default Report")
938 ));
939 list.push_back(MyMoneyReport(
940 eMyMoney::Report::RowType::AssetLiability,
941 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
942 TransactionFilter::Date::Next7Days,
943 eMyMoney::Report::DetailLevel::Top,
944 i18n("7-day Cash Flow Forecast"),
945 i18n("Default Report")
946 ));
947 list.back().setIncludingSchedules(true);
948 list.back().setColumnsAreDays(true);
949
950 list.push_back(MyMoneyReport(
951 eMyMoney::Report::RowType::AssetLiability,
952 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
953 TransactionFilter::Date::Last12Months,
954 eMyMoney::Report::DetailLevel::Total,
955 i18n("Net Worth Graph"),
956 i18n("Default Report")
957 ));
958 list.back().setChartByDefault(true);
959 list.back().setChartCHGridLines(false);
960 list.back().setChartSVGridLines(false);
961 list.back().setChartType(eMyMoney::Report::ChartType::Line);
962
963 list.push_back(MyMoneyReport(
964 eMyMoney::Report::RowType::Institution,
965 eMyMoney::Report::QueryColumn::None,
966 TransactionFilter::Date::YearToDate,
967 eMyMoney::Report::DetailLevel::Top,
968 i18n("Account Balances by Institution"),
969 i18n("Default Report")
970 ));
971
972 list.push_back(MyMoneyReport(
973 eMyMoney::Report::RowType::AccountType,
974 eMyMoney::Report::QueryColumn::None,
975 TransactionFilter::Date::YearToDate,
976 eMyMoney::Report::DetailLevel::Top,
977 i18n("Account Balances by Type"),
978 i18n("Default Report")
979 ));
980
981 groups.push_back(list);
982 }
983 {
984 ReportGroup list("Transactions", i18n("Transactions"));
985
986 list.push_back(MyMoneyReport(
987 eMyMoney::Report::RowType::Account,
988 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Tag | eMyMoney::Report::QueryColumn::Balance,
989 TransactionFilter::Date::YearToDate,
990 eMyMoney::Report::DetailLevel::All,
991 i18n("Transactions by Account"),
992 i18n("Default Report")
993 ));
994 //list.back().setConvertCurrency(false);
995 list.push_back(MyMoneyReport(
996 eMyMoney::Report::RowType::Category,
997 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Account | eMyMoney::Report::QueryColumn::Tag,
998 TransactionFilter::Date::YearToDate,
999 eMyMoney::Report::DetailLevel::All,
1000 i18n("Transactions by Category"),
1001 i18n("Default Report")
1002 ));
1003 list.push_back(MyMoneyReport(
1004 eMyMoney::Report::RowType::Payee,
1005 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Tag,
1006 TransactionFilter::Date::YearToDate,
1007 eMyMoney::Report::DetailLevel::All,
1008 i18n("Transactions by Payee"),
1009 i18n("Default Report")
1010 ));
1011 list.push_back(MyMoneyReport(
1012 eMyMoney::Report::RowType::Tag,
1013 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Category,
1014 TransactionFilter::Date::YearToDate,
1015 eMyMoney::Report::DetailLevel::All,
1016 i18n("Transactions by Tag"),
1017 i18n("Default Report")
1018 ));
1019 list.push_back(MyMoneyReport(
1020 eMyMoney::Report::RowType::Month,
1021 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Tag,
1022 TransactionFilter::Date::YearToDate,
1023 eMyMoney::Report::DetailLevel::All,
1024 i18n("Transactions by Month"),
1025 i18n("Default Report")
1026 ));
1027 list.push_back(MyMoneyReport(
1028 eMyMoney::Report::RowType::Week,
1029 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Tag,
1030 TransactionFilter::Date::YearToDate,
1031 eMyMoney::Report::DetailLevel::All,
1032 i18n("Transactions by Week"),
1033 i18n("Default Report")
1034 ));
1035 list.push_back(MyMoneyReport(
1036 eMyMoney::Report::RowType::Account,
1037 eMyMoney::Report::QueryColumn::Loan,
1038 TransactionFilter::Date::All,
1039 eMyMoney::Report::DetailLevel::All,
1040 i18n("Loan Transactions"),
1041 i18n("Default Report")
1042 ));
1043 list.back().setLoansOnly(true);
1044 list.push_back(MyMoneyReport(
1045 eMyMoney::Report::RowType::AccountReconcile,
1046 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Balance,
1047 TransactionFilter::Date::Last3Months,
1048 eMyMoney::Report::DetailLevel::All,
1049 i18n("Transactions by Reconciliation Status"),
1050 i18n("Default Report")
1051 ));
1052 groups.push_back(list);
1053 }
1054 {
1055 ReportGroup list("CashFlow", i18n("Cash Flow"));
1056 list.push_back(MyMoneyReport(
1057 eMyMoney::Report::RowType::CashFlow,
1058 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Account,
1059 TransactionFilter::Date::YearToDate,
1060 eMyMoney::Report::DetailLevel::All,
1061 i18n("Cash Flow Transactions This Month"),
1062 i18n("Default Report")
1063 ));
1064 groups.push_back(list);
1065 }
1066 {
1067 ReportGroup list("Investments", i18n("Investments"));
1068
1069 list.push_back(MyMoneyReport(
1070 eMyMoney::Report::RowType::TopAccount,
1071 eMyMoney::Report::QueryColumn::Action | eMyMoney::Report::QueryColumn::Shares | eMyMoney::Report::QueryColumn::Price,
1072 TransactionFilter::Date::YearToDate,
1073 eMyMoney::Report::DetailLevel::All,
1074 i18n("Investment Transactions"),
1075 i18n("Default Report")
1076 ));
1077 list.back().setInvestmentsOnly(true);
1078
1079 list.push_back(MyMoneyReport(
1080 eMyMoney::Report::RowType::AccountByTopAccount,
1081 eMyMoney::Report::QueryColumn::Shares | eMyMoney::Report::QueryColumn::Price,
1082 TransactionFilter::Date::YearToDate,
1083 eMyMoney::Report::DetailLevel::All,
1084 i18n("Investment Holdings by Account"),
1085 i18n("Default Report")
1086 ));
1087 list.back().setInvestmentsOnly(true);
1088
1089 list.push_back(MyMoneyReport(
1090 eMyMoney::Report::RowType::EquityType,
1091 eMyMoney::Report::QueryColumn::Shares | eMyMoney::Report::QueryColumn::Price,
1092 TransactionFilter::Date::YearToDate,
1093 eMyMoney::Report::DetailLevel::All,
1094 i18n("Investment Holdings by Type"),
1095 i18n("Default Report")
1096 ));
1097 list.back().setInvestmentsOnly(true);
1098
1099 list.push_back(MyMoneyReport(
1100 eMyMoney::Report::RowType::AccountByTopAccount,
1101 eMyMoney::Report::QueryColumn::Performance,
1102 TransactionFilter::Date::YearToDate,
1103 eMyMoney::Report::DetailLevel::All,
1104 i18n("Investment Performance by Account"),
1105 i18n("Default Report")
1106 ));
1107 list.back().setInvestmentsOnly(true);
1108
1109 list.push_back(MyMoneyReport(
1110 eMyMoney::Report::RowType::EquityType,
1111 eMyMoney::Report::QueryColumn::Performance,
1112 TransactionFilter::Date::YearToDate,
1113 eMyMoney::Report::DetailLevel::All,
1114 i18n("Investment Performance by Type"),
1115 i18n("Default Report")
1116 ));
1117 list.back().setInvestmentsOnly(true);
1118
1119 list.push_back(MyMoneyReport(
1120 eMyMoney::Report::RowType::AccountByTopAccount,
1121 eMyMoney::Report::QueryColumn::CapitalGain,
1122 TransactionFilter::Date::YearToDate,
1123 eMyMoney::Report::DetailLevel::All,
1124 i18n("Investment Capital Gains by Account"),
1125 i18n("Default Report")
1126 ));
1127 list.back().setInvestmentsOnly(true);
1128
1129 list.push_back(MyMoneyReport(
1130 eMyMoney::Report::RowType::EquityType,
1131 eMyMoney::Report::QueryColumn::CapitalGain,
1132 TransactionFilter::Date::YearToDate,
1133 eMyMoney::Report::DetailLevel::All,
1134 i18n("Investment Capital Gains by Type"),
1135 i18n("Default Report")
1136 ));
1137 list.back().setInvestmentsOnly(true);
1138
1139 list.push_back(MyMoneyReport(
1140 eMyMoney::Report::RowType::AssetLiability,
1141 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1142 TransactionFilter::Date::Today,
1143 eMyMoney::Report::DetailLevel::All,
1144 i18n("Investment Holdings Pie"),
1145 i18n("Default Report")
1146 ));
1147 list.back().setChartByDefault(true);
1148 list.back().setChartCHGridLines(false);
1149 list.back().setChartSVGridLines(false);
1150 list.back().setChartType(eMyMoney::Report::ChartType::Pie);
1151 list.back().setInvestmentsOnly(true);
1152
1153 list.push_back(MyMoneyReport(
1154 eMyMoney::Report::RowType::AssetLiability,
1155 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1156 TransactionFilter::Date::Last12Months,
1157 eMyMoney::Report::DetailLevel::All,
1158 i18n("Investment Worth Graph"),
1159 i18n("Default Report")
1160 ));
1161 list.back().setChartByDefault(true);
1162 list.back().setChartCHGridLines(false);
1163 list.back().setChartSVGridLines(false);
1164 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1165 list.back().setColumnsAreDays(true);
1166 list.back().setInvestmentsOnly(true);
1167
1168 list.push_back(MyMoneyReport(
1169 eMyMoney::Report::RowType::AssetLiability,
1170 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1171 TransactionFilter::Date::Last12Months,
1172 eMyMoney::Report::DetailLevel::All,
1173 i18n("Investment Price Graph"),
1174 i18n("Default Report")
1175 ));
1176 list.back().setChartByDefault(true);
1177 list.back().setChartCHGridLines(false);
1178 list.back().setChartSVGridLines(false);
1179 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1180 list.back().setColumnsAreDays(true);
1181 list.back().setInvestmentsOnly(true);
1182 list.back().setIncludingBudgetActuals(false);
1183 list.back().setIncludingPrice(true);
1184 list.back().setConvertCurrency(true);
1185 list.back().setChartDataLabels(false);
1186 list.back().setSkipZero(true);
1187 list.back().setShowingColumnTotals(false);
1188 list.back().setShowingRowTotals(false);
1189
1190 list.push_back(MyMoneyReport(
1191 eMyMoney::Report::RowType::AssetLiability,
1192 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1193 TransactionFilter::Date::Last12Months,
1194 eMyMoney::Report::DetailLevel::All,
1195 i18n("Investment Moving Average Price Graph"),
1196 i18n("Default Report")
1197 ));
1198 list.back().setChartByDefault(true);
1199 list.back().setChartCHGridLines(false);
1200 list.back().setChartSVGridLines(false);
1201 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1202 list.back().setColumnsAreDays(true);
1203 list.back().setInvestmentsOnly(true);
1204 list.back().setIncludingBudgetActuals(false);
1205 list.back().setIncludingAveragePrice(true);
1206 list.back().setMovingAverageDays(10);
1207 list.back().setConvertCurrency(true);
1208 list.back().setChartDataLabels(false);
1209 list.back().setShowingColumnTotals(false);
1210 list.back().setShowingRowTotals(false);
1211
1212 list.push_back(MyMoneyReport(
1213 eMyMoney::Report::RowType::AssetLiability,
1214 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1215 TransactionFilter::Date::Last30Days,
1216 eMyMoney::Report::DetailLevel::All,
1217 i18n("Investment Moving Average"),
1218 i18n("Default Report")
1219 ));
1220 list.back().setChartCHGridLines(false);
1221 list.back().setChartSVGridLines(false);
1222 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1223 list.back().setColumnsAreDays(true);
1224 list.back().setInvestmentsOnly(true);
1225 list.back().setIncludingBudgetActuals(false);
1226 list.back().setIncludingMovingAverage(true);
1227 list.back().setMovingAverageDays(10);
1228
1229 list.push_back(MyMoneyReport(
1230 eMyMoney::Report::RowType::AssetLiability,
1231 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1232 TransactionFilter::Date::Last30Days,
1233 eMyMoney::Report::DetailLevel::All,
1234 i18n("Investment Moving Average vs Actual"),
1235 i18n("Default Report")
1236 ));
1237 list.back().setChartByDefault(true);
1238 list.back().setChartCHGridLines(false);
1239 list.back().setChartSVGridLines(false);
1240 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1241 list.back().setColumnsAreDays(true);
1242 list.back().setInvestmentsOnly(true);
1243 list.back().setIncludingBudgetActuals(true);
1244 list.back().setIncludingMovingAverage(true);
1245 list.back().setMovingAverageDays(10);
1246 groups.push_back(list);
1247 }
1248 {
1249 ReportGroup list("Taxes", i18n("Taxes"));
1250
1251 list.push_back(MyMoneyReport(
1252 eMyMoney::Report::RowType::Category,
1253 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Account,
1254 TransactionFilter::Date::YearToDate,
1255 eMyMoney::Report::DetailLevel::All,
1256 i18n("Tax Transactions by Category"),
1257 i18n("Default Report")
1258 ));
1259 list.back().setTax(true);
1260 list.push_back(MyMoneyReport(
1261 eMyMoney::Report::RowType::Payee,
1262 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Account,
1263 TransactionFilter::Date::YearToDate,
1264 eMyMoney::Report::DetailLevel::All,
1265 i18n("Tax Transactions by Payee"),
1266 i18n("Default Report")
1267 ));
1268 list.back().setTax(true);
1269 list.push_back(MyMoneyReport(
1270 eMyMoney::Report::RowType::Category,
1271 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Payee | eMyMoney::Report::QueryColumn::Account,
1272 TransactionFilter::Date::LastFiscalYear,
1273 eMyMoney::Report::DetailLevel::All,
1274 i18n("Tax Transactions by Category Last Fiscal Year"),
1275 i18n("Default Report")
1276 ));
1277 list.back().setTax(true);
1278 list.push_back(MyMoneyReport(
1279 eMyMoney::Report::RowType::Payee,
1280 eMyMoney::Report::QueryColumn::Number | eMyMoney::Report::QueryColumn::Category | eMyMoney::Report::QueryColumn::Account,
1281 TransactionFilter::Date::LastFiscalYear,
1282 eMyMoney::Report::DetailLevel::All,
1283 i18n("Tax Transactions by Payee Last Fiscal Year"),
1284 i18n("Default Report")
1285 ));
1286 list.back().setTax(true);
1287 groups.push_back(list);
1288 }
1289 {
1290 ReportGroup list("Budgeting", i18n("Budgeting"));
1291
1292 list.push_back(MyMoneyReport(
1293 eMyMoney::Report::RowType::BudgetActual,
1294 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1295 TransactionFilter::Date::YearToDate,
1296 eMyMoney::Report::DetailLevel::All,
1297 i18n("Budgeted vs. Actual This Year"),
1298 i18n("Default Report")
1299 ));
1300 list.back().setShowingRowTotals(true);
1301 list.back().setBudget("Any", true);
1302
1303 list.push_back(MyMoneyReport(
1304 eMyMoney::Report::RowType::BudgetActual,
1305 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1306 TransactionFilter::Date::YearToMonth,
1307 eMyMoney::Report::DetailLevel::All,
1308 i18n("Budgeted vs. Actual This Year (YTM)"),
1309 i18n("Default Report")
1310 ));
1311 list.back().setShowingRowTotals(true);
1312 list.back().setBudget("Any", true);
1313 // in case we're in January, we show the last year
1314 if (QDate::currentDate().month() == 1) {
1315 list.back().setDateFilter(TransactionFilter::Date::LastYear);
1316 }
1317
1318 list.push_back(MyMoneyReport(
1319 eMyMoney::Report::RowType::BudgetActual,
1320 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1321 TransactionFilter::Date::CurrentMonth,
1322 eMyMoney::Report::DetailLevel::All,
1323 i18n("Monthly Budgeted vs. Actual"),
1324 i18n("Default Report")
1325 ));
1326 list.back().setBudget("Any", true);
1327
1328 list.push_back(MyMoneyReport(
1329 eMyMoney::Report::RowType::BudgetActual,
1330 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1331 TransactionFilter::Date::CurrentYear,
1332 eMyMoney::Report::DetailLevel::All,
1333 i18n("Yearly Budgeted vs. Actual"),
1334 i18n("Default Report")
1335 ));
1336 list.back().setBudget("Any", true);
1337 list.back().setShowingRowTotals(true);
1338
1339 list.push_back(MyMoneyReport(
1340 eMyMoney::Report::RowType::Budget,
1341 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1342 TransactionFilter::Date::CurrentMonth,
1343 eMyMoney::Report::DetailLevel::All,
1344 i18n("Monthly Budget"),
1345 i18n("Default Report")
1346 ));
1347 list.back().setBudget("Any", false);
1348
1349 list.push_back(MyMoneyReport(
1350 eMyMoney::Report::RowType::Budget,
1351 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1352 TransactionFilter::Date::CurrentYear,
1353 eMyMoney::Report::DetailLevel::All,
1354 i18n("Yearly Budget"),
1355 i18n("Default Report")
1356 ));
1357 list.back().setBudget("Any", false);
1358 list.back().setShowingRowTotals(true);
1359 list.push_back(MyMoneyReport(
1360 eMyMoney::Report::RowType::BudgetActual,
1361 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1362 TransactionFilter::Date::CurrentYear,
1363 eMyMoney::Report::DetailLevel::Group,
1364 i18n("Yearly Budgeted vs Actual Graph"),
1365 i18n("Default Report")
1366 ));
1367 list.back().setChartByDefault(true);
1368 list.back().setChartCHGridLines(false);
1369 list.back().setChartSVGridLines(false);
1370 list.back().setBudget("Any", true);
1371 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1372
1373 groups.push_back(list);
1374 }
1375 {
1376 ReportGroup list("Forecast", i18n("Forecast"));
1377
1378 list.push_back(MyMoneyReport(
1379 eMyMoney::Report::RowType::AssetLiability,
1380 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1381 TransactionFilter::Date::Next12Months,
1382 eMyMoney::Report::DetailLevel::Top,
1383 i18n("Forecast By Month"),
1384 i18n("Default Report")
1385 ));
1386 list.back().setIncludingForecast(true);
1387
1388 list.push_back(MyMoneyReport(
1389 eMyMoney::Report::RowType::AssetLiability,
1390 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1391 TransactionFilter::Date::NextQuarter,
1392 eMyMoney::Report::DetailLevel::Top,
1393 i18n("Forecast Next Quarter"),
1394 i18n("Default Report")
1395 ));
1396 list.back().setColumnsAreDays(true);
1397 list.back().setIncludingForecast(true);
1398
1399 list.push_back(MyMoneyReport(
1400 eMyMoney::Report::RowType::ExpenseIncome,
1401 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1402 TransactionFilter::Date::CurrentYear,
1403 eMyMoney::Report::DetailLevel::Top,
1404 i18n("Income and Expenses Forecast This Year"),
1405 i18n("Default Report")
1406 ));
1407 list.back().setIncludingForecast(true);
1408
1409 list.push_back(MyMoneyReport(
1410 eMyMoney::Report::RowType::AssetLiability,
1411 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1412 TransactionFilter::Date::Next3Months,
1413 eMyMoney::Report::DetailLevel::Total,
1414 i18n("Net Worth Forecast Graph"),
1415 i18n("Default Report")
1416 ));
1417 list.back().setColumnsAreDays(true);
1418 list.back().setIncludingForecast(true);
1419 list.back().setChartByDefault(true);
1420 list.back().setChartCHGridLines(false);
1421 list.back().setChartSVGridLines(false);
1422 list.back().setChartType(eMyMoney::Report::ChartType::Line);
1423 groups.push_back(list);
1424 }
1425 {
1426 ReportGroup list("Information", i18n("General Information"));
1427
1428 list.push_back(MyMoneyReport(
1429 eMyMoney::Report::RowType::Schedule,
1430 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1431 TransactionFilter::Date::Next12Months,
1432 eMyMoney::Report::DetailLevel::All,
1433 i18n("Schedule Information"),
1434 i18n("Default Report")
1435 ));
1436 list.back().setDetailLevel(eMyMoney::Report::DetailLevel::All);
1437 list.push_back(MyMoneyReport(
1438 eMyMoney::Report::RowType::Schedule,
1439 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1440 TransactionFilter::Date::Next12Months,
1441 eMyMoney::Report::DetailLevel::All,
1442 i18n("Schedule Summary Information"),
1443 i18n("Default Report")
1444 ));
1445 list.back().setDetailLevel(eMyMoney::Report::DetailLevel::Top);
1446 list.push_back(MyMoneyReport(
1447 eMyMoney::Report::RowType::AccountInfo,
1448 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1449 TransactionFilter::Date::Today,
1450 eMyMoney::Report::DetailLevel::All,
1451 i18n("Account Information"),
1452 i18n("Default Report")
1453 ));
1454 list.back().setConvertCurrency(false);
1455 list.push_back(MyMoneyReport(
1456 eMyMoney::Report::RowType::AccountLoanInfo,
1457 static_cast<unsigned>(eMyMoney::Report::ColumnType::Months),
1458 TransactionFilter::Date::Today,
1459 eMyMoney::Report::DetailLevel::All,
1460 i18n("Loan Information"),
1461 i18n("Default Report")
1462 ));
1463 list.back().setConvertCurrency(false);
1464 groups.push_back(list);
1465 }
1466 }
1467
columnsAlreadyAdjusted()1468 bool columnsAlreadyAdjusted() const
1469 {
1470 return m_columnsAlreadyAdjusted;
1471 }
1472
setColumnsAlreadyAdjusted(bool adjusted)1473 void setColumnsAlreadyAdjusted(bool adjusted)
1474 {
1475 m_columnsAlreadyAdjusted = adjusted;
1476 }
1477
1478 KReportsView *q_ptr;
1479
1480 /**
1481 * This member holds the load state of page
1482 */
1483 bool m_needLoad;
1484
1485 QListWidget* m_reportListView;
1486 QTabWidget* m_reportTabWidget;
1487 QWidget* m_listTab;
1488 QVBoxLayout* m_listTabLayout;
1489 QTreeWidget* m_tocTreeWidget;
1490 QMap<QString, TocItemGroup*> m_allTocItemGroups;
1491 QString m_selectedExportFilter;
1492
1493 bool m_columnsAlreadyAdjusted;
1494 MyMoneyAccount m_currentAccount;
1495 };
1496
1497 #endif
1498