diff --git a/kmymoney/dialogs/kfindtransactiondlg.cpp b/kmymoney/dialogs/kfindtransactiondlg.cpp index 4f72ad207..fc502e603 100644 --- a/kmymoney/dialogs/kfindtransactiondlg.cpp +++ b/kmymoney/dialogs/kfindtransactiondlg.cpp @@ -1,944 +1,944 @@ /*************************************************************************** kfindtransactiondlg.cpp ------------------- copyright : (C) 2003, 2007 by Thomas Baumgart email : ipwizard@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "config-kmymoney.h" #include "kfindtransactiondlg.h" // ---------------------------------------------------------------------------- // QT Includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include // ---------------------------------------------------------------------------- // KDE Includes #include #include #include #include #include #include #include #include // ---------------------------------------------------------------------------- // Project Includes #include #include #include #include #include #include #include #include #include #include "ui_kfindtransactiondlgdecl.h" #include "ui_ksortoptiondlg.h" #include enum ItemRoles { ItemIdRole = Qt::UserRole }; struct KSortOptionDlg::Private { Ui::KSortOptionDlg ui; }; KSortOptionDlg::KSortOptionDlg(QWidget *parent) : QDialog(parent), d(new Private) { d->ui.setupUi(this); init(); } KSortOptionDlg::~KSortOptionDlg() { delete d; } void KSortOptionDlg::init() { } void KSortOptionDlg::setSortOption(const QString& option, const QString& def) { if (option.isEmpty()) { d->ui.m_sortOption->setSettings(def); d->ui.m_useDefault->setChecked(true); } else { d->ui.m_sortOption->setSettings(option); d->ui.m_useDefault->setChecked(false); } } QString KSortOptionDlg::sortOption() const { QString rc; if (!d->ui.m_useDefault->isChecked()) { rc = d->ui.m_sortOption->settings(); } return rc; } void KSortOptionDlg::hideDefaultButton() { d->ui.m_useDefault->hide(); } KFindTransactionDlg::KFindTransactionDlg(QWidget *parent, bool withEquityAccounts) : QDialog(parent) , m_needReload(false) , m_ui(new Ui::KFindTransactionDlgDecl) { m_ui->setupUi(this); m_dateRange = new DateRangeDlg; m_ui->dateRangeLayout->insertWidget(0, m_dateRange); m_ui->ButtonGroup1->setId(m_ui->m_amountButton, 0); m_ui->ButtonGroup1->setId(m_ui->m_amountRangeButton, 1); m_ui->m_register->installEventFilter(this); m_ui->m_tabWidget->setTabEnabled(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage), false); // 'cause we don't have a separate setupTextPage connect(m_ui->m_textEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); // if return is pressed trigger a search (slotSearch checks if it's possible to perform the search) connect(m_ui->m_textEdit, SIGNAL(returnPressed()), this, SLOT(slotSearch())); // in case the date selection changes, we update the selection connect(m_dateRange, SIGNAL(rangeChanged()), this, SLOT(slotUpdateSelections())); setupAccountsPage(withEquityAccounts); setupCategoriesPage(); setupAmountPage(); setupPayeesPage(); setupTagsPage(); setupDetailsPage(); // We don't need to add the default into the list (see ::slotShowHelp() why) // m_helpAnchor[m_ui->m_textTab] = QLatin1String("details.search"); m_helpAnchor[m_ui->m_accountTab] = QLatin1String("details.search.account"); m_helpAnchor[m_ui->m_dateTab] = QLatin1String("details.search.date"); m_helpAnchor[m_ui->m_amountTab] = QLatin1String("details.search.amount"); m_helpAnchor[m_ui->m_categoryTab] = QLatin1String("details.search.category"); m_helpAnchor[m_ui->m_payeeTab] = QLatin1String("details.search.payee"); m_helpAnchor[m_ui->m_tagTab] = QLatin1String("details.search.tag"); //FIXME-ALEX update Help m_helpAnchor[m_ui->m_detailsTab] = QLatin1String("details.search.details"); // setup the register QList cols; cols << KMyMoneyRegister::DateColumn; cols << KMyMoneyRegister::AccountColumn; cols << KMyMoneyRegister::DetailColumn; cols << KMyMoneyRegister::ReconcileFlagColumn; cols << KMyMoneyRegister::PaymentColumn; cols << KMyMoneyRegister::DepositColumn; m_ui->m_register->setupRegister(MyMoneyAccount(), cols); m_ui->m_register->setSelectionMode(QTableWidget::SingleSelection); connect(m_ui->m_register, SIGNAL(editTransaction()), this, SLOT(slotSelectTransaction())); connect(m_ui->m_register->horizontalHeader(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotSortOptions())); slotUpdateSelections(); // setup the connections connect(m_ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotSearch())); connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(slotReset())); connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), m_ui->m_accountsView, SLOT(slotSelectAllAccounts())); connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), m_ui->m_categoriesView, SLOT(slotSelectAllAccounts())); connect(m_ui->buttonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(deleteLater())); connect(m_ui->buttonBox->button(QDialogButtonBox::Help), SIGNAL(clicked()), this, SLOT(slotShowHelp())); // only allow searches when a selection has been made m_ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); KGuiItem::assign(m_ui->buttonBox->button(QDialogButtonBox::Apply), KStandardGuiItem::find()); m_ui->buttonBox->button(QDialogButtonBox::Apply)->setToolTip(i18nc("@info:tooltip for find transaction apply button", "Search transactions")); connect(this, SIGNAL(selectionNotEmpty(bool)), m_ui->buttonBox->button(QDialogButtonBox::Apply), SLOT(setEnabled(bool))); // get signal about engine changes connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotRefreshView())); slotUpdateSelections(); m_ui->m_textEdit->setFocus(); } KFindTransactionDlg::~KFindTransactionDlg() { delete m_ui; } void KFindTransactionDlg::slotReset() { m_ui->m_textEdit->setText(QString()); m_ui->m_regExp->setChecked(false); m_ui->m_caseSensitive->setChecked(false); m_ui->m_textNegate->setCurrentItem(0); m_ui->m_amountEdit->setEnabled(true); m_ui->m_amountFromEdit->setEnabled(false); m_ui->m_amountToEdit->setEnabled(false); m_ui->m_amountEdit->loadText(QString()); m_ui->m_amountFromEdit->loadText(QString()); m_ui->m_amountToEdit->loadText(QString()); m_ui->m_amountButton->setChecked(true); m_ui->m_amountRangeButton->setChecked(false); m_ui->m_emptyPayeesButton->setChecked(false); selectAllItems(m_ui->m_payeesView, true); m_ui->m_emptyTagsButton->setChecked(false); selectAllItems(m_ui->m_tagsView, true); m_ui->m_typeBox->setCurrentIndex(MyMoneyTransactionFilter::allTypes); m_ui->m_stateBox->setCurrentIndex(MyMoneyTransactionFilter::allStates); m_ui->m_validityBox->setCurrentIndex(MyMoneyTransactionFilter::anyValidity); m_ui->m_nrEdit->setEnabled(true); m_ui->m_nrFromEdit->setEnabled(false); m_ui->m_nrToEdit->setEnabled(false); m_ui->m_nrEdit->setText(QString()); m_ui->m_nrFromEdit->setText(QString()); m_ui->m_nrToEdit->setText(QString()); m_ui->m_nrButton->setChecked(true); m_ui->m_nrRangeButton->setChecked(false); m_ui->m_tabWidget->setTabEnabled(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage), false); m_ui->m_tabWidget->setCurrentIndex(m_ui->m_tabWidget->indexOf(m_ui->m_criteriaTab)); // the following call implies a call to slotUpdateSelections, // that's why we call it last m_dateRange->slotReset(); slotUpdateSelections(); } void KFindTransactionDlg::slotUpdateSelections() { QString txt; // Text tab if (!m_ui->m_textEdit->text().isEmpty()) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Text"); m_ui->m_regExp->setEnabled(QRegExp(m_ui->m_textEdit->text()).isValid()); } else m_ui->m_regExp->setEnabled(false); m_ui->m_caseSensitive->setEnabled(!m_ui->m_textEdit->text().isEmpty()); m_ui->m_textNegate->setEnabled(!m_ui->m_textEdit->text().isEmpty()); // Account tab if (!m_ui->m_accountsView->allItemsSelected()) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Account"); } if (m_dateRange->dateRange() != MyMoneyTransactionFilter::allDates) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Date"); } // Amount tab if ((m_ui->m_amountButton->isChecked() && m_ui->m_amountEdit->isValid()) || (m_ui->m_amountRangeButton->isChecked() && (m_ui->m_amountFromEdit->isValid() || m_ui->m_amountToEdit->isValid()))) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Amount"); } // Categories tab if (!m_ui->m_categoriesView->allItemsSelected()) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Category"); } // Tags tab if (!allItemsSelected(m_ui->m_tagsView) || m_ui->m_emptyTagsButton->isChecked()) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Tags"); } m_ui->m_tagsView->setEnabled(!m_ui->m_emptyTagsButton->isChecked()); // Payees tab if (!allItemsSelected(m_ui->m_payeesView) || m_ui->m_emptyPayeesButton->isChecked()) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Payees"); } m_ui->m_payeesView->setEnabled(!m_ui->m_emptyPayeesButton->isChecked()); // Details tab if (m_ui->m_typeBox->currentIndex() != 0 || m_ui->m_stateBox->currentIndex() != 0 || m_ui->m_validityBox->currentIndex() != 0 || (m_ui->m_nrButton->isChecked() && m_ui->m_nrEdit->text().length() != 0) || (m_ui->m_nrRangeButton->isChecked() && (m_ui->m_nrFromEdit->text().length() != 0 || m_ui->m_nrToEdit->text().length() != 0))) { if (!txt.isEmpty()) txt += ", "; txt += i18n("Details"); } //Show a warning about transfers if Categories are filtered - bug #1523508 if (!m_ui->m_categoriesView->allItemsSelected()) { m_ui->m_transferWarning->setText(i18n("Warning: Filtering by Category will exclude all transfers from the results.")); } else { m_ui->m_transferWarning->setText(""); } // disable the search button if no selection is made emit selectionNotEmpty(!txt.isEmpty()); if (txt.isEmpty()) { txt = i18nc("No selection", "(None)"); } m_ui->m_selectedCriteria->setText(i18n("Current selections: %1", txt)); } bool KFindTransactionDlg::allItemsSelected(const QTreeWidgetItem *item) const { QTreeWidgetItem* it_v; for (int i = 0; i < item->childCount(); ++i) { it_v = item->child(i); if (!(it_v->checkState(0) == Qt::Checked && allItemsSelected(it_v))) { return false; } } return true; } bool KFindTransactionDlg::allItemsSelected(const QTreeWidget* view) const { QTreeWidgetItem* it_v; for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { it_v = view->invisibleRootItem()->child(i); if (it_v->flags() & Qt::ItemIsUserCheckable) { if (!(it_v->checkState(0) == Qt::Checked && allItemsSelected(it_v))) { return false; } else { if (!allItemsSelected(it_v)) return false; } } } return true; } void KFindTransactionDlg::setupAccountsPage(bool withEquityAccounts) { m_ui->m_accountsView->setSelectionMode(QTreeWidget::MultiSelection); AccountSet accountSet; accountSet.addAccountGroup(MyMoneyAccount::Asset); accountSet.addAccountGroup(MyMoneyAccount::Liability); + if (withEquityAccounts) accountSet.addAccountGroup(MyMoneyAccount::Equity); - accountSet.addAccountGroup(MyMoneyAccount::Income); - accountSet.addAccountGroup(MyMoneyAccount::Expense); + //set the accountset to show closed account if the settings say so accountSet.setHideClosedAccounts(KMyMoneyGlobalSettings::hideClosedAccounts()); accountSet.load(m_ui->m_accountsView); connect(m_ui->m_accountsView, SIGNAL(stateChanged()), this, SLOT(slotUpdateSelections())); } void KFindTransactionDlg::selectAllItems(QTreeWidget* view, const bool state) { QTreeWidgetItem* it_v; for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { it_v = view->invisibleRootItem()->child(i); if (it_v->flags() & Qt::ItemIsUserCheckable) { it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); } selectAllSubItems(it_v, state); } slotUpdateSelections(); } void KFindTransactionDlg::selectItems(QTreeWidget* view, const QStringList& list, const bool state) { QTreeWidgetItem* it_v; for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { it_v = view->invisibleRootItem()->child(i); QVariant idData = it_v->data(0, ItemIdRole); if (it_v->flags() & Qt::ItemIsUserCheckable && list.contains(idData.toString())) { it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); } selectSubItems(it_v, list, state); } slotUpdateSelections(); } void KFindTransactionDlg::setupCategoriesPage() { m_ui->m_categoriesView->setSelectionMode(QTreeWidget::MultiSelection); AccountSet categorySet; categorySet.addAccountGroup(MyMoneyAccount::Income); categorySet.addAccountGroup(MyMoneyAccount::Expense); categorySet.load(m_ui->m_categoriesView); connect(m_ui->m_categoriesView, SIGNAL(stateChanged()), this, SLOT(slotUpdateSelections())); } void KFindTransactionDlg::selectAllSubItems(QTreeWidgetItem* item, const bool state) { QTreeWidgetItem* it_v; for (int i = 0; i < item->childCount(); ++i) { it_v = item->child(i); it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); selectAllSubItems(it_v, state); } } void KFindTransactionDlg::selectSubItems(QTreeWidgetItem* item, const QStringList& list, const bool state) { QTreeWidgetItem* it_v; for (int i = 0; i < item->childCount(); ++i) { it_v = item->child(i); QVariant idData = it_v->data(0, ItemIdRole); if (list.contains(idData.toString())) it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); selectSubItems(it_v, list, state); } } void KFindTransactionDlg::setupAmountPage() { connect(m_ui->m_amountButton, SIGNAL(clicked()), this, SLOT(slotAmountSelected())); connect(m_ui->m_amountRangeButton, SIGNAL(clicked()), this, SLOT(slotAmountRangeSelected())); connect(m_ui->m_amountEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_amountFromEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_amountToEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); m_ui->m_amountButton->setChecked(true); slotAmountSelected(); } void KFindTransactionDlg::slotAmountSelected() { m_ui->m_amountEdit->setEnabled(true); m_ui->m_amountFromEdit->setEnabled(false); m_ui->m_amountToEdit->setEnabled(false); slotUpdateSelections(); } void KFindTransactionDlg::slotAmountRangeSelected() { m_ui->m_amountEdit->setEnabled(false); m_ui->m_amountFromEdit->setEnabled(true); m_ui->m_amountToEdit->setEnabled(true); slotUpdateSelections(); } void KFindTransactionDlg::setupPayeesPage() { m_ui->m_payeesView->setSelectionMode(QAbstractItemView::SingleSelection); m_ui->m_payeesView->header()->hide(); m_ui->m_payeesView->setAlternatingRowColors(true); loadPayees(); m_ui->m_payeesView->sortItems(0, Qt::AscendingOrder); m_ui->m_emptyPayeesButton->setCheckState(Qt::Unchecked); connect(m_ui->m_allPayeesButton, SIGNAL(clicked()), this, SLOT(slotSelectAllPayees())); connect(m_ui->m_clearPayeesButton, SIGNAL(clicked()), this, SLOT(slotDeselectAllPayees())); connect(m_ui->m_emptyPayeesButton, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_payeesView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateSelections())); } void KFindTransactionDlg::loadPayees() { MyMoneyFile* file = MyMoneyFile::instance(); QList list; QList::Iterator it_l; list = file->payeeList(); // load view for (it_l = list.begin(); it_l != list.end(); ++it_l) { QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_payeesView); item->setText(0, (*it_l).name()); item->setData(0, ItemIdRole, (*it_l).id()); item->setCheckState(0, Qt::Checked); } } void KFindTransactionDlg::slotSelectAllPayees() { selectAllItems(m_ui->m_payeesView, true); } void KFindTransactionDlg::slotDeselectAllPayees() { selectAllItems(m_ui->m_payeesView, false); } void KFindTransactionDlg::setupTagsPage() { m_ui->m_tagsView->setSelectionMode(QAbstractItemView::SingleSelection); m_ui->m_tagsView->header()->hide(); m_ui->m_tagsView->setAlternatingRowColors(true); loadTags(); m_ui->m_tagsView->sortItems(0, Qt::AscendingOrder); m_ui->m_emptyTagsButton->setCheckState(Qt::Unchecked); connect(m_ui->m_allTagsButton, SIGNAL(clicked()), this, SLOT(slotSelectAllTags())); connect(m_ui->m_clearTagsButton, SIGNAL(clicked()), this, SLOT(slotDeselectAllTags())); connect(m_ui->m_emptyTagsButton, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_tagsView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateSelections())); } void KFindTransactionDlg::loadTags() { MyMoneyFile* file = MyMoneyFile::instance(); QList list; QList::Iterator it_l; list = file->tagList(); // load view for (it_l = list.begin(); it_l != list.end(); ++it_l) { QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_tagsView); item->setText(0, (*it_l).name()); item->setData(0, ItemIdRole, (*it_l).id()); item->setCheckState(0, Qt::Checked); } } void KFindTransactionDlg::slotSelectAllTags() { selectAllItems(m_ui->m_tagsView, true); } void KFindTransactionDlg::slotDeselectAllTags() { selectAllItems(m_ui->m_tagsView, false); } void KFindTransactionDlg::setupDetailsPage() { connect(m_ui->m_typeBox, SIGNAL(activated(int)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_stateBox, SIGNAL(activated(int)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_validityBox, SIGNAL(activated(int)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_nrButton, SIGNAL(clicked()), this, SLOT(slotNrSelected())); connect(m_ui->m_nrRangeButton, SIGNAL(clicked()), this, SLOT(slotNrRangeSelected())); connect(m_ui->m_nrEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_nrFromEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); connect(m_ui->m_nrToEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); m_ui->m_nrButton->setChecked(true); slotNrSelected(); } void KFindTransactionDlg::slotNrSelected() { m_ui->m_nrEdit->setEnabled(true); m_ui->m_nrFromEdit->setEnabled(false); m_ui->m_nrToEdit->setEnabled(false); slotUpdateSelections(); } void KFindTransactionDlg::slotNrRangeSelected() { m_ui->m_nrEdit->setEnabled(false); m_ui->m_nrFromEdit->setEnabled(true); m_ui->m_nrToEdit->setEnabled(true); slotUpdateSelections(); } void KFindTransactionDlg::addItemToFilter(const opTypeE op, const QString& id) { switch (op) { case addAccountToFilter: m_filter.addAccount(id); break; case addCategoryToFilter: m_filter.addCategory(id); break; case addPayeeToFilter: m_filter.addPayee(id); break; case addTagToFilter: m_filter.addTag(id); break; } } void KFindTransactionDlg::scanCheckListItems(const QTreeWidgetItem* item, const opTypeE op) { QTreeWidgetItem* it_v; for (int i = 0; i < item->childCount(); ++i) { it_v = item->child(i); QVariant idData = it_v->data(0, ItemIdRole); if (it_v->flags() & Qt::ItemIsUserCheckable) { if (it_v->checkState(0) == Qt::Checked) addItemToFilter(op, idData.toString()); } scanCheckListItems(it_v, op); } } void KFindTransactionDlg::scanCheckListItems(const QTreeWidget* view, const opTypeE op) { QTreeWidgetItem* it_v; for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { it_v = view->invisibleRootItem()->child(i); QVariant idData = it_v->data(0, ItemIdRole); if (it_v->flags() & Qt::ItemIsUserCheckable) { if (it_v->checkState(0) == Qt::Checked) { addItemToFilter(op, idData.toString()); } } scanCheckListItems(it_v, op); } } void KFindTransactionDlg::setupFilter() { m_filter.clear(); // Text tab if (!m_ui->m_textEdit->text().isEmpty()) { QRegExp exp(m_ui->m_textEdit->text(), m_ui->m_caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, !m_ui->m_regExp->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp); m_filter.setTextFilter(exp, m_ui->m_textNegate->currentIndex() != 0); } // Account tab if (!m_ui->m_accountsView->allItemsSelected()) { // retrieve a list of selected accounts QStringList list; m_ui->m_accountsView->selectedItems(list); // if we're not in expert mode, we need to make sure // that all stock accounts for the selected investment // account are also selected if (!KMyMoneyGlobalSettings::expertMode()) { QStringList missing; QStringList::const_iterator it_a, it_b; for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { MyMoneyAccount acc = MyMoneyFile::instance()->account(*it_a); if (acc.accountType() == MyMoneyAccount::Investment) { for (it_b = acc.accountList().constBegin(); it_b != acc.accountList().constEnd(); ++it_b) { if (!list.contains(*it_b)) { missing.append(*it_b); } } } } list += missing; } m_filter.addAccount(list); } // Date tab if (m_dateRange->dateRange() != 0) { m_filter.setDateFilter(m_dateRange->fromDate(), m_dateRange->toDate()); } // Amount tab if ((m_ui->m_amountButton->isChecked() && m_ui->m_amountEdit->isValid())) { m_filter.setAmountFilter(m_ui->m_amountEdit->value(), m_ui->m_amountEdit->value()); } else if ((m_ui->m_amountRangeButton->isChecked() && (m_ui->m_amountFromEdit->isValid() || m_ui->m_amountToEdit->isValid()))) { MyMoneyMoney from(MyMoneyMoney::minValue), to(MyMoneyMoney::maxValue); if (m_ui->m_amountFromEdit->isValid()) from = m_ui->m_amountFromEdit->value(); if (m_ui->m_amountToEdit->isValid()) to = m_ui->m_amountToEdit->value(); m_filter.setAmountFilter(from, to); } // Categories tab if (!m_ui->m_categoriesView->allItemsSelected()) { m_filter.addCategory(m_ui->m_categoriesView->selectedItems()); } // Tags tab if (m_ui->m_emptyTagsButton->isChecked()) { m_filter.addTag(QString()); } else if (!allItemsSelected(m_ui->m_tagsView)) { scanCheckListItems(m_ui->m_tagsView, addTagToFilter); } // Payees tab if (m_ui->m_emptyPayeesButton->isChecked()) { m_filter.addPayee(QString()); } else if (!allItemsSelected(m_ui->m_payeesView)) { scanCheckListItems(m_ui->m_payeesView, addPayeeToFilter); } // Details tab if (m_ui->m_typeBox->currentIndex() != 0) m_filter.addType(m_ui->m_typeBox->currentIndex()); if (m_ui->m_stateBox->currentIndex() != 0) m_filter.addState(m_ui->m_stateBox->currentIndex()); if (m_ui->m_validityBox->currentIndex() != 0) m_filter.addValidity(m_ui->m_validityBox->currentIndex()); if (m_ui->m_nrButton->isChecked() && !m_ui->m_nrEdit->text().isEmpty()) m_filter.setNumberFilter(m_ui->m_nrEdit->text(), m_ui->m_nrEdit->text()); if (m_ui->m_nrRangeButton->isChecked() && (!m_ui->m_nrFromEdit->text().isEmpty() || !m_ui->m_nrToEdit->text().isEmpty())) { m_filter.setNumberFilter(m_ui->m_nrFromEdit->text(), m_ui->m_nrToEdit->text()); } } void KFindTransactionDlg::slotSearch() { // perform the search only if the button is enabled if (!m_ui->buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) return; // setup the filter from the dialog widgets setupFilter(); // filter is setup, now fill the register slotRefreshView(); m_ui->m_register->setFocus(); } void KFindTransactionDlg::slotRefreshView() { m_needReload = true; if (isVisible()) { loadView(); m_needReload = false; } } void KFindTransactionDlg::showEvent(QShowEvent* event) { if (m_needReload) { loadView(); m_needReload = false; } QDialog::showEvent(event); } void KFindTransactionDlg::loadView() { // setup sort order m_ui->m_register->setSortOrder(KMyMoneyGlobalSettings::sortSearchView()); // clear out old data m_ui->m_register->clear(); // retrieve the list from the engine MyMoneyFile::instance()->transactionList(m_transactionList, m_filter); // create the elements for the register QList >::const_iterator it; QMapuniqueMap; MyMoneyMoney deposit, payment; int splitCount = 0; for (it = m_transactionList.constBegin(); it != m_transactionList.constEnd(); ++it) { const MyMoneySplit& split = (*it).second; MyMoneyAccount acc = MyMoneyFile::instance()->account(split.accountId()); ++splitCount; uniqueMap[(*it).first.id()]++; KMyMoneyRegister::Register::transactionFactory(m_ui->m_register, (*it).first, (*it).second, uniqueMap[(*it).first.id()]); { // debug stuff if (split.shares().isNegative()) { payment += split.shares().abs(); } else { deposit += split.shares().abs(); } } } // add the group markers m_ui->m_register->addGroupMarkers(); // sort the transactions according to the sort setting m_ui->m_register->sortItems(); // remove trailing and adjacent markers m_ui->m_register->removeUnwantedGroupMarkers(); // turn on the ledger lens for the register m_ui->m_register->setLedgerLensForced(); m_ui->m_register->updateRegister(true); m_ui->m_register->setFocusToTop(); m_ui->m_register->selectItem(m_ui->m_register->focusItem()); #ifdef KMM_DEBUG m_ui->m_foundText->setText(i18np("Found %1 matching transaction (D %2 / P %3 = %4)", "Found %1 matching transactions (D %2 / P %3 = %4)", splitCount, deposit.formatMoney("", 2), payment.formatMoney("", 2), (deposit - payment).formatMoney("", 2))); #else m_ui->m_foundText->setText(i18np("Found %1 matching transaction", "Found %1 matching transactions", splitCount)); #endif m_ui->m_tabWidget->setTabEnabled(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage), true); m_ui->m_tabWidget->setCurrentIndex(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage)); QTimer::singleShot(10, this, SLOT(slotRightSize())); } void KFindTransactionDlg::slotRightSize() { m_ui->m_register->update(); } void KFindTransactionDlg::resizeEvent(QResizeEvent* ev) { // Columns // 1 = Date // 2 = Account // 4 = Detail // 5 = C // 6 = Payment // 7 = Deposit // don't forget the resizer QDialog::resizeEvent(ev); if (!m_ui->m_register->isVisible()) return; // resize the register int w = m_ui->m_register->contentsRect().width(); int m_debitWidth = 80; int m_creditWidth = 80; m_ui->m_register->adjustColumn(1); m_ui->m_register->adjustColumn(2); m_ui->m_register->adjustColumn(5); m_ui->m_register->setColumnWidth(6, m_debitWidth); m_ui->m_register->setColumnWidth(7, m_creditWidth); for (int i = 0; i < m_ui->m_register->columnCount(); ++i) { switch (i) { case 4: // skip the one, we want to set break; default: w -= m_ui->m_register->columnWidth(i); break; } } m_ui->m_register->setColumnWidth(4, w); } void KFindTransactionDlg::slotSelectTransaction() { QList list = m_ui->m_register->selectedItems(); if (!list.isEmpty()) { KMyMoneyRegister::Transaction* t = dynamic_cast(list[0]); if (t) { emit transactionSelected(t->split().accountId(), t->transaction().id()); hide(); } } } bool KFindTransactionDlg::eventFilter(QObject* o, QEvent* e) { bool rc = false; if (o->isWidgetType()) { if (e->type() == QEvent::KeyPress) { const QWidget* w = dynamic_cast(o); QKeyEvent *k = static_cast(e); if (w == m_ui->m_register) { switch (k->key()) { default: break; case Qt::Key_Return: case Qt::Key_Enter: rc = true; slotSelectTransaction(); break; } } } } return rc; } void KFindTransactionDlg::slotShowHelp() { QString anchor = m_helpAnchor[m_ui->m_criteriaTab->currentWidget()]; if (anchor.isEmpty()) anchor = QString("details.search"); KHelpClient::invokeHelp(anchor); } void KFindTransactionDlg::slotSortOptions() { QPointer dlg = new KSortOptionDlg(this); dlg->setSortOption(KMyMoneyGlobalSettings::sortSearchView(), QString()); dlg->hideDefaultButton(); if (dlg->exec() == QDialog::Accepted) { QString sortOrder = dlg->sortOption(); if (sortOrder != KMyMoneyGlobalSettings::sortSearchView()) { KMyMoneyGlobalSettings::setSortSearchView(sortOrder); slotRefreshView(); } } delete dlg; } diff --git a/kmymoney/dialogs/kfindtransactiondlg.h b/kmymoney/dialogs/kfindtransactiondlg.h index cd1221c2c..101381947 100644 --- a/kmymoney/dialogs/kfindtransactiondlg.h +++ b/kmymoney/dialogs/kfindtransactiondlg.h @@ -1,208 +1,208 @@ /*************************************************************************** kfindtransactiondlg.h ------------------- copyright : (C) 2003 by Thomas Baumgart email : ipwizard@users.sourceforge.net ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef KFINDTRANSACTIONDLG_H #define KFINDTRANSACTIONDLG_H // ---------------------------------------------------------------------------- // QT Includes #include #include #include #include #include // ---------------------------------------------------------------------------- // KDE Includes #include // ---------------------------------------------------------------------------- // Project Includes #include "mymoneyutils.h" #include "mymoneytransactionfilter.h" class QTreeWidget; class QTreeWidgetItem; class DateRangeDlg; /** * @author Thomas Baumgart */ class KSortOptionDlg : public QDialog { public: KSortOptionDlg(QWidget *parent); ~KSortOptionDlg(); void init(); void setSortOption(const QString& option, const QString& def); QString sortOption() const; void hideDefaultButton(); private: struct Private; Private* const d; }; namespace Ui { class KFindTransactionDlgDecl; } class KFindTransactionDlg : public QDialog { Q_OBJECT public: /** @param withEquityAccounts set to false to hide equity accounts in account page */ - KFindTransactionDlg(QWidget *parent = 0, bool withEquityAccounts=true); + KFindTransactionDlg(QWidget *parent = 0, bool withEquityAccounts = false); ~KFindTransactionDlg(); virtual bool eventFilter(QObject *o, QEvent *e); protected: void resizeEvent(QResizeEvent*); void showEvent(QShowEvent* event); protected slots: virtual void slotReset(); virtual void slotSearch(); /** * This slot opens the detailed help page in khelpcenter. The * anchor for the information is taken from m_helpAnchor. */ virtual void slotShowHelp(); void slotUpdateSelections(); virtual void slotAmountSelected(); virtual void slotAmountRangeSelected(); virtual void slotSelectAllPayees(); virtual void slotDeselectAllPayees(); virtual void slotSelectAllTags(); virtual void slotDeselectAllTags(); virtual void slotNrSelected(); virtual void slotNrRangeSelected(); void slotRefreshView(); /** * This slot selects the current selected transaction/split and emits * the signal @a transactionSelected(const QString& accountId, const QString& transactionId) */ void slotSelectTransaction(); void slotRightSize(); void slotSortOptions(); signals: void transactionSelected(const QString& accountId, const QString& transactionId); /** * This signal is sent out when a selection has been made. It is * used to control the state of the Search button. * The Search button is only active when a selection has been made * (i.e. notEmpty == true) */ void selectionNotEmpty(bool); protected: enum opTypeE { addAccountToFilter = 0, addCategoryToFilter, addPayeeToFilter, addTagToFilter }; void setupCategoriesPage(); void setupAccountsPage(bool withEquityAccounts=false); void setupAmountPage(); void setupPayeesPage(); void setupTagsPage(); void setupDetailsPage(); void setupFilter(); void selectAllItems(QTreeWidget* view, const bool state); void selectAllSubItems(QTreeWidgetItem* item, const bool state); void selectItems(QTreeWidget* view, const QStringList& list, const bool state); void selectSubItems(QTreeWidgetItem* item, const QStringList& list, const bool state); /** * This method loads the m_payeesView with the payees name * found in the engine. */ void loadPayees(); /** * This method loads the m_tagsView with the tags name * found in the engine. */ void loadTags(); /** * This method loads the register with the matching transactions */ void loadView(); /** * This method returns information about the selection state * of the items in the m_accountsView. * * @param view pointer to the listview to scan * * @retval true if all items in the view are marked * @retval false if at least one item is not marked * * @note If the view contains no items the method returns @p true. */ bool allItemsSelected(const QTreeWidget* view) const; bool allItemsSelected(const QTreeWidgetItem *item) const; void scanCheckListItems(const QTreeWidget* view, const opTypeE op); void scanCheckListItems(const QTreeWidgetItem* item, const opTypeE op); void addItemToFilter(const opTypeE op, const QString& id); protected: QDate m_startDates[MyMoneyTransactionFilter::dateOptionCount]; QDate m_endDates[MyMoneyTransactionFilter::dateOptionCount]; /** * This member holds a list of all transactions matching the filter criteria */ QList > m_transactionList; MyMoneyTransactionFilter m_filter; QMap m_helpAnchor; bool m_needReload; Ui::KFindTransactionDlgDecl* m_ui; DateRangeDlg *m_dateRange; }; #endif