author | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-27 19:51:32 (UTC) |
commit | 951d1d4125a80dc814f95d2956853bf53ca52e9a (patch) (side-by-side diff) | |
tree | 46c7a70b80a7eebb54cd59c46204c28335f3821c /noncore/apps/checkbook/cbinfo.cpp | |
parent | f0a15a9866f9eddfe10596e63a1e6300b92b9e3f (diff) | |
download | opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.zip opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.gz opie-951d1d4125a80dc814f95d2956853bf53ca52e9a.tar.bz2 |
merge noncore/apps/* except
- advancedfm (ljp, please...)
- odict (tille, please...)
Diffstat (limited to 'noncore/apps/checkbook/cbinfo.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/cbinfo.cpp | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/noncore/apps/checkbook/cbinfo.cpp b/noncore/apps/checkbook/cbinfo.cpp index 9fdc6b2..36dde04 100644 --- a/noncore/apps/checkbook/cbinfo.cpp +++ b/noncore/apps/checkbook/cbinfo.cpp @@ -35,2 +35,3 @@ +// --- CBInfo ----------------------------------------------------------------- CBInfo::CBInfo() @@ -46,2 +47,5 @@ CBInfo::CBInfo() sb = 0.0; + _sLastTab=""; + _first=-1; + _last=-1; @@ -50,2 +54,4 @@ CBInfo::CBInfo() + +// --- CBInfo ----------------------------------------------------------------- CBInfo::CBInfo( const QString &name, const QString &filename ) @@ -64,2 +70,5 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) nt = config.readEntry( "Notes", "" ); + _sLastTab = config.readEntry("LastTab", ""); + _first=config.readNumEntry("First", -1); + _sSortOrder = config.readEntry( "SortOrder", QWidget::tr("Date") ); @@ -71,2 +80,3 @@ CBInfo::CBInfo( const QString &name, const QString &filename ) +// --- balance ---------------------------------------------------------------- float CBInfo::balance() @@ -77,2 +87,3 @@ float CBInfo::balance() +// --- write ------------------------------------------------------------------ void CBInfo::write() @@ -81,5 +92,3 @@ void CBInfo::write() if ( f.exists() ) - { f.remove(); - } @@ -87,3 +96,20 @@ void CBInfo::write() + + // fix transaction numbers + _first=-1; + TranInfo *prev=NULL; + for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) { + if( _first<0 ) _first=tran->id(); + if( prev ) prev->setNext( tran->id() ); + tran->setNext(-1); + prev=tran; + } + + // Save transactions + for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) { + tran->write(config); + } + // Save info + if( _first<0 && _last>=0 ) _first=_last; config->setGroup( "Account" ); @@ -95,2 +121,3 @@ void CBInfo::write() config->writeEntry( "Notes", nt ); + config->writeEntry( "LastTab", _sLastTab ); QString balstr; @@ -98,12 +125,6 @@ void CBInfo::write() config->writeEntry( "Balance", balstr ); + config->writeEntry( "First", _first ); + config->writeEntry( "SortOrder", _sSortOrder ); - // Save transactions - int i = 1; - for ( TranInfo *tran = tl->first(); tran; tran = tl->next() ) - { - tran->write( config, i ); - i++; - } config->write(); - delete config; @@ -111,12 +132,14 @@ void CBInfo::write() -TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date, - const QString &desc ) -{ - TranInfo *traninfo = tl->first(); - while ( traninfo ) + +// --- findTransaction -------------------------------------------------------- +TranInfo *CBInfo::findTransaction( const QString &sId ) { - if ( traninfo->number() == checknum && traninfo->datestr() == date && - traninfo->desc() == desc ) + bool bOk; + int id=sId.toInt( &bOk ); + if( !bOk ) + return(false); + TranInfo *traninfo; + for(traninfo=tl->first(); traninfo; traninfo=tl->next()) { + if( traninfo->id() == id ) break; - traninfo = tl->next(); } @@ -127,3 +150,3 @@ void CBInfo::addTransaction( TranInfo *tran ) { - tl->inSort( tran ); + tl->append( tran ); calcBalance(); @@ -133,3 +156,3 @@ void CBInfo::removeTransaction( TranInfo *tran ) { - tl->remove( tran ); + tl->removeRef( tran ); delete tran; @@ -138,2 +161,5 @@ void CBInfo::removeTransaction( TranInfo *tran ) + +// --- loadTransactions ------------------------------------------------------- +// Reads the transactions. Either the old way 1-n or as linked list. void CBInfo::loadTransactions() @@ -146,15 +172,18 @@ void CBInfo::loadTransactions() Config config( fn, Config::File ); - - for ( int i = 1; trandesc != QString::null; i++ ) - { + int i=_first; + bool bOld=false; + if( i==-1 ) { + i=1; + bOld=true; + } + while( i>=0 ) { + _last=i; tran = new TranInfo( config, i ); trandesc = tran->desc(); - if ( trandesc != QString::null ) - { - tl->inSort( tran ); - } - else - { + if( trandesc==QString::null ) { delete tran; + break; } + tl->append(tran); + i= bOld ? i+1 : tran->getNext(); } @@ -164,2 +193,4 @@ void CBInfo::loadTransactions() + +// --- calcBalance ------------------------------------------------------------ void CBInfo::calcBalance() @@ -182,2 +213,3 @@ void CBInfo::calcBalance() + int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 ) |