author | mickeyl <mickeyl> | 2003-10-30 13:18:08 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-30 13:18:08 (UTC) |
commit | 37414f207b147af4cf6778b323a0aa23127901bd (patch) (unidiff) | |
tree | b08c10043ab689b0a40425d268cd72226799b0cf /noncore/apps/checkbook/transaction.cpp | |
parent | d53637f46cf217fc760d7aac58b4596843a73803 (diff) | |
download | opie-37414f207b147af4cf6778b323a0aa23127901bd.zip opie-37414f207b147af4cf6778b323a0aa23127901bd.tar.gz opie-37414f207b147af4cf6778b323a0aa23127901bd.tar.bz2 |
apply patch to HEAD
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 | |||
@@ -26,32 +26,35 @@ | |||
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
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> |
37 | #include <qlabel.h> | 39 | #include <qlabel.h> |
38 | #include <qlayout.h> | 40 | #include <qlayout.h> |
39 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
40 | #include <qmultilineedit.h> | 42 | #include <qmultilineedit.h> |
41 | #include <qradiobutton.h> | 43 | #include <qradiobutton.h> |
42 | #include <qwhatsthis.h> | 44 | #include <qwhatsthis.h> |
43 | 45 | ||
44 | Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *info, | 46 | Transaction::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 | ||
55 | QVBoxLayout *vb = new QVBoxLayout( this ); | 58 | QVBoxLayout *vb = new QVBoxLayout( this ); |
56 | 59 | ||
57 | QScrollView *sv = new QScrollView( this ); | 60 | QScrollView *sv = new QScrollView( this ); |
@@ -111,15 +114,18 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in | |||
111 | layout->addWidget( numEdit, 1, 3 ); | 114 | layout->addWidget( numEdit, 1, 3 ); |
112 | 115 | ||
113 | // Description | 116 | // Description |
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 ); |
123 | QWhatsThis::add( label, tr( "Select transaction category here." ) ); | 129 | QWhatsThis::add( label, tr( "Select transaction category here." ) ); |
124 | layout->addWidget( label, 3, 0 ); | 130 | layout->addWidget( label, 3, 0 ); |
125 | catList = new QComboBox( container ); | 131 | catList = new QComboBox( container ); |
@@ -131,12 +137,13 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in | |||
131 | QWhatsThis::add( label, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) ); | 137 | QWhatsThis::add( label, tr( "Select transaction type here.\n\nThe options available vary based on whether the transaction is a deposit or withdrawal." ) ); |
132 | layout->addWidget( label, 4, 0 ); | 138 | layout->addWidget( label, 4, 0 ); |
133 | typeList = new QComboBox( container ); | 139 | typeList = new QComboBox( container ); |
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." ) ); |
140 | layout->addWidget( label, 5, 0 ); | 147 | layout->addWidget( label, 5, 0 ); |
141 | amtEdit = new QLineEdit( container ); | 148 | amtEdit = new QLineEdit( container ); |
142 | QWhatsThis::add( amtEdit, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) ); | 149 | QWhatsThis::add( amtEdit, tr( "Enter the amount of transaction here.\n\nThe value entered should always be positive." ) ); |
@@ -155,12 +162,28 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in | |||
155 | QWhatsThis::add( label, tr( "Enter any additional information for this transaction here." ) ); | 162 | QWhatsThis::add( label, tr( "Enter any additional information for this transaction here." ) ); |
156 | layout->addWidget( label, 7, 0 ); | 163 | layout->addWidget( label, 7, 0 ); |
157 | noteEdit = new QMultiLineEdit( container ); | 164 | noteEdit = new QMultiLineEdit( container ); |
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 ----------------------------------------------------------- | ||
182 | void 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 | { |
164 | if ( info->withdrawal() ) | 187 | if ( info->withdrawal() ) |
165 | { | 188 | { |
166 | withBtn->setChecked( TRUE ); | 189 | withBtn->setChecked( TRUE ); |
@@ -168,19 +191,33 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in | |||
168 | } | 191 | } |
169 | else | 192 | else |
170 | { | 193 | { |
171 | depBtn->setChecked( TRUE ); | 194 | depBtn->setChecked( TRUE ); |
172 | slotDepositClicked(); | 195 | slotDepositClicked(); |
173 | } | 196 | } |
174 | QDate dt = info->date(); | 197 | |
175 | slotDateChanged( dt.year(), dt.month(), dt.day() ); | 198 | if( !bPopulateOld ) { |
176 | datePicker->setDate( dt ); | 199 | QDate dt = info->date(); |
177 | numEdit->setText( info->number() ); | 200 | slotDateChanged( dt.year(), dt.month(), dt.day() ); |
178 | descEdit->setText( info->desc() ); | 201 | datePicker->setDate( dt ); |
202 | numEdit->setText( info->number() ); | ||
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--; |
184 | catList->setCurrentItem( i ); | 221 | catList->setCurrentItem( i ); |
185 | if ( catList->currentText() == temptext ) | 222 | if ( catList->currentText() == temptext ) |
186 | { | 223 | { |
@@ -205,19 +242,22 @@ Transaction::Transaction( QWidget *parent, const QString &acctname, TranInfo *in | |||
205 | else | 242 | else |
206 | { | 243 | { |
207 | withBtn->setChecked( TRUE ); | 244 | withBtn->setChecked( TRUE ); |
208 | } | 245 | } |
209 | } | 246 | } |
210 | 247 | ||
248 | |||
249 | // --- ~Transaction ----------------------------------------------------------- | ||
211 | Transaction::~Transaction() | 250 | Transaction::~Transaction() |
212 | { | 251 | { |
213 | } | 252 | } |
214 | 253 | ||
254 | // --- accept ----------------------------------------------------------------- | ||
215 | void Transaction::accept() | 255 | void 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() ); |
221 | tran->setCategory( catList->currentText() ); | 261 | tran->setCategory( catList->currentText() ); |
222 | bool ok; | 262 | bool ok; |
223 | tran->setAmount( amtEdit->text().toFloat( &ok ) ); | 263 | tran->setAmount( amtEdit->text().toFloat( &ok ) ); |
@@ -259,12 +299,40 @@ void Transaction::slotDepositClicked() | |||
259 | typeList->insertItem( tr( "Written Check" ) ); | 299 | typeList->insertItem( tr( "Written Check" ) ); |
260 | typeList->insertItem( tr( "Automatic Payment" ) ); | 300 | typeList->insertItem( tr( "Automatic Payment" ) ); |
261 | typeList->insertItem( tr( "Transfer" ) ); | 301 | typeList->insertItem( tr( "Transfer" ) ); |
262 | typeList->insertItem( tr( "Cash" ) ); | 302 | typeList->insertItem( tr( "Cash" ) ); |
263 | } | 303 | } |
264 | 304 | ||
305 | // --- slotDateChanged -------------------------------------------------------- | ||
265 | void Transaction::slotDateChanged( int y, int m, int d ) | 306 | void 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 | ||
318 | void 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 ----------------------------------------------------------------- | ||
334 | void Transaction::slotNotNew() | ||
335 | { | ||
336 | qDebug("Not new"); | ||
337 | _bNew=false; | ||
338 | } | ||