summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/cbinfo.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/checkbook/cbinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/cbinfo.cpp116
1 files changed, 74 insertions, 42 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()
- // Save info
+
+ // 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();
-
+ config->write();
delete config;
@@ -111,14 +132,16 @@ void CBInfo::write()
-TranInfo *CBInfo::findTransaction( const QString &checknum, const QString &date,
- const QString &desc )
+
+// --- findTransaction --------------------------------------------------------
+TranInfo *CBInfo::findTransaction( const QString &sId )
{
- TranInfo *traninfo = tl->first();
- while ( traninfo )
- {
- if ( traninfo->number() == checknum && traninfo->datestr() == date &&
- traninfo->desc() == desc )
- break;
- traninfo = tl->next();
- }
- return( traninfo );
+ 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;
+ }
+ return(traninfo);
}
@@ -127,3 +150,3 @@ void CBInfo::addTransaction( TranInfo *tran )
{
- tl->inSort( tran );
+ tl->append( tran );
calcBalance();
@@ -133,4 +156,4 @@ void CBInfo::removeTransaction( TranInfo *tran )
{
- tl->remove( tran );
- delete tran;
+ tl->removeRef( tran );
+ delete tran;
calcBalance();
@@ -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,20 +172,25 @@ void CBInfo::loadTransactions()
Config config( fn, Config::File );
-
- for ( int i = 1; trandesc != QString::null; i++ )
- {
- tran = new TranInfo( config, i );
- trandesc = tran->desc();
- if ( trandesc != QString::null )
- {
- tl->inSort( tran );
- }
- else
- {
- delete tran;
- }
- }
-
- calcBalance();
+ 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 ) {
+ delete tran;
+ break;
+ }
+ tl->append(tran);
+ i= bOld ? i+1 : tran->getNext();
+ }
+
+ calcBalance();
}
+
+// --- calcBalance ------------------------------------------------------------
void CBInfo::calcBalance()
@@ -182,2 +213,3 @@ void CBInfo::calcBalance()
+
int CBInfoList::compareItems( QCollection::Item item1, QCollection::Item item2 )