-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.cpp | 15 | ||||
-rw-r--r-- | noncore/apps/checkbook/traninfo.h | 8 |
3 files changed, 25 insertions, 4 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 77c1f57..ab25516 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp @@ -298,33 +298,33 @@ void Checkbook::loadCheckbook() for ( int i = 1; trandesc != QString::null; i++ ) { tran = new TranInfo( config, i ); trandesc = tran->desc(); if ( trandesc != QString::null ) { currBalance -= tran->fee(); amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } currBalance += amount; stramount.sprintf( "%c%.2f", currencySymbol, amount ); // Add to transaction list - transactions.append( tran ); + transactions.inSort( tran ); // Add to transaction table ( void ) new QListViewItem( tranTable, QString::number( i ), tran->datestr(), trandesc, stramount ); } else { delete tran; } } balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) ); highTranNum = transactions.count(); } void Checkbook::adjustBalance( float amount ) @@ -402,33 +402,33 @@ void Checkbook::slotNewTran() Transaction *currtran = new Transaction( this, name, traninfo, currencySymbol ); currtran->showMaximized(); if ( currtran->exec() == QDialog::Accepted ) { float amount = traninfo->amount(); if ( traninfo->withdrawal() ) { amount *= -1; } QString stramount; stramount.sprintf( "%c%.2f", currencySymbol, amount ); // Add to transaction list - transactions.append( traninfo ); + transactions.inSort( traninfo ); // Add to transaction table ( void ) new QListViewItem( tranTable, QString::number( highTranNum ), traninfo->datestr(), traninfo->desc(), stramount ); adjustBalance( amount ); } else { highTranNum--; delete traninfo; } } void Checkbook::slotEditTran() { @@ -549,33 +549,33 @@ void Checkbook::drawBalanceChart() } else { label = ""; } list->append( new DataPointInfo( label, balance ) ); } graphInfo = new GraphInfo( GraphInfo::BarChart, list ); } void Checkbook::drawCategoryChart( bool withdrawals ) { DataPointList *list = new DataPointList(); TranInfo *tran = transactions.first(); - if ( tran->withdrawal() == withdrawals ) + if ( tran && tran->withdrawal() == withdrawals ) { list->append( new DataPointInfo( tran->category(), tran->amount() ) ); } tran = transactions.next(); DataPointInfo *cat; for ( ; tran; tran = transactions.next() ) { if ( tran->withdrawal() == withdrawals ) { // Find category in list for ( cat = list->first(); cat; cat = list->next() ) { if ( cat->label() == tran->category() ) { break; diff --git a/noncore/apps/checkbook/traninfo.cpp b/noncore/apps/checkbook/traninfo.cpp index 460466c..dcba869 100644 --- a/noncore/apps/checkbook/traninfo.cpp +++ b/noncore/apps/checkbook/traninfo.cpp @@ -160,16 +160,31 @@ void TranInfo::write( Config *config, int entry ) else if ( t == "Credit Card" || t == "Cash" ) tempstr = "3"; config->writeEntry( "Type", tempstr ); config->writeEntry( "Category", c ); tempstr.setNum( a, 'f', 2 ); config->writeEntry( "Amount", tempstr ); tempstr.setNum( f, 'f', 2 ); config->writeEntry( "TransactionFee", tempstr ); config->writeEntry( "CheckNumber", cn ); config->writeEntry( "Comments", n ); } + +int TranInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) +{ + QDate d1 = ((TranInfo *)item1)->date(); + QDate d2 = ((TranInfo *)item2)->date(); + int r = -1; + + if ( d1 < d2 ) + r = -1; + else if ( d1 == d2 ) + r = 0; + else if ( d1 > d2 ) + r = 1; + return( r ); +}
\ No newline at end of file diff --git a/noncore/apps/checkbook/traninfo.h b/noncore/apps/checkbook/traninfo.h index e944c29..e488816 100644 --- a/noncore/apps/checkbook/traninfo.h +++ b/noncore/apps/checkbook/traninfo.h @@ -68,19 +68,25 @@ class TranInfo void write( Config *, int ); private: int i; QString d; QDate td; bool w; QString t; QString c; float a; float f; QString cn; QString n; }; -typedef QList<TranInfo> TranInfoList; +class TranInfoList : public QList<TranInfo> +{ + protected: + int compareItems( QCollection::Item, QCollection::Item ); +}; + +//typedef TranList<TranInfo> TranInfoList; #endif |