Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 122 |
1 files changed, 103 insertions, 19 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 20b42b5..77c1f57 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp | |||
@@ -229,39 +229,36 @@ QWidget *Checkbook::initTransactions() | |||
229 | 229 | ||
230 | return( control ); | 230 | return( control ); |
231 | } | 231 | } |
232 | 232 | ||
233 | QWidget *Checkbook::initCharts() | 233 | QWidget *Checkbook::initCharts() |
234 | { | 234 | { |
235 | graphInfo = 0x0; | ||
236 | |||
235 | QWidget *control = new QWidget( mainWidget ); | 237 | QWidget *control = new QWidget( mainWidget ); |
236 | 238 | ||
237 | QGridLayout *layout = new QGridLayout( control ); | 239 | QGridLayout *layout = new QGridLayout( control ); |
238 | layout->setSpacing( 2 ); | 240 | layout->setSpacing( 2 ); |
239 | layout->setMargin( 4 ); | 241 | layout->setMargin( 4 ); |
240 | 242 | ||
241 | /* | 243 | graphWidget = new Graph( control ); |
242 | QLabel *label = new QLabel( control ); | 244 | QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); |
243 | label->setText( tr( "Graph type:" ) ); | 245 | layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); |
244 | layout->addWidget( label, 0, 0 ); | 246 | |
245 | graphList = new QComboBox( control ); | 247 | graphList = new QComboBox( control ); |
246 | graphList->insertItem( tr( "By category" ) ); | 248 | QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); |
247 | graphList->insertItem( tr( "..." ) ); | 249 | graphList->insertItem( tr( "Account balance" ) ); |
248 | graphList->insertItem( tr( "..." ) ); | 250 | graphList->insertItem( tr( "Withdrawals by category" ) ); |
249 | layout->addWidget( graphList, 0, 1 ); | 251 | graphList->insertItem( tr( "Deposits by category" ) ); |
250 | */ | ||
251 | 252 | ||
252 | GraphInfo* info = new GraphInfo( GraphInfo::BarChart, 0x0, tr( "Graph Title" ), | 253 | layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); |
253 | tr( "X-Axis" ), tr( "Y-Axis" ) ); | ||
254 | graphWidget = new Graph( control, info ); | ||
255 | QWhatsThis::add( graphWidget, tr( "Charting is not implemented yet." ) ); | ||
256 | layout->addMultiCellWidget( graphWidget, 0, 0, 0, 1 ); | ||
257 | 254 | ||
258 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); | 255 | QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); |
259 | QWhatsThis::add( btn, tr( "Click here to draw the chart." ) ); | 256 | QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); |
260 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); | 257 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); |
261 | layout->addWidget( btn, 1, 1 ); | 258 | layout->addWidget( btn, 1, 2 ); |
262 | 259 | ||
263 | return control; | 260 | return control; |
264 | } | 261 | } |
265 | 262 | ||
266 | void Checkbook::loadCheckbook() | 263 | void Checkbook::loadCheckbook() |
267 | { | 264 | { |
@@ -364,18 +361,16 @@ void Checkbook::accept() | |||
364 | config->writeEntryCrypt( "Number", acctNumEdit->text() ); | 361 | config->writeEntryCrypt( "Number", acctNumEdit->text() ); |
365 | config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); | 362 | config->writeEntryCrypt( "PINNumber", pinNumEdit->text() ); |
366 | config->writeEntry( "Balance", balanceEdit->text() ); | 363 | config->writeEntry( "Balance", balanceEdit->text() ); |
367 | config->writeEntry( "Notes", notesEdit->text() ); | 364 | config->writeEntry( "Notes", notesEdit->text() ); |
368 | 365 | ||
369 | // Save transactions | 366 | // Save transactions |
370 | TranInfo *tran = transactions.first(); | ||
371 | int i = 1; | 367 | int i = 1; |
372 | while ( tran ) | 368 | for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) |
373 | { | 369 | { |
374 | tran->write( config, i ); | 370 | tran->write( config, i ); |
375 | tran = transactions.next(); | ||
376 | i++; | 371 | i++; |
377 | } | 372 | } |
378 | config->write(); | 373 | config->write(); |
379 | 374 | ||
380 | QDialog::accept(); | 375 | QDialog::accept(); |
381 | } | 376 | } |
@@ -506,7 +501,96 @@ void Checkbook::slotDeleteTran() | |||
506 | adjustBalance( amount * -1 ); | 501 | adjustBalance( amount * -1 ); |
507 | } | 502 | } |
508 | } | 503 | } |
509 | 504 | ||
510 | void Checkbook::slotDrawGraph() | 505 | void Checkbook::slotDrawGraph() |
511 | { | 506 | { |
507 | if ( graphInfo ) | ||
508 | { | ||
509 | delete graphInfo; | ||
510 | } | ||
511 | |||
512 | switch ( graphList->currentItem() ) | ||
513 | { | ||
514 | case 0 : drawBalanceChart(); | ||
515 | break; | ||
516 | case 1 : drawCategoryChart( TRUE ); | ||
517 | break; | ||
518 | case 2 : drawCategoryChart( FALSE ); | ||
519 | break; | ||
520 | }; | ||
521 | |||
522 | graphWidget->setGraphInfo( graphInfo ); | ||
523 | graphWidget->drawGraph( TRUE ); | ||
524 | } | ||
525 | |||
526 | void Checkbook::drawBalanceChart() | ||
527 | { | ||
528 | DataPointList *list = new DataPointList(); | ||
529 | |||
530 | float balance = startBalance; | ||
531 | float amount; | ||
532 | QString label; | ||
533 | int i = 0; | ||
534 | int count = transactions.count(); | ||
535 | |||
536 | for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() ) | ||
537 | { | ||
538 | i++; | ||
539 | balance -= tran->fee(); | ||
540 | amount = tran->amount(); | ||
541 | if ( tran->withdrawal() ) | ||
542 | { | ||
543 | amount *= -1; | ||
544 | } | ||
545 | balance += amount; | ||
546 | if ( i == 1 || i == count / 2 || i == count ) | ||
547 | { | ||
548 | label = tran->datestr(); | ||
549 | } | ||
550 | else | ||
551 | { | ||
552 | label = ""; | ||
553 | } | ||
554 | list->append( new DataPointInfo( label, balance ) ); | ||
555 | } | ||
556 | |||
557 | graphInfo = new GraphInfo( GraphInfo::BarChart, list ); | ||
558 | } | ||
559 | |||
560 | void Checkbook::drawCategoryChart( bool withdrawals ) | ||
561 | { | ||
562 | DataPointList *list = new DataPointList(); | ||
563 | |||
564 | TranInfo *tran = transactions.first(); | ||
565 | if ( tran->withdrawal() == withdrawals ) | ||
566 | { | ||
567 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); | ||
568 | } | ||
569 | tran = transactions.next(); | ||
570 | |||
571 | DataPointInfo *cat; | ||
572 | for ( ; tran; tran = transactions.next() ) | ||
573 | { | ||
574 | if ( tran->withdrawal() == withdrawals ) | ||
575 | { | ||
576 | // Find category in list | ||
577 | for ( cat = list->first(); cat; cat = list->next() ) | ||
578 | { | ||
579 | if ( cat->label() == tran->category() ) | ||
580 | { | ||
581 | break; | ||
582 | } | ||
583 | } | ||
584 | if ( cat && cat->label() == tran->category() ) | ||
585 | { // Found category, add to transaction to category total | ||
586 | cat->addToValue( tran->amount() ); | ||
587 | } | ||
588 | else | ||
589 | { // Didn't find category, add category to list | ||
590 | list->append( new DataPointInfo( tran->category(), tran->amount() ) ); | ||
591 | } | ||
592 | } | ||
593 | } | ||
594 | |||
595 | graphInfo = new GraphInfo( GraphInfo::PieChart, list ); | ||
512 | } | 596 | } |