Diffstat (limited to 'noncore/apps/qashmoney/accountdisplay.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/apps/qashmoney/accountdisplay.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/noncore/apps/qashmoney/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp index 5ef5454..0fe5b09 100755 --- a/noncore/apps/qashmoney/accountdisplay.cpp +++ b/noncore/apps/qashmoney/accountdisplay.cpp | |||
@@ -1,73 +1,73 @@ | |||
1 | #include <qmessagebox.h> | 1 | #include <qmessagebox.h> |
2 | #include <qheader.h> | 2 | #include <qheader.h> |
3 | 3 | ||
4 | #include "accountdisplay.h" | 4 | #include "accountdisplay.h" |
5 | #include "newaccount.h" | 5 | #include "newaccount.h" |
6 | #include "transaction.h" | 6 | #include "transaction.h" |
7 | #include "transferdialog.h" | 7 | #include "transferdialog.h" |
8 | #include "transfer.h" | 8 | #include "transfer.h" |
9 | 9 | ||
10 | extern Account *account; | 10 | extern Account *account; |
11 | extern Transaction *transaction; | 11 | extern Transaction *transaction; |
12 | extern Transfer *transfer; | 12 | extern Transfer *transfer; |
13 | extern Preferences *preferences; | 13 | extern Preferences *preferences; |
14 | 14 | ||
15 | AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) | 15 | AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) |
16 | { | 16 | { |
17 | cleared = 0; | 17 | cleared = 0; |
18 | 18 | ||
19 | firstline = new QHBox ( this ); | 19 | firstline = new QHBox ( this ); |
20 | firstline->setSpacing ( 2 ); | 20 | firstline->setSpacing ( 2 ); |
21 | 21 | ||
22 | newaccount = new QPushButton ( firstline ); | 22 | newaccount = new QPushButton ( firstline ); |
23 | newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); | 23 | newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); |
24 | connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); | 24 | connect ( newaccount, SIGNAL ( released() ), this, SLOT ( addAccount() ) ); |
25 | 25 | ||
26 | editaccount = new QPushButton ( firstline ); | 26 | editaccount = new QPushButton ( firstline ); |
27 | editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); | 27 | editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); |
28 | connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); | 28 | connect ( editaccount, SIGNAL ( released() ), this, SLOT ( editAccount() ) ); |
29 | 29 | ||
30 | deleteaccount = new QPushButton ( firstline ); | 30 | deleteaccount = new QPushButton ( firstline ); |
31 | deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); | 31 | deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); |
32 | connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); | 32 | connect ( deleteaccount, SIGNAL ( released() ), this, SLOT ( deleteAccount() ) ); |
33 | 33 | ||
34 | transferbutton = new QPushButton ( firstline ); | 34 | transferbutton = new QPushButton ( firstline ); |
35 | transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); | 35 | transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); |
36 | transferbutton->setToggleButton ( TRUE ); | 36 | transferbutton->setToggleButton ( TRUE ); |
37 | connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); | 37 | connect ( transferbutton, SIGNAL ( toggled(bool) ), this, SLOT ( accountTransfer(bool) ) ); |
38 | 38 | ||
39 | listview = new QListView ( this ); | 39 | listview = new QListView ( this ); |
40 | listview->setAllColumnsShowFocus ( TRUE ); | 40 | listview->setAllColumnsShowFocus ( TRUE ); |
41 | listview->setShowSortIndicator ( TRUE ); | 41 | listview->setShowSortIndicator ( TRUE ); |
42 | listview->setRootIsDecorated ( TRUE ); | 42 | listview->setRootIsDecorated ( TRUE ); |
43 | listview->setMultiSelection ( FALSE ); | 43 | listview->setMultiSelection ( FALSE ); |
44 | connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); | 44 | connect ( listview, SIGNAL ( expanded(QListViewItem*) ), this, SLOT ( setAccountExpanded(QListViewItem*) ) ); |
45 | connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); | 45 | connect ( listview, SIGNAL ( collapsed(QListViewItem*) ), this, SLOT ( setAccountCollapsed(QListViewItem*) ) ); |
46 | 46 | ||
47 | listview->header()->setTracking ( FALSE ); | 47 | listview->header()->setTracking ( FALSE ); |
48 | connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); | 48 | connect ( listview->header(), SIGNAL ( sizeChange(int,int,int) ), this, SLOT ( saveColumnSize(int,int,int) ) ); |
49 | connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); | 49 | connect ( listview->header(), SIGNAL ( clicked(int) ), this, SLOT ( saveSortingPreference(int) ) ); |
50 | 50 | ||
51 | layout = new QVBoxLayout ( this, 2, 5 ); | 51 | layout = new QVBoxLayout ( this, 2, 5 ); |
52 | layout->addWidget ( firstline ); | 52 | layout->addWidget ( firstline ); |
53 | layout->addWidget ( listview ); | 53 | layout->addWidget ( listview ); |
54 | } | 54 | } |
55 | 55 | ||
56 | void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) | 56 | void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) |
57 | { | 57 | { |
58 | tab2 = newtab2; | 58 | tab2 = newtab2; |
59 | maintabs = newtabs; | 59 | maintabs = newtabs; |
60 | } | 60 | } |
61 | 61 | ||
62 | void AccountDisplay::addAccount () | 62 | void AccountDisplay::addAccount () |
63 | { | 63 | { |
64 | // initialize local variables | 64 | // initialize local variables |
65 | int parentid = 0; | 65 | int parentid = 0; |
66 | type = 0; | 66 | type = 0; |
67 | QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; | 67 | QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; |
68 | 68 | ||
69 | // create new account window for entering data | 69 | // create new account window for entering data |
70 | NewAccount *newaccount = new NewAccount ( this ); | 70 | NewAccount *newaccount = new NewAccount ( this ); |
71 | int width = this->width(); | 71 | int width = this->width(); |
72 | newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); | 72 | newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); |
73 | newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | 73 | newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); |
@@ -204,58 +204,58 @@ void AccountDisplay::setToggleButton () | |||
204 | // if there are less than two, disable the transfer button | 204 | // if there are less than two, disable the transfer button |
205 | QListViewItemIterator it ( listview ); | 205 | QListViewItemIterator it ( listview ); |
206 | int counter = 0; | 206 | int counter = 0; |
207 | for ( ; it.current(); ++it ) | 207 | for ( ; it.current(); ++it ) |
208 | { | 208 | { |
209 | // add one to counter if we find a transferable account | 209 | // add one to counter if we find a transferable account |
210 | if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) | 210 | if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) |
211 | counter++; | 211 | counter++; |
212 | } | 212 | } |
213 | if ( counter > 1 ) | 213 | if ( counter > 1 ) |
214 | transferbutton->show(); | 214 | transferbutton->show(); |
215 | else | 215 | else |
216 | transferbutton->hide(); | 216 | transferbutton->hide(); |
217 | } | 217 | } |
218 | 218 | ||
219 | void AccountDisplay::accountTransfer ( bool state ) | 219 | void AccountDisplay::accountTransfer ( bool state ) |
220 | { | 220 | { |
221 | if ( state == TRUE ) | 221 | if ( state == TRUE ) |
222 | { | 222 | { |
223 | firstaccountid = -1; | 223 | firstaccountid = -1; |
224 | secondaccountid = -1; | 224 | secondaccountid = -1; |
225 | listview->clearSelection (); | 225 | listview->clearSelection (); |
226 | listview->setMultiSelection ( TRUE ); | 226 | listview->setMultiSelection ( TRUE ); |
227 | disableParentsWithChildren (); | 227 | disableParentsWithChildren (); |
228 | connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | 228 | connect ( listview, SIGNAL ( clicked(QListViewItem*) ), this, SLOT ( getTransferAccounts(QListViewItem*) ) ); |
229 | } | 229 | } |
230 | else | 230 | else |
231 | { | 231 | { |
232 | firstaccountid = -1; | 232 | firstaccountid = -1; |
233 | secondaccountid = -1; | 233 | secondaccountid = -1; |
234 | listview->clearSelection (); | 234 | listview->clearSelection (); |
235 | listview->setMultiSelection ( FALSE ); | 235 | listview->setMultiSelection ( FALSE ); |
236 | enableAccounts (); | 236 | enableAccounts (); |
237 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | 237 | disconnect ( listview, SIGNAL ( clicked(QListViewItem*) ), this, SLOT ( getTransferAccounts(QListViewItem*) ) ); |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | void AccountDisplay::getTransferAccounts ( QListViewItem * item ) | 241 | void AccountDisplay::getTransferAccounts ( QListViewItem * item ) |
242 | { | 242 | { |
243 | if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children | 243 | if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children |
244 | { | 244 | { |
245 | if ( firstaccountid == -1 ) | 245 | if ( firstaccountid == -1 ) |
246 | firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account | 246 | firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account |
247 | else | 247 | else |
248 | if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first | 248 | if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first |
249 | secondaccountid = item->text ( getIDColumn() ).toInt(); | 249 | secondaccountid = item->text ( getIDColumn() ).toInt(); |
250 | } | 250 | } |
251 | 251 | ||
252 | // open transfer window if both accounts are set | 252 | // open transfer window if both accounts are set |
253 | if ( firstaccountid != -1 && secondaccountid != -1 ) | 253 | if ( firstaccountid != -1 && secondaccountid != -1 ) |
254 | { | 254 | { |
255 | // construct the transferdialog window | 255 | // construct the transferdialog window |
256 | TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); | 256 | TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); |
257 | 257 | ||
258 | // enter today's date in the date box as default | 258 | // enter today's date in the date box as default |
259 | QDate today = QDate::currentDate (); | 259 | QDate today = QDate::currentDate (); |
260 | int defaultday = today.day(); | 260 | int defaultday = today.day(); |
261 | int defaultmonth = today.month(); | 261 | int defaultmonth = today.month(); |
@@ -270,49 +270,49 @@ void AccountDisplay::getTransferAccounts ( QListViewItem * item ) | |||
270 | qDebug("Year from transferdialog = %i",td->getYear()); | 270 | qDebug("Year from transferdialog = %i",td->getYear()); |
271 | // add the transfer with a new date if its been edited or use the default date | 271 | // add the transfer with a new date if its been edited or use the default date |
272 | if ( td->getDateEdited () == TRUE ) | 272 | if ( td->getDateEdited () == TRUE ) |
273 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); | 273 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); |
274 | else | 274 | else |
275 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); | 275 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); |
276 | 276 | ||
277 | // update account balances of both accounts and parents if necessary | 277 | // update account balances of both accounts and parents if necessary |
278 | account->updateAccountBalance ( firstaccountid ); | 278 | account->updateAccountBalance ( firstaccountid ); |
279 | if ( account->getParentAccountID ( firstaccountid ) != -1 ) | 279 | if ( account->getParentAccountID ( firstaccountid ) != -1 ) |
280 | account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); | 280 | account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); |
281 | account->updateAccountBalance ( secondaccountid ); | 281 | account->updateAccountBalance ( secondaccountid ); |
282 | if ( account->getParentAccountID ( secondaccountid ) != -1 ) | 282 | if ( account->getParentAccountID ( secondaccountid ) != -1 ) |
283 | account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); | 283 | account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); |
284 | 284 | ||
285 | // redisplay accounts | 285 | // redisplay accounts |
286 | account->displayAccounts ( listview ); | 286 | account->displayAccounts ( listview ); |
287 | } | 287 | } |
288 | else | 288 | else |
289 | { | 289 | { |
290 | firstaccountid = -1; | 290 | firstaccountid = -1; |
291 | secondaccountid = -1; | 291 | secondaccountid = -1; |
292 | listview->clearSelection (); | 292 | listview->clearSelection (); |
293 | listview->setMultiSelection ( FALSE ); | 293 | listview->setMultiSelection ( FALSE ); |
294 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | 294 | disconnect ( listview, SIGNAL ( clicked(QListViewItem*) ), this, SLOT ( getTransferAccounts(QListViewItem*) ) ); |
295 | } | 295 | } |
296 | 296 | ||
297 | // reset the accounts display window | 297 | // reset the accounts display window |
298 | transferbutton->toggle(); // toggling this button with clear the window as well | 298 | transferbutton->toggle(); // toggling this button with clear the window as well |
299 | 299 | ||
300 | // reenable all the accounts so the transaction tab will be properly set | 300 | // reenable all the accounts so the transaction tab will be properly set |
301 | enableAccounts (); | 301 | enableAccounts (); |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | void AccountDisplay::disableParentsWithChildren () | 305 | void AccountDisplay::disableParentsWithChildren () |
306 | { | 306 | { |
307 | // iterate through accountdisplay listview and disable all the parents that have children | 307 | // iterate through accountdisplay listview and disable all the parents that have children |
308 | QListViewItemIterator it ( listview ); | 308 | QListViewItemIterator it ( listview ); |
309 | for ( ; it.current(); ++it ) | 309 | for ( ; it.current(); ++it ) |
310 | { | 310 | { |
311 | if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) | 311 | if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) |
312 | it.current()->setSelectable ( FALSE ); | 312 | it.current()->setSelectable ( FALSE ); |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | void AccountDisplay::enableAccounts () | 316 | void AccountDisplay::enableAccounts () |
317 | { | 317 | { |
318 | // iterate through accountdisplay listview and enable all accounts | 318 | // iterate through accountdisplay listview and enable all accounts |