Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kmymoneysplittable.cpp
Context not available. | |||||
9 | John C <thetacoturtle@users.sourceforge.net> | 9 | John C <thetacoturtle@users.sourceforge.net> | ||
---|---|---|---|---|---|
10 | Thomas Baumgart <ipwizard@users.sourceforge.net> | 10 | Thomas Baumgart <ipwizard@users.sourceforge.net> | ||
11 | Kevin Tambascio <ktambascio@users.sourceforge.net> | 11 | Kevin Tambascio <ktambascio@users.sourceforge.net> | ||
12 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
12 | ***************************************************************************/ | 13 | ***************************************************************************/ | ||
13 | 14 | | |||
14 | /*************************************************************************** | 15 | /*************************************************************************** | ||
Context not available. | |||||
36 | #include <QPushButton> | 37 | #include <QPushButton> | ||
37 | #include <QMenu> | 38 | #include <QMenu> | ||
38 | #include <QIcon> | 39 | #include <QIcon> | ||
40 | #include <QHeaderView> | ||||
41 | #include <QPointer> | ||||
42 | #include <QList> | ||||
39 | 43 | | |||
40 | // ---------------------------------------------------------------------------- | 44 | // ---------------------------------------------------------------------------- | ||
41 | // KDE Includes | 45 | // KDE Includes | ||
Context not available. | |||||
48 | // ---------------------------------------------------------------------------- | 52 | // ---------------------------------------------------------------------------- | ||
49 | // Project Includes | 53 | // Project Includes | ||
50 | 54 | | |||
55 | #include "mymoneysplit.h" | ||||
56 | #include "mymoneytransaction.h" | ||||
57 | #include "mymoneyaccount.h" | ||||
51 | #include "mymoneyfile.h" | 58 | #include "mymoneyfile.h" | ||
52 | #include "mymoneyprice.h" | 59 | #include "mymoneyprice.h" | ||
53 | #include "kmymoneyedit.h" | 60 | #include "kmymoneyedit.h" | ||
Context not available. | |||||
62 | 69 | | |||
63 | using namespace Icons; | 70 | using namespace Icons; | ||
64 | 71 | | |||
65 | kMyMoneySplitTable::kMyMoneySplitTable(QWidget *parent) : | 72 | class KMyMoneySplitTablePrivate | ||
66 | QTableWidget(parent), | 73 | { | ||
74 | Q_DISABLE_COPY(KMyMoneySplitTablePrivate) | ||||
75 | | ||||
76 | public: | ||||
77 | KMyMoneySplitTablePrivate() : | ||||
67 | m_currentRow(0), | 78 | m_currentRow(0), | ||
68 | m_maxRows(0), | 79 | m_maxRows(0), | ||
69 | m_precision(2), | 80 | m_precision(2), | ||
70 | m_editCategory(0), | 81 | m_editCategory(0), | ||
71 | m_editMemo(0), | 82 | m_editMemo(0), | ||
72 | m_editAmount(0) | 83 | m_editAmount(0) | ||
84 | { | ||||
85 | } | ||||
86 | | ||||
87 | ~KMyMoneySplitTablePrivate() | ||||
88 | { | ||||
89 | } | ||||
90 | | ||||
91 | /// the currently selected row (will be printed as selected) | ||||
92 | int m_currentRow; | ||||
93 | | ||||
94 | /// the number of rows filled with data | ||||
95 | int m_maxRows; | ||||
96 | | ||||
97 | MyMoneyTransaction m_transaction; | ||||
98 | MyMoneyAccount m_account; | ||||
99 | MyMoneySplit m_split; | ||||
100 | MyMoneySplit m_hiddenSplit; | ||||
101 | | ||||
102 | /** | ||||
103 | * This member keeps the precision for the values | ||||
104 | */ | ||||
105 | int m_precision; | ||||
106 | | ||||
107 | /** | ||||
108 | * This member keeps a pointer to the context menu | ||||
109 | */ | ||||
110 | QMenu* m_contextMenu; | ||||
111 | | ||||
112 | /// keeps the QAction of the delete entry in the context menu | ||||
113 | QAction* m_contextMenuDelete; | ||||
114 | | ||||
115 | /// keeps the QAction of the duplicate entry in the context menu | ||||
116 | QAction* m_contextMenuDuplicate; | ||||
117 | | ||||
118 | /** | ||||
119 | * This member contains a pointer to the input widget for the category. | ||||
120 | * The widget will be created and destroyed dynamically in createInputWidgets() | ||||
121 | * and destroyInputWidgets(). | ||||
122 | */ | ||||
123 | QPointer<KMyMoneyCategory> m_editCategory; | ||||
124 | | ||||
125 | /** | ||||
126 | * This member contains a pointer to the input widget for the memo. | ||||
127 | * The widget will be created and destroyed dynamically in createInputWidgets() | ||||
128 | * and destroyInputWidgets(). | ||||
129 | */ | ||||
130 | QPointer<kMyMoneyLineEdit> m_editMemo; | ||||
131 | | ||||
132 | /** | ||||
133 | * This member contains a pointer to the input widget for the amount. | ||||
134 | * The widget will be created and destroyed dynamically in createInputWidgets() | ||||
135 | * and destroyInputWidgets(). | ||||
136 | */ | ||||
137 | QPointer<kMyMoneyEdit> m_editAmount; | ||||
138 | | ||||
139 | /** | ||||
140 | * This member keeps the tab order for the above widgets | ||||
141 | */ | ||||
142 | QWidgetList m_tabOrderWidgets; | ||||
143 | | ||||
144 | QPointer<QFrame> m_registerButtonFrame; | ||||
145 | QPointer<QPushButton> m_registerEnterButton; | ||||
146 | QPointer<QPushButton> m_registerCancelButton; | ||||
147 | | ||||
148 | QMap<QString, MyMoneyMoney> m_priceInfo; | ||||
149 | }; | ||||
150 | | ||||
151 | KMyMoneySplitTable::KMyMoneySplitTable(QWidget *parent) : | ||||
152 | QTableWidget(parent), | ||||
153 | d_ptr(new KMyMoneySplitTablePrivate) | ||||
73 | { | 154 | { | ||
155 | Q_D(KMyMoneySplitTable); | ||||
74 | // used for custom coloring with the help of the application's stylesheet | 156 | // used for custom coloring with the help of the application's stylesheet | ||
75 | setObjectName(QLatin1String("splittable")); | 157 | setObjectName(QLatin1String("splittable")); | ||
76 | 158 | | |||
Context not available. | |||||
105 | setEditTriggers(QAbstractItemView::NoEditTriggers); | 187 | setEditTriggers(QAbstractItemView::NoEditTriggers); | ||
106 | 188 | | |||
107 | // setup the context menu | 189 | // setup the context menu | ||
108 | m_contextMenu = new QMenu(this); | 190 | d->m_contextMenu = new QMenu(this); | ||
109 | m_contextMenu->setTitle(i18n("Split Options")); | 191 | d->m_contextMenu->setTitle(i18n("Split Options")); | ||
110 | m_contextMenu->setIcon(QIcon::fromTheme(g_Icons[Icon::ViewFinancialTransfer])); | 192 | d->m_contextMenu->setIcon(QIcon::fromTheme(g_Icons[Icon::ViewFinancialTransfer])); | ||
111 | m_contextMenu->addAction(QIcon::fromTheme(g_Icons[Icon::DocumentEdit]), i18n("Edit..."), this, SLOT(slotStartEdit())); | 193 | d->m_contextMenu->addAction(QIcon::fromTheme(g_Icons[Icon::DocumentEdit]), i18n("Edit..."), this, SLOT(slotStartEdit())); | ||
112 | m_contextMenuDuplicate = m_contextMenu->addAction(QIcon::fromTheme(g_Icons[Icon::EditCopy]), i18nc("To duplicate a split", "Duplicate"), this, SLOT(slotDuplicateSplit())); | 194 | d->m_contextMenuDuplicate = d->m_contextMenu->addAction(QIcon::fromTheme(g_Icons[Icon::EditCopy]), i18nc("To duplicate a split", "Duplicate"), this, SLOT(slotDuplicateSplit())); | ||
113 | m_contextMenuDelete = m_contextMenu->addAction(QIcon::fromTheme(g_Icons[Icon::EditDelete]), | 195 | d->m_contextMenuDelete = d->m_contextMenu->addAction(QIcon::fromTheme(g_Icons[Icon::EditDelete]), | ||
114 | i18n("Delete..."), | 196 | i18n("Delete..."), | ||
115 | this, SLOT(slotDeleteSplit())); | 197 | this, SLOT(slotDeleteSplit())); | ||
116 | 198 | | |||
117 | connect(this, SIGNAL(clicked(QModelIndex)), | 199 | connect(this, &QAbstractItemView::clicked, | ||
118 | this, SLOT(slotSetFocus(QModelIndex))); | 200 | this, static_cast<void (KMyMoneySplitTable::*)(const QModelIndex&)>(&KMyMoneySplitTable::slotSetFocus)); | ||
119 | 201 | | |||
120 | connect(this, SIGNAL(transactionChanged(MyMoneyTransaction)), | 202 | connect(this, &KMyMoneySplitTable::transactionChanged, | ||
121 | this, SLOT(slotUpdateData(MyMoneyTransaction))); | 203 | this, &KMyMoneySplitTable::slotUpdateData); | ||
122 | 204 | | |||
123 | installEventFilter(this); | 205 | installEventFilter(this); | ||
124 | } | 206 | } | ||
125 | 207 | | |||
126 | kMyMoneySplitTable::~kMyMoneySplitTable() | 208 | KMyMoneySplitTable::~KMyMoneySplitTable() | ||
127 | { | 209 | { | ||
128 | KConfigGroup grp = KSharedConfig::openConfig()->group("SplitTable"); | 210 | Q_D(KMyMoneySplitTable); | ||
211 | auto grp = KSharedConfig::openConfig()->group("SplitTable"); | ||||
129 | QByteArray columns = horizontalHeader()->saveState(); | 212 | QByteArray columns = horizontalHeader()->saveState(); | ||
130 | grp.writeEntry("HeaderState", columns); | 213 | grp.writeEntry("HeaderState", columns); | ||
131 | grp.sync(); | 214 | grp.sync(); | ||
215 | delete d; | ||||
132 | } | 216 | } | ||
133 | 217 | | |||
134 | int kMyMoneySplitTable::currentRow() const | 218 | int KMyMoneySplitTable::currentRow() const | ||
135 | { | 219 | { | ||
136 | return m_currentRow; | 220 | Q_D(const KMyMoneySplitTable); | ||
221 | return d->m_currentRow; | ||||
137 | } | 222 | } | ||
138 | 223 | | |||
139 | void kMyMoneySplitTable::setup(const QMap<QString, MyMoneyMoney>& priceInfo, int precision) | 224 | void KMyMoneySplitTable::setup(const QMap<QString, MyMoneyMoney>& priceInfo, int precision) | ||
140 | { | 225 | { | ||
141 | m_priceInfo = priceInfo; | 226 | Q_D(KMyMoneySplitTable); | ||
142 | m_precision = precision; | 227 | d->m_priceInfo = priceInfo; | ||
228 | d->m_precision = precision; | ||||
143 | } | 229 | } | ||
144 | 230 | | |||
145 | bool kMyMoneySplitTable::eventFilter(QObject *o, QEvent *e) | 231 | bool KMyMoneySplitTable::eventFilter(QObject *o, QEvent *e) | ||
146 | { | 232 | { | ||
233 | Q_D(KMyMoneySplitTable); | ||||
147 | // MYMONEYTRACER(tracer); | 234 | // MYMONEYTRACER(tracer); | ||
148 | QKeyEvent *k = static_cast<QKeyEvent *>(e); | 235 | QKeyEvent *k = static_cast<QKeyEvent *>(e); | ||
149 | bool rc = false; | 236 | bool rc = false; | ||
Context not available. | |||||
159 | break; | 246 | break; | ||
160 | 247 | | |||
161 | case Qt::Key_Down: | 248 | case Qt::Key_Down: | ||
162 | if (row < m_transaction.splits().count() - 1) | 249 | if (row < d->m_transaction.splits().count() - 1) | ||
163 | slotSetFocus(model()->index(row + 1, 0)); | 250 | slotSetFocus(model()->index(row + 1, 0)); | ||
164 | break; | 251 | break; | ||
165 | 252 | | |||
Context not available. | |||||
168 | break; | 255 | break; | ||
169 | 256 | | |||
170 | case Qt::Key_End: | 257 | case Qt::Key_End: | ||
171 | slotSetFocus(model()->index(m_transaction.splits().count() - 1, 0)); | 258 | slotSetFocus(model()->index(d->m_transaction.splits().count() - 1, 0)); | ||
172 | break; | 259 | break; | ||
173 | 260 | | |||
174 | case Qt::Key_PageUp: | 261 | case Qt::Key_PageUp: | ||
Context not available. | |||||
180 | break; | 267 | break; | ||
181 | 268 | | |||
182 | case Qt::Key_PageDown: | 269 | case Qt::Key_PageDown: | ||
183 | if (row < m_transaction.splits().count() - 1) { | 270 | if (row < d->m_transaction.splits().count() - 1) { | ||
184 | while (lines-- > 0 && row < m_transaction.splits().count() - 1) | 271 | while (lines-- > 0 && row < d->m_transaction.splits().count() - 1) | ||
185 | ++row; | 272 | ++row; | ||
186 | slotSetFocus(model()->index(row, 0)); | 273 | slotSetFocus(model()->index(row, 0)); | ||
187 | } | 274 | } | ||
Context not available. | |||||
193 | 280 | | |||
194 | case Qt::Key_Return: | 281 | case Qt::Key_Return: | ||
195 | case Qt::Key_Enter: | 282 | case Qt::Key_Enter: | ||
196 | if (row < m_transaction.splits().count() - 1 | 283 | if (row < d->m_transaction.splits().count() - 1 | ||
197 | && KMyMoneyGlobalSettings::enterMovesBetweenFields()) { | 284 | && KMyMoneyGlobalSettings::enterMovesBetweenFields()) { | ||
198 | slotStartEdit(); | 285 | slotStartEdit(); | ||
199 | } else | 286 | } else | ||
Context not available. | |||||
217 | 304 | | |||
218 | // new split | 305 | // new split | ||
219 | } else if (Qt::Key_Insert == k->key() && Qt::ControlModifier == k->modifiers()) { | 306 | } else if (Qt::Key_Insert == k->key() && Qt::ControlModifier == k->modifiers()) { | ||
220 | slotSetFocus(model()->index(m_transaction.splits().count() - 1, 0)); | 307 | slotSetFocus(model()->index(d->m_transaction.splits().count() - 1, 0)); | ||
221 | slotStartEdit(); | 308 | slotStartEdit(); | ||
222 | 309 | | |||
223 | } else if (k->text()[ 0 ].isPrint()) { | 310 | } else if (k->text()[ 0 ].isPrint()) { | ||
Context not available. | |||||
271 | // in case we have the 'enter moves focus between fields', we need to simulate | 358 | // in case we have the 'enter moves focus between fields', we need to simulate | ||
272 | // a TAB key when the object 'o' points to the category or memo field. | 359 | // a TAB key when the object 'o' points to the category or memo field. | ||
273 | if (KMyMoneyGlobalSettings::enterMovesBetweenFields()) { | 360 | if (KMyMoneyGlobalSettings::enterMovesBetweenFields()) { | ||
274 | if (o == m_editCategory->lineEdit() || o == m_editMemo) { | 361 | if (o == d->m_editCategory->lineEdit() || o == d->m_editMemo) { | ||
275 | terminate = false; | 362 | terminate = false; | ||
276 | QKeyEvent evt(e->type(), | 363 | QKeyEvent evt(e->type(), | ||
277 | Qt::Key_Tab, k->modifiers(), QString(), | 364 | Qt::Key_Tab, k->modifiers(), QString(), | ||
Context not available. | |||||
305 | case Qt::Key_Menu: | 392 | case Qt::Key_Menu: | ||
306 | // if the very last entry is selected, the delete | 393 | // if the very last entry is selected, the delete | ||
307 | // operation is not available otherwise it is | 394 | // operation is not available otherwise it is | ||
308 | m_contextMenuDelete->setEnabled( | 395 | d->m_contextMenuDelete->setEnabled( | ||
309 | row < m_transaction.splits().count() - 1); | 396 | row < d->m_transaction.splits().count() - 1); | ||
310 | m_contextMenuDuplicate->setEnabled( | 397 | d->m_contextMenuDuplicate->setEnabled( | ||
311 | row < m_transaction.splits().count() - 1); | 398 | row < d->m_transaction.splits().count() - 1); | ||
312 | 399 | | |||
313 | m_contextMenu->exec(QCursor::pos()); | 400 | d->m_contextMenu->exec(QCursor::pos()); | ||
314 | rc = true; | 401 | rc = true; | ||
315 | break; | 402 | break; | ||
316 | default: | 403 | default: | ||
Context not available. | |||||
330 | return rc; | 417 | return rc; | ||
331 | } | 418 | } | ||
332 | 419 | | |||
333 | void kMyMoneySplitTable::slotSetFocus(const QModelIndex& index, int button) | 420 | void KMyMoneySplitTable::slotSetFocus(const QModelIndex& index) | ||
421 | { | ||||
422 | slotSetFocus(index, Qt::LeftButton); | ||||
423 | } | ||||
424 | | ||||
425 | void KMyMoneySplitTable::slotSetFocus(const QModelIndex& index, int button) | ||||
334 | { | 426 | { | ||
427 | Q_D(KMyMoneySplitTable); | ||||
335 | MYMONEYTRACER(tracer); | 428 | MYMONEYTRACER(tracer); | ||
336 | int row = index.row(); | 429 | auto row = index.row(); | ||
337 | 430 | | |||
338 | // adjust row to used area | 431 | // adjust row to used area | ||
339 | if (row > m_transaction.splits().count() - 1) | 432 | if (row > d->m_transaction.splits().count() - 1) | ||
340 | row = m_transaction.splits().count() - 1; | 433 | row = d->m_transaction.splits().count() - 1; | ||
341 | if (row < 0) | 434 | if (row < 0) | ||
342 | row = 0; | 435 | row = 0; | ||
343 | 436 | | |||
Context not available. | |||||
355 | if (row != currentRow()) { | 448 | if (row != currentRow()) { | ||
356 | // setup new current row and update visible selection | 449 | // setup new current row and update visible selection | ||
357 | selectRow(row); | 450 | selectRow(row); | ||
358 | slotUpdateData(m_transaction); | 451 | slotUpdateData(d->m_transaction); | ||
359 | } | 452 | } | ||
360 | } else if (button == Qt::RightButton) { | 453 | } else if (button == Qt::RightButton) { | ||
361 | // context menu is only available when cursor is on | 454 | // context menu is only available when cursor is on | ||
Context not available. | |||||
363 | if (row == index.row()) { | 456 | if (row == index.row()) { | ||
364 | // setup new current row and update visible selection | 457 | // setup new current row and update visible selection | ||
365 | selectRow(row); | 458 | selectRow(row); | ||
366 | slotUpdateData(m_transaction); | 459 | slotUpdateData(d->m_transaction); | ||
367 | 460 | | |||
368 | // if the very last entry is selected, the delete | 461 | // if the very last entry is selected, the delete | ||
369 | // operation is not available otherwise it is | 462 | // operation is not available otherwise it is | ||
370 | m_contextMenuDelete->setEnabled( | 463 | d->m_contextMenuDelete->setEnabled( | ||
371 | row < m_transaction.splits().count() - 1); | 464 | row < d->m_transaction.splits().count() - 1); | ||
372 | m_contextMenuDuplicate->setEnabled( | 465 | d->m_contextMenuDuplicate->setEnabled( | ||
373 | row < m_transaction.splits().count() - 1); | 466 | row < d->m_transaction.splits().count() - 1); | ||
374 | 467 | | |||
375 | m_contextMenu->exec(QCursor::pos()); | 468 | d->m_contextMenu->exec(QCursor::pos()); | ||
376 | } | 469 | } | ||
377 | } | 470 | } | ||
378 | } | 471 | } | ||
379 | 472 | | |||
380 | void kMyMoneySplitTable::mousePressEvent(QMouseEvent* e) | 473 | void KMyMoneySplitTable::mousePressEvent(QMouseEvent* e) | ||
381 | { | 474 | { | ||
382 | slotSetFocus(indexAt(e->pos()), e->button()); | 475 | slotSetFocus(indexAt(e->pos()), e->button()); | ||
383 | } | 476 | } | ||
384 | 477 | | |||
385 | /* turn off QTable behaviour */ | 478 | /* turn off QTable behaviour */ | ||
386 | void kMyMoneySplitTable::mouseReleaseEvent(QMouseEvent* /* e */) | 479 | void KMyMoneySplitTable::mouseReleaseEvent(QMouseEvent* /* e */) | ||
387 | { | 480 | { | ||
388 | } | 481 | } | ||
389 | 482 | | |||
390 | void kMyMoneySplitTable::mouseDoubleClickEvent(QMouseEvent *e) | 483 | void KMyMoneySplitTable::mouseDoubleClickEvent(QMouseEvent *e) | ||
391 | { | 484 | { | ||
485 | Q_D(KMyMoneySplitTable); | ||||
392 | MYMONEYTRACER(tracer); | 486 | MYMONEYTRACER(tracer); | ||
393 | 487 | | |||
394 | int col = columnAt(e->pos().x()); | 488 | int col = columnAt(e->pos().x()); | ||
Context not available. | |||||
398 | QLineEdit* editWidget = 0; //krazy:exclude=qmethods | 492 | QLineEdit* editWidget = 0; //krazy:exclude=qmethods | ||
399 | switch (col) { | 493 | switch (col) { | ||
400 | case 0: | 494 | case 0: | ||
401 | editWidget = m_editCategory->lineEdit(); | 495 | editWidget = d->m_editCategory->lineEdit(); | ||
402 | break; | 496 | break; | ||
403 | 497 | | |||
404 | case 1: | 498 | case 1: | ||
405 | editWidget = m_editMemo; | 499 | editWidget = d->m_editMemo; | ||
406 | break; | 500 | break; | ||
407 | 501 | | |||
408 | case 2: | 502 | case 2: | ||
409 | editWidget = m_editAmount->lineedit(); | 503 | editWidget = d->m_editAmount->lineedit(); | ||
410 | break; | 504 | break; | ||
411 | 505 | | |||
412 | default: | 506 | default: | ||
Context not available. | |||||
418 | } | 512 | } | ||
419 | } | 513 | } | ||
420 | 514 | | |||
421 | void kMyMoneySplitTable::selectRow(int row) | 515 | void KMyMoneySplitTable::selectRow(int row) | ||
422 | { | 516 | { | ||
517 | Q_D(KMyMoneySplitTable); | ||||
423 | MYMONEYTRACER(tracer); | 518 | MYMONEYTRACER(tracer); | ||
424 | 519 | | |||
425 | if (row > m_maxRows) | 520 | if (row > d->m_maxRows) | ||
426 | row = m_maxRows; | 521 | row = d->m_maxRows; | ||
427 | m_currentRow = row; | 522 | d->m_currentRow = row; | ||
428 | QTableWidget::selectRow(row); | 523 | QTableWidget::selectRow(row); | ||
429 | QList<MyMoneySplit> list = getSplits(m_transaction); | 524 | QList<MyMoneySplit> list = getSplits(d->m_transaction); | ||
430 | if (row < list.count()) | 525 | if (row < list.count()) | ||
431 | m_split = list[row]; | 526 | d->m_split = list[row]; | ||
432 | else | 527 | else | ||
433 | m_split = MyMoneySplit(); | 528 | d->m_split = MyMoneySplit(); | ||
434 | } | 529 | } | ||
435 | 530 | | |||
436 | void kMyMoneySplitTable::setRowCount(int irows) | 531 | void KMyMoneySplitTable::setRowCount(int irows) | ||
437 | { | 532 | { | ||
438 | QTableWidget::setRowCount(irows); | 533 | QTableWidget::setRowCount(irows); | ||
439 | 534 | | |||
Context not available. | |||||
449 | 544 | | |||
450 | verticalHeader()->setUpdatesEnabled(false); | 545 | verticalHeader()->setUpdatesEnabled(false); | ||
451 | 546 | | |||
452 | for (int i = 0; i < irows; ++i) | 547 | for (auto i = 0; i < irows; ++i) | ||
453 | verticalHeader()->resizeSection(i, height); | 548 | verticalHeader()->resizeSection(i, height); | ||
454 | 549 | | |||
455 | verticalHeader()->setUpdatesEnabled(true); | 550 | verticalHeader()->setUpdatesEnabled(true); | ||
456 | } | 551 | } | ||
457 | 552 | | |||
458 | void kMyMoneySplitTable::setTransaction(const MyMoneyTransaction& t, const MyMoneySplit& s, const MyMoneyAccount& acc) | 553 | void KMyMoneySplitTable::setTransaction(const MyMoneyTransaction& t, const MyMoneySplit& s, const MyMoneyAccount& acc) | ||
459 | { | 554 | { | ||
555 | Q_D(KMyMoneySplitTable); | ||||
460 | MYMONEYTRACER(tracer); | 556 | MYMONEYTRACER(tracer); | ||
461 | m_transaction = t; | 557 | d->m_transaction = t; | ||
462 | m_account = acc; | 558 | d->m_account = acc; | ||
463 | m_hiddenSplit = s; | 559 | d->m_hiddenSplit = s; | ||
464 | selectRow(0); | 560 | selectRow(0); | ||
465 | slotUpdateData(m_transaction); | 561 | slotUpdateData(d->m_transaction); | ||
562 | } | ||||
563 | | ||||
564 | MyMoneyTransaction KMyMoneySplitTable::transaction() const | ||||
565 | { | ||||
566 | Q_D(const KMyMoneySplitTable); | ||||
567 | return d->m_transaction; | ||||
466 | } | 568 | } | ||
467 | 569 | | |||
468 | const QList<MyMoneySplit> kMyMoneySplitTable::getSplits(const MyMoneyTransaction& t) const | 570 | QList<MyMoneySplit> KMyMoneySplitTable::getSplits(const MyMoneyTransaction& t) const | ||
469 | { | 571 | { | ||
572 | Q_D(const KMyMoneySplitTable); | ||||
470 | // get list of splits | 573 | // get list of splits | ||
471 | QList<MyMoneySplit> list = t.splits(); | 574 | QList<MyMoneySplit> list = t.splits(); | ||
472 | 575 | | |||
473 | // and ignore the one that should be hidden | 576 | // and ignore the one that should be hidden | ||
474 | QList<MyMoneySplit>::Iterator it; | 577 | QList<MyMoneySplit>::Iterator it; | ||
475 | for (it = list.begin(); it != list.end(); ++it) { | 578 | for (it = list.begin(); it != list.end(); ++it) { | ||
476 | if ((*it).id() == m_hiddenSplit.id()) { | 579 | if ((*it).id() == d->m_hiddenSplit.id()) { | ||
477 | list.erase(it); | 580 | list.erase(it); | ||
478 | break; | 581 | break; | ||
479 | } | 582 | } | ||
Context not available. | |||||
481 | return list; | 584 | return list; | ||
482 | } | 585 | } | ||
483 | 586 | | |||
484 | void kMyMoneySplitTable::slotUpdateData(const MyMoneyTransaction& t) | 587 | void KMyMoneySplitTable::slotUpdateData(const MyMoneyTransaction& t) | ||
485 | { | 588 | { | ||
589 | Q_D(KMyMoneySplitTable); | ||||
486 | MYMONEYTRACER(tracer); | 590 | MYMONEYTRACER(tracer); | ||
487 | unsigned long numRows = 0; | 591 | unsigned long numRows = 0; | ||
488 | QTableWidgetItem* textItem; | 592 | QTableWidgetItem* textItem; | ||
Context not available. | |||||
499 | try { | 603 | try { | ||
500 | colText = MyMoneyFile::instance()->accountToCategory((*it).accountId()); | 604 | colText = MyMoneyFile::instance()->accountToCategory((*it).accountId()); | ||
501 | } catch (const MyMoneyException &) { | 605 | } catch (const MyMoneyException &) { | ||
502 | qDebug("Unexpected exception in kMyMoneySplitTable::slotUpdateData()"); | 606 | qDebug("Unexpected exception in KMyMoneySplitTable::slotUpdateData()"); | ||
503 | } | 607 | } | ||
504 | } | 608 | } | ||
505 | QString amountTxt = value.formatMoney(m_account.fraction()); | 609 | QString amountTxt = value.formatMoney(d->m_account.fraction()); | ||
506 | if (value == MyMoneyMoney::autoCalc) { | 610 | if (value == MyMoneyMoney::autoCalc) { | ||
507 | amountTxt = i18n("will be calculated"); | 611 | amountTxt = i18n("will be calculated"); | ||
508 | } | 612 | } | ||
Context not available. | |||||
541 | 645 | | |||
542 | // now clean out the remainder of the table | 646 | // now clean out the remainder of the table | ||
543 | while (numRows < static_cast<unsigned long>(rowCount())) { | 647 | while (numRows < static_cast<unsigned long>(rowCount())) { | ||
544 | for (int i = 0 ; i < 3; ++i) { | 648 | for (auto i = 0 ; i < 3; ++i) { | ||
545 | textItem = item(numRows, i); | 649 | textItem = item(numRows, i); | ||
546 | if (textItem) | 650 | if (textItem) | ||
547 | textItem->setText(""); | 651 | textItem->setText(""); | ||
Context not available. | |||||
553 | } | 657 | } | ||
554 | } | 658 | } | ||
555 | 659 | | |||
556 | void kMyMoneySplitTable::updateTransactionTableSize() | 660 | void KMyMoneySplitTable::updateTransactionTableSize() | ||
557 | { | 661 | { | ||
662 | Q_D(KMyMoneySplitTable); | ||||
558 | // get current size of transactions table | 663 | // get current size of transactions table | ||
559 | int tableHeight = height(); | 664 | int tableHeight = height(); | ||
560 | int splitCount = m_transaction.splits().count() - 1; | 665 | int splitCount = d->m_transaction.splits().count() - 1; | ||
561 | 666 | | |||
562 | if (splitCount < 0) | 667 | if (splitCount < 0) | ||
563 | splitCount = 0; | 668 | splitCount = 0; | ||
Context not available. | |||||
568 | numExtraLines = 2; | 673 | numExtraLines = 2; | ||
569 | 674 | | |||
570 | setRowCount(splitCount + numExtraLines); | 675 | setRowCount(splitCount + numExtraLines); | ||
571 | m_maxRows = splitCount; | 676 | d->m_maxRows = splitCount; | ||
572 | } | 677 | } | ||
573 | 678 | | |||
574 | void kMyMoneySplitTable::resizeEvent(QResizeEvent* ev) | 679 | void KMyMoneySplitTable::resizeEvent(QResizeEvent* ev) | ||
575 | { | 680 | { | ||
576 | QTableWidget::resizeEvent(ev); | 681 | QTableWidget::resizeEvent(ev); | ||
577 | if (!isEditMode()) { | 682 | if (!isEditMode()) { | ||
Context not available. | |||||
581 | } | 686 | } | ||
582 | } | 687 | } | ||
583 | 688 | | |||
584 | void kMyMoneySplitTable::slotDuplicateSplit() | 689 | void KMyMoneySplitTable::slotDuplicateSplit() | ||
585 | { | 690 | { | ||
691 | Q_D(KMyMoneySplitTable); | ||||
586 | MYMONEYTRACER(tracer); | 692 | MYMONEYTRACER(tracer); | ||
587 | QList<MyMoneySplit> list = getSplits(m_transaction); | 693 | QList<MyMoneySplit> list = getSplits(d->m_transaction); | ||
588 | if (m_currentRow < list.count()) { | 694 | if (d->m_currentRow < list.count()) { | ||
589 | MyMoneySplit split = list[m_currentRow]; | 695 | MyMoneySplit split = list[d->m_currentRow]; | ||
590 | split.clearId(); | 696 | split.clearId(); | ||
591 | try { | 697 | try { | ||
592 | m_transaction.addSplit(split); | 698 | d->m_transaction.addSplit(split); | ||
593 | emit transactionChanged(m_transaction); | 699 | emit transactionChanged(d->m_transaction); | ||
594 | } catch (const MyMoneyException &e) { | 700 | } catch (const MyMoneyException &e) { | ||
595 | qDebug("Cannot duplicate split: %s", qPrintable(e.what())); | 701 | qDebug("Cannot duplicate split: %s", qPrintable(e.what())); | ||
596 | } | 702 | } | ||
597 | } | 703 | } | ||
598 | } | 704 | } | ||
599 | 705 | | |||
600 | void kMyMoneySplitTable::slotDeleteSplit() | 706 | void KMyMoneySplitTable::slotDeleteSplit() | ||
601 | { | 707 | { | ||
708 | Q_D(KMyMoneySplitTable); | ||||
602 | MYMONEYTRACER(tracer); | 709 | MYMONEYTRACER(tracer); | ||
603 | QList<MyMoneySplit> list = getSplits(m_transaction); | 710 | QList<MyMoneySplit> list = getSplits(d->m_transaction); | ||
604 | if (m_currentRow < list.count()) { | 711 | if (d->m_currentRow < list.count()) { | ||
605 | if (KMessageBox::warningContinueCancel(this, | 712 | if (KMessageBox::warningContinueCancel(this, | ||
606 | i18n("You are about to delete the selected split. " | 713 | i18n("You are about to delete the selected split. " | ||
607 | "Do you really want to continue?"), | 714 | "Do you really want to continue?"), | ||
608 | i18n("KMyMoney"), | 715 | i18n("KMyMoney") | ||
609 | KGuiItem(i18n("Continue")) | | |||
610 | ) == KMessageBox::Continue) { | 716 | ) == KMessageBox::Continue) { | ||
611 | try { | 717 | try { | ||
612 | m_transaction.removeSplit(list[m_currentRow]); | 718 | d->m_transaction.removeSplit(list[d->m_currentRow]); | ||
613 | // if we removed the last split, select the previous | 719 | // if we removed the last split, select the previous | ||
614 | if (m_currentRow && m_currentRow == list.count() - 1) | 720 | if (d->m_currentRow && d->m_currentRow == list.count() - 1) | ||
615 | selectRow(m_currentRow - 1); | 721 | selectRow(d->m_currentRow - 1); | ||
616 | else | 722 | else | ||
617 | selectRow(m_currentRow); | 723 | selectRow(d->m_currentRow); | ||
618 | emit transactionChanged(m_transaction); | 724 | emit transactionChanged(d->m_transaction); | ||
619 | } catch (const MyMoneyException &e) { | 725 | } catch (const MyMoneyException &e) { | ||
620 | qDebug("Cannot remove split: %s", qPrintable(e.what())); | 726 | qDebug("Cannot remove split: %s", qPrintable(e.what())); | ||
621 | } | 727 | } | ||
Context not available. | |||||
623 | } | 729 | } | ||
624 | } | 730 | } | ||
625 | 731 | | |||
626 | KMyMoneyCategory* kMyMoneySplitTable::slotStartEdit() | 732 | KMyMoneyCategory* KMyMoneySplitTable::slotStartEdit() | ||
627 | { | 733 | { | ||
628 | MYMONEYTRACER(tracer); | 734 | MYMONEYTRACER(tracer); | ||
629 | return createEditWidgets(true); | 735 | return createEditWidgets(true); | ||
630 | } | 736 | } | ||
631 | 737 | | |||
632 | void kMyMoneySplitTable::slotEndEdit() | 738 | void KMyMoneySplitTable::slotEndEdit() | ||
633 | { | 739 | { | ||
634 | endEdit(false); | 740 | endEdit(false); | ||
635 | } | 741 | } | ||
636 | 742 | | |||
637 | void kMyMoneySplitTable::slotEndEditKeyboard() | 743 | void KMyMoneySplitTable::slotEndEditKeyboard() | ||
638 | { | 744 | { | ||
639 | endEdit(true); | 745 | endEdit(true); | ||
640 | } | 746 | } | ||
641 | 747 | | |||
642 | void kMyMoneySplitTable::endEdit(bool keyboardDriven, bool setFocusToNextRow) | 748 | void KMyMoneySplitTable::endEdit(bool keyboardDriven, bool setFocusToNextRow) | ||
643 | { | 749 | { | ||
644 | MyMoneyFile* file = MyMoneyFile::instance(); | 750 | Q_D(KMyMoneySplitTable); | ||
751 | auto file = MyMoneyFile::instance(); | ||||
645 | 752 | | |||
646 | MYMONEYTRACER(tracer); | 753 | MYMONEYTRACER(tracer); | ||
647 | MyMoneySplit s1 = m_split; | 754 | MyMoneySplit s1 = d->m_split; | ||
648 | 755 | | |||
649 | if (!isEditSplitValid()) { | 756 | if (!isEditSplitValid()) { | ||
650 | KMessageBox::information(this, i18n("You need to assign a category to this split before it can be entered."), i18n("Enter split"), "EnterSplitWithEmptyCategory"); | 757 | KMessageBox::information(this, i18n("You need to assign a category to this split before it can be entered."), i18n("Enter split"), "EnterSplitWithEmptyCategory"); | ||
651 | m_editCategory->setFocus(); | 758 | d->m_editCategory->setFocus(); | ||
652 | return; | 759 | return; | ||
653 | } | 760 | } | ||
654 | 761 | | |||
655 | bool needUpdate = false; | 762 | bool needUpdate = false; | ||
656 | if (m_editCategory->selectedItem() != m_split.accountId()) { | 763 | if (d->m_editCategory->selectedItem() != d->m_split.accountId()) { | ||
657 | s1.setAccountId(m_editCategory->selectedItem()); | 764 | s1.setAccountId(d->m_editCategory->selectedItem()); | ||
658 | needUpdate = true; | 765 | needUpdate = true; | ||
659 | } | 766 | } | ||
660 | if (m_editMemo->text() != m_split.memo()) { | 767 | if (d->m_editMemo->text() != d->m_split.memo()) { | ||
661 | s1.setMemo(m_editMemo->text()); | 768 | s1.setMemo(d->m_editMemo->text()); | ||
662 | needUpdate = true; | 769 | needUpdate = true; | ||
663 | } | 770 | } | ||
664 | if (m_editAmount->value() != m_split.value()) { | 771 | if (d->m_editAmount->value() != d->m_split.value()) { | ||
665 | s1.setValue(m_editAmount->value()); | 772 | s1.setValue(d->m_editAmount->value()); | ||
666 | needUpdate = true; | 773 | needUpdate = true; | ||
667 | } | 774 | } | ||
668 | 775 | | |||
669 | if (needUpdate) { | 776 | if (needUpdate) { | ||
670 | if (!s1.value().isZero()) { | 777 | if (!s1.value().isZero()) { | ||
671 | MyMoneyAccount cat = file->account(s1.accountId()); | 778 | MyMoneyAccount cat = file->account(s1.accountId()); | ||
672 | if (cat.currencyId() != m_transaction.commodity()) { | 779 | if (cat.currencyId() != d->m_transaction.commodity()) { | ||
673 | 780 | | |||
674 | MyMoneySecurity fromCurrency, toCurrency; | 781 | MyMoneySecurity fromCurrency, toCurrency; | ||
675 | MyMoneyMoney fromValue, toValue; | 782 | MyMoneyMoney fromValue, toValue; | ||
676 | fromCurrency = file->security(m_transaction.commodity()); | 783 | fromCurrency = file->security(d->m_transaction.commodity()); | ||
677 | toCurrency = file->security(cat.currencyId()); | 784 | toCurrency = file->security(cat.currencyId()); | ||
678 | 785 | | |||
679 | // determine the fraction required for this category | 786 | // determine the fraction required for this category | ||
Context not available. | |||||
685 | fromValue = s1.value().abs(); | 792 | fromValue = s1.value().abs(); | ||
686 | 793 | | |||
687 | // if we had a price info in the beginning, we use it here | 794 | // if we had a price info in the beginning, we use it here | ||
688 | if (m_priceInfo.find(cat.currencyId()) != m_priceInfo.end()) { | 795 | if (d->m_priceInfo.find(cat.currencyId()) != d->m_priceInfo.end()) { | ||
689 | toValue = (fromValue * m_priceInfo[cat.currencyId()]).convert(fract); | 796 | toValue = (fromValue * d->m_priceInfo[cat.currencyId()]).convert(fract); | ||
690 | } | 797 | } | ||
691 | 798 | | |||
692 | // if the shares are still 0, we need to change that | 799 | // if the shares are still 0, we need to change that | ||
Context not available. | |||||
707 | toCurrency, | 814 | toCurrency, | ||
708 | fromValue, | 815 | fromValue, | ||
709 | toValue, | 816 | toValue, | ||
710 | m_transaction.postDate(), | 817 | d->m_transaction.postDate(), | ||
711 | fract, | 818 | fract, | ||
712 | this); | 819 | this); | ||
713 | 820 | | |||
Context not available. | |||||
725 | } else | 832 | } else | ||
726 | s1.setShares(s1.value()); | 833 | s1.setShares(s1.value()); | ||
727 | 834 | | |||
728 | m_split = s1; | 835 | d->m_split = s1; | ||
729 | try { | 836 | try { | ||
730 | if (m_split.id().isEmpty()) { | 837 | if (d->m_split.id().isEmpty()) { | ||
731 | m_transaction.addSplit(m_split); | 838 | d->m_transaction.addSplit(d->m_split); | ||
732 | } else { | 839 | } else { | ||
733 | m_transaction.modifySplit(m_split); | 840 | d->m_transaction.modifySplit(d->m_split); | ||
734 | } | 841 | } | ||
735 | emit transactionChanged(m_transaction); | 842 | emit transactionChanged(d->m_transaction); | ||
736 | } catch (const MyMoneyException &e) { | 843 | } catch (const MyMoneyException &e) { | ||
737 | qDebug("Cannot add/modify split: %s", qPrintable(e.what())); | 844 | qDebug("Cannot add/modify split: %s", qPrintable(e.what())); | ||
738 | } | 845 | } | ||
Context not available. | |||||
746 | // if we still have more splits, we start editing right away | 853 | // if we still have more splits, we start editing right away | ||
747 | // in case we have selected 'enter moves between fields' | 854 | // in case we have selected 'enter moves between fields' | ||
748 | if (keyboardDriven | 855 | if (keyboardDriven | ||
749 | && currentRow() < m_transaction.splits().count() - 1 | 856 | && currentRow() < d->m_transaction.splits().count() - 1 | ||
750 | && KMyMoneyGlobalSettings::enterMovesBetweenFields()) { | 857 | && KMyMoneyGlobalSettings::enterMovesBetweenFields()) { | ||
751 | slotStartEdit(); | 858 | slotStartEdit(); | ||
752 | } | 859 | } | ||
753 | 860 | | |||
754 | } | 861 | } | ||
755 | 862 | | |||
756 | void kMyMoneySplitTable::slotCancelEdit() | 863 | void KMyMoneySplitTable::slotCancelEdit() | ||
757 | { | 864 | { | ||
758 | MYMONEYTRACER(tracer); | 865 | MYMONEYTRACER(tracer); | ||
759 | if (isEditMode()) { | 866 | if (isEditMode()) { | ||
Context not available. | |||||
762 | } | 869 | } | ||
763 | } | 870 | } | ||
764 | 871 | | |||
765 | bool kMyMoneySplitTable::isEditMode() const | 872 | bool KMyMoneySplitTable::isEditMode() const | ||
766 | { | 873 | { | ||
874 | Q_D(const KMyMoneySplitTable); | ||||
767 | // while the edit widgets exist we're in edit mode | 875 | // while the edit widgets exist we're in edit mode | ||
768 | return m_editAmount || m_editMemo || m_editCategory; | 876 | return d->m_editAmount || d->m_editMemo || d->m_editCategory; | ||
769 | } | 877 | } | ||
770 | 878 | | |||
771 | bool kMyMoneySplitTable::isEditSplitValid() const | 879 | bool KMyMoneySplitTable::isEditSplitValid() const | ||
772 | { | 880 | { | ||
773 | return isEditMode() && !m_editCategory->selectedItem().isEmpty(); | 881 | Q_D(const KMyMoneySplitTable); | ||
882 | return isEditMode() && !d->m_editCategory->selectedItem().isEmpty(); | ||||
774 | } | 883 | } | ||
775 | 884 | | |||
776 | void kMyMoneySplitTable::destroyEditWidgets() | 885 | void KMyMoneySplitTable::destroyEditWidgets() | ||
777 | { | 886 | { | ||
778 | MYMONEYTRACER(tracer); | 887 | MYMONEYTRACER(tracer); | ||
779 | 888 | | |||
889 | Q_D(KMyMoneySplitTable); | ||||
780 | emit editFinished(); | 890 | emit editFinished(); | ||
781 | 891 | | |||
782 | disconnect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadEditWidgets())); | 892 | disconnect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KMyMoneySplitTable::slotLoadEditWidgets); | ||
783 | 893 | | |||
784 | destroyEditWidget(m_currentRow, 0); | 894 | destroyEditWidget(d->m_currentRow, 0); | ||
785 | destroyEditWidget(m_currentRow, 1); | 895 | destroyEditWidget(d->m_currentRow, 1); | ||
786 | destroyEditWidget(m_currentRow, 2); | 896 | destroyEditWidget(d->m_currentRow, 2); | ||
787 | destroyEditWidget(m_currentRow + 1, 0); | 897 | destroyEditWidget(d->m_currentRow + 1, 0); | ||
788 | } | 898 | } | ||
789 | 899 | | |||
790 | void kMyMoneySplitTable::destroyEditWidget(int r, int c) | 900 | void KMyMoneySplitTable::destroyEditWidget(int r, int c) | ||
791 | { | 901 | { | ||
792 | if (QWidget* cw = cellWidget(r, c)) | 902 | if (QWidget* cw = cellWidget(r, c)) | ||
793 | cw->hide(); | 903 | cw->hide(); | ||
794 | removeCellWidget(r, c); | 904 | removeCellWidget(r, c); | ||
795 | } | 905 | } | ||
796 | 906 | | |||
797 | KMyMoneyCategory* kMyMoneySplitTable::createEditWidgets(bool setFocus) | 907 | KMyMoneyCategory* KMyMoneySplitTable::createEditWidgets(bool setFocus) | ||
798 | { | 908 | { | ||
799 | MYMONEYTRACER(tracer); | 909 | MYMONEYTRACER(tracer); | ||
800 | 910 | | |||
801 | emit editStarted(); | 911 | emit editStarted(); | ||
802 | 912 | | |||
803 | QFont cellFont = KMyMoneyGlobalSettings::listCellFont(); | 913 | Q_D(KMyMoneySplitTable); | ||
804 | m_tabOrderWidgets.clear(); | 914 | auto cellFont = KMyMoneyGlobalSettings::listCellFont(); | ||
915 | d->m_tabOrderWidgets.clear(); | ||||
805 | 916 | | |||
806 | // create the widgets | 917 | // create the widgets | ||
807 | m_editAmount = new kMyMoneyEdit(0); | 918 | d->m_editAmount = new kMyMoneyEdit(0); | ||
808 | m_editAmount->setFont(cellFont); | 919 | d->m_editAmount->setFont(cellFont); | ||
809 | m_editAmount->setResetButtonVisible(false); | 920 | d->m_editAmount->setResetButtonVisible(false); | ||
810 | m_editAmount->setPrecision(m_precision); | 921 | d->m_editAmount->setPrecision(d->m_precision); | ||
811 | 922 | | |||
812 | m_editCategory = new KMyMoneyCategory(); | 923 | d->m_editCategory = new KMyMoneyCategory(); | ||
813 | m_editCategory->setPlaceholderText(i18n("Category")); | 924 | d->m_editCategory->setPlaceholderText(i18n("Category")); | ||
814 | m_editCategory->setFont(cellFont); | 925 | d->m_editCategory->setFont(cellFont); | ||
815 | connect(m_editCategory, SIGNAL(createItem(QString,QString&)), this, SIGNAL(createCategory(QString,QString&))); | 926 | connect(d->m_editCategory, SIGNAL(createItem(QString,QString&)), this, SIGNAL(createCategory(QString,QString&))); | ||
816 | connect(m_editCategory, SIGNAL(objectCreation(bool)), this, SIGNAL(objectCreation(bool))); | 927 | connect(d->m_editCategory, SIGNAL(objectCreation(bool)), this, SIGNAL(objectCreation(bool))); | ||
817 | 928 | | |||
818 | m_editMemo = new kMyMoneyLineEdit(0, false, Qt::AlignLeft | Qt::AlignVCenter); | 929 | d->m_editMemo = new kMyMoneyLineEdit(0, false, Qt::AlignLeft | Qt::AlignVCenter); | ||
819 | m_editMemo->setPlaceholderText(i18n("Memo")); | 930 | d->m_editMemo->setPlaceholderText(i18n("Memo")); | ||
820 | m_editMemo->setFont(cellFont); | 931 | d->m_editMemo->setFont(cellFont); | ||
821 | 932 | | |||
822 | // create buttons for the mouse users | 933 | // create buttons for the mouse users | ||
823 | m_registerButtonFrame = new QFrame(this); | 934 | d->m_registerButtonFrame = new QFrame(this); | ||
824 | m_registerButtonFrame->setContentsMargins(0, 0, 0, 0); | 935 | d->m_registerButtonFrame->setContentsMargins(0, 0, 0, 0); | ||
825 | m_registerButtonFrame->setAutoFillBackground(true); | 936 | d->m_registerButtonFrame->setAutoFillBackground(true); | ||
826 | 937 | | |||
827 | QHBoxLayout* l = new QHBoxLayout(m_registerButtonFrame); | 938 | QHBoxLayout* l = new QHBoxLayout(d->m_registerButtonFrame); | ||
828 | l->setContentsMargins(0, 0, 0, 0); | 939 | l->setContentsMargins(0, 0, 0, 0); | ||
829 | l->setSpacing(0); | 940 | l->setSpacing(0); | ||
830 | m_registerEnterButton = new QPushButton(QIcon::fromTheme(g_Icons[Icon::DialogOK]) | 941 | d->m_registerEnterButton = new QPushButton(QIcon::fromTheme(g_Icons[Icon::DialogOK]) | ||
831 | , QString(), m_registerButtonFrame); | 942 | , QString(), d->m_registerButtonFrame); | ||
832 | m_registerCancelButton = new QPushButton(QIcon::fromTheme(g_Icons[Icon::DialogCancel]) | 943 | d->m_registerCancelButton = new QPushButton(QIcon::fromTheme(g_Icons[Icon::DialogCancel]) | ||
833 | , QString(), m_registerButtonFrame); | 944 | , QString(), d->m_registerButtonFrame); | ||
834 | 945 | | |||
835 | l->addWidget(m_registerEnterButton); | 946 | l->addWidget(d->m_registerEnterButton); | ||
836 | l->addWidget(m_registerCancelButton); | 947 | l->addWidget(d->m_registerCancelButton); | ||
837 | l->addStretch(2); | 948 | l->addStretch(2); | ||
838 | 949 | | |||
839 | connect(m_registerEnterButton, SIGNAL(clicked()), this, SLOT(slotEndEdit())); | 950 | connect(d->m_registerEnterButton.data(), &QAbstractButton::clicked, this, &KMyMoneySplitTable::slotEndEdit); | ||
840 | connect(m_registerCancelButton, SIGNAL(clicked()), this, SLOT(slotCancelEdit())); | 951 | connect(d->m_registerCancelButton.data(), &QAbstractButton::clicked, this, &KMyMoneySplitTable::slotCancelEdit); | ||
841 | 952 | | |||
842 | // setup tab order | 953 | // setup tab order | ||
843 | addToTabOrder(m_editCategory); | 954 | addToTabOrder(d->m_editCategory); | ||
844 | addToTabOrder(m_editMemo); | 955 | addToTabOrder(d->m_editMemo); | ||
845 | addToTabOrder(m_editAmount); | 956 | addToTabOrder(d->m_editAmount); | ||
846 | addToTabOrder(m_registerEnterButton); | 957 | addToTabOrder(d->m_registerEnterButton); | ||
847 | addToTabOrder(m_registerCancelButton); | 958 | addToTabOrder(d->m_registerCancelButton); | ||
848 | 959 | | |||
849 | if (!m_split.accountId().isEmpty()) { | 960 | if (!d->m_split.accountId().isEmpty()) { | ||
850 | m_editCategory->setSelectedItem(m_split.accountId()); | 961 | d->m_editCategory->setSelectedItem(d->m_split.accountId()); | ||
851 | } else { | 962 | } else { | ||
852 | // check if the transaction is balanced or not. If not, | 963 | // check if the transaction is balanced or not. If not, | ||
853 | // assign the remainder to the amount. | 964 | // assign the remainder to the amount. | ||
854 | MyMoneyMoney diff; | 965 | MyMoneyMoney diff; | ||
855 | QList<MyMoneySplit> list = m_transaction.splits(); | 966 | QList<MyMoneySplit> list = d->m_transaction.splits(); | ||
856 | QList<MyMoneySplit>::ConstIterator it_s; | 967 | QList<MyMoneySplit>::ConstIterator it_s; | ||
857 | for (it_s = list.constBegin(); it_s != list.constEnd(); ++it_s) { | 968 | for (it_s = list.constBegin(); it_s != list.constEnd(); ++it_s) { | ||
858 | if (!(*it_s).accountId().isEmpty()) | 969 | if (!(*it_s).accountId().isEmpty()) | ||
859 | diff += (*it_s).value(); | 970 | diff += (*it_s).value(); | ||
860 | } | 971 | } | ||
861 | m_split.setValue(-diff); | 972 | d->m_split.setValue(-diff); | ||
862 | } | 973 | } | ||
863 | 974 | | |||
864 | m_editMemo->loadText(m_split.memo()); | 975 | d->m_editMemo->loadText(d->m_split.memo()); | ||
865 | // don't allow automatically calculated values to be modified | 976 | // don't allow automatically calculated values to be modified | ||
866 | if (m_split.value() == MyMoneyMoney::autoCalc) { | 977 | if (d->m_split.value() == MyMoneyMoney::autoCalc) { | ||
867 | m_editAmount->setEnabled(false); | 978 | d->m_editAmount->setEnabled(false); | ||
868 | m_editAmount->loadText("will be calculated"); | 979 | d->m_editAmount->loadText("will be calculated"); | ||
869 | } else | 980 | } else | ||
870 | m_editAmount->setValue(m_split.value()); | 981 | d->m_editAmount->setValue(d->m_split.value()); | ||
871 | 982 | | |||
872 | setCellWidget(m_currentRow, 0, m_editCategory); | 983 | setCellWidget(d->m_currentRow, 0, d->m_editCategory); | ||
873 | setCellWidget(m_currentRow, 1, m_editMemo); | 984 | setCellWidget(d->m_currentRow, 1, d->m_editMemo); | ||
874 | setCellWidget(m_currentRow, 2, m_editAmount); | 985 | setCellWidget(d->m_currentRow, 2, d->m_editAmount); | ||
875 | setCellWidget(m_currentRow + 1, 0, m_registerButtonFrame); | 986 | setCellWidget(d->m_currentRow + 1, 0, d->m_registerButtonFrame); | ||
876 | 987 | | |||
877 | // load e.g. the category widget with the account list | 988 | // load e.g. the category widget with the account list | ||
878 | slotLoadEditWidgets(); | 989 | slotLoadEditWidgets(); | ||
879 | connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadEditWidgets())); | 990 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KMyMoneySplitTable::slotLoadEditWidgets); | ||
880 | 991 | | |||
881 | foreach (QWidget* w, m_tabOrderWidgets) { | 992 | foreach (QWidget* w, d->m_tabOrderWidgets) { | ||
882 | if (w) { | 993 | if (w) { | ||
883 | w->installEventFilter(this); | 994 | w->installEventFilter(this); | ||
884 | } | 995 | } | ||
885 | } | 996 | } | ||
886 | 997 | | |||
887 | if (setFocus) { | 998 | if (setFocus) { | ||
888 | m_editCategory->lineEdit()->setFocus(); | 999 | d->m_editCategory->lineEdit()->setFocus(); | ||
889 | m_editCategory->lineEdit()->selectAll(); | 1000 | d->m_editCategory->lineEdit()->selectAll(); | ||
890 | } | 1001 | } | ||
891 | 1002 | | |||
892 | // resize the rows so the added edit widgets would fit appropriately | 1003 | // resize the rows so the added edit widgets would fit appropriately | ||
893 | resizeRowsToContents(); | 1004 | resizeRowsToContents(); | ||
894 | 1005 | | |||
895 | return m_editCategory; | 1006 | return d->m_editCategory; | ||
896 | } | 1007 | } | ||
897 | 1008 | | |||
898 | void kMyMoneySplitTable::slotLoadEditWidgets() | 1009 | void KMyMoneySplitTable::slotLoadEditWidgets() | ||
899 | { | 1010 | { | ||
1011 | Q_D(KMyMoneySplitTable); | ||||
900 | // reload category widget | 1012 | // reload category widget | ||
901 | QString categoryId = m_editCategory->selectedItem(); | 1013 | auto categoryId = d->m_editCategory->selectedItem(); | ||
902 | 1014 | | |||
903 | AccountSet aSet; | 1015 | AccountSet aSet; | ||
904 | aSet.addAccountGroup(eMyMoney::Account::Asset); | 1016 | aSet.addAccountGroup(eMyMoney::Account::Asset); | ||
Context not available. | |||||
914 | aSet.removeAccountType(eMyMoney::Account::Stock); | 1026 | aSet.removeAccountType(eMyMoney::Account::Stock); | ||
915 | aSet.removeAccountType(eMyMoney::Account::MoneyMarket); | 1027 | aSet.removeAccountType(eMyMoney::Account::MoneyMarket); | ||
916 | 1028 | | |||
917 | aSet.load(m_editCategory->selector()); | 1029 | aSet.load(d->m_editCategory->selector()); | ||
918 | 1030 | | |||
919 | // if an account is specified then remove it from the widget so that the user | 1031 | // if an account is specified then remove it from the widget so that the user | ||
920 | // cannot create a transfer with from and to account being the same account | 1032 | // cannot create a transfer with from and to account being the same account | ||
921 | if (!m_account.id().isEmpty()) | 1033 | if (!d->m_account.id().isEmpty()) | ||
922 | m_editCategory->selector()->removeItem(m_account.id()); | 1034 | d->m_editCategory->selector()->removeItem(d->m_account.id()); | ||
923 | 1035 | | |||
924 | if (!categoryId.isEmpty()) | 1036 | if (!categoryId.isEmpty()) | ||
925 | m_editCategory->setSelectedItem(categoryId); | 1037 | d->m_editCategory->setSelectedItem(categoryId); | ||
926 | } | 1038 | } | ||
927 | 1039 | | |||
928 | void kMyMoneySplitTable::addToTabOrder(QWidget* w) | 1040 | void KMyMoneySplitTable::addToTabOrder(QWidget* w) | ||
929 | { | 1041 | { | ||
1042 | Q_D(KMyMoneySplitTable); | ||||
930 | if (w) { | 1043 | if (w) { | ||
931 | while (w->focusProxy()) | 1044 | while (w->focusProxy()) | ||
932 | w = w->focusProxy(); | 1045 | w = w->focusProxy(); | ||
933 | m_tabOrderWidgets.append(w); | 1046 | d->m_tabOrderWidgets.append(w); | ||
934 | } | 1047 | } | ||
935 | } | 1048 | } | ||
936 | 1049 | | |||
937 | bool kMyMoneySplitTable::focusNextPrevChild(bool next) | 1050 | bool KMyMoneySplitTable::focusNextPrevChild(bool next) | ||
938 | { | 1051 | { | ||
939 | MYMONEYTRACER(tracer); | 1052 | MYMONEYTRACER(tracer); | ||
940 | bool rc = false; | 1053 | Q_D(KMyMoneySplitTable); | ||
1054 | auto rc = false; | ||||
941 | if (isEditMode()) { | 1055 | if (isEditMode()) { | ||
942 | QWidget *w = 0; | 1056 | QWidget *w = 0; | ||
943 | 1057 | | |||
944 | w = qApp->focusWidget(); | 1058 | w = qApp->focusWidget(); | ||
945 | int currentWidgetIndex = m_tabOrderWidgets.indexOf(w); | 1059 | int currentWidgetIndex = d->m_tabOrderWidgets.indexOf(w); | ||
946 | while (w && currentWidgetIndex == -1) { | 1060 | while (w && currentWidgetIndex == -1) { | ||
947 | // qDebug("'%s' not in list, use parent", w->className()); | 1061 | // qDebug("'%s' not in list, use parent", w->className()); | ||
948 | w = w->parentWidget(); | 1062 | w = w->parentWidget(); | ||
949 | currentWidgetIndex = m_tabOrderWidgets.indexOf(w); | 1063 | currentWidgetIndex = d->m_tabOrderWidgets.indexOf(w); | ||
950 | } | 1064 | } | ||
951 | 1065 | | |||
952 | if (currentWidgetIndex != -1) { | 1066 | if (currentWidgetIndex != -1) { | ||
953 | // if(w) qDebug("tab order is at '%s'", w->className()); | 1067 | // if(w) qDebug("tab order is at '%s'", w->className()); | ||
954 | currentWidgetIndex += next ? 1 : -1; | 1068 | currentWidgetIndex += next ? 1 : -1; | ||
955 | if (currentWidgetIndex < 0) | 1069 | if (currentWidgetIndex < 0) | ||
956 | currentWidgetIndex = m_tabOrderWidgets.size() - 1; | 1070 | currentWidgetIndex = d->m_tabOrderWidgets.size() - 1; | ||
957 | else if (currentWidgetIndex >= m_tabOrderWidgets.size()) | 1071 | else if (currentWidgetIndex >= d->m_tabOrderWidgets.size()) | ||
958 | currentWidgetIndex = 0; | 1072 | currentWidgetIndex = 0; | ||
959 | 1073 | | |||
960 | w = m_tabOrderWidgets[currentWidgetIndex]; | 1074 | w = d->m_tabOrderWidgets[currentWidgetIndex]; | ||
961 | 1075 | | |||
962 | if (((w->focusPolicy() & Qt::TabFocus) == Qt::TabFocus) && w->isVisible() && w->isEnabled()) { | 1076 | if (((w->focusPolicy() & Qt::TabFocus) == Qt::TabFocus) && w->isVisible() && w->isEnabled()) { | ||
963 | // qDebug("Selecting '%s' as focus", w->className()); | 1077 | // qDebug("Selecting '%s' as focus", w->className()); | ||
Context not available. |