summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/checkbook.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/checkbook/checkbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp6
1 files changed, 3 insertions, 3 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
@@ -266,97 +266,97 @@ void Checkbook::loadCheckbook()
Config config(filename, Config::File);
// Load info
config.setGroup( "Account" );
nameEdit->setText( name );
QString temptext = config.readEntry( "Type" );
int i = typeList->count();
while ( i > 0 )
{
i--;
typeList->setCurrentItem( i );
if ( typeList->currentText() == temptext )
{
break;
}
}
bankEdit->setText( config.readEntry( "Bank", "" ) );
acctNumEdit->setText( config.readEntryCrypt( "Number", "" ) );
pinNumEdit->setText( config.readEntryCrypt( "PINNumber", "" ) );
balanceEdit->setText( config.readEntry( "Balance", "0.0" ) );
notesEdit->setText( config.readEntry( "Notes", "" ) );
bool ok;
currBalance = balanceEdit->text().toFloat( &ok );
startBalance = currBalance;
// Load transactions
TranInfo *tran;
QString trandesc = "";
float amount;
QString stramount;
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 )
{
currBalance += amount;
balanceLabel->setText( tr( "Current balance: %1%2" ).arg( currencySymbol ).arg( currBalance, 0, 'f', 2 ) );
}
TranInfo *Checkbook::findTranByID( int id )
{
TranInfo *traninfo = transactions.first();
while ( traninfo && traninfo->id() != id )
{
traninfo = transactions.next();
}
return( traninfo );
}
void Checkbook::accept()
{
QFile f( filename );
if ( f.exists() )
{
f.remove();
}
Config *config = new Config(filename, Config::File);
// Save info
config->setGroup( "Account" );
config->writeEntry( "Type", typeList->currentText() );
config->writeEntry( "Bank", bankEdit->text() );
config->writeEntryCrypt( "Number", acctNumEdit->text() );
config->writeEntryCrypt( "PINNumber", pinNumEdit->text() );
@@ -370,97 +370,97 @@ void Checkbook::accept()
tran->write( config, i );
i++;
}
config->write();
QDialog::accept();
}
void Checkbook::slotNameChanged( const QString &newname )
{
name = newname;
filename = filedir;
filename.append( newname );
filename.append( ".qcb" );
QString tempstr = name;
tempstr.append( " - " );
tempstr.append( tr( "Checkbook" ) );
setCaption( tempstr );
}
void Checkbook::slotStartingBalanceChanged( const QString &newbalance )
{
currBalance -= startBalance;
bool ok;
startBalance = newbalance.toFloat( &ok );
adjustBalance( startBalance );
}
void Checkbook::slotNewTran()
{
highTranNum++;
TranInfo *traninfo = new TranInfo( highTranNum );
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()
{
bool ok;
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
{
return;
}
int tranid = curritem->text( 0 ).toInt( &ok );
TranInfo *traninfo = findTranByID( tranid );
float origamt = traninfo->amount();
if ( traninfo->withdrawal() )
{
origamt *= -1;
}
Transaction *currtran = new Transaction( this, name,
traninfo,
currencySymbol );
currtran->showMaximized();
if ( currtran->exec() == QDialog::Accepted )
{
curritem->setText( 1, traninfo->datestr() );
curritem->setText( 2, traninfo->desc() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
adjustBalance( origamt * -1 );
adjustBalance( amount );
@@ -517,80 +517,80 @@ void Checkbook::slotDrawGraph()
break;
case 2 : drawCategoryChart( FALSE );
break;
};
graphWidget->setGraphInfo( graphInfo );
graphWidget->drawGraph( TRUE );
}
void Checkbook::drawBalanceChart()
{
DataPointList *list = new DataPointList();
float balance = startBalance;
float amount;
QString label;
int i = 0;
int count = transactions.count();
for ( TranInfo *tran = transactions.first(); tran; tran = transactions.next() )
{
i++;
balance -= tran->fee();
amount = tran->amount();
if ( tran->withdrawal() )
{
amount *= -1;
}
balance += amount;
if ( i == 1 || i == count / 2 || i == count )
{
label = tran->datestr();
}
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;
}
}
if ( cat && cat->label() == tran->category() )
{ // Found category, add to transaction to category total
cat->addToValue( tran->amount() );
}
else
{ // Didn't find category, add category to list
list->append( new DataPointInfo( tran->category(), tran->amount() ) );
}
}
}
graphInfo = new GraphInfo( GraphInfo::PieChart, list );
}