Diffstat (limited to 'noncore/apps/checkbook/transaction.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/checkbook/transaction.cpp | 92 |
1 files changed, 80 insertions, 12 deletions
diff --git a/noncore/apps/checkbook/transaction.cpp b/noncore/apps/checkbook/transaction.cpp index 138d0e6..9379da0 100644 --- a/noncore/apps/checkbook/transaction.cpp +++ b/noncore/apps/checkbook/transaction.cpp @@ -28,10 +28,12 @@ #include "transaction.h" #include "traninfo.h" #include "cfg.h" +#include "checkbook.h" #include <qpe/datebookmonth.h> +#include <qpe/resource.h> #include <qbuttongroup.h> #include <qcombobox.h> #include <qlabel.h> @@ -40,16 +42,17 @@ #include <qmultilineedit.h> #include <qradiobutton.h> #include <qwhatsthis.h> -Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, - Cfg *pCfg ) +Transaction::Transaction( QWidget *parent, bool bNew, const QString &acctname, + TranInfo *info, Cfg *pCfg ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { QString tempstr = tr( "Transaction for " ); tempstr.append( acctname ); setCaption( tempstr ); + _bNew=bNew; tran = info; _pCfg=pCfg; QVBoxLayout *vb = new QVBoxLayout( this ); @@ -113,11 +116,14 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in // Description label = new QLabel( tr( "Description:" ), container ); QWhatsThis::add( label, tr( "Enter description of transaction here." ) ); layout->addWidget( label, 2, 0 ); - descEdit = new QLineEdit( container ); - QWhatsThis::add( descEdit, tr( "Enter description of transaction here." ) ); - layout->addMultiCellWidget( descEdit, 2, 2, 1, 3 ); + _cbDesc=new QComboBox( true, container ); + _cbDesc->insertStringList( _pCfg->getPayees() ); + QWhatsThis::add( _cbDesc, tr( "Enter description of transaction here." ) ); + layout->addMultiCellWidget( _cbDesc, 2, 2, 1, 3 ); + connect( _cbDesc, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) ); + // Category label = new QLabel( tr( "Category:" ), container ); QWhatsThis::add( label, tr( "Select transaction category here." ) ); @@ -133,8 +139,9 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in typeList = new QComboBox( container ); QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) ); layout->addMultiCellWidget( typeList, 4, 4, 1, 3 ); + // Amount label = new QLabel( tr( "Amount:" ), container ); QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) ); layout->addWidget( label, 5, 0 ); @@ -157,8 +164,24 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in noteEdit = new QMultiLineEdit( container ); QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) ); layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 ); + // init date + initFromInfo( info ); + + // not new handlers + connect( withBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) ); + connect( depBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) ); + connect( catList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) ); + connect( typeList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) ); + connect( amtEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) ); + connect( feeEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) ); + connect( noteEdit, SIGNAL(textChanged()), this, SLOT( slotNotNew() ) ); +} + +// --- initFromInfo ----------------------------------------------------------- +void Transaction::initFromInfo(TranInfo *info, bool bPopulateOld) +{ // Populate current values if provided if ( info ) { if ( info->withdrawal() ) @@ -170,15 +193,29 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in { depBtn->setChecked( TRUE ); slotDepositClicked(); } - QDate dt = info->date(); - slotDateChanged( dt.year(), dt.month(), dt.day() ); - datePicker->setDate( dt ); - numEdit->setText( info->number() ); - descEdit->setText( info->desc() ); + + if( !bPopulateOld ) { + QDate dt = info->date(); + slotDateChanged( dt.year(), dt.month(), dt.day() ); + datePicker->setDate( dt ); + numEdit->setText( info->number() ); + } QString temptext = info->category(); - int i = catList->count(); + + // set description field + int i; + for(i=_cbDesc->count()-1; i>=0; i--) { + if( _cbDesc->text(i)==info->desc() ) { + _cbDesc->setCurrentItem(i); + break; + } + } + if( i<=0 ) + _cbDesc->setEditText( info->desc() ); + + i = catList->count(); while ( i > 0 ) { i--; catList->setCurrentItem( i ); @@ -207,15 +244,18 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in withBtn->setChecked( TRUE ); } } + +// --- ~Transaction ----------------------------------------------------------- Transaction::~Transaction() { } +// --- accept ----------------------------------------------------------------- void Transaction::accept() { - tran->setDesc( descEdit->text() ); + tran->setDesc( _cbDesc->currentText() ); tran->setDate( datePicker->selectedDate() ); tran->setWithdrawal( withBtn->isChecked() ); tran->setType( typeList->currentText() ); tran->setCategory( catList->currentText() ); @@ -261,10 +301,38 @@ void Transaction::slotDepositClicked() typeList->insertItem( tr( "Transfer" ) ); typeList->insertItem( tr( "Cash" ) ); } +// --- slotDateChanged -------------------------------------------------------- void Transaction::slotDateChanged( int y, int m, int d ) { QDate date; date.setYMD( y, m, d ); dateBtn->setText( TimeString::shortDate( date ) ); } + + + +// --- slotActivated ---------------------------------------------------------- +// Search for the most recent transaction with this description/payee and +// fill amount etc here, as long the new flag is set +void Transaction::slotActivated(const QString &arg ) +{ + if( !_bNew ) return; + TranInfoList *pTl=((Checkbook *)parentWidget())->getTranList(); + if( pTl ) { + TranInfo *pTi=pTl->findMostRecentByDesc( arg ); + if( pTi ) { + initFromInfo( pTi, true ); + amtEdit->setFocus(); + amtEdit->setSelection(0, amtEdit->text().length() ); + amtEdit->setCursorPosition(0); + } + } +} + +// slotNotNew ----------------------------------------------------------------- +void Transaction::slotNotNew() +{ + qDebug("Not new"); + _bNew=false; +} |