Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kenterscheduledlg.cpp
Context not available. | |||||
4 | begin : Sat Apr 7 2007 | 4 | begin : Sat Apr 7 2007 | ||
---|---|---|---|---|---|
5 | copyright : (C) 2007 by Thomas Baumgart | 5 | copyright : (C) 2007 by Thomas Baumgart | ||
6 | email : Thomas Baumgart <ipwizard@users.sourceforge.net> | 6 | email : Thomas Baumgart <ipwizard@users.sourceforge.net> | ||
7 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
7 | ***************************************************************************/ | 8 | ***************************************************************************/ | ||
8 | 9 | | |||
9 | /*************************************************************************** | 10 | /*************************************************************************** | ||
Context not available. | |||||
38 | // ---------------------------------------------------------------------------- | 39 | // ---------------------------------------------------------------------------- | ||
39 | // Project Includes | 40 | // Project Includes | ||
40 | 41 | | |||
42 | #include "ui_kenterscheduledlg.h" | ||||
41 | #include "mymoneyfile.h" | 43 | #include "mymoneyfile.h" | ||
42 | #include "mymoneyschedule.h" | 44 | #include "mymoneyschedule.h" | ||
43 | #include "register.h" | 45 | #include "register.h" | ||
Context not available. | |||||
50 | #include "kmymoney.h" | 52 | #include "kmymoney.h" | ||
51 | #include "icons/icons.h" | 53 | #include "icons/icons.h" | ||
52 | #include "mymoneyenums.h" | 54 | #include "mymoneyenums.h" | ||
55 | #include "dialogenums.h" | ||||
53 | 56 | | |||
54 | using namespace Icons; | 57 | using namespace Icons; | ||
55 | 58 | | |||
56 | class KEnterScheduleDlg::Private | 59 | class KEnterScheduleDlgPrivate | ||
57 | { | 60 | { | ||
61 | Q_DISABLE_COPY(KEnterScheduleDlgPrivate) | ||||
62 | | ||||
58 | public: | 63 | public: | ||
59 | Private() : m_item(0), m_showWarningOnce(true) {} | 64 | KEnterScheduleDlgPrivate() : | ||
60 | ~Private() {} | 65 | ui(new Ui::KEnterScheduleDlg), | ||
66 | m_item(nullptr), | ||||
67 | m_showWarningOnce(true) | ||||
68 | { | ||||
69 | } | ||||
61 | 70 | | |||
71 | ~KEnterScheduleDlgPrivate() | ||||
72 | { | ||||
73 | delete ui; | ||||
74 | } | ||||
75 | | ||||
76 | Ui::KEnterScheduleDlg *ui; | ||||
62 | MyMoneySchedule m_schedule; | 77 | MyMoneySchedule m_schedule; | ||
63 | KMyMoneyRegister::Transaction* m_item; | 78 | KMyMoneyRegister::Transaction* m_item; | ||
64 | QWidgetList m_tabOrderWidgets; | 79 | QWidgetList m_tabOrderWidgets; | ||
65 | bool m_showWarningOnce; | 80 | bool m_showWarningOnce; | ||
66 | KMyMoneyUtils::EnterScheduleResultCodeE m_extendedReturnCode; | 81 | eDialogs::ScheduleResultCode m_extendedReturnCode; | ||
67 | }; | 82 | }; | ||
68 | 83 | | |||
69 | KEnterScheduleDlg::KEnterScheduleDlg(QWidget *parent, const MyMoneySchedule& schedule) : | 84 | KEnterScheduleDlg::KEnterScheduleDlg(QWidget *parent, const MyMoneySchedule& schedule) : | ||
70 | KEnterScheduleDlgDecl(parent), | 85 | QDialog(parent), | ||
71 | d(new Private) | 86 | d_ptr(new KEnterScheduleDlgPrivate) | ||
72 | { | 87 | { | ||
88 | Q_D(KEnterScheduleDlg); | ||||
89 | d->ui->setupUi(this); | ||||
73 | d->m_schedule = schedule; | 90 | d->m_schedule = schedule; | ||
74 | d->m_extendedReturnCode = KMyMoneyUtils::Enter; | 91 | d->m_extendedReturnCode = eDialogs::ScheduleResultCode::Enter; | ||
75 | buttonOk->setIcon(QIcon::fromTheme(g_Icons[Icon::KeyEnter])); | 92 | d->ui->buttonOk->setIcon(QIcon::fromTheme(g_Icons[Icon::KeyEnter])); | ||
76 | buttonSkip->setIcon(QIcon::fromTheme(g_Icons[Icon::MediaSeekForward])); | 93 | d->ui->buttonSkip->setIcon(QIcon::fromTheme(g_Icons[Icon::MediaSeekForward])); | ||
77 | KGuiItem::assign(buttonCancel, KStandardGuiItem::cancel()); | 94 | KGuiItem::assign(d->ui->buttonCancel, KStandardGuiItem::cancel()); | ||
78 | KGuiItem::assign(buttonHelp, KStandardGuiItem::help()); | 95 | KGuiItem::assign(d->ui->buttonHelp, KStandardGuiItem::help()); | ||
79 | buttonIgnore->setHidden(true); | 96 | d->ui->buttonIgnore->setHidden(true); | ||
80 | buttonSkip->setHidden(true); | 97 | d->ui->buttonSkip->setHidden(true); | ||
81 | 98 | | |||
82 | // make sure, we have a tabbar with the form | 99 | // make sure, we have a tabbar with the form | ||
83 | KMyMoneyTransactionForm::TabBar* tabbar = m_form->tabBar(m_form->parentWidget()); | 100 | KMyMoneyTransactionForm::TabBar* tabbar = d->ui->m_form->tabBar(d->ui->m_form->parentWidget()); | ||
84 | 101 | | |||
85 | // we never need to see the register | 102 | // we never need to see the register | ||
86 | m_register->hide(); | 103 | d->ui->m_register->hide(); | ||
87 | 104 | | |||
88 | // ... setup the form ... | 105 | // ... setup the form ... | ||
89 | m_form->setupForm(d->m_schedule.account()); | 106 | d->ui->m_form->setupForm(d->m_schedule.account()); | ||
90 | 107 | | |||
91 | // ... and the register ... | 108 | // ... and the register ... | ||
92 | m_register->clear(); | 109 | d->ui->m_register->clear(); | ||
93 | 110 | | |||
94 | // ... now add the transaction to register and form ... | 111 | // ... now add the transaction to register and form ... | ||
95 | MyMoneyTransaction t = transaction(); | 112 | MyMoneyTransaction t = transaction(); | ||
96 | d->m_item = KMyMoneyRegister::Register::transactionFactory(m_register, t, | 113 | d->m_item = KMyMoneyRegister::Register::transactionFactory(d->ui->m_register, t, | ||
97 | d->m_schedule.transaction().splits().isEmpty() ? MyMoneySplit() : d->m_schedule.transaction().splits().front(), 0); | 114 | d->m_schedule.transaction().splits().isEmpty() ? MyMoneySplit() : d->m_schedule.transaction().splits().front(), 0); | ||
98 | m_register->selectItem(d->m_item); | 115 | d->ui->m_register->selectItem(d->m_item); | ||
99 | // show the account row | 116 | // show the account row | ||
100 | d->m_item->setShowRowInForm(0, true); | 117 | d->m_item->setShowRowInForm(0, true); | ||
101 | 118 | | |||
102 | m_form->slotSetTransaction(d->m_item); | 119 | d->ui->m_form->slotSetTransaction(d->m_item); | ||
103 | 120 | | |||
104 | // no need to see the tabbar | 121 | // no need to see the tabbar | ||
105 | tabbar->hide(); | 122 | tabbar->hide(); | ||
106 | 123 | | |||
107 | // setup name and type | 124 | // setup name and type | ||
108 | m_scheduleName->setText(d->m_schedule.name()); | 125 | d->ui->m_scheduleName->setText(d->m_schedule.name()); | ||
109 | m_type->setText(KMyMoneyUtils::scheduleTypeToString(d->m_schedule.type())); | 126 | d->ui->m_type->setText(KMyMoneyUtils::scheduleTypeToString(d->m_schedule.type())); | ||
110 | 127 | | |||
111 | connect(buttonHelp, SIGNAL(clicked()), this, SLOT(slotShowHelp())); | 128 | connect(d->ui->buttonHelp, &QAbstractButton::clicked, this, &KEnterScheduleDlg::slotShowHelp); | ||
112 | connect(buttonIgnore, SIGNAL(clicked()), this, SLOT(slotIgnore())); | 129 | connect(d->ui->buttonIgnore, &QAbstractButton::clicked, this, &KEnterScheduleDlg::slotIgnore); | ||
113 | connect(buttonSkip, SIGNAL(clicked()), this, SLOT(slotSkip())); | 130 | connect(d->ui->buttonSkip, &QAbstractButton::clicked, this, &KEnterScheduleDlg::slotSkip); | ||
114 | } | 131 | } | ||
115 | 132 | | |||
116 | KEnterScheduleDlg::~KEnterScheduleDlg() | 133 | KEnterScheduleDlg::~KEnterScheduleDlg() | ||
117 | { | 134 | { | ||
135 | Q_D(KEnterScheduleDlg); | ||||
118 | delete d; | 136 | delete d; | ||
119 | } | 137 | } | ||
120 | 138 | | |||
121 | KMyMoneyUtils::EnterScheduleResultCodeE KEnterScheduleDlg::resultCode() const | 139 | eDialogs::ScheduleResultCode KEnterScheduleDlg::resultCode() const | ||
122 | { | 140 | { | ||
141 | Q_D(const KEnterScheduleDlg); | ||||
123 | if (result() == QDialog::Accepted) | 142 | if (result() == QDialog::Accepted) | ||
124 | return d->m_extendedReturnCode; | 143 | return d->m_extendedReturnCode; | ||
125 | return KMyMoneyUtils::Cancel; | 144 | return eDialogs::ScheduleResultCode::Cancel; | ||
126 | } | 145 | } | ||
127 | 146 | | |||
128 | void KEnterScheduleDlg::showExtendedKeys(bool visible) | 147 | void KEnterScheduleDlg::showExtendedKeys(bool visible) | ||
129 | { | 148 | { | ||
130 | buttonIgnore->setVisible(visible); | 149 | Q_D(KEnterScheduleDlg); | ||
131 | buttonSkip->setVisible(visible); | 150 | d->ui->buttonIgnore->setVisible(visible); | ||
151 | d->ui->buttonSkip->setVisible(visible); | ||||
132 | } | 152 | } | ||
133 | 153 | | |||
134 | void KEnterScheduleDlg::slotIgnore() | 154 | void KEnterScheduleDlg::slotIgnore() | ||
135 | { | 155 | { | ||
136 | d->m_extendedReturnCode = KMyMoneyUtils::Ignore; | 156 | Q_D(KEnterScheduleDlg); | ||
157 | d->m_extendedReturnCode = eDialogs::ScheduleResultCode::Ignore; | ||||
137 | accept(); | 158 | accept(); | ||
138 | } | 159 | } | ||
139 | 160 | | |||
140 | void KEnterScheduleDlg::slotSkip() | 161 | void KEnterScheduleDlg::slotSkip() | ||
141 | { | 162 | { | ||
142 | d->m_extendedReturnCode = KMyMoneyUtils::Skip; | 163 | Q_D(KEnterScheduleDlg); | ||
164 | d->m_extendedReturnCode = eDialogs::ScheduleResultCode::Skip; | ||||
143 | accept(); | 165 | accept(); | ||
144 | } | 166 | } | ||
145 | 167 | | |||
146 | MyMoneyTransaction KEnterScheduleDlg::transaction() | 168 | MyMoneyTransaction KEnterScheduleDlg::transaction() | ||
147 | { | 169 | { | ||
148 | MyMoneyTransaction t = d->m_schedule.transaction(); | 170 | Q_D(KEnterScheduleDlg); | ||
171 | auto t = d->m_schedule.transaction(); | ||||
149 | 172 | | |||
150 | try { | 173 | try { | ||
151 | if (d->m_schedule.type() == eMyMoney::Schedule::Type::LoanPayment) { | 174 | if (d->m_schedule.type() == eMyMoney::Schedule::Type::LoanPayment) { | ||
Context not available. | |||||
162 | 185 | | |||
163 | QDate KEnterScheduleDlg::date(const QDate& _date) const | 186 | QDate KEnterScheduleDlg::date(const QDate& _date) const | ||
164 | { | 187 | { | ||
165 | QDate date(_date); | 188 | Q_D(const KEnterScheduleDlg); | ||
189 | auto date(_date); | ||||
166 | return d->m_schedule.adjustedDate(date, d->m_schedule.weekendOption()); | 190 | return d->m_schedule.adjustedDate(date, d->m_schedule.weekendOption()); | ||
167 | } | 191 | } | ||
168 | 192 | | |||
169 | void KEnterScheduleDlg::resizeEvent(QResizeEvent* ev) | 193 | void KEnterScheduleDlg::resizeEvent(QResizeEvent* ev) | ||
170 | { | 194 | { | ||
171 | m_register->resize(KMyMoneyRegister::DetailColumn); | 195 | Q_UNUSED(ev) | ||
172 | m_form->resize(KMyMoneyTransactionForm::ValueColumn1); | 196 | Q_D(KEnterScheduleDlg); | ||
173 | KEnterScheduleDlgDecl::resizeEvent(ev); | 197 | d->ui->m_register->resize(KMyMoneyRegister::DetailColumn); | ||
198 | d->ui->m_form->resize(KMyMoneyTransactionForm::ValueColumn1); | ||||
199 | QDialog::resizeEvent(ev); | ||||
174 | } | 200 | } | ||
175 | 201 | | |||
176 | | ||||
177 | void KEnterScheduleDlg::slotSetupSize() | 202 | void KEnterScheduleDlg::slotSetupSize() | ||
178 | { | 203 | { | ||
179 | resize(width(), minimumSizeHint().height()); | 204 | resize(width(), minimumSizeHint().height()); | ||
Context not available. | |||||
181 | 206 | | |||
182 | int KEnterScheduleDlg::exec() | 207 | int KEnterScheduleDlg::exec() | ||
183 | { | 208 | { | ||
209 | Q_D(KEnterScheduleDlg); | ||||
184 | if (d->m_showWarningOnce) { | 210 | if (d->m_showWarningOnce) { | ||
185 | d->m_showWarningOnce = false; | 211 | d->m_showWarningOnce = false; | ||
186 | KMessageBox::information(this, QString("<qt>") + i18n("<p>Please check that all the details in the following dialog are correct and press OK.</p><p>Editable data can be changed and can either be applied to just this occurrence or for all subsequent occurrences for this schedule. (You will be asked what you intend after pressing OK in the following dialog)</p>") + QString("</qt>"), i18n("Enter scheduled transaction"), "EnterScheduleDlgInfo"); | 212 | KMessageBox::information(this, QString("<qt>") + i18n("<p>Please check that all the details in the following dialog are correct and press OK.</p><p>Editable data can be changed and can either be applied to just this occurrence or for all subsequent occurrences for this schedule. (You will be asked what you intend after pressing OK in the following dialog)</p>") + QString("</qt>"), i18n("Enter scheduled transaction"), "EnterScheduleDlgInfo"); | ||
Context not available. | |||||
188 | 214 | | |||
189 | // force the initial height to be as small as possible | 215 | // force the initial height to be as small as possible | ||
190 | QTimer::singleShot(0, this, SLOT(slotSetupSize())); | 216 | QTimer::singleShot(0, this, SLOT(slotSetupSize())); | ||
191 | 217 | return QDialog::exec(); | |||
192 | return KEnterScheduleDlgDecl::exec(); | | |||
193 | } | 218 | } | ||
194 | 219 | | |||
195 | TransactionEditor* KEnterScheduleDlg::startEdit() | 220 | TransactionEditor* KEnterScheduleDlg::startEdit() | ||
196 | { | 221 | { | ||
197 | KMyMoneyRegister::SelectedTransactions list(m_register); | 222 | Q_D(KEnterScheduleDlg); | ||
198 | TransactionEditor* editor = d->m_item->createEditor(m_form, list, QDate()); | 223 | KMyMoneyRegister::SelectedTransactions list(d->ui->m_register); | ||
199 | editor->m_scheduleInfo = d->m_schedule.name(); | 224 | TransactionEditor* editor = d->m_item->createEditor(d->ui->m_form, list, QDate()); | ||
200 | editor->m_paymentMethod = d->m_schedule.paymentType(); | 225 | editor->setScheduleInfo(d->m_schedule.name()); | ||
226 | editor->setPaymentMethod(d->m_schedule.paymentType()); | ||||
201 | 227 | | |||
202 | // check that we use the same transaction commodity in all selected transactions | 228 | // check that we use the same transaction commodity in all selected transactions | ||
203 | // if not, we need to update this in the editor's list. The user can also bail out | 229 | // if not, we need to update this in the editor's list. The user can also bail out | ||
Context not available. | |||||
212 | } | 238 | } | ||
213 | 239 | | |||
214 | if (editor) { | 240 | if (editor) { | ||
215 | connect(editor, SIGNAL(transactionDataSufficient(bool)), buttonOk, SLOT(setEnabled(bool))); | 241 | connect(editor, &TransactionEditor::transactionDataSufficient, d->ui->buttonOk, &QWidget::setEnabled); | ||
216 | connect(editor, SIGNAL(escapePressed()), buttonCancel, SLOT(animateClick())); | 242 | connect(editor, &TransactionEditor::escapePressed, d->ui->buttonCancel, &QAbstractButton::animateClick); | ||
217 | connect(editor, SIGNAL(returnPressed()), buttonOk, SLOT(animateClick())); | 243 | connect(editor, &TransactionEditor::returnPressed, d->ui->buttonOk, &QAbstractButton::animateClick); | ||
218 | 244 | | |||
219 | connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), editor, SLOT(slotReloadEditWidgets())); | 245 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, editor, &TransactionEditor::slotReloadEditWidgets); | ||
220 | // connect(editor, SIGNAL(finishEdit(KMyMoneyRegister::SelectedTransactions)), this, SLOT(slotLeaveEditMode(KMyMoneyRegister::SelectedTransactions))); | 246 | // connect(editor, SIGNAL(finishEdit(KMyMoneyRegister::SelectedTransactions)), this, SLOT(slotLeaveEditMode(KMyMoneyRegister::SelectedTransactions))); | ||
221 | connect(editor, SIGNAL(createPayee(QString,QString&)), kmymoney, SLOT(slotPayeeNew(QString,QString&))); | 247 | connect(editor, &TransactionEditor::createPayee, kmymoney, static_cast<void (KMyMoneyApp::*)(const QString&, QString&)>(&KMyMoneyApp::slotPayeeNew)); | ||
222 | connect(editor, SIGNAL(createTag(QString,QString&)), kmymoney, SLOT(slotTagNew(QString,QString&))); | 248 | connect(editor, &TransactionEditor::createTag, kmymoney, static_cast<void (KMyMoneyApp::*)(const QString&, QString&)>(&KMyMoneyApp::slotTagNew)); | ||
223 | connect(editor, SIGNAL(createCategory(MyMoneyAccount&,MyMoneyAccount)), kmymoney, SLOT(slotCategoryNew(MyMoneyAccount&,MyMoneyAccount))); | 249 | connect(editor, &TransactionEditor::createCategory, kmymoney, static_cast<void (KMyMoneyApp::*)(MyMoneyAccount&,const MyMoneyAccount&)>(&KMyMoneyApp::slotCategoryNew)); | ||
224 | connect(editor, SIGNAL(createSecurity(MyMoneyAccount&,MyMoneyAccount)), kmymoney, SLOT(slotInvestmentNew(MyMoneyAccount&,MyMoneyAccount))); | 250 | connect(editor, &TransactionEditor::createSecurity, kmymoney, static_cast<void (KMyMoneyApp::*)(MyMoneyAccount&,const MyMoneyAccount&)>(&KMyMoneyApp::slotInvestmentNew)); | ||
225 | connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), editor, SLOT(slotReloadEditWidgets())); | 251 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, editor, &TransactionEditor::slotReloadEditWidgets); | ||
226 | 252 | | |||
227 | // create the widgets, place them in the parent and load them with data | 253 | // create the widgets, place them in the parent and load them with data | ||
228 | // setup tab order | 254 | // setup tab order | ||
Context not available. | |||||
254 | QString num = t.splits().first().number(); | 280 | QString num = t.splits().first().number(); | ||
255 | QWidget* w = editor->haveWidget("number"); | 281 | QWidget* w = editor->haveWidget("number"); | ||
256 | if (d->m_schedule.paymentType() == eMyMoney::Schedule::PaymentType::WriteChecque) { | 282 | if (d->m_schedule.paymentType() == eMyMoney::Schedule::PaymentType::WriteChecque) { | ||
257 | MyMoneyFile* file = MyMoneyFile::instance(); | 283 | auto file = MyMoneyFile::instance(); | ||
258 | if (file->checkNoUsed(d->m_schedule.account().id(), num)) { | 284 | if (file->checkNoUsed(d->m_schedule.account().id(), num)) { | ||
259 | // increment and try again | 285 | // increment and try again | ||
260 | num = KMyMoneyUtils::getAdjacentNumber(num); | 286 | num = KMyMoneyUtils::getAdjacentNumber(num); | ||
Context not available. | |||||
286 | } | 312 | } | ||
287 | 313 | | |||
288 | // don't forget our three buttons | 314 | // don't forget our three buttons | ||
289 | d->m_tabOrderWidgets.append(buttonOk); | 315 | d->m_tabOrderWidgets.append(d->ui->buttonOk); | ||
290 | d->m_tabOrderWidgets.append(buttonCancel); | 316 | d->m_tabOrderWidgets.append(d->ui->buttonCancel); | ||
291 | d->m_tabOrderWidgets.append(buttonHelp); | 317 | d->m_tabOrderWidgets.append(d->ui->buttonHelp); | ||
292 | 318 | | |||
293 | for (int i = 0; i < d->m_tabOrderWidgets.size(); ++i) { | 319 | for (auto i = 0; i < d->m_tabOrderWidgets.size(); ++i) { | ||
294 | QWidget* w = d->m_tabOrderWidgets.at(i); | 320 | QWidget* w = d->m_tabOrderWidgets.at(i); | ||
295 | if (w) { | 321 | if (w) { | ||
296 | w->installEventFilter(this); | 322 | w->installEventFilter(this); | ||
Context not available. | |||||
316 | 342 | | |||
317 | bool KEnterScheduleDlg::focusNextPrevChild(bool next) | 343 | bool KEnterScheduleDlg::focusNextPrevChild(bool next) | ||
318 | { | 344 | { | ||
319 | bool rc = false; | 345 | Q_D(KEnterScheduleDlg); | ||
320 | QWidget *w = 0; | 346 | auto rc = false; | ||
321 | 347 | | |||
322 | w = qApp->focusWidget(); | 348 | auto w = qApp->focusWidget(); | ||
323 | int currentWidgetIndex = d->m_tabOrderWidgets.indexOf(w); | 349 | int currentWidgetIndex = d->m_tabOrderWidgets.indexOf(w); | ||
324 | while (w && currentWidgetIndex == -1) { | 350 | while (w && currentWidgetIndex == -1) { | ||
325 | // qDebug("'%s' not in list, use parent", w->className()); | 351 | // qDebug("'%s' not in list, use parent", w->className()); | ||
Context not available. |