author | alwin <alwin> | 2004-02-23 12:16:18 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-02-23 12:16:18 (UTC) |
commit | 2d37d653310da0a9d6e2e2e6c9f5bf092e54cbbb (patch) (unidiff) | |
tree | 35694478a6b36a1e707719262b1642c42f3f7968 | |
parent | 957697a1158c9bfeae88ea35190b821fe002834a (diff) | |
download | opie-2d37d653310da0a9d6e2e2e6c9f5bf092e54cbbb.zip opie-2d37d653310da0a9d6e2e2e6c9f5bf092e54cbbb.tar.gz opie-2d37d653310da0a9d6e2e2e6c9f5bf092e54cbbb.tar.bz2 |
sorry, forgot a stdc++ reference
-rwxr-xr-x | noncore/apps/qashmoney/accountdisplay.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/noncore/apps/qashmoney/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp index 64f4ea8..d0ba82a 100755 --- a/noncore/apps/qashmoney/accountdisplay.cpp +++ b/noncore/apps/qashmoney/accountdisplay.cpp | |||
@@ -1,132 +1,131 @@ | |||
1 | #include <qdatetime.h> | 1 | #include <qdatetime.h> |
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qheader.h> | 3 | #include <qheader.h> |
4 | #include <iostream.h> | ||
5 | 4 | ||
6 | #include "accountdisplay.h" | 5 | #include "accountdisplay.h" |
7 | #include "newaccount.h" | 6 | #include "newaccount.h" |
8 | #include "transaction.h" | 7 | #include "transaction.h" |
9 | #include "transferdialog.h" | 8 | #include "transferdialog.h" |
10 | #include "preferences.h" | 9 | #include "preferences.h" |
11 | #include "transfer.h" | 10 | #include "transfer.h" |
12 | 11 | ||
13 | extern Account *account; | 12 | extern Account *account; |
14 | extern Transaction *transaction; | 13 | extern Transaction *transaction; |
15 | extern Transfer *transfer; | 14 | extern Transfer *transfer; |
16 | extern Preferences *preferences; | 15 | extern Preferences *preferences; |
17 | 16 | ||
18 | AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) | 17 | AccountDisplay::AccountDisplay ( QWidget *parent ) : QWidget ( parent ) |
19 | { | 18 | { |
20 | cleared = 0; | 19 | cleared = 0; |
21 | 20 | ||
22 | firstline = new QHBox ( this ); | 21 | firstline = new QHBox ( this ); |
23 | firstline->setSpacing ( 2 ); | 22 | firstline->setSpacing ( 2 ); |
24 | 23 | ||
25 | newaccount = new QPushButton ( firstline ); | 24 | newaccount = new QPushButton ( firstline ); |
26 | newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); | 25 | newaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); |
27 | connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); | 26 | connect ( newaccount, SIGNAL ( released () ), this, SLOT ( addAccount () ) ); |
28 | 27 | ||
29 | editaccount = new QPushButton ( firstline ); | 28 | editaccount = new QPushButton ( firstline ); |
30 | editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); | 29 | editaccount->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); |
31 | connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); | 30 | connect ( editaccount, SIGNAL ( released () ), this, SLOT ( editAccount () ) ); |
32 | 31 | ||
33 | deleteaccount = new QPushButton ( firstline ); | 32 | deleteaccount = new QPushButton ( firstline ); |
34 | deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); | 33 | deleteaccount->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); |
35 | connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); | 34 | connect ( deleteaccount, SIGNAL ( released () ), this, SLOT ( deleteAccount () ) ); |
36 | 35 | ||
37 | transferbutton = new QPushButton ( firstline ); | 36 | transferbutton = new QPushButton ( firstline ); |
38 | transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); | 37 | transferbutton->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/transfer.png") ); |
39 | transferbutton->setToggleButton ( TRUE ); | 38 | transferbutton->setToggleButton ( TRUE ); |
40 | connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); | 39 | connect ( transferbutton, SIGNAL ( toggled ( bool ) ), this, SLOT ( accountTransfer ( bool ) ) ); |
41 | 40 | ||
42 | listview = new QListView ( this ); | 41 | listview = new QListView ( this ); |
43 | listview->setAllColumnsShowFocus ( TRUE ); | 42 | listview->setAllColumnsShowFocus ( TRUE ); |
44 | listview->setShowSortIndicator ( TRUE ); | 43 | listview->setShowSortIndicator ( TRUE ); |
45 | listview->setRootIsDecorated ( TRUE ); | 44 | listview->setRootIsDecorated ( TRUE ); |
46 | listview->setMultiSelection ( FALSE ); | 45 | listview->setMultiSelection ( FALSE ); |
47 | connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); | 46 | connect ( listview, SIGNAL ( expanded ( QListViewItem * ) ), this, SLOT ( setAccountExpanded ( QListViewItem * ) ) ); |
48 | connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); | 47 | connect ( listview, SIGNAL ( collapsed ( QListViewItem * ) ), this, SLOT ( setAccountCollapsed ( QListViewItem * ) ) ); |
49 | 48 | ||
50 | listview->header()->setTracking ( FALSE ); | 49 | listview->header()->setTracking ( FALSE ); |
51 | connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); | 50 | connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); |
52 | connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); | 51 | connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( int ) ) ); |
53 | 52 | ||
54 | layout = new QVBoxLayout ( this, 2, 5 ); | 53 | layout = new QVBoxLayout ( this, 2, 5 ); |
55 | layout->addWidget ( firstline ); | 54 | layout->addWidget ( firstline ); |
56 | layout->addWidget ( listview ); | 55 | layout->addWidget ( listview ); |
57 | } | 56 | } |
58 | 57 | ||
59 | void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) | 58 | void AccountDisplay::setTabs ( QWidget *newtab2, QTabWidget *newtabs ) |
60 | { | 59 | { |
61 | tab2 = newtab2; | 60 | tab2 = newtab2; |
62 | maintabs = newtabs; | 61 | maintabs = newtabs; |
63 | } | 62 | } |
64 | 63 | ||
65 | void AccountDisplay::addAccount () | 64 | void AccountDisplay::addAccount () |
66 | { | 65 | { |
67 | // initialize local variables | 66 | // initialize local variables |
68 | int parentid = 0; | 67 | int parentid = 0; |
69 | type = 0; | 68 | type = 0; |
70 | QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; | 69 | QString parentlist [ listview->childCount() + 1 ] [ 3 ] ; |
71 | 70 | ||
72 | // create new account window for entering data | 71 | // create new account window for entering data |
73 | NewAccount *newaccount = new NewAccount ( this ); | 72 | NewAccount *newaccount = new NewAccount ( this ); |
74 | int width = this->width(); | 73 | int width = this->width(); |
75 | newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); | 74 | newaccount->accountbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); |
76 | newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | 75 | newaccount->datebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); |
77 | newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); | 76 | newaccount->childbox->setMaximumWidth ( ( int ) ( width * 0.5 ) ); |
78 | newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | 77 | newaccount->balancebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); |
79 | newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); | 78 | newaccount->creditlimitbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); |
80 | 79 | ||
81 | // if there are no accounts, disable the child check box | 80 | // if there are no accounts, disable the child check box |
82 | if ( account->getNumberOfAccounts () == 0 ) | 81 | if ( account->getNumberOfAccounts () == 0 ) |
83 | newaccount->childcheckbox->setEnabled ( FALSE ); | 82 | newaccount->childcheckbox->setEnabled ( FALSE ); |
84 | 83 | ||
85 | // if there are accounts, fill up the pulldown menu for | 84 | // if there are accounts, fill up the pulldown menu for |
86 | // selecting a parent account. We should only add those parents without transactions | 85 | // selecting a parent account. We should only add those parents without transactions |
87 | else | 86 | else |
88 | { | 87 | { |
89 | int c = 0; | 88 | int c = 0; |
90 | QListViewItemIterator it ( listview ); | 89 | QListViewItemIterator it ( listview ); |
91 | for ( ; it.current(); ++it ) | 90 | for ( ; it.current(); ++it ) |
92 | { | 91 | { |
93 | int id = it.current()->text ( getIDColumn() ).toInt(); | 92 | int id = it.current()->text ( getIDColumn() ).toInt(); |
94 | // iterate through accountdisplay listview and add parents with no transactions | 93 | // iterate through accountdisplay listview and add parents with no transactions |
95 | // add this item to the list box only if it is a parent and has no transactions | 94 | // add this item to the list box only if it is a parent and has no transactions |
96 | if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 ) | 95 | if ( transfer->getNumberOfTransfers ( id ) == 0 && transaction->getNumberOfTransactions ( id ) == 0 && it.current()->parent() == 0 ) |
97 | { | 96 | { |
98 | newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); | 97 | newaccount->childbox->insertItem ( it.current()->text ( 0 ) ); |
99 | parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); | 98 | parentlist [ c ] [ 0 ] = it.current()->text ( 0 ); |
100 | parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); | 99 | parentlist [ c ] [ 1 ] = it.current()->text ( getIDColumn() ); |
101 | parentlist [ c ] [ 2 ] = QString::number ( c ); | 100 | parentlist [ c ] [ 2 ] = QString::number ( c ); |
102 | c++; | 101 | c++; |
103 | } | 102 | } |
104 | } | 103 | } |
105 | } | 104 | } |
106 | 105 | ||
107 | if ( preferences->getPreference ( 4 ) == 0 ) | 106 | if ( preferences->getPreference ( 4 ) == 0 ) |
108 | newaccount->currencybox->setEnabled ( FALSE ); | 107 | newaccount->currencybox->setEnabled ( FALSE ); |
109 | 108 | ||
110 | // enter today's date in the date box as default | 109 | // enter today's date in the date box as default |
111 | QDate today = QDate::currentDate (); | 110 | QDate today = QDate::currentDate (); |
112 | int defaultday = today.day(); | 111 | int defaultday = today.day(); |
113 | int defaultmonth = today.month(); | 112 | int defaultmonth = today.month(); |
114 | int defaultyear = today.year(); | 113 | int defaultyear = today.year(); |
115 | newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); | 114 | newaccount->startdate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); |
116 | 115 | ||
117 | //add account information if user pushes OK button | 116 | //add account information if user pushes OK button |
118 | if ( newaccount->exec() == QDialog::Accepted ) | 117 | if ( newaccount->exec() == QDialog::Accepted ) |
119 | { | 118 | { |
120 | if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account | 119 | if ( newaccount->childcheckbox->isChecked () == TRUE ) // set a parent id and type for a child account |
121 | { | 120 | { |
122 | // go through the parentlist we created and determine the parent accountid | 121 | // go through the parentlist we created and determine the parent accountid |
123 | // we can't use the name of the account because there may be two accounts | 122 | // we can't use the name of the account because there may be two accounts |
124 | // with the same name. This function does it all by accountid | 123 | // with the same name. This function does it all by accountid |
125 | int counter; | 124 | int counter; |
126 | for ( counter = 0; counter < listview->childCount() + 1; counter++ ) | 125 | for ( counter = 0; counter < listview->childCount() + 1; counter++ ) |
127 | if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) | 126 | if ( ( parentlist [ counter ] [ 2 ].toInt() ) == newaccount->childbox->currentItem() ) |
128 | { | 127 | { |
129 | parentid = parentlist [ counter ] [ 1 ].toInt(); | 128 | parentid = parentlist [ counter ] [ 1 ].toInt(); |
130 | break; | 129 | break; |
131 | } | 130 | } |
132 | type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types | 131 | type = ( newaccount->accounttype->currentItem() ) + 6; // sets account ids for child accounts. See accountdisplay.h for types |
@@ -145,257 +144,257 @@ void AccountDisplay::addAccount () | |||
145 | else | 144 | else |
146 | account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, | 145 | account->addAccount ( newaccount->accountname->text (), parentid, newaccount->accountbalance->text().toFloat(), type, |
147 | newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, | 146 | newaccount->getDescription(), newaccount->creditlimit->text().toFloat(), defaultyear, |
148 | defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); | 147 | defaultmonth, defaultday, newaccount->accountbalance->text().toFloat(), newaccount->currencybox->currencybox->currentText() ); |
149 | 148 | ||
150 | if ( parentid != -1 ) | 149 | if ( parentid != -1 ) |
151 | account->changeParentAccountBalance ( parentid ); | 150 | account->changeParentAccountBalance ( parentid ); |
152 | 151 | ||
153 | // redisplay accounts | 152 | // redisplay accounts |
154 | // this function clears the account display first | 153 | // this function clears the account display first |
155 | account->displayAccounts ( listview ); | 154 | account->displayAccounts ( listview ); |
156 | setToggleButton(); | 155 | setToggleButton(); |
157 | } | 156 | } |
158 | maintabs->setTabEnabled ( tab2, FALSE ); | 157 | maintabs->setTabEnabled ( tab2, FALSE ); |
159 | } | 158 | } |
160 | 159 | ||
161 | void AccountDisplay::deleteAccount () | 160 | void AccountDisplay::deleteAccount () |
162 | { | 161 | { |
163 | if ( listview->selectedItem() == 0 ) | 162 | if ( listview->selectedItem() == 0 ) |
164 | QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); | 163 | QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); |
165 | else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) | 164 | else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) |
166 | QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); | 165 | QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); |
167 | else | 166 | else |
168 | { | 167 | { |
169 | QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); | 168 | QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); |
170 | if ( mb.exec() == QMessageBox::Ok ) | 169 | if ( mb.exec() == QMessageBox::Ok ) |
171 | { | 170 | { |
172 | int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); | 171 | int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); |
173 | int parentid = account->getParentAccountID ( accountid ); | 172 | int parentid = account->getParentAccountID ( accountid ); |
174 | 173 | ||
175 | // delete all the transactions and transfers for the account | 174 | // delete all the transactions and transfers for the account |
176 | transaction->deleteAllTransactions ( accountid ); | 175 | transaction->deleteAllTransactions ( accountid ); |
177 | transfer->deleteAllTransfers ( accountid ); | 176 | transfer->deleteAllTransfers ( accountid ); |
178 | 177 | ||
179 | // delete the account | 178 | // delete the account |
180 | account->deleteAccount ( accountid ); | 179 | account->deleteAccount ( accountid ); |
181 | 180 | ||
182 | // update account balances | 181 | // update account balances |
183 | if ( parentid != -1 ) | 182 | if ( parentid != -1 ) |
184 | account->changeParentAccountBalance ( parentid ); | 183 | account->changeParentAccountBalance ( parentid ); |
185 | 184 | ||
186 | //redisplay accounts | 185 | //redisplay accounts |
187 | account->displayAccounts ( listview ); | 186 | account->displayAccounts ( listview ); |
188 | 187 | ||
189 | //remove all the columns from the accountdisplay if there are not any accounts | 188 | //remove all the columns from the accountdisplay if there are not any accounts |
190 | if ( account->getNumberOfAccounts() == 0 ) | 189 | if ( account->getNumberOfAccounts() == 0 ) |
191 | { | 190 | { |
192 | int columns = listview->columns(); | 191 | int columns = listview->columns(); |
193 | int counter; | 192 | int counter; |
194 | for ( counter = 0; counter <= columns; counter++ ) | 193 | for ( counter = 0; counter <= columns; counter++ ) |
195 | listview->removeColumn ( 0 ); | 194 | listview->removeColumn ( 0 ); |
196 | } | 195 | } |
197 | 196 | ||
198 | setToggleButton(); | 197 | setToggleButton(); |
199 | } | 198 | } |
200 | } | 199 | } |
201 | maintabs->setTabEnabled ( tab2, FALSE ); | 200 | maintabs->setTabEnabled ( tab2, FALSE ); |
202 | } | 201 | } |
203 | 202 | ||
204 | void AccountDisplay::setToggleButton () | 203 | void AccountDisplay::setToggleButton () |
205 | { | 204 | { |
206 | // iterate through account display and determine how many "transferable" accounts we have | 205 | // iterate through account display and determine how many "transferable" accounts we have |
207 | // if there are less than two, disable the transfer button | 206 | // if there are less than two, disable the transfer button |
208 | QListViewItemIterator it ( listview ); | 207 | QListViewItemIterator it ( listview ); |
209 | int counter = 0; | 208 | int counter = 0; |
210 | for ( ; it.current(); ++it ) | 209 | for ( ; it.current(); ++it ) |
211 | { | 210 | { |
212 | // add one to counter if we find a transferable account | 211 | // add one to counter if we find a transferable account |
213 | if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) | 212 | if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) |
214 | counter++; | 213 | counter++; |
215 | } | 214 | } |
216 | if ( counter > 1 ) | 215 | if ( counter > 1 ) |
217 | transferbutton->show(); | 216 | transferbutton->show(); |
218 | else | 217 | else |
219 | transferbutton->hide(); | 218 | transferbutton->hide(); |
220 | } | 219 | } |
221 | 220 | ||
222 | void AccountDisplay::accountTransfer ( bool state ) | 221 | void AccountDisplay::accountTransfer ( bool state ) |
223 | { | 222 | { |
224 | if ( state == TRUE ) | 223 | if ( state == TRUE ) |
225 | { | 224 | { |
226 | firstaccountid = -1; | 225 | firstaccountid = -1; |
227 | secondaccountid = -1; | 226 | secondaccountid = -1; |
228 | listview->clearSelection (); | 227 | listview->clearSelection (); |
229 | listview->setMultiSelection ( TRUE ); | 228 | listview->setMultiSelection ( TRUE ); |
230 | disableParentsWithChildren (); | 229 | disableParentsWithChildren (); |
231 | connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | 230 | connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); |
232 | } | 231 | } |
233 | else | 232 | else |
234 | { | 233 | { |
235 | firstaccountid = -1; | 234 | firstaccountid = -1; |
236 | secondaccountid = -1; | 235 | secondaccountid = -1; |
237 | listview->clearSelection (); | 236 | listview->clearSelection (); |
238 | listview->setMultiSelection ( FALSE ); | 237 | listview->setMultiSelection ( FALSE ); |
239 | enableAccounts (); | 238 | enableAccounts (); |
240 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | 239 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); |
241 | } | 240 | } |
242 | } | 241 | } |
243 | 242 | ||
244 | void AccountDisplay::getTransferAccounts ( QListViewItem * item ) | 243 | void AccountDisplay::getTransferAccounts ( QListViewItem * item ) |
245 | { | 244 | { |
246 | if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children | 245 | if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children |
247 | { | 246 | { |
248 | if ( firstaccountid == -1 ) | 247 | if ( firstaccountid == -1 ) |
249 | firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account | 248 | firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account |
250 | else | 249 | else |
251 | if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first | 250 | if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first |
252 | secondaccountid = item->text ( getIDColumn() ).toInt(); | 251 | secondaccountid = item->text ( getIDColumn() ).toInt(); |
253 | } | 252 | } |
254 | 253 | ||
255 | // open transfer window if both accounts are set | 254 | // open transfer window if both accounts are set |
256 | if ( firstaccountid != -1 && secondaccountid != -1 ) | 255 | if ( firstaccountid != -1 && secondaccountid != -1 ) |
257 | { | 256 | { |
258 | // construct the transferdialog window | 257 | // construct the transferdialog window |
259 | TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); | 258 | TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); |
260 | 259 | ||
261 | // enter today's date in the date box as default | 260 | // enter today's date in the date box as default |
262 | QDate today = QDate::currentDate (); | 261 | QDate today = QDate::currentDate (); |
263 | int defaultday = today.day(); | 262 | int defaultday = today.day(); |
264 | int defaultmonth = today.month(); | 263 | int defaultmonth = today.month(); |
265 | int defaultyear = today.year(); | 264 | int defaultyear = today.year(); |
266 | td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); | 265 | td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); |
267 | 266 | ||
268 | if ( td->exec() == QDialog::Accepted ) | 267 | if ( td->exec() == QDialog::Accepted ) |
269 | { | 268 | { |
270 | // set the cleared integer if the checkbox is checked | 269 | // set the cleared integer if the checkbox is checked |
271 | if ( td->clearedcheckbox->isChecked() == TRUE ) | 270 | if ( td->clearedcheckbox->isChecked() == TRUE ) |
272 | cleared = 1; | 271 | cleared = 1; |
273 | cout << "Year from transferdialog = " << td->getYear() << endl; | 272 | qDebug("Year from transferdialog = %i",td->getYear()); |
274 | // add the transfer with a new date if its been edited or use the default date | 273 | // add the transfer with a new date if its been edited or use the default date |
275 | if ( td->getDateEdited () == TRUE ) | 274 | if ( td->getDateEdited () == TRUE ) |
276 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); | 275 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); |
277 | else | 276 | else |
278 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); | 277 | transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); |
279 | 278 | ||
280 | // update account balances of both accounts and parents if necessary | 279 | // update account balances of both accounts and parents if necessary |
281 | account->updateAccountBalance ( firstaccountid ); | 280 | account->updateAccountBalance ( firstaccountid ); |
282 | if ( account->getParentAccountID ( firstaccountid ) != -1 ) | 281 | if ( account->getParentAccountID ( firstaccountid ) != -1 ) |
283 | account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); | 282 | account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); |
284 | account->updateAccountBalance ( secondaccountid ); | 283 | account->updateAccountBalance ( secondaccountid ); |
285 | if ( account->getParentAccountID ( secondaccountid ) != -1 ) | 284 | if ( account->getParentAccountID ( secondaccountid ) != -1 ) |
286 | account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); | 285 | account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); |
287 | 286 | ||
288 | // redisplay accounts | 287 | // redisplay accounts |
289 | account->displayAccounts ( listview ); | 288 | account->displayAccounts ( listview ); |
290 | } | 289 | } |
291 | else | 290 | else |
292 | { | 291 | { |
293 | firstaccountid = -1; | 292 | firstaccountid = -1; |
294 | secondaccountid = -1; | 293 | secondaccountid = -1; |
295 | listview->clearSelection (); | 294 | listview->clearSelection (); |
296 | listview->setMultiSelection ( FALSE ); | 295 | listview->setMultiSelection ( FALSE ); |
297 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); | 296 | disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); |
298 | } | 297 | } |
299 | 298 | ||
300 | // reset the accounts display window | 299 | // reset the accounts display window |
301 | transferbutton->toggle(); // toggling this button with clear the window as well | 300 | transferbutton->toggle(); // toggling this button with clear the window as well |
302 | 301 | ||
303 | // reenable all the accounts so the transaction tab will be properly set | 302 | // reenable all the accounts so the transaction tab will be properly set |
304 | enableAccounts (); | 303 | enableAccounts (); |
305 | } | 304 | } |
306 | } | 305 | } |
307 | 306 | ||
308 | void AccountDisplay::disableParentsWithChildren () | 307 | void AccountDisplay::disableParentsWithChildren () |
309 | { | 308 | { |
310 | // iterate through accountdisplay listview and disable all the parents that have children | 309 | // iterate through accountdisplay listview and disable all the parents that have children |
311 | QListViewItemIterator it ( listview ); | 310 | QListViewItemIterator it ( listview ); |
312 | for ( ; it.current(); ++it ) | 311 | for ( ; it.current(); ++it ) |
313 | { | 312 | { |
314 | if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) | 313 | if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) |
315 | it.current()->setSelectable ( FALSE ); | 314 | it.current()->setSelectable ( FALSE ); |
316 | } | 315 | } |
317 | } | 316 | } |
318 | 317 | ||
319 | void AccountDisplay::enableAccounts () | 318 | void AccountDisplay::enableAccounts () |
320 | { | 319 | { |
321 | // iterate through accountdisplay listview and enable all accounts | 320 | // iterate through accountdisplay listview and enable all accounts |
322 | QListViewItemIterator it ( listview ); | 321 | QListViewItemIterator it ( listview ); |
323 | for ( ; it.current(); ++it ) | 322 | for ( ; it.current(); ++it ) |
324 | it.current()->setSelectable ( TRUE ); | 323 | it.current()->setSelectable ( TRUE ); |
325 | } | 324 | } |
326 | 325 | ||
327 | void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) | 326 | void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) |
328 | { | 327 | { |
329 | switch ( column ) | 328 | switch ( column ) |
330 | { | 329 | { |
331 | case 0: | 330 | case 0: |
332 | if ( listview->columns() == 3 ) | 331 | if ( listview->columns() == 3 ) |
333 | preferences->changeColumnPreference ( 1, newsize ); | 332 | preferences->changeColumnPreference ( 1, newsize ); |
334 | else | 333 | else |
335 | preferences->changeColumnPreference ( 10, newsize ); | 334 | preferences->changeColumnPreference ( 10, newsize ); |
336 | break; | 335 | break; |
337 | case 1: | 336 | case 1: |
338 | if ( listview->columns() == 3 ) | 337 | if ( listview->columns() == 3 ) |
339 | preferences->changeColumnPreference ( 2, newsize ); | 338 | preferences->changeColumnPreference ( 2, newsize ); |
340 | else | 339 | else |
341 | preferences->changeColumnPreference ( 11, newsize ); | 340 | preferences->changeColumnPreference ( 11, newsize ); |
342 | break; | 341 | break; |
343 | case 2: | 342 | case 2: |
344 | preferences->changeColumnPreference ( 12, newsize ); | 343 | preferences->changeColumnPreference ( 12, newsize ); |
345 | break; | 344 | break; |
346 | } | 345 | } |
347 | 346 | ||
348 | } | 347 | } |
349 | 348 | ||
350 | void AccountDisplay::saveSortingPreference ( int column ) | 349 | void AccountDisplay::saveSortingPreference ( int column ) |
351 | { | 350 | { |
352 | preferences->changeSortingPreference ( 1, column ); | 351 | preferences->changeSortingPreference ( 1, column ); |
353 | } | 352 | } |
354 | 353 | ||
355 | int AccountDisplay::getIDColumn () | 354 | int AccountDisplay::getIDColumn () |
356 | { | 355 | { |
357 | int counter; | 356 | int counter; |
358 | int columns = listview->columns(); | 357 | int columns = listview->columns(); |
359 | for ( counter = 0; counter <= columns; counter++ ) | 358 | for ( counter = 0; counter <= columns; counter++ ) |
360 | if ( listview->header()->label ( counter ).length() == 0 ) | 359 | if ( listview->header()->label ( counter ).length() == 0 ) |
361 | return counter; | 360 | return counter; |
362 | } | 361 | } |
363 | 362 | ||
364 | void AccountDisplay::editAccount () | 363 | void AccountDisplay::editAccount () |
365 | { | 364 | { |
366 | if ( listview->selectedItem() == 0 ) | 365 | if ( listview->selectedItem() == 0 ) |
367 | QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); | 366 | QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); |
368 | else | 367 | else |
369 | { | 368 | { |
370 | // set the accountid | 369 | // set the accountid |
371 | int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); | 370 | int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); |
372 | 371 | ||
373 | //construct new dialog box | 372 | //construct new dialog box |
374 | QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); | 373 | QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); |
375 | editaccountwindow->setCaption ( "Edit Account" ); | 374 | editaccountwindow->setCaption ( "Edit Account" ); |
376 | 375 | ||
377 | // construct the items which will go in the dialog bix | 376 | // construct the items which will go in the dialog bix |
378 | QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); | 377 | QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); |
379 | QLineEdit *accountname = new QLineEdit ( editaccountwindow ); | 378 | QLineEdit *accountname = new QLineEdit ( editaccountwindow ); |
380 | QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); | 379 | QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); |
381 | QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); | 380 | QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); |
382 | Currency *currencybox = new Currency ( editaccountwindow ); | 381 | Currency *currencybox = new Currency ( editaccountwindow ); |
383 | 382 | ||
384 | QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); | 383 | QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); |
385 | layout->addWidget ( namelabel ); | 384 | layout->addWidget ( namelabel ); |
386 | layout->addWidget ( accountname ); | 385 | layout->addWidget ( accountname ); |
387 | layout->addWidget ( descriptionlabel ); | 386 | layout->addWidget ( descriptionlabel ); |
388 | layout->addWidget ( accountdescription ); | 387 | layout->addWidget ( accountdescription ); |
389 | layout->addWidget ( currencybox ); | 388 | layout->addWidget ( currencybox ); |
390 | 389 | ||
391 | //set the account name | 390 | //set the account name |
392 | accountname->setText ( listview->selectedItem()->text ( 0 ) ); | 391 | accountname->setText ( listview->selectedItem()->text ( 0 ) ); |
393 | 392 | ||
394 | //set the account description | 393 | //set the account description |
395 | accountdescription->setText ( account->getAccountDescription ( accountid ) ); | 394 | accountdescription->setText ( account->getAccountDescription ( accountid ) ); |
396 | 395 | ||
397 | if ( preferences->getPreference ( 4 ) == 1 ) | 396 | if ( preferences->getPreference ( 4 ) == 1 ) |
398 | { | 397 | { |
399 | // get currency code for this account then iterate through the currency box | 398 | // get currency code for this account then iterate through the currency box |
400 | // to find the one we want | 399 | // to find the one we want |
401 | int count = currencybox->currencybox->count(); | 400 | int count = currencybox->currencybox->count(); |