Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/reports/kreportchartview.cpp
Show First 20 Lines • Show All 292 Lines • ▼ Show 20 Line(s) | 288 | while (it_innergroup != (*it_outergroup).end()) { | |||
---|---|---|---|---|---|
293 | while (it_row != (*it_innergroup).end()) { | 293 | while (it_row != (*it_innergroup).end()) { | ||
294 | //Do not include investments accounts in the chart because they are merely container of stock and other accounts | 294 | //Do not include investments accounts in the chart because they are merely container of stock and other accounts | ||
295 | if (it_row.key().accountType() != MyMoneyAccount::Investment) { | 295 | if (it_row.key().accountType() != MyMoneyAccount::Investment) { | ||
296 | //iterate row types | 296 | //iterate row types | ||
297 | for (int i = 0; i < rowTypeList.size(); ++i) { | 297 | for (int i = 0; i < rowTypeList.size(); ++i) { | ||
298 | //skip the budget difference rowset | 298 | //skip the budget difference rowset | ||
299 | if (rowTypeList[i] != eBudgetDiff) { | 299 | if (rowTypeList[i] != eBudgetDiff) { | ||
300 | QString legendText; | 300 | QString legendText; | ||
301 | QString rowName = it_row.key().name(); | ||||
301 | 302 | | |||
302 | //only show the column type in the header if there is more than one type | 303 | //only show the column type in the header if there is more than one type | ||
303 | if (rowTypeList.size() > 1) { | 304 | if (rowTypeList.size() > 1) | ||
304 | legendText = QString(columnTypeHeaderList[i] + " - " + it_row.key().name()); | 305 | legendText = QString(columnTypeHeaderList.at(i) + QLatin1Literal(" - ") + rowName); | ||
305 | } else { | 306 | else | ||
306 | legendText = QString(it_row.key().name()); | 307 | legendText = rowName; | ||
307 | } | | |||
308 | 308 | | |||
309 | //set the legend text | 309 | //set the legend text | ||
310 | legend->setText(rowNum, legendText); | 310 | legend->setText(rowNum, legendText); | ||
311 | 311 | | |||
312 | //clear to speed up drawPivotRowSet | 312 | //clear to speed up drawPivotRowSet | ||
313 | if (!config.isChartDataLabels()) | 313 | if (!config.isChartDataLabels()) | ||
314 | legendText.clear(); | 314 | legendText.clear(); | ||
315 | 315 | | |||
316 | //set the cell value and tooltip | 316 | //set the cell value and tooltip | ||
317 | rowNum = drawPivotRowSet(rowNum, it_row.value(), rowTypeList[i], legendText, 1, numColumns() - 1); | 317 | rowNum = drawPivotRowSet(it_row.key().id(), rowNum, it_row.value(), rowTypeList[i], legendText, 1, numColumns() - 1); | ||
318 | } | 318 | } | ||
319 | } | 319 | } | ||
320 | } | 320 | } | ||
321 | ++it_row; | 321 | ++it_row; | ||
322 | } | 322 | } | ||
323 | ++it_innergroup; | 323 | ++it_innergroup; | ||
324 | } | 324 | } | ||
325 | ++it_outergroup; | 325 | ++it_outergroup; | ||
Show All 11 Lines | 335 | while (it_outergroup != grid.end()) { | |||
337 | // iterate over inner groups | 337 | // iterate over inner groups | ||
338 | PivotOuterGroup::const_iterator it_innergroup = (*it_outergroup).begin(); | 338 | PivotOuterGroup::const_iterator it_innergroup = (*it_outergroup).begin(); | ||
339 | while (it_innergroup != (*it_outergroup).end()) { | 339 | while (it_innergroup != (*it_outergroup).end()) { | ||
340 | //iterate row types | 340 | //iterate row types | ||
341 | for (int i = 0; i < rowTypeList.size(); ++i) { | 341 | for (int i = 0; i < rowTypeList.size(); ++i) { | ||
342 | //skip the budget difference rowset | 342 | //skip the budget difference rowset | ||
343 | if (rowTypeList[i] != eBudgetDiff) { | 343 | if (rowTypeList[i] != eBudgetDiff) { | ||
344 | QString legendText; | 344 | QString legendText; | ||
345 | 345 | QString rowName = it_innergroup.key(); | |||
346 | 346 | | |||
347 | //only show the column type in the header if there is more than one type | 347 | //only show the column type in the header if there is more than one type | ||
348 | if (rowTypeList.size() > 1) { | 348 | if (rowTypeList.size() > 1) | ||
349 | legendText = QString(columnTypeHeaderList[i] + " - " + it_innergroup.key()); | 349 | legendText = QString(columnTypeHeaderList.at(i) + QLatin1Literal(" - ") + rowName); | ||
350 | } else { | 350 | else | ||
351 | legendText = QString(it_innergroup.key()); | 351 | legendText = rowName; | ||
352 | } | | |||
353 | 352 | | |||
354 | //set the legend text | 353 | //set the legend text | ||
355 | legend->setText(rowNum, legendText); | 354 | legend->setText(rowNum, legendText); | ||
356 | 355 | | |||
357 | //clear to speed up drawPivotRowSet | 356 | //clear to speed up drawPivotRowSet | ||
358 | if (!config.isChartDataLabels()) | 357 | if (!config.isChartDataLabels()) | ||
359 | legendText.clear(); | 358 | legendText.clear(); | ||
360 | 359 | | |||
361 | //set the cell value and tooltip | 360 | //set the cell value and tooltip | ||
362 | rowNum = drawPivotRowSet(rowNum, (*it_innergroup).m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | 361 | rowNum = drawPivotRowSet(QString(), rowNum, (*it_innergroup).m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | ||
363 | } | 362 | } | ||
364 | } | 363 | } | ||
365 | ++it_innergroup; | 364 | ++it_innergroup; | ||
366 | } | 365 | } | ||
367 | ++it_outergroup; | 366 | ++it_outergroup; | ||
368 | } | 367 | } | ||
369 | } | 368 | } | ||
370 | break; | 369 | break; | ||
371 | 370 | | |||
372 | case MyMoneyReport::eDetailGroup: { | 371 | case MyMoneyReport::eDetailGroup: { | ||
373 | int rowNum = 0; | 372 | int rowNum = 0; | ||
374 | 373 | | |||
375 | // iterate over outer groups | 374 | // iterate over outer groups | ||
376 | PivotGrid::const_iterator it_outergroup = grid.begin(); | 375 | PivotGrid::const_iterator it_outergroup = grid.begin(); | ||
377 | while (it_outergroup != grid.end()) { | 376 | while (it_outergroup != grid.end()) { | ||
378 | //iterate row types | 377 | //iterate row types | ||
379 | for (int i = 0; i < rowTypeList.size(); ++i) { | 378 | for (int i = 0; i < rowTypeList.size(); ++i) { | ||
380 | //skip the budget difference rowset | 379 | //skip the budget difference rowset | ||
381 | if (rowTypeList[i] != eBudgetDiff) { | 380 | if (rowTypeList[i] != eBudgetDiff) { | ||
382 | QString legendText; | 381 | QString legendText; | ||
382 | QString rowName = it_outergroup.key(); | ||||
383 | 383 | | |||
384 | //only show the column type in the header if there is more than one type | 384 | //only show the column type in the header if there is more than one type | ||
385 | if (rowTypeList.size() > 1) { | 385 | if (rowTypeList.size() > 1) | ||
386 | legendText = QString(columnTypeHeaderList[i] + " - " + it_outergroup.key()); | 386 | legendText = QString(columnTypeHeaderList.at(i) + QLatin1Literal(" - ") + rowName); | ||
387 | } else { | 387 | else | ||
388 | legendText = QString(it_outergroup.key()); | 388 | legendText = rowName; | ||
389 | } | | |||
390 | 389 | | |||
391 | //set the legend text | 390 | //set the legend text | ||
392 | legend->setText(rowNum, legendText); | 391 | legend->setText(rowNum, legendText); | ||
393 | 392 | | |||
394 | //clear to speed up drawPivotRowSet | 393 | //clear to speed up drawPivotRowSet | ||
395 | if (!config.isChartDataLabels()) | 394 | if (!config.isChartDataLabels()) | ||
396 | legendText.clear(); | 395 | legendText.clear(); | ||
397 | 396 | | |||
398 | //set the cell value and tooltip | 397 | //set the cell value and tooltip | ||
399 | rowNum = drawPivotRowSet(rowNum, (*it_outergroup).m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | 398 | rowNum = drawPivotRowSet(QString(), rowNum, (*it_outergroup).m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | ||
400 | } | 399 | } | ||
401 | } | 400 | } | ||
402 | ++it_outergroup; | 401 | ++it_outergroup; | ||
403 | } | 402 | } | ||
404 | 403 | | |||
405 | //if selected, show totals too | 404 | //if selected, show totals too | ||
406 | if (config.isShowingRowTotals()) { | 405 | if (config.isShowingRowTotals()) { | ||
407 | //iterate row types | 406 | //iterate row types | ||
408 | for (int i = 0; i < rowTypeList.size(); ++i) { | 407 | for (int i = 0; i < rowTypeList.size(); ++i) { | ||
409 | //skip the budget difference rowset | 408 | //skip the budget difference rowset | ||
410 | if (rowTypeList[i] != eBudgetDiff) { | 409 | if (rowTypeList[i] != eBudgetDiff) { | ||
411 | QString legendText; | 410 | QString legendText; | ||
412 | 411 | | |||
413 | //only show the column type in the header if there is more than one type | 412 | //only show the column type in the header if there is more than one type | ||
414 | if (rowTypeList.size() > 1) { | 413 | if (rowTypeList.size() > 1) | ||
415 | legendText = QString(columnTypeHeaderList[i] + " - " + i18nc("Total balance", "Total")); | 414 | legendText = QString(columnTypeHeaderList.at(i) + QLatin1Literal(" - ") + i18nc("Total balance", "Total")); | ||
415 | else | ||||
416 | legendText = QString(i18nc("Total balance", "Total")); | 416 | legendText = QString(i18nc("Total balance", "Total")); | ||
417 | } else { | | |||
418 | } | | |||
419 | 417 | | |||
420 | //set the legend text | 418 | //set the legend text | ||
421 | legend->setText(rowNum, legendText); | 419 | legend->setText(rowNum, legendText); | ||
422 | 420 | | |||
423 | //clear to speed up drawPivotRowSet | 421 | //clear to speed up drawPivotRowSet | ||
424 | if (!config.isChartDataLabels()) | 422 | if (!config.isChartDataLabels()) | ||
425 | legendText.clear(); | 423 | legendText.clear(); | ||
426 | 424 | | |||
427 | //set the cell value | 425 | //set the cell value | ||
428 | rowNum = drawPivotRowSet(rowNum, grid.m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | 426 | rowNum = drawPivotRowSet(QString(), rowNum, grid.m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | ||
429 | } | 427 | } | ||
430 | } | 428 | } | ||
431 | } | 429 | } | ||
432 | } | 430 | } | ||
433 | break; | 431 | break; | ||
434 | 432 | | |||
435 | case MyMoneyReport::eDetailTotal: { | 433 | case MyMoneyReport::eDetailTotal: { | ||
436 | int rowNum = 0; | 434 | int rowNum = 0; | ||
437 | 435 | | |||
438 | //iterate row types | 436 | //iterate row types | ||
439 | for (int i = 0; i < rowTypeList.size(); ++i) { | 437 | for (int i = 0; i < rowTypeList.size(); ++i) { | ||
440 | //skip the budget difference rowset | 438 | //skip the budget difference rowset | ||
441 | if (rowTypeList[i] != eBudgetDiff) { | 439 | if (rowTypeList[i] != eBudgetDiff) { | ||
442 | QString legendText; | 440 | QString legendText; | ||
443 | 441 | | |||
444 | //only show the column type in the header if there is more than one type | 442 | //only show the column type in the header if there is more than one type | ||
445 | if (rowTypeList.size() > 1) { | 443 | if (rowTypeList.size() > 1) | ||
446 | legendText = QString(columnTypeHeaderList[i] + " - " + i18nc("Total balance", "Total")); | 444 | legendText = QString(columnTypeHeaderList.at(i) + QLatin1Literal(" - ") + i18nc("Total balance", "Total")); | ||
447 | } else { | 445 | else | ||
448 | legendText = QString(i18nc("Total balance", "Total")); | 446 | legendText = QString(i18nc("Total balance", "Total")); | ||
449 | } | | |||
450 | 447 | | |||
451 | //set the legend | 448 | //set the legend | ||
452 | legend->setText(rowNum, legendText); | 449 | legend->setText(rowNum, legendText); | ||
453 | 450 | | |||
454 | //clear to speed up drawPivotRowSet | 451 | //clear to speed up drawPivotRowSet | ||
455 | if (!config.isChartDataLabels()) | 452 | if (!config.isChartDataLabels()) | ||
456 | legendText.clear(); | 453 | legendText.clear(); | ||
457 | 454 | | |||
458 | if (config.isMixedTime() && (rowTypeList[i] == eActual || rowTypeList[i] == eForecast)) { | 455 | if (config.isMixedTime() && (rowTypeList[i] == eActual || rowTypeList[i] == eForecast)) { | ||
459 | if (rowTypeList[i] == eActual) { | 456 | if (rowTypeList[i] == eActual) { | ||
460 | rowNum = drawPivotRowSet(rowNum, grid.m_total, rowTypeList[i], legendText, 1, config.currentDateColumn()); | 457 | rowNum = drawPivotRowSet(QString(), rowNum, grid.m_total, rowTypeList[i], legendText, 1, config.currentDateColumn()); | ||
461 | } else if (rowTypeList[i] == eForecast) { | 458 | } else if (rowTypeList[i] == eForecast) { | ||
462 | rowNum = drawPivotRowSet(rowNum, grid.m_total, rowTypeList[i], legendText, config.currentDateColumn(), numColumns() - 1); | 459 | rowNum = drawPivotRowSet(QString(), rowNum, grid.m_total, rowTypeList[i], legendText, config.currentDateColumn(), numColumns() - 1); | ||
463 | } else { | 460 | } else { | ||
464 | rowNum = drawPivotRowSet(rowNum, grid.m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | 461 | rowNum = drawPivotRowSet(QString(), rowNum, grid.m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | ||
465 | } | 462 | } | ||
466 | } else { | 463 | } else { | ||
467 | //set cell value | 464 | //set cell value | ||
468 | rowNum = drawPivotRowSet(rowNum, grid.m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | 465 | rowNum = drawPivotRowSet(QString(), rowNum, grid.m_total, rowTypeList[i], legendText, 1, numColumns() - 1); | ||
469 | } | 466 | } | ||
470 | } | 467 | } | ||
471 | } | 468 | } | ||
472 | } | 469 | } | ||
473 | break; | 470 | break; | ||
474 | } | 471 | } | ||
475 | m_model.blockSignals(blocked); // reenable dataChanged() signal | 472 | m_model.blockSignals(blocked); // reenable dataChanged() signal | ||
476 | 473 | | |||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | 553 | { | |||
592 | if (lineDiagram) | 589 | if (lineDiagram) | ||
593 | lineDiagram->axes().at(1)->setLabels(labels); | 590 | lineDiagram->axes().at(1)->setLabels(labels); | ||
594 | 591 | | |||
595 | KChart::BarDiagram* barDiagram = qobject_cast<BarDiagram*>(coordinatePlane()->diagram()); | 592 | KChart::BarDiagram* barDiagram = qobject_cast<BarDiagram*>(coordinatePlane()->diagram()); | ||
596 | if (barDiagram) | 593 | if (barDiagram) | ||
597 | barDiagram->axes().at(1)->setLabels(labels); | 594 | barDiagram->axes().at(1)->setLabels(labels); | ||
598 | } | 595 | } | ||
599 | 596 | | |||
600 | unsigned KReportChartView::drawPivotRowSet(int rowNum, const PivotGridRowSet& rowSet, const ERowType rowType, const QString& legendText, int startColumn, int endColumn) | 597 | unsigned KReportChartView::drawPivotRowSet(const QString& rowAcc, int rowNum, const PivotGridRowSet& rowSet, const ERowType rowType, const QString& legendText, int startColumn, int endColumn) | ||
601 | { | 598 | { | ||
602 | if (coordinatePlane()->diagram()->datasetDimension() != 1) | 599 | if (coordinatePlane()->diagram()->datasetDimension() != 1) | ||
603 | return ++rowNum; | 600 | return ++rowNum; | ||
604 | //if endColumn is invalid, make it the same as numColumns | 601 | //if endColumn is invalid, make it the same as numColumns | ||
605 | if (endColumn == 0) | 602 | if (endColumn == 0) | ||
606 | endColumn = numColumns(); | 603 | endColumn = numColumns(); | ||
607 | 604 | | |||
605 | MyMoneyFile* file = MyMoneyFile::instance(); | ||||
608 | double value; | 606 | double value; | ||
609 | QString toolTip; | 607 | QString toolTip; | ||
610 | 608 | | |||
611 | if (( accountSeries() && !seriesTotals()) || | 609 | if (( accountSeries() && !seriesTotals()) || | ||
612 | (!accountSeries() && seriesTotals())) { | 610 | (!accountSeries() && seriesTotals())) { | ||
613 | justifyModelSize(endColumn > numColumns() - 1 ? endColumn + 1 : numColumns(), rowNum + 1); | 611 | justifyModelSize(endColumn > numColumns() - 1 ? endColumn + 1 : numColumns(), rowNum + 1); | ||
614 | } else { | 612 | } else { | ||
615 | justifyModelSize(rowNum + 1, endColumn > numColumns() - 1 ? endColumn + 1 : numColumns()); | 613 | justifyModelSize(rowNum + 1, endColumn > numColumns() - 1 ? endColumn + 1 : numColumns()); | ||
616 | } | 614 | } | ||
617 | 615 | | |||
616 | int precision = 0; | ||||
617 | if (!rowAcc.isEmpty()) { | ||||
618 | const MyMoneyAccount acc = file->account(rowAcc); | ||||
619 | if (rowType == ePrice) { | ||||
620 | if (acc.isInvest()) | ||||
621 | precision = file->currency(acc.currencyId()).pricePrecision(); | ||||
622 | } else { | ||||
623 | if (acc.isInvest()) // stock account isn't eveluated in currency, so take investment account instead | ||||
624 | precision = MyMoneyMoney::denomToPrec(file->account(acc.parentAccountId()).fraction()); | ||||
625 | else | ||||
626 | precision = MyMoneyMoney::denomToPrec(acc.fraction()); | ||||
627 | } | ||||
628 | } | ||||
629 | if (precision == 0) | ||||
630 | precision = file->baseCurrency().pricePrecision(); | ||||
631 | | ||||
618 | // Columns | 632 | // Columns | ||
619 | if (seriesTotals()) { | 633 | if (seriesTotals()) { | ||
620 | value = rowSet[rowType].m_total.toDouble(); | 634 | value = rowSet[rowType].m_total.toDouble(); | ||
621 | 635 | | |||
622 | //set the tooltip | 636 | //set the tooltip | ||
623 | if (!legendText.isEmpty()) | 637 | if (!legendText.isEmpty()) | ||
624 | toolTip = QString("<h2>%1</h2><strong>%2</strong><br>") | 638 | toolTip = QString("<h2>%1</h2><strong>%2</strong><br>") | ||
625 | .arg(legendText) | 639 | .arg(legendText) | ||
626 | .arg(value, 0, 'g', KMyMoneyGlobalSettings::pricePrecision()); | 640 | .arg(value, 0, 'f', precision); | ||
627 | 641 | | |||
628 | //set the cell value | 642 | //set the cell value | ||
629 | if (accountSeries()) | 643 | if (accountSeries()) | ||
630 | this->setDataCell(rowNum, 0, value, toolTip); | 644 | this->setDataCell(rowNum, 0, value, toolTip); | ||
631 | else | 645 | else | ||
632 | this->setDataCell(0, rowNum, value, toolTip); | 646 | this->setDataCell(0, rowNum, value, toolTip); | ||
633 | } else { | 647 | } else { | ||
634 | int column = startColumn; | 648 | int column = startColumn; | ||
635 | while (column <= endColumn && column < numColumns()) { | 649 | while (column <= endColumn && column < numColumns()) { | ||
636 | //if zero and set to skip, increase column and continue with next value | 650 | //if zero and set to skip, increase column and continue with next value | ||
637 | if (m_skipZero && rowSet[rowType][column].isZero()) { | 651 | if (m_skipZero && rowSet[rowType][column].isZero()) { | ||
638 | ++column; | 652 | ++column; | ||
639 | continue; | 653 | continue; | ||
640 | } else { | 654 | } else { | ||
641 | value = rowSet[rowType][column].toDouble(); | 655 | value = rowSet[rowType][column].toDouble(); | ||
642 | if (!legendText.isEmpty()) | 656 | if (!legendText.isEmpty()) | ||
643 | toolTip = QString("<h2>%1</h2><strong>%2</strong><br>") | 657 | toolTip = QString("<h2>%1</h2><strong>%2</strong><br>") | ||
644 | .arg(legendText) | 658 | .arg(legendText) | ||
645 | .arg(value, 0, 'g', KMyMoneyGlobalSettings::pricePrecision()); | 659 | .arg(value, 0, 'f', precision); | ||
646 | 660 | | |||
647 | if (accountSeries()) | 661 | if (accountSeries()) | ||
648 | this->setDataCell(column, rowNum, value, toolTip); | 662 | this->setDataCell(column, rowNum, value, toolTip); | ||
649 | else | 663 | else | ||
650 | this->setDataCell(rowNum, column, value, toolTip); | 664 | this->setDataCell(rowNum, column, value, toolTip); | ||
651 | } | 665 | } | ||
652 | ++column; | 666 | ++column; | ||
653 | } | 667 | } | ||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |