Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kfindtransactiondlg_p.h
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | kfindtransactiondlg.cpp | ||||
3 | ------------------- | ||||
4 | copyright : (C) 2003, 2007 by Thomas Baumgart | ||||
5 | email : ipwizard@users.sourceforge.net | ||||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
7 | ***************************************************************************/ | ||||
8 | | ||||
9 | /*************************************************************************** | ||||
10 | * * | ||||
11 | * q program is free software; you can redistribute it and/or modify * | ||||
12 | * it under the terms of the GNU General Public License as published by * | ||||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||||
14 | * (at your option) any later version. * | ||||
15 | * * | ||||
16 | ***************************************************************************/ | ||||
17 | | ||||
18 | #ifndef KFINDTRANSACTIONDLG_P_H | ||||
19 | #define KFINDTRANSACTIONDLG_P_H | ||||
20 | | ||||
21 | #include "kfindtransactiondlg.h" | ||||
22 | | ||||
23 | // ---------------------------------------------------------------------------- | ||||
24 | // QT Includes | ||||
25 | | ||||
26 | #include <QDate> | ||||
27 | #include <QLabel> | ||||
28 | #include <QButtonGroup> | ||||
29 | #include <QRadioButton> | ||||
30 | #include <QCheckBox> | ||||
31 | #include <QTimer> | ||||
32 | #include <QTabWidget> | ||||
33 | #include <QList> | ||||
34 | #include <QPushButton> | ||||
35 | #include <QDialogButtonBox> | ||||
36 | | ||||
37 | // ---------------------------------------------------------------------------- | ||||
38 | // KDE Includes | ||||
39 | | ||||
40 | #include <KLineEdit> | ||||
41 | #include <KComboBox> | ||||
42 | #include <KGuiItem> | ||||
43 | #include <KStandardGuiItem> | ||||
44 | #include <KLocalizedString> | ||||
45 | | ||||
46 | // ---------------------------------------------------------------------------- | ||||
47 | // Project Includes | ||||
48 | | ||||
49 | #include "kmymoneyedit.h" | ||||
50 | #include "mymoneyfile.h" | ||||
51 | #include "mymoneypayee.h" | ||||
52 | #include "mymoneytag.h" | ||||
53 | #include "kmymoneyglobalsettings.h" | ||||
54 | #include "register.h" | ||||
55 | #include "transaction.h" | ||||
56 | #include "daterangedlg.h" | ||||
57 | | ||||
58 | #include "ui_kfindtransactiondlg.h" | ||||
59 | | ||||
60 | class KFindTransactionDlgPrivate | ||||
61 | { | ||||
62 | Q_DISABLE_COPY(KFindTransactionDlgPrivate) | ||||
63 | Q_DECLARE_PUBLIC(KFindTransactionDlg) | ||||
64 | | ||||
65 | public: | ||||
66 | enum opTypeE { | ||||
67 | addAccountToFilter = 0, | ||||
68 | addCategoryToFilter, | ||||
69 | addPayeeToFilter, | ||||
70 | addTagToFilter | ||||
71 | }; | ||||
72 | | ||||
73 | KFindTransactionDlgPrivate(KFindTransactionDlg *qq) : | ||||
74 | q_ptr(qq), | ||||
75 | ui(new Ui::KFindTransactionDlg) | ||||
76 | { | ||||
77 | } | ||||
78 | | ||||
79 | ~KFindTransactionDlgPrivate() | ||||
80 | { | ||||
81 | delete ui; | ||||
82 | } | ||||
83 | | ||||
84 | void init(bool withEquityAccounts) | ||||
85 | { | ||||
86 | Q_Q(KFindTransactionDlg); | ||||
87 | m_needReload = false; | ||||
88 | ui->setupUi(q); | ||||
89 | m_dateRange = new DateRangeDlg; | ||||
90 | ui->dateRangeLayout->insertWidget(0, m_dateRange); | ||||
91 | | ||||
92 | ui->ButtonGroup1->setId(ui->m_amountButton, 0); | ||||
93 | ui->ButtonGroup1->setId(ui->m_amountRangeButton, 1); | ||||
94 | | ||||
95 | ui->m_register->installEventFilter(q); | ||||
96 | ui->m_tabWidget->setTabEnabled(ui->m_tabWidget->indexOf(ui->m_resultPage), false); | ||||
97 | | ||||
98 | // 'cause we don't have a separate setupTextPage | ||||
99 | q->connect(ui->m_textEdit, &QLineEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
100 | // if return is pressed trigger a search (slotSearch checks if it's possible to perform the search) | ||||
101 | q->connect(ui->m_textEdit, &KLineEdit::returnPressed, q, &KFindTransactionDlg::slotSearch); | ||||
102 | // in case the date selection changes, we update the selection | ||||
103 | q->connect(m_dateRange, &DateRangeDlg::rangeChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
104 | | ||||
105 | setupAccountsPage(withEquityAccounts); | ||||
106 | setupCategoriesPage(); | ||||
107 | setupAmountPage(); | ||||
108 | setupPayeesPage(); | ||||
109 | setupTagsPage(); | ||||
110 | setupDetailsPage(); | ||||
111 | | ||||
112 | // We don't need to add the default into the list (see ::slotShowHelp() why) | ||||
113 | // m_helpAnchor[m_ui->m_textTab] = QLatin1String("details.search"); | ||||
114 | m_helpAnchor[ui->m_accountTab] = QLatin1String("details.search.account"); | ||||
115 | m_helpAnchor[ui->m_dateTab] = QLatin1String("details.search.date"); | ||||
116 | m_helpAnchor[ui->m_amountTab] = QLatin1String("details.search.amount"); | ||||
117 | m_helpAnchor[ui->m_categoryTab] = QLatin1String("details.search.category"); | ||||
118 | m_helpAnchor[ui->m_payeeTab] = QLatin1String("details.search.payee"); | ||||
119 | m_helpAnchor[ui->m_tagTab] = QLatin1String("details.search.tag"); //FIXME-ALEX update Help | ||||
120 | m_helpAnchor[ui->m_detailsTab] = QLatin1String("details.search.details"); | ||||
121 | | ||||
122 | // setup the register | ||||
123 | QList<KMyMoneyRegister::Column> cols { | ||||
124 | KMyMoneyRegister::DateColumn, | ||||
125 | KMyMoneyRegister::AccountColumn, | ||||
126 | KMyMoneyRegister::DetailColumn, | ||||
127 | KMyMoneyRegister::ReconcileFlagColumn, | ||||
128 | KMyMoneyRegister::PaymentColumn, | ||||
129 | KMyMoneyRegister::DepositColumn}; | ||||
130 | ui->m_register->setupRegister(MyMoneyAccount(), cols); | ||||
131 | ui->m_register->setSelectionMode(QTableWidget::SingleSelection); | ||||
132 | | ||||
133 | q->connect(ui->m_register, &KMyMoneyRegister::Register::editTransaction, q, &KFindTransactionDlg::slotSelectTransaction); | ||||
134 | q->connect(ui->m_register->horizontalHeader(), &QWidget::customContextMenuRequested, q, &KFindTransactionDlg::slotSortOptions); | ||||
135 | | ||||
136 | q->slotUpdateSelections(); | ||||
137 | | ||||
138 | // setup the connections | ||||
139 | q->connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, q, &KFindTransactionDlg::slotSearch); | ||||
140 | q->connect(ui->buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, q, &KFindTransactionDlg::slotReset); | ||||
141 | q->connect(ui->buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, ui->m_accountsView, &kMyMoneyAccountSelector::slotSelectAllAccounts); | ||||
142 | q->connect(ui->buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, ui->m_categoriesView, &kMyMoneyAccountSelector::slotSelectAllAccounts); | ||||
143 | q->connect(ui->buttonBox->button(QDialogButtonBox::Close), &QAbstractButton::clicked, q, &QObject::deleteLater); | ||||
144 | q->connect(ui->buttonBox->button(QDialogButtonBox::Help), &QAbstractButton::clicked, q, &KFindTransactionDlg::slotShowHelp); | ||||
145 | | ||||
146 | // only allow searches when a selection has been made | ||||
147 | ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); | ||||
148 | KGuiItem::assign(ui->buttonBox->button(QDialogButtonBox::Apply), KStandardGuiItem::find()); | ||||
149 | ui->buttonBox->button(QDialogButtonBox::Apply)->setToolTip(i18nc("@info:tooltip for find transaction apply button", "Search transactions")); | ||||
150 | q->connect(q, &KFindTransactionDlg::selectionNotEmpty, ui->buttonBox->button(QDialogButtonBox::Apply), &QWidget::setEnabled); | ||||
151 | | ||||
152 | // get signal about engine changes | ||||
153 | q->connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, q, &KFindTransactionDlg::slotRefreshView); | ||||
154 | | ||||
155 | q->slotUpdateSelections(); | ||||
156 | | ||||
157 | ui->m_textEdit->setFocus(); | ||||
158 | } | ||||
159 | | ||||
160 | /** | ||||
161 | * q method returns information about the selection state | ||||
162 | * of the items in the m_accountsView. | ||||
163 | * | ||||
164 | * @param view pointer to the listview to scan | ||||
165 | * | ||||
166 | * @retval true if all items in the view are marked | ||||
167 | * @retval false if at least one item is not marked | ||||
168 | * | ||||
169 | * @note If the view contains no items the method returns @p true. | ||||
170 | */ | ||||
171 | bool allItemsSelected(const QTreeWidgetItem *item) const | ||||
172 | { | ||||
173 | QTreeWidgetItem* it_v; | ||||
174 | | ||||
175 | for (auto i = 0; i < item->childCount(); ++i) { | ||||
176 | it_v = item->child(i); | ||||
177 | if (!(it_v->checkState(0) == Qt::Checked && allItemsSelected(it_v))) { | ||||
178 | return false; | ||||
179 | } | ||||
180 | } | ||||
181 | return true; | ||||
182 | } | ||||
183 | | ||||
184 | bool allItemsSelected(const QTreeWidget* view) const | ||||
185 | { | ||||
186 | QTreeWidgetItem* it_v; | ||||
187 | | ||||
188 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | ||||
189 | it_v = view->invisibleRootItem()->child(i); | ||||
190 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | ||||
191 | if (!(it_v->checkState(0) == Qt::Checked && allItemsSelected(it_v))) { | ||||
192 | return false; | ||||
193 | } else { | ||||
194 | if (!allItemsSelected(it_v)) | ||||
195 | return false; | ||||
196 | } | ||||
197 | } | ||||
198 | } | ||||
199 | return true; | ||||
200 | } | ||||
201 | | ||||
202 | void addItemToFilter(const opTypeE op, const QString& id) | ||||
203 | { | ||||
204 | switch (op) { | ||||
205 | case addAccountToFilter: | ||||
206 | m_filter.addAccount(id); | ||||
207 | break; | ||||
208 | case addCategoryToFilter: | ||||
209 | m_filter.addCategory(id); | ||||
210 | break; | ||||
211 | case addPayeeToFilter: | ||||
212 | m_filter.addPayee(id); | ||||
213 | break; | ||||
214 | case addTagToFilter: | ||||
215 | m_filter.addTag(id); | ||||
216 | break; | ||||
217 | } | ||||
218 | } | ||||
219 | | ||||
220 | void scanCheckListItems(const QTreeWidgetItem* item, const opTypeE op) | ||||
221 | { | ||||
222 | QTreeWidgetItem* it_v; | ||||
223 | | ||||
224 | for (auto i = 0; i < item->childCount(); ++i) { | ||||
225 | it_v = item->child(i); | ||||
226 | QVariant idData = it_v->data(0, Qt::UserRole); | ||||
227 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | ||||
228 | if (it_v->checkState(0) == Qt::Checked) | ||||
229 | addItemToFilter(op, idData.toString()); | ||||
230 | } | ||||
231 | scanCheckListItems(it_v, op); | ||||
232 | } | ||||
233 | } | ||||
234 | | ||||
235 | void scanCheckListItems(const QTreeWidget* view, const opTypeE op) | ||||
236 | { | ||||
237 | QTreeWidgetItem* it_v; | ||||
238 | | ||||
239 | for (auto i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | ||||
240 | it_v = view->invisibleRootItem()->child(i); | ||||
241 | QVariant idData = it_v->data(0, Qt::UserRole); | ||||
242 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | ||||
243 | if (it_v->checkState(0) == Qt::Checked) { | ||||
244 | addItemToFilter(op, idData.toString()); | ||||
245 | } | ||||
246 | } | ||||
247 | scanCheckListItems(it_v, op); | ||||
248 | } | ||||
249 | } | ||||
250 | | ||||
251 | void selectAllItems(QTreeWidget* view, const bool state) | ||||
252 | { | ||||
253 | QTreeWidgetItem* it_v; | ||||
254 | | ||||
255 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | ||||
256 | it_v = view->invisibleRootItem()->child(i); | ||||
257 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | ||||
258 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | ||||
259 | } | ||||
260 | selectAllSubItems(it_v, state); | ||||
261 | } | ||||
262 | Q_Q(KFindTransactionDlg); | ||||
263 | q->slotUpdateSelections(); | ||||
264 | } | ||||
265 | | ||||
266 | void selectItems(QTreeWidget* view, const QStringList& list, const bool state) | ||||
267 | { | ||||
268 | QTreeWidgetItem* it_v; | ||||
269 | | ||||
270 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | ||||
271 | it_v = view->invisibleRootItem()->child(i); | ||||
272 | QVariant idData = it_v->data(0, Qt::UserRole); | ||||
273 | if (it_v->flags() & Qt::ItemIsUserCheckable && list.contains(idData.toString())) { | ||||
274 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | ||||
275 | } | ||||
276 | selectSubItems(it_v, list, state); | ||||
277 | } | ||||
278 | | ||||
279 | Q_Q(KFindTransactionDlg); | ||||
280 | q->slotUpdateSelections(); | ||||
281 | } | ||||
282 | | ||||
283 | void selectAllSubItems(QTreeWidgetItem* item, const bool state) | ||||
284 | { | ||||
285 | QTreeWidgetItem* it_v; | ||||
286 | | ||||
287 | for (int i = 0; i < item->childCount(); ++i) { | ||||
288 | it_v = item->child(i); | ||||
289 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | ||||
290 | selectAllSubItems(it_v, state); | ||||
291 | } | ||||
292 | } | ||||
293 | | ||||
294 | void selectSubItems(QTreeWidgetItem* item, const QStringList& list, const bool state) | ||||
295 | { | ||||
296 | QTreeWidgetItem* it_v; | ||||
297 | | ||||
298 | for (int i = 0; i < item->childCount(); ++i) { | ||||
299 | it_v = item->child(i); | ||||
300 | QVariant idData = it_v->data(0, Qt::UserRole); | ||||
301 | if (list.contains(idData.toString())) | ||||
302 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | ||||
303 | selectSubItems(it_v, list, state); | ||||
304 | } | ||||
305 | } | ||||
306 | | ||||
307 | /** | ||||
308 | * q method loads the register with the matching transactions | ||||
309 | */ | ||||
310 | void loadView() | ||||
311 | { | ||||
312 | // setup sort order | ||||
313 | ui->m_register->setSortOrder(KMyMoneyGlobalSettings::sortSearchView()); | ||||
314 | | ||||
315 | // clear out old data | ||||
316 | ui->m_register->clear(); | ||||
317 | | ||||
318 | // retrieve the list from the engine | ||||
319 | MyMoneyFile::instance()->transactionList(m_transactionList, m_filter); | ||||
320 | | ||||
321 | // create the elements for the register | ||||
322 | QList<QPair<MyMoneyTransaction, MyMoneySplit> >::const_iterator it; | ||||
323 | QMap<QString, int>uniqueMap; | ||||
324 | MyMoneyMoney deposit, payment; | ||||
325 | | ||||
326 | int splitCount = 0; | ||||
327 | for (it = m_transactionList.constBegin(); it != m_transactionList.constEnd(); ++it) { | ||||
328 | const MyMoneySplit& split = (*it).second; | ||||
329 | MyMoneyAccount acc = MyMoneyFile::instance()->account(split.accountId()); | ||||
330 | ++splitCount; | ||||
331 | uniqueMap[(*it).first.id()]++; | ||||
332 | | ||||
333 | KMyMoneyRegister::Register::transactionFactory(ui->m_register, (*it).first, (*it).second, uniqueMap[(*it).first.id()]); | ||||
334 | { // debug stuff | ||||
335 | if (split.shares().isNegative()) { | ||||
336 | payment += split.shares().abs(); | ||||
337 | } else { | ||||
338 | deposit += split.shares().abs(); | ||||
339 | } | ||||
340 | } | ||||
341 | } | ||||
342 | | ||||
343 | // add the group markers | ||||
344 | ui->m_register->addGroupMarkers(); | ||||
345 | | ||||
346 | // sort the transactions according to the sort setting | ||||
347 | ui->m_register->sortItems(); | ||||
348 | | ||||
349 | // remove trailing and adjacent markers | ||||
350 | ui->m_register->removeUnwantedGroupMarkers(); | ||||
351 | | ||||
352 | // turn on the ledger lens for the register | ||||
353 | ui->m_register->setLedgerLensForced(); | ||||
354 | | ||||
355 | ui->m_register->updateRegister(true); | ||||
356 | | ||||
357 | ui->m_register->setFocusToTop(); | ||||
358 | ui->m_register->selectItem(ui->m_register->focusItem()); | ||||
359 | | ||||
360 | #ifdef KMM_DEBUG | ||||
361 | ui->m_foundText->setText(i18np("Found %1 matching transaction (D %2 / P %3 = %4)", | ||||
362 | "Found %1 matching transactions (D %2 / P %3 = %4)", splitCount, deposit.formatMoney("", 2), payment.formatMoney("", 2), (deposit - payment).formatMoney("", 2))); | ||||
363 | #else | ||||
364 | ui->m_foundText->setText(i18np("Found %1 matching transaction", "Found %1 matching transactions", splitCount)); | ||||
365 | #endif | ||||
366 | | ||||
367 | ui->m_tabWidget->setTabEnabled(ui->m_tabWidget->indexOf(ui->m_resultPage), true); | ||||
368 | ui->m_tabWidget->setCurrentIndex(ui->m_tabWidget->indexOf(ui->m_resultPage)); | ||||
369 | | ||||
370 | Q_Q(KFindTransactionDlg); | ||||
371 | QTimer::singleShot(10, q, SLOT(slotRightSize())); | ||||
372 | } | ||||
373 | | ||||
374 | /** | ||||
375 | * q method loads the m_tagsView with the tags name | ||||
376 | * found in the engine. | ||||
377 | */ | ||||
378 | void loadTags() | ||||
379 | { | ||||
380 | MyMoneyFile* file = MyMoneyFile::instance(); | ||||
381 | QList<MyMoneyTag> list; | ||||
382 | QList<MyMoneyTag>::Iterator it_l; | ||||
383 | | ||||
384 | list = file->tagList(); | ||||
385 | // load view | ||||
386 | for (it_l = list.begin(); it_l != list.end(); ++it_l) { | ||||
387 | auto item = new QTreeWidgetItem(ui->m_tagsView); | ||||
388 | item->setText(0, (*it_l).name()); | ||||
389 | item->setData(0, Qt::UserRole, (*it_l).id()); | ||||
390 | item->setCheckState(0, Qt::Checked); | ||||
391 | } | ||||
392 | } | ||||
393 | | ||||
394 | /** | ||||
395 | * q method loads the m_payeesView with the payees name | ||||
396 | * found in the engine. | ||||
397 | */ | ||||
398 | void loadPayees() | ||||
399 | { | ||||
400 | MyMoneyFile* file = MyMoneyFile::instance(); | ||||
401 | QList<MyMoneyPayee> list; | ||||
402 | QList<MyMoneyPayee>::Iterator it_l; | ||||
403 | | ||||
404 | list = file->payeeList(); | ||||
405 | // load view | ||||
406 | for (it_l = list.begin(); it_l != list.end(); ++it_l) { | ||||
407 | auto item = new QTreeWidgetItem(ui->m_payeesView); | ||||
408 | item->setText(0, (*it_l).name()); | ||||
409 | item->setData(0, Qt::UserRole, (*it_l).id()); | ||||
410 | item->setCheckState(0, Qt::Checked); | ||||
411 | } | ||||
412 | } | ||||
413 | | ||||
414 | void setupFilter() | ||||
415 | { | ||||
416 | m_filter.clear(); | ||||
417 | | ||||
418 | // Text tab | ||||
419 | if (!ui->m_textEdit->text().isEmpty()) { | ||||
420 | QRegExp exp(ui->m_textEdit->text(), ui->m_caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, !ui->m_regExp->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp); | ||||
421 | m_filter.setTextFilter(exp, ui->m_textNegate->currentIndex() != 0); | ||||
422 | } | ||||
423 | | ||||
424 | // Account tab | ||||
425 | if (!ui->m_accountsView->allItemsSelected()) { | ||||
426 | // retrieve a list of selected accounts | ||||
427 | QStringList list; | ||||
428 | ui->m_accountsView->selectedItems(list); | ||||
429 | | ||||
430 | // if we're not in expert mode, we need to make sure | ||||
431 | // that all stock accounts for the selected investment | ||||
432 | // account are also selected | ||||
433 | if (!KMyMoneyGlobalSettings::expertMode()) { | ||||
434 | QStringList missing; | ||||
435 | QStringList::const_iterator it_a, it_b; | ||||
436 | for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { | ||||
437 | MyMoneyAccount acc = MyMoneyFile::instance()->account(*it_a); | ||||
438 | if (acc.accountType() == eMyMoney::Account::Investment) { | ||||
439 | for (it_b = acc.accountList().constBegin(); it_b != acc.accountList().constEnd(); ++it_b) { | ||||
440 | if (!list.contains(*it_b)) { | ||||
441 | missing.append(*it_b); | ||||
442 | } | ||||
443 | } | ||||
444 | } | ||||
445 | } | ||||
446 | list += missing; | ||||
447 | } | ||||
448 | | ||||
449 | m_filter.addAccount(list); | ||||
450 | } | ||||
451 | | ||||
452 | // Date tab | ||||
453 | if ((int)m_dateRange->dateRange() != 0) { | ||||
454 | m_filter.setDateFilter(m_dateRange->fromDate(), m_dateRange->toDate()); | ||||
455 | } | ||||
456 | | ||||
457 | // Amount tab | ||||
458 | if ((ui->m_amountButton->isChecked() && ui->m_amountEdit->isValid())) { | ||||
459 | m_filter.setAmountFilter(ui->m_amountEdit->value(), ui->m_amountEdit->value()); | ||||
460 | | ||||
461 | } else if ((ui->m_amountRangeButton->isChecked() | ||||
462 | && (ui->m_amountFromEdit->isValid() || ui->m_amountToEdit->isValid()))) { | ||||
463 | | ||||
464 | MyMoneyMoney from(MyMoneyMoney::minValue), to(MyMoneyMoney::maxValue); | ||||
465 | if (ui->m_amountFromEdit->isValid()) | ||||
466 | from = ui->m_amountFromEdit->value(); | ||||
467 | if (ui->m_amountToEdit->isValid()) | ||||
468 | to = ui->m_amountToEdit->value(); | ||||
469 | | ||||
470 | m_filter.setAmountFilter(from, to); | ||||
471 | } | ||||
472 | | ||||
473 | // Categories tab | ||||
474 | if (!ui->m_categoriesView->allItemsSelected()) { | ||||
475 | m_filter.addCategory(ui->m_categoriesView->selectedItems()); | ||||
476 | } | ||||
477 | | ||||
478 | // Tags tab | ||||
479 | if (ui->m_emptyTagsButton->isChecked()) { | ||||
480 | m_filter.addTag(QString()); | ||||
481 | | ||||
482 | } else if (!allItemsSelected(ui->m_tagsView)) { | ||||
483 | scanCheckListItems(ui->m_tagsView, addTagToFilter); | ||||
484 | } | ||||
485 | | ||||
486 | // Payees tab | ||||
487 | if (ui->m_emptyPayeesButton->isChecked()) { | ||||
488 | m_filter.addPayee(QString()); | ||||
489 | | ||||
490 | } else if (!allItemsSelected(ui->m_payeesView)) { | ||||
491 | scanCheckListItems(ui->m_payeesView, addPayeeToFilter); | ||||
492 | } | ||||
493 | | ||||
494 | // Details tab | ||||
495 | if (ui->m_typeBox->currentIndex() != 0) | ||||
496 | m_filter.addType(ui->m_typeBox->currentIndex()); | ||||
497 | | ||||
498 | if (ui->m_stateBox->currentIndex() != 0) | ||||
499 | m_filter.addState(ui->m_stateBox->currentIndex()); | ||||
500 | | ||||
501 | if (ui->m_validityBox->currentIndex() != 0) | ||||
502 | m_filter.addValidity(ui->m_validityBox->currentIndex()); | ||||
503 | | ||||
504 | if (ui->m_nrButton->isChecked() && !ui->m_nrEdit->text().isEmpty()) | ||||
505 | m_filter.setNumberFilter(ui->m_nrEdit->text(), ui->m_nrEdit->text()); | ||||
506 | | ||||
507 | if (ui->m_nrRangeButton->isChecked() | ||||
508 | && (!ui->m_nrFromEdit->text().isEmpty() || !ui->m_nrToEdit->text().isEmpty())) { | ||||
509 | m_filter.setNumberFilter(ui->m_nrFromEdit->text(), ui->m_nrToEdit->text()); | ||||
510 | } | ||||
511 | } | ||||
512 | | ||||
513 | void setupDetailsPage() | ||||
514 | { | ||||
515 | Q_Q(KFindTransactionDlg); | ||||
516 | q->connect(ui->m_typeBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), q, &KFindTransactionDlg::slotUpdateSelections); | ||||
517 | q->connect(ui->m_stateBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), q, &KFindTransactionDlg::slotUpdateSelections); | ||||
518 | q->connect(ui->m_validityBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), q, &KFindTransactionDlg::slotUpdateSelections); | ||||
519 | | ||||
520 | q->connect(ui->m_nrButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotNrSelected); | ||||
521 | q->connect(ui->m_nrRangeButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotNrRangeSelected); | ||||
522 | q->connect(ui->m_nrEdit, &QLineEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
523 | q->connect(ui->m_nrFromEdit, &QLineEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
524 | q->connect(ui->m_nrToEdit, &QLineEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
525 | | ||||
526 | ui->m_nrButton->setChecked(true); | ||||
527 | q->slotNrSelected(); | ||||
528 | } | ||||
529 | | ||||
530 | void setupTagsPage() | ||||
531 | { | ||||
532 | Q_Q(KFindTransactionDlg); | ||||
533 | ui->m_tagsView->setSelectionMode(QAbstractItemView::SingleSelection); | ||||
534 | ui->m_tagsView->header()->hide(); | ||||
535 | ui->m_tagsView->setAlternatingRowColors(true); | ||||
536 | | ||||
537 | loadTags(); | ||||
538 | | ||||
539 | ui->m_tagsView->sortItems(0, Qt::AscendingOrder); | ||||
540 | ui->m_emptyTagsButton->setCheckState(Qt::Unchecked); | ||||
541 | | ||||
542 | q->connect(ui->m_allTagsButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotSelectAllTags); | ||||
543 | q->connect(ui->m_clearTagsButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotDeselectAllTags); | ||||
544 | q->connect(ui->m_emptyTagsButton, &QCheckBox::stateChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
545 | q->connect(ui->m_tagsView, &QTreeWidget::itemChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
546 | } | ||||
547 | | ||||
548 | void setupPayeesPage() | ||||
549 | { | ||||
550 | Q_Q(KFindTransactionDlg); | ||||
551 | ui->m_payeesView->setSelectionMode(QAbstractItemView::SingleSelection); | ||||
552 | ui->m_payeesView->header()->hide(); | ||||
553 | ui->m_payeesView->setAlternatingRowColors(true); | ||||
554 | | ||||
555 | loadPayees(); | ||||
556 | | ||||
557 | ui->m_payeesView->sortItems(0, Qt::AscendingOrder); | ||||
558 | ui->m_emptyPayeesButton->setCheckState(Qt::Unchecked); | ||||
559 | | ||||
560 | q->connect(ui->m_allPayeesButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotSelectAllPayees); | ||||
561 | q->connect(ui->m_clearPayeesButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotDeselectAllPayees); | ||||
562 | q->connect(ui->m_emptyPayeesButton, &QCheckBox::stateChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
563 | q->connect(ui->m_payeesView, &QTreeWidget::itemChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
564 | } | ||||
565 | | ||||
566 | void setupAmountPage() | ||||
567 | { | ||||
568 | Q_Q(KFindTransactionDlg); | ||||
569 | q->connect(ui->m_amountButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotAmountSelected); | ||||
570 | q->connect(ui->m_amountRangeButton, &QAbstractButton::clicked, q, &KFindTransactionDlg::slotAmountRangeSelected); | ||||
571 | | ||||
572 | q->connect(ui->m_amountEdit, &kMyMoneyEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
573 | q->connect(ui->m_amountFromEdit, &kMyMoneyEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
574 | q->connect(ui->m_amountToEdit, &kMyMoneyEdit::textChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
575 | | ||||
576 | ui->m_amountButton->setChecked(true); | ||||
577 | q->slotAmountSelected(); | ||||
578 | } | ||||
579 | | ||||
580 | void setupCategoriesPage() | ||||
581 | { | ||||
582 | Q_Q(KFindTransactionDlg); | ||||
583 | ui->m_categoriesView->setSelectionMode(QTreeWidget::MultiSelection); | ||||
584 | AccountSet categorySet; | ||||
585 | categorySet.addAccountGroup(eMyMoney::Account::Income); | ||||
586 | categorySet.addAccountGroup(eMyMoney::Account::Expense); | ||||
587 | categorySet.load(ui->m_categoriesView); | ||||
588 | q->connect(ui->m_categoriesView, &kMyMoneyAccountSelector::stateChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
589 | } | ||||
590 | | ||||
591 | void setupAccountsPage(bool withEquityAccounts) | ||||
592 | { | ||||
593 | Q_Q(KFindTransactionDlg); | ||||
594 | ui->m_accountsView->setSelectionMode(QTreeWidget::MultiSelection); | ||||
595 | AccountSet accountSet; | ||||
596 | accountSet.addAccountGroup(eMyMoney::Account::Asset); | ||||
597 | accountSet.addAccountGroup(eMyMoney::Account::Liability); | ||||
598 | | ||||
599 | if (withEquityAccounts) | ||||
600 | accountSet.addAccountGroup(eMyMoney::Account::Equity); | ||||
601 | | ||||
602 | //set the accountset to show closed account if the settings say so | ||||
603 | accountSet.setHideClosedAccounts(KMyMoneyGlobalSettings::hideClosedAccounts()); | ||||
604 | accountSet.load(ui->m_accountsView); | ||||
605 | q->connect(ui->m_accountsView, &kMyMoneyAccountSelector::stateChanged, q, &KFindTransactionDlg::slotUpdateSelections); | ||||
606 | } | ||||
607 | | ||||
608 | KFindTransactionDlg *q_ptr; | ||||
609 | Ui::KFindTransactionDlg *ui; | ||||
610 | QDate m_startDates[(int)eMyMoney::TransactionFilter::Date::LastDateItem]; | ||||
611 | QDate m_endDates[(int)eMyMoney::TransactionFilter::Date::LastDateItem]; | ||||
612 | | ||||
613 | /** | ||||
614 | * q member holds a list of all transactions matching the filter criteria | ||||
615 | */ | ||||
616 | QList<QPair<MyMoneyTransaction, MyMoneySplit> > m_transactionList; | ||||
617 | | ||||
618 | MyMoneyTransactionFilter m_filter; | ||||
619 | | ||||
620 | QMap<QWidget*, QString> m_helpAnchor; | ||||
621 | | ||||
622 | bool m_needReload; | ||||
623 | DateRangeDlg *m_dateRange; | ||||
624 | | ||||
625 | }; | ||||
626 | | ||||
627 | #endif |