-rwxr-xr-x | noncore/apps/qashmoney/accountdisplay.cpp | 12 | ||||
-rwxr-xr-x | noncore/apps/qashmoney/qmaccounts.db | bin | 4096 -> 4096 bytes | |||
-rwxr-xr-x | noncore/apps/qashmoney/qmmemory.db | bin | 4096 -> 4096 bytes | |||
-rwxr-xr-x | noncore/apps/qashmoney/qmtransactions.db | bin | 4096 -> 4096 bytes | |||
-rwxr-xr-x | noncore/apps/qashmoney/qmtransfers.db | bin | 3072 -> 3072 bytes | |||
-rwxr-xr-x | noncore/apps/qashmoney/transactiondisplay.cpp | 2 |
6 files changed, 13 insertions, 1 deletions
diff --git a/noncore/apps/qashmoney/accountdisplay.cpp b/noncore/apps/qashmoney/accountdisplay.cpp index 46ab1db..b2c0838 100755 --- a/noncore/apps/qashmoney/accountdisplay.cpp +++ b/noncore/apps/qashmoney/accountdisplay.cpp @@ -160,273 +160,285 @@ void AccountDisplay::deleteAccount () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select an account\nto delete."); else if ( listview->selectedItem()->parent() == 0 && listview->selectedItem()->childCount() != 0 ) QMessageBox::warning ( this, "QashMoney", "Can't delete parent accounts\nwith children"); else { QMessageBox mb ( "Delete Account", "This will delete all transactions\nand transfers for this account.", QMessageBox::Information, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton ); if ( mb.exec() == QMessageBox::Ok ) { int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt (); int parentid = account->getParentAccountID ( accountid ); // delete all the transactions and transfers for the account transaction->deleteAllTransactions ( accountid ); transfer->deleteAllTransfers ( accountid ); // delete the account account->deleteAccount ( accountid ); // update account balances if ( parentid != -1 ) account->changeParentAccountBalance ( parentid ); //redisplay accounts account->displayAccounts ( listview ); //remove all the columns from the accountdisplay if there are not any accounts if ( account->getNumberOfAccounts() == 0 ) { int columns = listview->columns(); int counter; for ( counter = 0; counter <= columns; counter++ ) listview->removeColumn ( 0 ); } setToggleButton(); } } maintabs->setTabEnabled ( tab2, FALSE ); } void AccountDisplay::setToggleButton () { // iterate through account display and determine how many "transferable" accounts we have // if there are less than two, disable the transfer button QListViewItemIterator it ( listview ); int counter = 0; for ( ; it.current(); ++it ) { // add one to counter if we find a transferable account if ( it.current()->parent() != 0 || ( it.current()->childCount() ) == 0 ) counter++; } if ( counter > 1 ) transferbutton->show(); else transferbutton->hide(); } void AccountDisplay::accountTransfer ( bool state ) { if ( state == TRUE ) { firstaccountid = -1; secondaccountid = -1; listview->clearSelection (); listview->setMultiSelection ( TRUE ); disableParentsWithChildren (); connect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); } else { firstaccountid = -1; secondaccountid = -1; listview->clearSelection (); listview->setMultiSelection ( FALSE ); enableAccounts (); disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); } } void AccountDisplay::getTransferAccounts ( QListViewItem * item ) { if ( item->parent() != 0 || item->childCount() == 0 ) // only set an account for transfer if its a child or parent with no children { if ( firstaccountid == -1 ) firstaccountid = item->text ( getIDColumn() ).toInt(); // set first account if we've selected a valid account else if ( item->text ( getIDColumn() ).toInt() != firstaccountid ) // set the second account if its not equal to the first secondaccountid = item->text ( getIDColumn() ).toInt(); } // open transfer window if both accounts are set if ( firstaccountid != -1 && secondaccountid != -1 ) { // construct the transferdialog window TransferDialog *td = new TransferDialog ( this, firstaccountid, secondaccountid ); // enter today's date in the date box as default QDate today = QDate::currentDate (); int defaultday = today.day(); int defaultmonth = today.month(); int defaultyear = today.year(); td->date->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); if ( td->exec() == QDialog::Accepted ) { // set the cleared integer if the checkbox is checked if ( td->clearedcheckbox->isChecked() == TRUE ) cleared = 1; // add the transfer with a new date if its been edited or use the default date if ( td->getDateEdited () == TRUE ) transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), td->getDay(), td->getMonth(), td->getYear(), td->amount->text().toFloat(), cleared ); else transfer->addTransfer ( firstaccountid, account->getParentAccountID ( firstaccountid ), secondaccountid, account->getParentAccountID ( secondaccountid ), defaultday, defaultmonth, defaultyear, td->amount->text().toFloat(), cleared ); // update account balances of both accounts and parents if necessary account->updateAccountBalance ( firstaccountid ); if ( account->getParentAccountID ( firstaccountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( firstaccountid ) ); account->updateAccountBalance ( secondaccountid ); if ( account->getParentAccountID ( secondaccountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( secondaccountid ) ); // redisplay accounts account->displayAccounts ( listview ); } else { firstaccountid = -1; secondaccountid = -1; listview->clearSelection (); listview->setMultiSelection ( FALSE ); disconnect ( listview, SIGNAL ( clicked ( QListViewItem * ) ), this, SLOT ( getTransferAccounts ( QListViewItem * ) ) ); } // reset the accounts display window transferbutton->toggle(); // toggling this button with clear the window as well // reenable all the accounts so the transaction tab will be properly set enableAccounts (); } } void AccountDisplay::disableParentsWithChildren () { // iterate through accountdisplay listview and disable all the parents that have children QListViewItemIterator it ( listview ); for ( ; it.current(); ++it ) { if ( it.current()->parent() == 0 && it.current()->childCount() != 0 ) it.current()->setSelectable ( FALSE ); } } void AccountDisplay::enableAccounts () { // iterate through accountdisplay listview and enable all accounts QListViewItemIterator it ( listview ); for ( ; it.current(); ++it ) it.current()->setSelectable ( TRUE ); } void AccountDisplay::saveColumnSize ( int column, int oldsize, int newsize ) { switch ( column ) { case 0: if ( listview->columns() == 3 ) preferences->changeColumnPreference ( 1, newsize ); else preferences->changeColumnPreference ( 10, newsize ); break; case 1: if ( listview->columns() == 3 ) preferences->changeColumnPreference ( 2, newsize ); else preferences->changeColumnPreference ( 11, newsize ); break; case 2: preferences->changeColumnPreference ( 12, newsize ); break; } } int AccountDisplay::getIDColumn () { int counter; int columns = listview->columns(); for ( counter = 0; counter <= columns; counter++ ) if ( listview->header()->label ( counter ).length() == 0 ) return counter; } void AccountDisplay::editAccount () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select an account\nto edit."); else { // set the accountid int accountid = listview->selectedItem()->text ( getIDColumn() ).toInt(); //construct new dialog box QDialog *editaccountwindow = new QDialog ( this, 0, TRUE ); editaccountwindow->setCaption ( "Edit Account" ); // construct the items which will go in the dialog bix QLabel *namelabel = new QLabel ( "Account Name", editaccountwindow ); QLineEdit *accountname = new QLineEdit ( editaccountwindow ); QLabel *descriptionlabel = new QLabel ( "Account Description", editaccountwindow ); QLineEdit *accountdescription = new QLineEdit ( editaccountwindow ); Currency *currencybox = new Currency ( editaccountwindow ); QVBoxLayout *layout = new QVBoxLayout ( editaccountwindow, 5, 2 ); layout->addWidget ( namelabel ); layout->addWidget ( accountname ); layout->addWidget ( descriptionlabel ); layout->addWidget ( accountdescription ); layout->addWidget ( currencybox ); //set the account name accountname->setText ( listview->selectedItem()->text ( 0 ) ); //set the account description accountdescription->setText ( account->getAccountDescription ( accountid ) ); if ( preferences->getPreference ( 4 ) == 1 ) { // get currency code for this account then iterate through the currency box // to find the one we want int count = currencybox->currencybox->count(); QString code = account->getCurrencyCode ( accountid ); for ( int counter = 0; count - 1; counter++ ) { if ( QString::compare ( currencybox->currencybox->text ( counter ), code ) == 0 ) { currencybox->currencybox->setCurrentItem ( counter ); break; } } } else currencybox->setEnabled ( FALSE ); //execute the dialog box int response = editaccountwindow->exec(); if ( response == 1 ) { account->updateAccount ( accountname->text(), accountdescription->text(), currencybox->currencybox->currentText(), accountid ); account->displayAccounts ( listview ); + + // Try and select the same account that was just edited + QListViewItemIterator it ( listview ); + for ( ; it.current(); ++it ) + { + if ( it.current()->text ( 0 ) == accountname->text() ) + { + listview->setSelected ( it.current(), TRUE ); + return; + } + } + maintabs->setTabEnabled ( tab2, FALSE ); } } } void AccountDisplay::setAccountExpanded ( QListViewItem *item ) { int accountid = item->text ( getIDColumn() ).toInt(); account->setAccountExpanded ( 1, accountid ); } void AccountDisplay::setAccountCollapsed ( QListViewItem *item ) { int accountid = item->text ( getIDColumn() ).toInt(); account->setAccountExpanded ( 0, accountid ); } diff --git a/noncore/apps/qashmoney/qmaccounts.db b/noncore/apps/qashmoney/qmaccounts.db Binary files differindex 1c6f024..449bcab 100755 --- a/noncore/apps/qashmoney/qmaccounts.db +++ b/noncore/apps/qashmoney/qmaccounts.db diff --git a/noncore/apps/qashmoney/qmmemory.db b/noncore/apps/qashmoney/qmmemory.db Binary files differindex be33cd4..5c23122 100755 --- a/noncore/apps/qashmoney/qmmemory.db +++ b/noncore/apps/qashmoney/qmmemory.db diff --git a/noncore/apps/qashmoney/qmtransactions.db b/noncore/apps/qashmoney/qmtransactions.db Binary files differindex 1b05561..9e4acc9 100755 --- a/noncore/apps/qashmoney/qmtransactions.db +++ b/noncore/apps/qashmoney/qmtransactions.db diff --git a/noncore/apps/qashmoney/qmtransfers.db b/noncore/apps/qashmoney/qmtransfers.db Binary files differindex 4c04b5f..c31df1a 100755 --- a/noncore/apps/qashmoney/qmtransfers.db +++ b/noncore/apps/qashmoney/qmtransfers.db diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp index 6e5c4f6..14f5641 100755 --- a/noncore/apps/qashmoney/transactiondisplay.cpp +++ b/noncore/apps/qashmoney/transactiondisplay.cpp @@ -8,513 +8,513 @@ #include "calculator.h" #include "datepicker.h" #include <qdatetime.h> #include <qmessagebox.h> #include <qheader.h> #include <qmultilineedit.h> #include <iostream.h> #include <qdatetime.h> extern Transaction *transaction; extern Budget *budget; extern Account *account; extern Preferences *preferences; extern Memory *memory; extern Transfer *transfer; TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) { // set transactiondisplay variables; accountid = 0; children = TRUE; firstline = new QHBox ( this ); firstline->setSpacing ( 2 ); newtransaction = new QPushButton ( firstline ); newtransaction->setPixmap ( QPixmap ("/opt/QtPalmtop/pics/new.png") ); connect ( newtransaction, SIGNAL ( released () ), this, SLOT ( addTransaction () ) ); edittransaction = new QPushButton ( firstline ); edittransaction->setPixmap( QPixmap ("/opt/QtPalmtop/pics/edit.png") ); connect ( edittransaction, SIGNAL ( released () ), this, SLOT ( checkListViewEdit () ) ); deletetransaction = new QPushButton ( firstline ); deletetransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/delete.png") ); connect ( deletetransaction, SIGNAL ( released () ), this, SLOT ( checkListViewDelete () ) ); toggletransaction = new QPushButton ( firstline ); toggletransaction->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/redo.png") ); connect ( toggletransaction, SIGNAL ( released () ), this, SLOT ( checkListViewToggle () ) ); viewtransactionnotes = new QPushButton ( firstline ); viewtransactionnotes->setPixmap( QPixmap ( "/opt/QtPalmtop/pics/info.png") ); connect ( viewtransactionnotes, SIGNAL ( released () ), this, SLOT ( showTransactionNotes () ) ); secondline = new QHBox ( this ); secondline->setSpacing ( 5 ); name = new QLabel ( secondline ); balance = new QLabel ( secondline ); QLabel *limit = new QLabel ( "Limit", secondline ); limitbox = new QLineEdit ( secondline ); limitbox->setMinimumWidth ( ( int ) ( this->width() / 6 ) ); connect ( limitbox, SIGNAL ( textChanged ( const QString & ) ), this, SLOT ( limitDisplay ( const QString & ) ) ); listview = new QListView ( this ); listview->setAllColumnsShowFocus ( TRUE ); listview->setShowSortIndicator ( TRUE ); listview->header()->setTracking ( FALSE ); connect ( listview->header(), SIGNAL ( sizeChange ( int, int, int ) ), this, SLOT ( saveColumnSize ( int, int, int ) ) ); layout = new QVBoxLayout ( this, 2, 2 ); layout->addWidget ( firstline ); layout->addWidget ( secondline ); layout->addWidget ( listview ); } void TransactionDisplay::addTransaction () { // create local variables int cleared = -1; // create new transaction window NewTransaction *newtransaction = new NewTransaction ( this ); int width = this->size().width(); newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); // enter today's date in the date box as defaul QDate today = QDate::currentDate (); int defaultday = today.day(); int defaultmonth = today.month(); int defaultyear = today.year(); newtransaction->transactiondate->setText ( preferences->getDate ( defaultyear, defaultmonth, defaultday ) ); // add memory items to the transactionname combobox memory->displayMemoryItems ( newtransaction->transactionname ); newtransaction->transactionname->insertItem ( "", 0 ); if ( newtransaction->exec () == QDialog::Accepted ) { if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) // set a parent id and type for a child transaction cleared = 1; else cleared = 0; float amount = newtransaction->transactionamount->text().toFloat(); if ( newtransaction->depositbox->isChecked() == FALSE ) amount = amount * -1; // add the transaction name to the memory items memory->addMemoryItem ( newtransaction->transactionname->currentText() ); // add the transaction if ( newtransaction->getDateEdited () == TRUE ) transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); else transaction->addTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), accountid, account->getParentAccountID ( accountid ), newtransaction->transactionnumber->text().toInt(), defaultday, defaultmonth, defaultyear, amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem() ); // redisplay transactions listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext ); // redisplay transfers if ( transfer->getNumberOfTransfers() > 0 ) transfer->displayTransfers ( listview, accountid, children ); // add the transaction amount to the account it's associated with // and update its parent account balance if necessary account->updateAccountBalance ( accountid ); if ( account->getParentAccountID ( accountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); // format then reset the account balance redisplayAccountBalance (); } } void TransactionDisplay::checkListViewEdit () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select a transaction\nto edit."); else if ( listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) editTransfer (); else editTransaction(); } void TransactionDisplay::showCalculator () { Calculator *calculator = new Calculator ( this ); if ( calculator->exec () == QDialog::Accepted ) amount->setText ( calculator->display->text() ); } void TransactionDisplay::showCalendar () { QDate newDate = QDate::currentDate (); DatePicker *dp = new DatePicker ( newDate ); if ( dp->exec () == QDialog::Accepted ) { year = dp->getYear(); month = dp->getMonth(); day = dp->getDay(); date->setText ( preferences->getDate ( year, month, day ) ); } } void TransactionDisplay::editTransfer () { transferid = listview->currentItem()->text ( getIDColumn() ).toInt(); fromaccount = transfer->getFromAccountID ( transferid ); toaccount = transfer->getToAccountID ( transferid ); year = transfer->getYear ( transferid ); month = transfer->getMonth ( transferid ); day = transfer->getDay ( transferid ); QDialog *editransfer = new QDialog ( this, "edittransfer", TRUE ); editransfer->setCaption ( "Transfer" ); QStringList accountnames = account->getAccountNames(); QStringList accountids = account->getAccountIDs(); QLabel *fromaccountlabel = new QLabel ( "From Account:", editransfer ); QFont f = this->font(); f.setWeight ( QFont::Bold ); fromaccountlabel->setFont ( f ); QComboBox *fromaccountbox = new QComboBox ( editransfer ); fromaccountbox->insertStringList ( accountnames ); fromaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( fromaccount ) ) ); QLabel *toaccountlabel = new QLabel ( "To Account:", editransfer ); toaccountlabel->setFont ( f ); QComboBox *toaccountbox = new QComboBox ( editransfer ); toaccountbox->insertStringList ( accountnames ); toaccountbox->setCurrentItem ( accountids.findIndex ( QString::number ( toaccount ) ) ); QLabel *datelabel = new QLabel ( "Date", editransfer ); QHBox *datebox = new QHBox ( editransfer ); datebox->setSpacing ( 2 ); date = new QLineEdit ( datebox ); date->setAlignment ( Qt::AlignRight ); date->setDisabled ( TRUE ); date->setText ( preferences->getDate ( year, month, day ) ); QPushButton *datebutton = new QPushButton ( datebox ); datebutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/date.png" ) ); connect ( datebutton, SIGNAL ( released () ), this, SLOT ( showCalendar () ) ); QLabel *amounttlabel = new QLabel ( "Amount", editransfer ); QHBox *amountbox = new QHBox ( editransfer ); amountbox->setSpacing ( 2 ); amount = new QLineEdit ( amountbox ); amount->setAlignment ( Qt::AlignRight ); amount->setText ( transfer->getAmount ( transferid ) ); QPushButton *calculatorbutton = new QPushButton( amountbox ); calculatorbutton->setPixmap ( QPixmap ( "/opt/QtPalmtop/pics/kcalc.png" ) ); connect ( calculatorbutton, SIGNAL ( released() ), this, SLOT ( showCalculator() ) ); QCheckBox *clearedcheckbox = new QCheckBox ( "Cleared", editransfer ); QBoxLayout *layout = new QVBoxLayout ( editransfer, 4, 2 ); layout->addWidget ( fromaccountlabel, Qt::AlignLeft ); layout->addWidget ( fromaccountbox, Qt::AlignLeft ); layout->addWidget ( toaccountlabel, Qt::AlignLeft ); layout->addWidget ( toaccountbox, Qt::AlignLeft ); layout->addSpacing ( 5 ); layout->addWidget ( datelabel, Qt::AlignLeft ); layout->addWidget ( datebox, Qt::AlignLeft ); layout->addWidget ( amounttlabel, Qt::AlignLeft ); layout->addWidget ( amountbox, Qt::AlignLeft ); layout->addWidget ( clearedcheckbox, Qt::AlignLeft ); if ( editransfer->exec() == QDialog::Accepted ) { //get fromaccount fromaccount = ( accountids.operator[] ( fromaccountbox->currentItem() ) ).toInt(); //get to account toaccount = ( accountids.operator[] ( toaccountbox->currentItem() ) ).toInt(); //set cleared flag int cleared = 0; if ( clearedcheckbox->isChecked() == TRUE ) cleared = 1; //update transfer transfer->updateTransfer ( fromaccount, account->getParentAccountID ( fromaccount ), toaccount, account->getParentAccountID ( toaccount ), day, month, year, amount->text().toFloat(), cleared, transferid ); account->updateAccountBalance ( fromaccount ); if ( account->getParentAccountID ( fromaccount ) != -1 ) - account->changeParentAccountBalance ( fromaccount ); + account->changeParentAccountBalance ( account->getParentAccountID ( fromaccount ) ); updateAndDisplay ( toaccount ); } } void TransactionDisplay::editTransaction () { int cleared; // set the transaction id and budgetid int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); int budgetid = transaction->getBudgetID ( transactionid ); int lineitemid = transaction->getLineItemID ( transactionid ); // create edit transaction window NewTransaction *newtransaction = new NewTransaction ( this ); int width = this->width(); newtransaction->transactionname->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactionname->setMinimumWidth ( ( int ) ( width * 0.35 ) ); newtransaction->lineitembox->setMaximumWidth ( ( int ) ( width * 0.45 ) ); newtransaction->transactiondatebox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionamountbox->setMaximumWidth ( ( int ) ( width * 0.4 ) ); newtransaction->transactionnumber->setMaximumWidth ( ( int ) ( width * 0.25 ) ); // enter the date in the date box newtransaction->year = transaction->getYear ( transactionid ); newtransaction->month = transaction->getMonth ( transactionid ); newtransaction->day = transaction->getDay ( transactionid ); newtransaction->transactiondate->setText ( preferences->getDate ( newtransaction->year, newtransaction->month, newtransaction->day ) ); // set the description newtransaction->setDescription ( transaction->getTransactionDescription ( transactionid ) ); // add memory items to the transactionname combobox memory->displayMemoryItems ( newtransaction->transactionname ); // add correct transaction name newtransaction->transactionname->setEditText ( transaction->getPayee ( transactionid ) ); // add transaction number newtransaction->transactionnumber->setText ( transaction->getNumber ( transactionid ) ); // add transaction amount newtransaction->transactionamount->setText ( transaction->getAbsoluteAmount ( transactionid ) ); // check for and set the correct budget if ( budgetid >= 1 ) // only do it if this transaction has a budget and line item { newtransaction->budgetbox->setCurrentItem ( newtransaction->getBudgetIndex ( budgetid ) + 1 ); if ( lineitemid >= 1 ) { newtransaction->setLineItems (); newtransaction->lineitembox->setCurrentItem ( newtransaction->getLineItemIndex ( lineitemid ) ); } else { newtransaction->lineitemlabel->setEnabled ( FALSE ); newtransaction->lineitembox->setEnabled ( FALSE ); } } else { newtransaction->lineitemlabel->setEnabled ( FALSE ); newtransaction->lineitembox->setEnabled ( FALSE ); } // check cleared checkbox if necessary if ( transaction->getCleared ( transactionid ) == 1 ) newtransaction->clearedcheckbox->setChecked ( TRUE ); // check deposit box if necessary if ( transaction->getAmount ( transactionid ).toFloat() > 0 ) newtransaction->depositbox->setChecked ( TRUE ); if ( newtransaction->exec () == QDialog::Accepted ) { if ( newtransaction->clearedcheckbox->isChecked () == TRUE ) cleared = 1; else cleared = 0; float amount = newtransaction->transactionamount->text().toFloat(); if ( newtransaction->depositbox->isChecked() == FALSE ) amount = amount * -1; // add the transaction name to the memory items memory->addMemoryItem ( newtransaction->transactionname->currentText() ); // update the transaction transaction->updateTransaction ( newtransaction->getDescription(), newtransaction->transactionname->currentText(), newtransaction->transactionnumber->text().toInt(), newtransaction->getDay(), newtransaction->getMonth(), newtransaction->getYear(), amount, cleared, newtransaction->getCurrentBudget(), newtransaction->getCurrentLineItem(), transactionid ); updateAndDisplay ( transaction->getAccountID ( transactionid ) ); } } void TransactionDisplay::updateAndDisplay ( int id ) { // redisplay transactions listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext ); // redisplay transfers if ( transfer->getNumberOfTransfers() > 0 ) transfer->displayTransfers ( listview, accountid, children ); // add the transaction amount to the account it's associated with // and update its parent account balance if necessary account->updateAccountBalance ( id ); if ( account->getParentAccountID ( id ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( id ) ); // format then reset the account balance redisplayAccountBalance (); } void TransactionDisplay::checkListViewDelete () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\ndelete."); else deleteTransaction (); } void TransactionDisplay::deleteTransaction () { int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); if ( transactionid > 0 ) // takes care of deleting transactions { // check if we are viewing child transactions through a parent // in that case we will have to update balances for the parent // which is represented by accountid and the child account // which will be represented by childaccountid int childaccountid = -1; if ( listview->columns() == 5 ) childaccountid = transaction->getAccountID ( transactionid ); transaction->deleteTransaction ( transactionid ); listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext ); if ( transfer->getNumberOfTransfers() > 0 ) transfer->displayTransfers ( listview, accountid, children ); // if we are viewing different child accounts through the parent account // ie if there are five columns and the parentid is -1 // update the accountid ( which is the parent ) and update the child account // balance. Get its accountid from the transactionid account->updateAccountBalance ( accountid ); // will update either a parent or child if ( account->getParentAccountID ( accountid ) != -1 ) // update its parent if there is one account->changeParentAccountBalance ( account->getParentAccountID ( accountid ) ); if ( childaccountid != -1 ) // we've set childaccountid account->updateAccountBalance ( childaccountid ); // format then reset the account balance redisplayAccountBalance (); } else // takes care of deleting transfers { // get the accountids before we delete the transfer int fromaccountid = transfer->getFromAccountID ( transactionid ); int toaccountid = transfer->getToAccountID ( transactionid ); // delete the transfer and redisplay transactions transfer->deleteTransfer ( transactionid ); listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext ); if ( transfer->getNumberOfTransfers() > 0 ) transfer->displayTransfers ( listview, accountid, children ); // for the from account account->updateAccountBalance ( fromaccountid ); if ( account->getParentAccountID ( fromaccountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( fromaccountid ) ); // for the to account account->updateAccountBalance ( toaccountid ); if ( account->getParentAccountID ( toaccountid ) != -1 ) account->changeParentAccountBalance ( account->getParentAccountID ( toaccountid ) ); // format then reset the account balance redisplayAccountBalance (); } } void TransactionDisplay::checkListViewToggle () { if ( listview->selectedItem() == 0 ) QMessageBox::warning ( this, "QashMoney", "Please select a transaction to\nclear or reset."); else toggleTransaction (); } void TransactionDisplay::toggleTransaction () { //get the transaction of the selected transaction to determine if its a transaction or transfer int transactionid = listview->currentItem()->text ( getIDColumn() ).toInt(); if ( transactionid > 0 ) // if this is a transaction { if ( transaction->getCleared ( transactionid ) == 0 ) transaction->setCleared ( transactionid, 1 ); else transaction->setCleared ( transactionid, 0 ); } else { if ( transfer->getCleared ( transactionid ) == 0 ) transfer->setCleared ( transactionid, 1 ); else transfer->setCleared ( transactionid, 0 ); } listview->clear(); QString displaytext = "%"; displaytext.prepend ( limitbox->text() ); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext ); if ( transfer->getNumberOfTransfers() != 0 ) transfer->displayTransfers ( listview, accountid, children ); } void TransactionDisplay::redisplayAccountBalance () { QString accountbalance = account->getAccountBalance ( accountid ); balance->setText ( accountbalance ); } void TransactionDisplay::setChildren ( bool c ) { children = c; } void TransactionDisplay::setAccountID ( int id ) { accountid = id; } ColorListItem::ColorListItem ( QListView *parent ) : QListViewItem ( parent ) { } |