Diffstat (limited to 'noncore/apps/qashmoney/transactiondisplay.cpp') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | noncore/apps/qashmoney/transactiondisplay.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/noncore/apps/qashmoney/transactiondisplay.cpp b/noncore/apps/qashmoney/transactiondisplay.cpp index ae6223d..1839cd2 100755 --- a/noncore/apps/qashmoney/transactiondisplay.cpp +++ b/noncore/apps/qashmoney/transactiondisplay.cpp @@ -46,48 +46,49 @@ TransactionDisplay::TransactionDisplay ( QWidget* parent ) : QWidget ( parent ) 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 ) ) ); + connect ( listview->header(), SIGNAL ( clicked ( int ) ), this, SLOT ( saveSortingPreference ( 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 (); @@ -112,49 +113,49 @@ void TransactionDisplay::addTransaction () 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() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); // redisplay transfers if ( transfer->getNumberOfTransfers() > 0 ) - transfer->displayTransfers ( listview, accountid, children ); + transfer->displayTransfers ( listview, accountid, children, displaydate ); // 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 () { @@ -351,125 +352,125 @@ void TransactionDisplay::editTransaction () // 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() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); // redisplay transfers if ( transfer->getNumberOfTransfers() > 0 ) - transfer->displayTransfers ( listview, accountid, children ); + transfer->displayTransfers ( listview, accountid, children, displaydate ); // 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() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); if ( transfer->getNumberOfTransfers() > 0 ) - transfer->displayTransfers ( listview, accountid, children ); + transfer->displayTransfers ( listview, accountid, children, displaydate ); // 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() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); if ( transfer->getNumberOfTransfers() > 0 ) - transfer->displayTransfers ( listview, accountid, children ); + transfer->displayTransfers ( listview, accountid, children, displaydate ); // 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 (); } @@ -480,49 +481,49 @@ void TransactionDisplay::toggleTransaction () 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() ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); if ( transfer->getNumberOfTransfers() != 0 ) - transfer->displayTransfers ( listview, accountid, children ); + transfer->displayTransfers ( listview, accountid, children, displaydate ); } 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 ) { } ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4 ) : QListViewItem ( parent, label1, label2, label3, label4 ) @@ -530,59 +531,64 @@ ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2 } ColorListItem::ColorListItem ( QListView *parent, QString label1, QString label2, QString label3, QString label4, QString label5 ) : QListViewItem ( parent, label1, label2, label3, label4, label5 ) { } void ColorListItem::paintCell ( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { QColorGroup _cg ( cg ); _cg.setColor ( QColorGroup::Text, Qt::red ); QListViewItem::paintCell ( p, _cg, column, width, alignment ); } void TransactionDisplay::saveColumnSize ( int column, int oldsize, int newsize ) { if ( listview->columns() == 4 ) preferences->changeColumnPreference ( column + 3, newsize ); else if ( listview->columns() == 5 && column != 4 ) preferences->changeColumnPreference ( column + 6, newsize ); else preferences->changeColumnPreference ( 9, newsize ); } +void TransactionDisplay::saveSortingPreference ( int column ) + { + preferences->changeSortingPreference ( 2, column ); + } + void TransactionDisplay::limitDisplay ( const QString &text ) { listview->clear (); QString displaytext = "%"; displaytext.prepend ( text ); setTransactionDisplayDate (); if ( transaction->getNumberOfTransactions() > 0 ) transaction->displayTransactions ( listview, accountid, children, displaytext, displaydate ); if ( displaytext.length() == 1 || preferences->getPreference ( 6 ) == 1 ) - transfer->displayTransfers ( listview, accountid, children ); + transfer->displayTransfers ( listview, accountid, children, displaydate ); } int TransactionDisplay::getIDColumn () { int counter; int columns = listview->columns(); for ( counter = 0; counter <= columns; counter++ ) if ( listview->header()->label ( counter ).length() == 0 ) return counter; } void TransactionDisplay::showTransactionNotes () { if ( listview->selectedItem() == 0 || listview->currentItem()->text ( getIDColumn() ).toInt() < 0 ) QMessageBox::warning ( this, "QashMoney", "Please select a valid\ntransaction to view notes."); else { int transactionid = listview->selectedItem()->text ( getIDColumn() ).toInt (); QDialog *description = new QDialog ( this, "description", TRUE ); description->setCaption ( "Notes" ); QMultiLineEdit *notes = new QMultiLineEdit ( description ); notes->setFixedSize ( ( int ) (this->width() * 0.75 ), ( int ) ( this->height() * 0.5 ) ); notes->setWrapColumnOrWidth ( ( int ) (this->width() * 0.75 ) ); notes->setWordWrap ( QMultiLineEdit::WidgetWidth ); @@ -598,26 +604,26 @@ void TransactionDisplay::setTransactionDisplayDate () int limittype = preferences->getPreference ( 7 ); if ( limittype != 5 ) // set today's date if we are not showing all transactions { QDate today = QDate::currentDate (); switch ( limittype ) // if we are not showing all transactions { case 0: // viewing two weeks displaydate = today.addDays ( -14 ); break; case 1: // viewing one month displaydate = today.addDays ( -30 ); break; case 2: // three months displaydate = today.addDays ( -90 ); break; case 3: // six months displaydate = today.addDays ( -180 ); break; case 4: // one year displaydate = today.addDays ( -365 ); break; } } else - displaydate = QDate ( 1, 1, 1000 ); + displaydate = QDate ( 1900, 1, 1 ); } |