summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/transaction.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/transaction.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/transaction.cpp84
1 files changed, 76 insertions, 8 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
@@ -29,8 +29,10 @@
29#include "transaction.h" 29#include "transaction.h"
30#include "traninfo.h" 30#include "traninfo.h"
31#include "cfg.h" 31#include "cfg.h"
32#include "checkbook.h"
32 33
33#include <qpe/datebookmonth.h> 34#include <qpe/datebookmonth.h>
35#include <qpe/resource.h>
34 36
35#include <qbuttongroup.h> 37#include <qbuttongroup.h>
36#include <qcombobox.h> 38#include <qcombobox.h>
@@ -41,14 +43,15 @@
41#include <qradiobutton.h> 43#include <qradiobutton.h>
42#include <qwhatsthis.h> 44#include <qwhatsthis.h>
43 45
44Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, 46Transaction::Transaction( QWidget *parent, bool bNew, const QString &acctname,
45 Cfg *pCfg ) 47 TranInfo *info, Cfg *pCfg )
46 : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) 48 : QDialog( parent, 0, TRUE, WStyle_ContextHelp )
47{ 49{
48 QString tempstr = tr( "Transaction for " ); 50 QString tempstr = tr( "Transaction for " );
49 tempstr.append( acctname ); 51 tempstr.append( acctname );
50 setCaption( tempstr ); 52 setCaption( tempstr );
51 53
54 _bNew=bNew;
52 tran = info; 55 tran = info;
53 _pCfg=pCfg; 56 _pCfg=pCfg;
54 57
@@ -114,9 +117,12 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
114 label = new QLabel( tr( "Description:" ), container ); 117 label = new QLabel( tr( "Description:" ), container );
115 QWhatsThis::add( label, tr( "Enter description of transaction here." ) ); 118 QWhatsThis::add( label, tr( "Enter description of transaction here." ) );
116 layout->addWidget( label, 2, 0 ); 119 layout->addWidget( label, 2, 0 );
117 descEdit = new QLineEdit( container ); 120 _cbDesc=new QComboBox( true, container );
118 QWhatsThis::add( descEdit, tr( "Enter description of transaction here." ) ); 121 _cbDesc->insertStringList( _pCfg->getPayees() );
119 layout->addMultiCellWidget( descEdit, 2, 2, 1, 3 ); 122 QWhatsThis::add( _cbDesc, tr( "Enter description of transaction here." ) );
123 layout->addMultiCellWidget( _cbDesc, 2, 2, 1, 3 );
124 connect( _cbDesc, SIGNAL( activated(const QString &) ), this, SLOT( slotActivated(const QString &) ) );
125
120 126
121 // Category 127 // Category
122 label = new QLabel( tr( "Category:" ), container ); 128 label = new QLabel( tr( "Category:" ), container );
@@ -134,6 +140,7 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
134 QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) ); 140 QWhatsThis::add( typeList, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) );
135 layout->addMultiCellWidget( typeList, 4, 4, 1, 3 ); 141 layout->addMultiCellWidget( typeList, 4, 4, 1, 3 );
136 142
143
137 // Amount 144 // Amount
138 label = new QLabel( tr( "Amount:" ), container ); 145 label = new QLabel( tr( "Amount:" ), container );
139 QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) ); 146 QWhatsThis::add( label, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) );
@@ -158,6 +165,22 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
158 QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) ); 165 QWhatsThis::add( noteEdit, tr( "Enter any additional information for this transaction here." ) );
159 layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 ); 166 layout->addMultiCellWidget( noteEdit, 8, 8, 0, 3 );
160 167
168 // init date
169 initFromInfo( info );
170
171 // not new handlers
172 connect( withBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
173 connect( depBtn, SIGNAL( toggled(bool) ), this, SLOT( slotNotNew() ) );
174 connect( catList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
175 connect( typeList, SIGNAL(activated(const QString &)), this, SLOT( slotNotNew() ) );
176 connect( amtEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
177 connect( feeEdit, SIGNAL(textChanged(const QString &)), this, SLOT( slotNotNew() ) );
178 connect( noteEdit, SIGNAL(textChanged()), this, SLOT( slotNotNew() ) );
179}
180
181// --- initFromInfo -----------------------------------------------------------
182void Transaction::initFromInfo(TranInfo *info, bool bPopulateOld)
183{
161 // Populate current values if provided 184 // Populate current values if provided
162 if ( info ) 185 if ( info )
163 { 186 {
@@ -171,13 +194,27 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
171 depBtn->setChecked( TRUE ); 194 depBtn->setChecked( TRUE );
172 slotDepositClicked(); 195 slotDepositClicked();
173 } 196 }
197
198 if( !bPopulateOld ) {
174 QDate dt = info->date(); 199 QDate dt = info->date();
175 slotDateChanged( dt.year(), dt.month(), dt.day() ); 200 slotDateChanged( dt.year(), dt.month(), dt.day() );
176 datePicker->setDate( dt ); 201 datePicker->setDate( dt );
177 numEdit->setText( info->number() ); 202 numEdit->setText( info->number() );
178 descEdit->setText( info->desc() ); 203 }
179 QString temptext = info->category(); 204 QString temptext = info->category();
180 int i = catList->count(); 205
206 // set description field
207 int i;
208 for(i=_cbDesc->count()-1; i>=0; i--) {
209 if( _cbDesc->text(i)==info->desc() ) {
210 _cbDesc->setCurrentItem(i);
211 break;
212 }
213 }
214 if( i<=0 )
215 _cbDesc->setEditText( info->desc() );
216
217 i = catList->count();
181 while ( i > 0 ) 218 while ( i > 0 )
182 { 219 {
183 i--; 220 i--;
@@ -208,13 +245,16 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in
208 } 245 }
209} 246}
210 247
248
249// --- ~Transaction -----------------------------------------------------------
211Transaction::~Transaction() 250Transaction::~Transaction()
212{ 251{
213} 252}
214 253
254// --- accept -----------------------------------------------------------------
215void Transaction::accept() 255void Transaction::accept()
216{ 256{
217 tran->setDesc( descEdit->text() ); 257 tran->setDesc( _cbDesc->currentText() );
218 tran->setDate( datePicker->selectedDate() ); 258 tran->setDate( datePicker->selectedDate() );
219 tran->setWithdrawal( withBtn->isChecked() ); 259 tran->setWithdrawal( withBtn->isChecked() );
220 tran->setType( typeList->currentText() ); 260 tran->setType( typeList->currentText() );
@@ -262,9 +302,37 @@ void Transaction::slotDepositClicked()
262 typeList->insertItem( tr( "Cash" ) ); 302 typeList->insertItem( tr( "Cash" ) );
263} 303}
264 304
305// --- slotDateChanged --------------------------------------------------------
265void Transaction::slotDateChanged( int y, int m, int d ) 306void Transaction::slotDateChanged( int y, int m, int d )
266{ 307{
267 QDate date; 308 QDate date;
268 date.setYMD( y, m, d ); 309 date.setYMD( y, m, d );
269 dateBtn->setText( TimeString::shortDate( date ) ); 310 dateBtn->setText( TimeString::shortDate( date ) );
270} 311}
312
313
314
315// --- slotActivated ----------------------------------------------------------
316// Search for the most recent transaction with this description/payee and
317// fill amount etc here, as long the new flag is set
318void Transaction::slotActivated(const QString &arg )
319{
320 if( !_bNew ) return;
321 TranInfoList *pTl=((Checkbook *)parentWidget())->getTranList();
322 if( pTl ) {
323 TranInfo *pTi=pTl->findMostRecentByDesc( arg );
324 if( pTi ) {
325 initFromInfo( pTi, true );
326 amtEdit->setFocus();
327 amtEdit->setSelection(0, amtEdit->text().length() );
328 amtEdit->setCursorPosition(0);
329 }
330 }
331}
332
333// slotNotNew -----------------------------------------------------------------
334void Transaction::slotNotNew()
335{
336 qDebug("Not new");
337 _bNew=false;
338}