Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kfindtransactiondlg.cpp
Context not available. | |||||
3 | ------------------- | 3 | ------------------- | ||
---|---|---|---|---|---|
4 | copyright : (C) 2003, 2007 by Thomas Baumgart | 4 | copyright : (C) 2003, 2007 by Thomas Baumgart | ||
5 | email : ipwizard@users.sourceforge.net | 5 | email : ipwizard@users.sourceforge.net | ||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
6 | ***************************************************************************/ | 7 | ***************************************************************************/ | ||
7 | 8 | | |||
8 | /*************************************************************************** | 9 | /*************************************************************************** | ||
Context not available. | |||||
14 | * * | 15 | * * | ||
15 | ***************************************************************************/ | 16 | ***************************************************************************/ | ||
16 | 17 | | |||
17 | #include "config-kmymoney.h" | | |||
18 | | ||||
19 | #include "kfindtransactiondlg.h" | 18 | #include "kfindtransactiondlg.h" | ||
19 | #include "kfindtransactiondlg_p.h" | ||||
20 | 20 | | |||
21 | // ---------------------------------------------------------------------------- | 21 | // ---------------------------------------------------------------------------- | ||
22 | // QT Includes | 22 | // QT Includes | ||
23 | 23 | | |||
24 | #include <QLabel> | 24 | #include <QLabel> | ||
25 | #include <QButtonGroup> | | |||
26 | #include <QRadioButton> | 25 | #include <QRadioButton> | ||
27 | #include <QCheckBox> | 26 | #include <QCheckBox> | ||
28 | #include <QTimer> | | |||
29 | #include <QTabWidget> | 27 | #include <QTabWidget> | ||
30 | #include <QKeyEvent> | 28 | #include <QKeyEvent> | ||
31 | #include <QList> | 29 | #include <QList> | ||
Context not available. | |||||
39 | #include <KLineEdit> | 37 | #include <KLineEdit> | ||
40 | #include <KComboBox> | 38 | #include <KComboBox> | ||
41 | #include <KHelpClient> | 39 | #include <KHelpClient> | ||
42 | #include <KGuiItem> | | |||
43 | #include <KStandardGuiItem> | | |||
44 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
45 | 41 | | |||
46 | // ---------------------------------------------------------------------------- | 42 | // ---------------------------------------------------------------------------- | ||
47 | // Project Includes | 43 | // Project Includes | ||
48 | 44 | | |||
45 | #include "mymoneysplit.h" | ||||
46 | #include "mymoneytransaction.h" | ||||
47 | #include "mymoneytransactionfilter.h" | ||||
49 | #include "kmymoneyedit.h" | 48 | #include "kmymoneyedit.h" | ||
50 | #include "mymoneyfile.h" | | |||
51 | #include "mymoneypayee.h" | | |||
52 | #include "mymoneytag.h" | | |||
53 | #include "kmymoneyglobalsettings.h" | 49 | #include "kmymoneyglobalsettings.h" | ||
54 | #include "register.h" | 50 | #include "register.h" | ||
55 | #include "transaction.h" | 51 | #include "transaction.h" | ||
56 | #include "daterangedlg.h" | 52 | #include "daterangedlg.h" | ||
57 | 53 | | |||
58 | #include "ui_kfindtransactiondlgdecl.h" | 54 | #include "ui_kfindtransactiondlg.h" | ||
59 | #include "ui_ksortoptiondlg.h" | 55 | #include "ui_ksortoptiondlg.h" | ||
60 | 56 | | |||
61 | enum ItemRoles { | | |||
62 | ItemIdRole = Qt::UserRole | | |||
63 | }; | | |||
64 | | ||||
65 | struct KSortOptionDlg::Private { | | |||
66 | Ui::KSortOptionDlg ui; | | |||
67 | }; | | |||
68 | 57 | | |||
69 | KSortOptionDlg::KSortOptionDlg(QWidget *parent) | 58 | KSortOptionDlg::KSortOptionDlg(QWidget *parent) : | ||
70 | : QDialog(parent), d(new Private) | 59 | QDialog(parent), | ||
60 | ui(new Ui::KSortOptionDlg) | ||||
71 | { | 61 | { | ||
72 | d->ui.setupUi(this); | 62 | ui->setupUi(this); | ||
73 | init(); | | |||
74 | } | 63 | } | ||
75 | 64 | | |||
76 | KSortOptionDlg::~KSortOptionDlg() | 65 | KSortOptionDlg::~KSortOptionDlg() | ||
77 | { | 66 | { | ||
78 | delete d; | 67 | delete ui; | ||
79 | } | | |||
80 | | ||||
81 | void KSortOptionDlg::init() | | |||
82 | { | | |||
83 | } | 68 | } | ||
84 | 69 | | |||
85 | void KSortOptionDlg::setSortOption(const QString& option, const QString& def) | 70 | void KSortOptionDlg::setSortOption(const QString& option, const QString& def) | ||
86 | { | 71 | { | ||
87 | if (option.isEmpty()) { | 72 | if (option.isEmpty()) { | ||
88 | d->ui.m_sortOption->setSettings(def); | 73 | ui->m_sortOption->setSettings(def); | ||
89 | d->ui.m_useDefault->setChecked(true); | 74 | ui->m_useDefault->setChecked(true); | ||
90 | } else { | 75 | } else { | ||
91 | d->ui.m_sortOption->setSettings(option); | 76 | ui->m_sortOption->setSettings(option); | ||
92 | d->ui.m_useDefault->setChecked(false); | 77 | ui->m_useDefault->setChecked(false); | ||
93 | } | 78 | } | ||
94 | } | 79 | } | ||
95 | 80 | | |||
96 | QString KSortOptionDlg::sortOption() const | 81 | QString KSortOptionDlg::sortOption() const | ||
97 | { | 82 | { | ||
98 | QString rc; | 83 | QString rc; | ||
99 | if (!d->ui.m_useDefault->isChecked()) { | 84 | if (!ui->m_useDefault->isChecked()) { | ||
100 | rc = d->ui.m_sortOption->settings(); | 85 | rc = ui->m_sortOption->settings(); | ||
101 | } | 86 | } | ||
102 | return rc; | 87 | return rc; | ||
103 | } | 88 | } | ||
104 | 89 | | |||
105 | void KSortOptionDlg::hideDefaultButton() | 90 | void KSortOptionDlg::hideDefaultButton() | ||
106 | { | 91 | { | ||
107 | d->ui.m_useDefault->hide(); | 92 | ui->m_useDefault->hide(); | ||
108 | } | 93 | } | ||
109 | 94 | | |||
110 | 95 | KFindTransactionDlg::KFindTransactionDlg(QWidget *parent, bool withEquityAccounts) : | |||
111 | KFindTransactionDlg::KFindTransactionDlg(QWidget *parent, bool withEquityAccounts) | 96 | QDialog(parent), | ||
112 | : QDialog(parent) | 97 | d_ptr(new KFindTransactionDlgPrivate(this)) | ||
113 | , m_needReload(false) | | |||
114 | , m_ui(new Ui::KFindTransactionDlgDecl) | | |||
115 | { | 98 | { | ||
116 | m_ui->setupUi(this); | 99 | Q_D(KFindTransactionDlg); | ||
117 | m_dateRange = new DateRangeDlg; | 100 | d->init(withEquityAccounts); | ||
118 | m_ui->dateRangeLayout->insertWidget(0, m_dateRange); | 101 | } | ||
119 | | ||||
120 | m_ui->ButtonGroup1->setId(m_ui->m_amountButton, 0); | | |||
121 | m_ui->ButtonGroup1->setId(m_ui->m_amountRangeButton, 1); | | |||
122 | | ||||
123 | m_ui->m_register->installEventFilter(this); | | |||
124 | m_ui->m_tabWidget->setTabEnabled(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage), false); | | |||
125 | | ||||
126 | // 'cause we don't have a separate setupTextPage | | |||
127 | connect(m_ui->m_textEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
128 | // if return is pressed trigger a search (slotSearch checks if it's possible to perform the search) | | |||
129 | connect(m_ui->m_textEdit, SIGNAL(returnPressed()), this, SLOT(slotSearch())); | | |||
130 | // in case the date selection changes, we update the selection | | |||
131 | connect(m_dateRange, SIGNAL(rangeChanged()), this, SLOT(slotUpdateSelections())); | | |||
132 | | ||||
133 | setupAccountsPage(withEquityAccounts); | | |||
134 | setupCategoriesPage(); | | |||
135 | setupAmountPage(); | | |||
136 | setupPayeesPage(); | | |||
137 | setupTagsPage(); | | |||
138 | setupDetailsPage(); | | |||
139 | | ||||
140 | // We don't need to add the default into the list (see ::slotShowHelp() why) | | |||
141 | // m_helpAnchor[m_ui->m_textTab] = QLatin1String("details.search"); | | |||
142 | m_helpAnchor[m_ui->m_accountTab] = QLatin1String("details.search.account"); | | |||
143 | m_helpAnchor[m_ui->m_dateTab] = QLatin1String("details.search.date"); | | |||
144 | m_helpAnchor[m_ui->m_amountTab] = QLatin1String("details.search.amount"); | | |||
145 | m_helpAnchor[m_ui->m_categoryTab] = QLatin1String("details.search.category"); | | |||
146 | m_helpAnchor[m_ui->m_payeeTab] = QLatin1String("details.search.payee"); | | |||
147 | m_helpAnchor[m_ui->m_tagTab] = QLatin1String("details.search.tag"); //FIXME-ALEX update Help | | |||
148 | m_helpAnchor[m_ui->m_detailsTab] = QLatin1String("details.search.details"); | | |||
149 | | ||||
150 | // setup the register | | |||
151 | QList<KMyMoneyRegister::Column> cols; | | |||
152 | cols << KMyMoneyRegister::DateColumn; | | |||
153 | cols << KMyMoneyRegister::AccountColumn; | | |||
154 | cols << KMyMoneyRegister::DetailColumn; | | |||
155 | cols << KMyMoneyRegister::ReconcileFlagColumn; | | |||
156 | cols << KMyMoneyRegister::PaymentColumn; | | |||
157 | cols << KMyMoneyRegister::DepositColumn; | | |||
158 | m_ui->m_register->setupRegister(MyMoneyAccount(), cols); | | |||
159 | m_ui->m_register->setSelectionMode(QTableWidget::SingleSelection); | | |||
160 | | ||||
161 | connect(m_ui->m_register, SIGNAL(editTransaction()), this, SLOT(slotSelectTransaction())); | | |||
162 | connect(m_ui->m_register->horizontalHeader(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotSortOptions())); | | |||
163 | | ||||
164 | slotUpdateSelections(); | | |||
165 | | ||||
166 | // setup the connections | | |||
167 | connect(m_ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotSearch())); | | |||
168 | connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(slotReset())); | | |||
169 | connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), m_ui->m_accountsView, SLOT(slotSelectAllAccounts())); | | |||
170 | connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), m_ui->m_categoriesView, SLOT(slotSelectAllAccounts())); | | |||
171 | connect(m_ui->buttonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(deleteLater())); | | |||
172 | connect(m_ui->buttonBox->button(QDialogButtonBox::Help), SIGNAL(clicked()), this, SLOT(slotShowHelp())); | | |||
173 | | ||||
174 | // only allow searches when a selection has been made | | |||
175 | m_ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); | | |||
176 | KGuiItem::assign(m_ui->buttonBox->button(QDialogButtonBox::Apply), KStandardGuiItem::find()); | | |||
177 | m_ui->buttonBox->button(QDialogButtonBox::Apply)->setToolTip(i18nc("@info:tooltip for find transaction apply button", "Search transactions")); | | |||
178 | connect(this, SIGNAL(selectionNotEmpty(bool)), m_ui->buttonBox->button(QDialogButtonBox::Apply), SLOT(setEnabled(bool))); | | |||
179 | | ||||
180 | // get signal about engine changes | | |||
181 | connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotRefreshView())); | | |||
182 | | ||||
183 | slotUpdateSelections(); | | |||
184 | 102 | | |||
185 | m_ui->m_textEdit->setFocus(); | 103 | KFindTransactionDlg::KFindTransactionDlg(KFindTransactionDlgPrivate &dd, QWidget *parent, bool withEquityAccounts) : | ||
104 | QDialog(parent), | ||||
105 | d_ptr(&dd) | ||||
106 | { | ||||
107 | Q_D(KFindTransactionDlg); | ||||
108 | d->init(withEquityAccounts); | ||||
186 | } | 109 | } | ||
187 | 110 | | |||
188 | KFindTransactionDlg::~KFindTransactionDlg() | 111 | KFindTransactionDlg::~KFindTransactionDlg() | ||
189 | { | 112 | { | ||
190 | delete m_ui; | 113 | Q_D(KFindTransactionDlg); | ||
114 | delete d; | ||||
191 | } | 115 | } | ||
192 | 116 | | |||
193 | void KFindTransactionDlg::slotReset() | 117 | void KFindTransactionDlg::slotReset() | ||
194 | { | 118 | { | ||
195 | m_ui->m_textEdit->setText(QString()); | 119 | Q_D(KFindTransactionDlg); | ||
196 | m_ui->m_regExp->setChecked(false); | 120 | d->ui->m_textEdit->setText(QString()); | ||
197 | m_ui->m_caseSensitive->setChecked(false); | 121 | d->ui->m_regExp->setChecked(false); | ||
198 | m_ui->m_textNegate->setCurrentItem(0); | 122 | d->ui->m_caseSensitive->setChecked(false); | ||
199 | 123 | d->ui->m_textNegate->setCurrentItem(0); | |||
200 | m_ui->m_amountEdit->setEnabled(true); | 124 | | ||
201 | m_ui->m_amountFromEdit->setEnabled(false); | 125 | d->ui->m_amountEdit->setEnabled(true); | ||
202 | m_ui->m_amountToEdit->setEnabled(false); | 126 | d->ui->m_amountFromEdit->setEnabled(false); | ||
203 | m_ui->m_amountEdit->loadText(QString()); | 127 | d->ui->m_amountToEdit->setEnabled(false); | ||
204 | m_ui->m_amountFromEdit->loadText(QString()); | 128 | d->ui->m_amountEdit->loadText(QString()); | ||
205 | m_ui->m_amountToEdit->loadText(QString()); | 129 | d->ui->m_amountFromEdit->loadText(QString()); | ||
206 | m_ui->m_amountButton->setChecked(true); | 130 | d->ui->m_amountToEdit->loadText(QString()); | ||
207 | m_ui->m_amountRangeButton->setChecked(false); | 131 | d->ui->m_amountButton->setChecked(true); | ||
208 | 132 | d->ui->m_amountRangeButton->setChecked(false); | |||
209 | m_ui->m_emptyPayeesButton->setChecked(false); | 133 | | ||
210 | selectAllItems(m_ui->m_payeesView, true); | 134 | d->ui->m_emptyPayeesButton->setChecked(false); | ||
211 | 135 | d->selectAllItems(d->ui->m_payeesView, true); | |||
212 | m_ui->m_emptyTagsButton->setChecked(false); | 136 | | ||
213 | selectAllItems(m_ui->m_tagsView, true); | 137 | d->ui->m_emptyTagsButton->setChecked(false); | ||
214 | 138 | d->selectAllItems(d->ui->m_tagsView, true); | |||
215 | m_ui->m_typeBox->setCurrentIndex((int)eMyMoney::TransactionFilter::Type::All); | 139 | | ||
216 | m_ui->m_stateBox->setCurrentIndex((int)eMyMoney::TransactionFilter::State::All); | 140 | d->ui->m_typeBox->setCurrentIndex((int)eMyMoney::TransactionFilter::Type::All); | ||
217 | m_ui->m_validityBox->setCurrentIndex((int)eMyMoney::TransactionFilter::Validity::Any); | 141 | d->ui->m_stateBox->setCurrentIndex((int)eMyMoney::TransactionFilter::State::All); | ||
218 | 142 | d->ui->m_validityBox->setCurrentIndex((int)eMyMoney::TransactionFilter::Validity::Any); | |||
219 | m_ui->m_nrEdit->setEnabled(true); | 143 | | ||
220 | m_ui->m_nrFromEdit->setEnabled(false); | 144 | d->ui->m_nrEdit->setEnabled(true); | ||
221 | m_ui->m_nrToEdit->setEnabled(false); | 145 | d->ui->m_nrFromEdit->setEnabled(false); | ||
222 | m_ui->m_nrEdit->setText(QString()); | 146 | d->ui->m_nrToEdit->setEnabled(false); | ||
223 | m_ui->m_nrFromEdit->setText(QString()); | 147 | d->ui->m_nrEdit->setText(QString()); | ||
224 | m_ui->m_nrToEdit->setText(QString()); | 148 | d->ui->m_nrFromEdit->setText(QString()); | ||
225 | m_ui->m_nrButton->setChecked(true); | 149 | d->ui->m_nrToEdit->setText(QString()); | ||
226 | m_ui->m_nrRangeButton->setChecked(false); | 150 | d->ui->m_nrButton->setChecked(true); | ||
227 | 151 | d->ui->m_nrRangeButton->setChecked(false); | |||
228 | m_ui->m_tabWidget->setTabEnabled(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage), false); | 152 | | ||
229 | m_ui->m_tabWidget->setCurrentIndex(m_ui->m_tabWidget->indexOf(m_ui->m_criteriaTab)); | 153 | d->ui->m_tabWidget->setTabEnabled(d->ui->m_tabWidget->indexOf(d->ui->m_resultPage), false); | ||
154 | d->ui->m_tabWidget->setCurrentIndex(d->ui->m_tabWidget->indexOf(d->ui->m_criteriaTab)); | ||||
230 | 155 | | |||
231 | // the following call implies a call to slotUpdateSelections, | 156 | // the following call implies a call to slotUpdateSelections, | ||
232 | // that's why we call it last | 157 | // that's why we call it last | ||
233 | m_dateRange->slotReset(); | 158 | d->m_dateRange->slotReset(); | ||
234 | slotUpdateSelections(); | 159 | slotUpdateSelections(); | ||
235 | } | 160 | } | ||
236 | 161 | | |||
237 | void KFindTransactionDlg::slotUpdateSelections() | 162 | void KFindTransactionDlg::slotUpdateSelections() | ||
238 | { | 163 | { | ||
164 | Q_D(KFindTransactionDlg); | ||||
239 | QString txt; | 165 | QString txt; | ||
240 | 166 | | |||
241 | // Text tab | 167 | // Text tab | ||
242 | if (!m_ui->m_textEdit->text().isEmpty()) { | 168 | if (!d->ui->m_textEdit->text().isEmpty()) { | ||
243 | if (!txt.isEmpty()) | 169 | if (!txt.isEmpty()) | ||
244 | txt += ", "; | 170 | txt += ", "; | ||
245 | txt += i18n("Text"); | 171 | txt += i18n("Text"); | ||
246 | m_ui->m_regExp->setEnabled(QRegExp(m_ui->m_textEdit->text()).isValid()); | 172 | d->ui->m_regExp->setEnabled(QRegExp(d->ui->m_textEdit->text()).isValid()); | ||
247 | } else | 173 | } else | ||
248 | m_ui->m_regExp->setEnabled(false); | 174 | d->ui->m_regExp->setEnabled(false); | ||
249 | 175 | | |||
250 | m_ui->m_caseSensitive->setEnabled(!m_ui->m_textEdit->text().isEmpty()); | 176 | d->ui->m_caseSensitive->setEnabled(!d->ui->m_textEdit->text().isEmpty()); | ||
251 | m_ui->m_textNegate->setEnabled(!m_ui->m_textEdit->text().isEmpty()); | 177 | d->ui->m_textNegate->setEnabled(!d->ui->m_textEdit->text().isEmpty()); | ||
252 | 178 | | |||
253 | // Account tab | 179 | // Account tab | ||
254 | if (!m_ui->m_accountsView->allItemsSelected()) { | 180 | if (!d->ui->m_accountsView->allItemsSelected()) { | ||
255 | if (!txt.isEmpty()) | 181 | if (!txt.isEmpty()) | ||
256 | txt += ", "; | 182 | txt += ", "; | ||
257 | txt += i18n("Account"); | 183 | txt += i18n("Account"); | ||
258 | } | 184 | } | ||
259 | 185 | | |||
260 | if (m_dateRange->dateRange() != eMyMoney::TransactionFilter::Date::All) { | 186 | if (d->m_dateRange->dateRange() != eMyMoney::TransactionFilter::Date::All) { | ||
261 | if (!txt.isEmpty()) | 187 | if (!txt.isEmpty()) | ||
262 | txt += ", "; | 188 | txt += ", "; | ||
263 | txt += i18n("Date"); | 189 | txt += i18n("Date"); | ||
264 | } | 190 | } | ||
265 | 191 | | |||
266 | // Amount tab | 192 | // Amount tab | ||
267 | if ((m_ui->m_amountButton->isChecked() && m_ui->m_amountEdit->isValid()) | 193 | if ((d->ui->m_amountButton->isChecked() && d->ui->m_amountEdit->isValid()) | ||
268 | || (m_ui->m_amountRangeButton->isChecked() | 194 | || (d->ui->m_amountRangeButton->isChecked() | ||
269 | && (m_ui->m_amountFromEdit->isValid() || m_ui->m_amountToEdit->isValid()))) { | 195 | && (d->ui->m_amountFromEdit->isValid() || d->ui->m_amountToEdit->isValid()))) { | ||
270 | if (!txt.isEmpty()) | 196 | if (!txt.isEmpty()) | ||
271 | txt += ", "; | 197 | txt += ", "; | ||
272 | txt += i18n("Amount"); | 198 | txt += i18n("Amount"); | ||
273 | } | 199 | } | ||
274 | 200 | | |||
275 | // Categories tab | 201 | // Categories tab | ||
276 | if (!m_ui->m_categoriesView->allItemsSelected()) { | 202 | if (!d->ui->m_categoriesView->allItemsSelected()) { | ||
277 | if (!txt.isEmpty()) | 203 | if (!txt.isEmpty()) | ||
278 | txt += ", "; | 204 | txt += ", "; | ||
279 | txt += i18n("Category"); | 205 | txt += i18n("Category"); | ||
280 | } | 206 | } | ||
281 | 207 | | |||
282 | // Tags tab | 208 | // Tags tab | ||
283 | if (!allItemsSelected(m_ui->m_tagsView) | 209 | if (!d->allItemsSelected(d->ui->m_tagsView) | ||
284 | || m_ui->m_emptyTagsButton->isChecked()) { | 210 | || d->ui->m_emptyTagsButton->isChecked()) { | ||
285 | if (!txt.isEmpty()) | 211 | if (!txt.isEmpty()) | ||
286 | txt += ", "; | 212 | txt += ", "; | ||
287 | txt += i18n("Tags"); | 213 | txt += i18n("Tags"); | ||
288 | } | 214 | } | ||
289 | m_ui->m_tagsView->setEnabled(!m_ui->m_emptyTagsButton->isChecked()); | 215 | d->ui->m_tagsView->setEnabled(!d->ui->m_emptyTagsButton->isChecked()); | ||
290 | 216 | | |||
291 | // Payees tab | 217 | // Payees tab | ||
292 | if (!allItemsSelected(m_ui->m_payeesView) | 218 | if (!d->allItemsSelected(d->ui->m_payeesView) | ||
293 | || m_ui->m_emptyPayeesButton->isChecked()) { | 219 | || d->ui->m_emptyPayeesButton->isChecked()) { | ||
294 | if (!txt.isEmpty()) | 220 | if (!txt.isEmpty()) | ||
295 | txt += ", "; | 221 | txt += ", "; | ||
296 | txt += i18n("Payees"); | 222 | txt += i18n("Payees"); | ||
297 | } | 223 | } | ||
298 | m_ui->m_payeesView->setEnabled(!m_ui->m_emptyPayeesButton->isChecked()); | 224 | d->ui->m_payeesView->setEnabled(!d->ui->m_emptyPayeesButton->isChecked()); | ||
299 | 225 | | |||
300 | // Details tab | 226 | // Details tab | ||
301 | if (m_ui->m_typeBox->currentIndex() != 0 | 227 | if (d->ui->m_typeBox->currentIndex() != 0 | ||
302 | || m_ui->m_stateBox->currentIndex() != 0 | 228 | || d->ui->m_stateBox->currentIndex() != 0 | ||
303 | || m_ui->m_validityBox->currentIndex() != 0 | 229 | || d->ui->m_validityBox->currentIndex() != 0 | ||
304 | || (m_ui->m_nrButton->isChecked() && m_ui->m_nrEdit->text().length() != 0) | 230 | || (d->ui->m_nrButton->isChecked() && d->ui->m_nrEdit->text().length() != 0) | ||
305 | || (m_ui->m_nrRangeButton->isChecked() | 231 | || (d->ui->m_nrRangeButton->isChecked() | ||
306 | && (m_ui->m_nrFromEdit->text().length() != 0 || m_ui->m_nrToEdit->text().length() != 0))) { | 232 | && (d->ui->m_nrFromEdit->text().length() != 0 || d->ui->m_nrToEdit->text().length() != 0))) { | ||
307 | if (!txt.isEmpty()) | 233 | if (!txt.isEmpty()) | ||
308 | txt += ", "; | 234 | txt += ", "; | ||
309 | txt += i18n("Details"); | 235 | txt += i18n("Details"); | ||
310 | } | 236 | } | ||
311 | 237 | | |||
312 | //Show a warning about transfers if Categories are filtered - bug #1523508 | 238 | //Show a warning about transfers if Categories are filtered - bug #1523508 | ||
313 | if (!m_ui->m_categoriesView->allItemsSelected()) { | 239 | if (!d->ui->m_categoriesView->allItemsSelected()) { | ||
314 | m_ui->m_transferWarning->setText(i18n("Warning: Filtering by Category will exclude all transfers from the results.")); | 240 | d->ui->m_transferWarning->setText(i18n("Warning: Filtering by Category will exclude all transfers from the results.")); | ||
315 | } else { | 241 | } else { | ||
316 | m_ui->m_transferWarning->setText(""); | 242 | d->ui->m_transferWarning->setText(""); | ||
317 | } | 243 | } | ||
318 | 244 | | |||
319 | // disable the search button if no selection is made | 245 | // disable the search button if no selection is made | ||
Context not available. | |||||
322 | if (txt.isEmpty()) { | 248 | if (txt.isEmpty()) { | ||
323 | txt = i18nc("No selection", "(None)"); | 249 | txt = i18nc("No selection", "(None)"); | ||
324 | } | 250 | } | ||
325 | m_ui->m_selectedCriteria->setText(i18n("Current selections: %1", txt)); | 251 | d->ui->m_selectedCriteria->setText(i18n("Current selections: %1", txt)); | ||
326 | } | | |||
327 | | ||||
328 | bool KFindTransactionDlg::allItemsSelected(const QTreeWidgetItem *item) const | | |||
329 | { | | |||
330 | QTreeWidgetItem* it_v; | | |||
331 | | ||||
332 | for (int i = 0; i < item->childCount(); ++i) { | | |||
333 | it_v = item->child(i); | | |||
334 | if (!(it_v->checkState(0) == Qt::Checked && allItemsSelected(it_v))) { | | |||
335 | return false; | | |||
336 | } | | |||
337 | } | | |||
338 | return true; | | |||
339 | } | | |||
340 | | ||||
341 | bool KFindTransactionDlg::allItemsSelected(const QTreeWidget* view) const | | |||
342 | { | | |||
343 | QTreeWidgetItem* it_v; | | |||
344 | | ||||
345 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | | |||
346 | it_v = view->invisibleRootItem()->child(i); | | |||
347 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | | |||
348 | if (!(it_v->checkState(0) == Qt::Checked && allItemsSelected(it_v))) { | | |||
349 | return false; | | |||
350 | } else { | | |||
351 | if (!allItemsSelected(it_v)) | | |||
352 | return false; | | |||
353 | } | | |||
354 | } | | |||
355 | } | | |||
356 | return true; | | |||
357 | } | | |||
358 | | ||||
359 | void KFindTransactionDlg::setupAccountsPage(bool withEquityAccounts) | | |||
360 | { | | |||
361 | m_ui->m_accountsView->setSelectionMode(QTreeWidget::MultiSelection); | | |||
362 | AccountSet accountSet; | | |||
363 | accountSet.addAccountGroup(eMyMoney::Account::Asset); | | |||
364 | accountSet.addAccountGroup(eMyMoney::Account::Liability); | | |||
365 | | ||||
366 | if (withEquityAccounts) | | |||
367 | accountSet.addAccountGroup(eMyMoney::Account::Equity); | | |||
368 | | ||||
369 | //set the accountset to show closed account if the settings say so | | |||
370 | accountSet.setHideClosedAccounts(KMyMoneyGlobalSettings::hideClosedAccounts()); | | |||
371 | accountSet.load(m_ui->m_accountsView); | | |||
372 | connect(m_ui->m_accountsView, SIGNAL(stateChanged()), this, SLOT(slotUpdateSelections())); | | |||
373 | } | | |||
374 | | ||||
375 | void KFindTransactionDlg::selectAllItems(QTreeWidget* view, const bool state) | | |||
376 | { | | |||
377 | QTreeWidgetItem* it_v; | | |||
378 | | ||||
379 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | | |||
380 | it_v = view->invisibleRootItem()->child(i); | | |||
381 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | | |||
382 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | | |||
383 | } | | |||
384 | selectAllSubItems(it_v, state); | | |||
385 | } | | |||
386 | slotUpdateSelections(); | | |||
387 | } | | |||
388 | | ||||
389 | void KFindTransactionDlg::selectItems(QTreeWidget* view, const QStringList& list, const bool state) | | |||
390 | { | | |||
391 | QTreeWidgetItem* it_v; | | |||
392 | | ||||
393 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | | |||
394 | it_v = view->invisibleRootItem()->child(i); | | |||
395 | QVariant idData = it_v->data(0, ItemIdRole); | | |||
396 | if (it_v->flags() & Qt::ItemIsUserCheckable && list.contains(idData.toString())) { | | |||
397 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | | |||
398 | } | | |||
399 | selectSubItems(it_v, list, state); | | |||
400 | } | | |||
401 | | ||||
402 | slotUpdateSelections(); | | |||
403 | } | | |||
404 | | ||||
405 | void KFindTransactionDlg::setupCategoriesPage() | | |||
406 | { | | |||
407 | m_ui->m_categoriesView->setSelectionMode(QTreeWidget::MultiSelection); | | |||
408 | AccountSet categorySet; | | |||
409 | categorySet.addAccountGroup(eMyMoney::Account::Income); | | |||
410 | categorySet.addAccountGroup(eMyMoney::Account::Expense); | | |||
411 | categorySet.load(m_ui->m_categoriesView); | | |||
412 | connect(m_ui->m_categoriesView, SIGNAL(stateChanged()), this, SLOT(slotUpdateSelections())); | | |||
413 | } | | |||
414 | | ||||
415 | void KFindTransactionDlg::selectAllSubItems(QTreeWidgetItem* item, const bool state) | | |||
416 | { | | |||
417 | QTreeWidgetItem* it_v; | | |||
418 | | ||||
419 | for (int i = 0; i < item->childCount(); ++i) { | | |||
420 | it_v = item->child(i); | | |||
421 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | | |||
422 | selectAllSubItems(it_v, state); | | |||
423 | } | | |||
424 | } | | |||
425 | | ||||
426 | void KFindTransactionDlg::selectSubItems(QTreeWidgetItem* item, const QStringList& list, const bool state) | | |||
427 | { | | |||
428 | QTreeWidgetItem* it_v; | | |||
429 | | ||||
430 | for (int i = 0; i < item->childCount(); ++i) { | | |||
431 | it_v = item->child(i); | | |||
432 | QVariant idData = it_v->data(0, ItemIdRole); | | |||
433 | if (list.contains(idData.toString())) | | |||
434 | it_v->setCheckState(0, state ? Qt::Checked : Qt::Unchecked); | | |||
435 | selectSubItems(it_v, list, state); | | |||
436 | } | | |||
437 | } | | |||
438 | | ||||
439 | void KFindTransactionDlg::setupAmountPage() | | |||
440 | { | | |||
441 | connect(m_ui->m_amountButton, SIGNAL(clicked()), this, SLOT(slotAmountSelected())); | | |||
442 | connect(m_ui->m_amountRangeButton, SIGNAL(clicked()), this, SLOT(slotAmountRangeSelected())); | | |||
443 | | ||||
444 | connect(m_ui->m_amountEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
445 | connect(m_ui->m_amountFromEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
446 | connect(m_ui->m_amountToEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
447 | | ||||
448 | m_ui->m_amountButton->setChecked(true); | | |||
449 | slotAmountSelected(); | | |||
450 | } | 252 | } | ||
451 | 253 | | |||
452 | void KFindTransactionDlg::slotAmountSelected() | 254 | void KFindTransactionDlg::slotAmountSelected() | ||
453 | { | 255 | { | ||
454 | m_ui->m_amountEdit->setEnabled(true); | 256 | Q_D(KFindTransactionDlg); | ||
455 | m_ui->m_amountFromEdit->setEnabled(false); | 257 | d->ui->m_amountEdit->setEnabled(true); | ||
456 | m_ui->m_amountToEdit->setEnabled(false); | 258 | d->ui->m_amountFromEdit->setEnabled(false); | ||
259 | d->ui->m_amountToEdit->setEnabled(false); | ||||
457 | slotUpdateSelections(); | 260 | slotUpdateSelections(); | ||
458 | } | 261 | } | ||
459 | 262 | | |||
460 | void KFindTransactionDlg::slotAmountRangeSelected() | 263 | void KFindTransactionDlg::slotAmountRangeSelected() | ||
461 | { | 264 | { | ||
462 | m_ui->m_amountEdit->setEnabled(false); | 265 | Q_D(KFindTransactionDlg); | ||
463 | m_ui->m_amountFromEdit->setEnabled(true); | 266 | d->ui->m_amountEdit->setEnabled(false); | ||
464 | m_ui->m_amountToEdit->setEnabled(true); | 267 | d->ui->m_amountFromEdit->setEnabled(true); | ||
268 | d->ui->m_amountToEdit->setEnabled(true); | ||||
465 | slotUpdateSelections(); | 269 | slotUpdateSelections(); | ||
466 | } | 270 | } | ||
467 | 271 | | |||
468 | void KFindTransactionDlg::setupPayeesPage() | | |||
469 | { | | |||
470 | m_ui->m_payeesView->setSelectionMode(QAbstractItemView::SingleSelection); | | |||
471 | m_ui->m_payeesView->header()->hide(); | | |||
472 | m_ui->m_payeesView->setAlternatingRowColors(true); | | |||
473 | | ||||
474 | loadPayees(); | | |||
475 | | ||||
476 | m_ui->m_payeesView->sortItems(0, Qt::AscendingOrder); | | |||
477 | m_ui->m_emptyPayeesButton->setCheckState(Qt::Unchecked); | | |||
478 | | ||||
479 | connect(m_ui->m_allPayeesButton, SIGNAL(clicked()), this, SLOT(slotSelectAllPayees())); | | |||
480 | connect(m_ui->m_clearPayeesButton, SIGNAL(clicked()), this, SLOT(slotDeselectAllPayees())); | | |||
481 | connect(m_ui->m_emptyPayeesButton, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateSelections())); | | |||
482 | connect(m_ui->m_payeesView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateSelections())); | | |||
483 | } | | |||
484 | | ||||
485 | void KFindTransactionDlg::loadPayees() | | |||
486 | { | | |||
487 | MyMoneyFile* file = MyMoneyFile::instance(); | | |||
488 | QList<MyMoneyPayee> list; | | |||
489 | QList<MyMoneyPayee>::Iterator it_l; | | |||
490 | | ||||
491 | list = file->payeeList(); | | |||
492 | // load view | | |||
493 | for (it_l = list.begin(); it_l != list.end(); ++it_l) { | | |||
494 | QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_payeesView); | | |||
495 | item->setText(0, (*it_l).name()); | | |||
496 | item->setData(0, ItemIdRole, (*it_l).id()); | | |||
497 | item->setCheckState(0, Qt::Checked); | | |||
498 | } | | |||
499 | } | | |||
500 | void KFindTransactionDlg::slotSelectAllPayees() | 272 | void KFindTransactionDlg::slotSelectAllPayees() | ||
501 | { | 273 | { | ||
502 | selectAllItems(m_ui->m_payeesView, true); | 274 | Q_D(KFindTransactionDlg); | ||
275 | d->selectAllItems(d->ui->m_payeesView, true); | ||||
503 | } | 276 | } | ||
504 | 277 | | |||
505 | void KFindTransactionDlg::slotDeselectAllPayees() | 278 | void KFindTransactionDlg::slotDeselectAllPayees() | ||
506 | { | 279 | { | ||
507 | selectAllItems(m_ui->m_payeesView, false); | 280 | Q_D(KFindTransactionDlg); | ||
508 | } | 281 | d->selectAllItems(d->ui->m_payeesView, false); | ||
509 | | ||||
510 | void KFindTransactionDlg::setupTagsPage() | | |||
511 | { | | |||
512 | m_ui->m_tagsView->setSelectionMode(QAbstractItemView::SingleSelection); | | |||
513 | m_ui->m_tagsView->header()->hide(); | | |||
514 | m_ui->m_tagsView->setAlternatingRowColors(true); | | |||
515 | | ||||
516 | loadTags(); | | |||
517 | | ||||
518 | m_ui->m_tagsView->sortItems(0, Qt::AscendingOrder); | | |||
519 | m_ui->m_emptyTagsButton->setCheckState(Qt::Unchecked); | | |||
520 | | ||||
521 | connect(m_ui->m_allTagsButton, SIGNAL(clicked()), this, SLOT(slotSelectAllTags())); | | |||
522 | connect(m_ui->m_clearTagsButton, SIGNAL(clicked()), this, SLOT(slotDeselectAllTags())); | | |||
523 | connect(m_ui->m_emptyTagsButton, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateSelections())); | | |||
524 | connect(m_ui->m_tagsView, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateSelections())); | | |||
525 | } | 282 | } | ||
526 | 283 | | |||
527 | void KFindTransactionDlg::loadTags() | | |||
528 | { | | |||
529 | MyMoneyFile* file = MyMoneyFile::instance(); | | |||
530 | QList<MyMoneyTag> list; | | |||
531 | QList<MyMoneyTag>::Iterator it_l; | | |||
532 | | ||||
533 | list = file->tagList(); | | |||
534 | // load view | | |||
535 | for (it_l = list.begin(); it_l != list.end(); ++it_l) { | | |||
536 | QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_tagsView); | | |||
537 | item->setText(0, (*it_l).name()); | | |||
538 | item->setData(0, ItemIdRole, (*it_l).id()); | | |||
539 | item->setCheckState(0, Qt::Checked); | | |||
540 | } | | |||
541 | } | | |||
542 | void KFindTransactionDlg::slotSelectAllTags() | 284 | void KFindTransactionDlg::slotSelectAllTags() | ||
543 | { | 285 | { | ||
544 | selectAllItems(m_ui->m_tagsView, true); | 286 | Q_D(KFindTransactionDlg); | ||
287 | d->selectAllItems(d->ui->m_tagsView, true); | ||||
545 | } | 288 | } | ||
546 | 289 | | |||
547 | void KFindTransactionDlg::slotDeselectAllTags() | 290 | void KFindTransactionDlg::slotDeselectAllTags() | ||
548 | { | 291 | { | ||
549 | selectAllItems(m_ui->m_tagsView, false); | 292 | Q_D(KFindTransactionDlg); | ||
550 | } | 293 | d->selectAllItems(d->ui->m_tagsView, false); | ||
551 | | ||||
552 | void KFindTransactionDlg::setupDetailsPage() | | |||
553 | { | | |||
554 | connect(m_ui->m_typeBox, SIGNAL(activated(int)), this, SLOT(slotUpdateSelections())); | | |||
555 | connect(m_ui->m_stateBox, SIGNAL(activated(int)), this, SLOT(slotUpdateSelections())); | | |||
556 | connect(m_ui->m_validityBox, SIGNAL(activated(int)), this, SLOT(slotUpdateSelections())); | | |||
557 | | ||||
558 | connect(m_ui->m_nrButton, SIGNAL(clicked()), this, SLOT(slotNrSelected())); | | |||
559 | connect(m_ui->m_nrRangeButton, SIGNAL(clicked()), this, SLOT(slotNrRangeSelected())); | | |||
560 | connect(m_ui->m_nrEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
561 | connect(m_ui->m_nrFromEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
562 | connect(m_ui->m_nrToEdit, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateSelections())); | | |||
563 | | ||||
564 | m_ui->m_nrButton->setChecked(true); | | |||
565 | slotNrSelected(); | | |||
566 | } | 294 | } | ||
567 | 295 | | |||
568 | void KFindTransactionDlg::slotNrSelected() | 296 | void KFindTransactionDlg::slotNrSelected() | ||
569 | { | 297 | { | ||
570 | m_ui->m_nrEdit->setEnabled(true); | 298 | Q_D(KFindTransactionDlg); | ||
571 | m_ui->m_nrFromEdit->setEnabled(false); | 299 | d->ui->m_nrEdit->setEnabled(true); | ||
572 | m_ui->m_nrToEdit->setEnabled(false); | 300 | d->ui->m_nrFromEdit->setEnabled(false); | ||
301 | d->ui->m_nrToEdit->setEnabled(false); | ||||
573 | slotUpdateSelections(); | 302 | slotUpdateSelections(); | ||
574 | } | 303 | } | ||
575 | 304 | | |||
576 | void KFindTransactionDlg::slotNrRangeSelected() | 305 | void KFindTransactionDlg::slotNrRangeSelected() | ||
577 | { | 306 | { | ||
578 | m_ui->m_nrEdit->setEnabled(false); | 307 | Q_D(KFindTransactionDlg); | ||
579 | m_ui->m_nrFromEdit->setEnabled(true); | 308 | d->ui->m_nrEdit->setEnabled(false); | ||
580 | m_ui->m_nrToEdit->setEnabled(true); | 309 | d->ui->m_nrFromEdit->setEnabled(true); | ||
310 | d->ui->m_nrToEdit->setEnabled(true); | ||||
581 | slotUpdateSelections(); | 311 | slotUpdateSelections(); | ||
582 | } | 312 | } | ||
583 | 313 | | |||
584 | void KFindTransactionDlg::addItemToFilter(const opTypeE op, const QString& id) | | |||
585 | { | | |||
586 | switch (op) { | | |||
587 | case addAccountToFilter: | | |||
588 | m_filter.addAccount(id); | | |||
589 | break; | | |||
590 | case addCategoryToFilter: | | |||
591 | m_filter.addCategory(id); | | |||
592 | break; | | |||
593 | case addPayeeToFilter: | | |||
594 | m_filter.addPayee(id); | | |||
595 | break; | | |||
596 | case addTagToFilter: | | |||
597 | m_filter.addTag(id); | | |||
598 | break; | | |||
599 | } | | |||
600 | } | | |||
601 | | ||||
602 | void KFindTransactionDlg::scanCheckListItems(const QTreeWidgetItem* item, const opTypeE op) | | |||
603 | { | | |||
604 | QTreeWidgetItem* it_v; | | |||
605 | | ||||
606 | for (int i = 0; i < item->childCount(); ++i) { | | |||
607 | it_v = item->child(i); | | |||
608 | QVariant idData = it_v->data(0, ItemIdRole); | | |||
609 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | | |||
610 | if (it_v->checkState(0) == Qt::Checked) | | |||
611 | addItemToFilter(op, idData.toString()); | | |||
612 | } | | |||
613 | scanCheckListItems(it_v, op); | | |||
614 | } | | |||
615 | } | | |||
616 | | ||||
617 | void KFindTransactionDlg::scanCheckListItems(const QTreeWidget* view, const opTypeE op) | | |||
618 | { | | |||
619 | QTreeWidgetItem* it_v; | | |||
620 | | ||||
621 | for (int i = 0; i < view->invisibleRootItem()->childCount(); ++i) { | | |||
622 | it_v = view->invisibleRootItem()->child(i); | | |||
623 | QVariant idData = it_v->data(0, ItemIdRole); | | |||
624 | if (it_v->flags() & Qt::ItemIsUserCheckable) { | | |||
625 | if (it_v->checkState(0) == Qt::Checked) { | | |||
626 | addItemToFilter(op, idData.toString()); | | |||
627 | } | | |||
628 | } | | |||
629 | scanCheckListItems(it_v, op); | | |||
630 | } | | |||
631 | } | | |||
632 | | ||||
633 | void KFindTransactionDlg::setupFilter() | | |||
634 | { | | |||
635 | m_filter.clear(); | | |||
636 | | ||||
637 | // Text tab | | |||
638 | if (!m_ui->m_textEdit->text().isEmpty()) { | | |||
639 | QRegExp exp(m_ui->m_textEdit->text(), m_ui->m_caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, !m_ui->m_regExp->isChecked() ? QRegExp::Wildcard : QRegExp::RegExp); | | |||
640 | m_filter.setTextFilter(exp, m_ui->m_textNegate->currentIndex() != 0); | | |||
641 | } | | |||
642 | | ||||
643 | // Account tab | | |||
644 | if (!m_ui->m_accountsView->allItemsSelected()) { | | |||
645 | // retrieve a list of selected accounts | | |||
646 | QStringList list; | | |||
647 | m_ui->m_accountsView->selectedItems(list); | | |||
648 | | ||||
649 | // if we're not in expert mode, we need to make sure | | |||
650 | // that all stock accounts for the selected investment | | |||
651 | // account are also selected | | |||
652 | if (!KMyMoneyGlobalSettings::expertMode()) { | | |||
653 | QStringList missing; | | |||
654 | QStringList::const_iterator it_a, it_b; | | |||
655 | for (it_a = list.constBegin(); it_a != list.constEnd(); ++it_a) { | | |||
656 | MyMoneyAccount acc = MyMoneyFile::instance()->account(*it_a); | | |||
657 | if (acc.accountType() == eMyMoney::Account::Investment) { | | |||
658 | for (it_b = acc.accountList().constBegin(); it_b != acc.accountList().constEnd(); ++it_b) { | | |||
659 | if (!list.contains(*it_b)) { | | |||
660 | missing.append(*it_b); | | |||
661 | } | | |||
662 | } | | |||
663 | } | | |||
664 | } | | |||
665 | list += missing; | | |||
666 | } | | |||
667 | | ||||
668 | m_filter.addAccount(list); | | |||
669 | } | | |||
670 | | ||||
671 | // Date tab | | |||
672 | if ((int)m_dateRange->dateRange() != 0) { | | |||
673 | m_filter.setDateFilter(m_dateRange->fromDate(), m_dateRange->toDate()); | | |||
674 | } | | |||
675 | | ||||
676 | // Amount tab | | |||
677 | if ((m_ui->m_amountButton->isChecked() && m_ui->m_amountEdit->isValid())) { | | |||
678 | m_filter.setAmountFilter(m_ui->m_amountEdit->value(), m_ui->m_amountEdit->value()); | | |||
679 | | ||||
680 | } else if ((m_ui->m_amountRangeButton->isChecked() | | |||
681 | && (m_ui->m_amountFromEdit->isValid() || m_ui->m_amountToEdit->isValid()))) { | | |||
682 | | ||||
683 | MyMoneyMoney from(MyMoneyMoney::minValue), to(MyMoneyMoney::maxValue); | | |||
684 | if (m_ui->m_amountFromEdit->isValid()) | | |||
685 | from = m_ui->m_amountFromEdit->value(); | | |||
686 | if (m_ui->m_amountToEdit->isValid()) | | |||
687 | to = m_ui->m_amountToEdit->value(); | | |||
688 | | ||||
689 | m_filter.setAmountFilter(from, to); | | |||
690 | } | | |||
691 | | ||||
692 | // Categories tab | | |||
693 | if (!m_ui->m_categoriesView->allItemsSelected()) { | | |||
694 | m_filter.addCategory(m_ui->m_categoriesView->selectedItems()); | | |||
695 | } | | |||
696 | | ||||
697 | // Tags tab | | |||
698 | if (m_ui->m_emptyTagsButton->isChecked()) { | | |||
699 | m_filter.addTag(QString()); | | |||
700 | | ||||
701 | } else if (!allItemsSelected(m_ui->m_tagsView)) { | | |||
702 | scanCheckListItems(m_ui->m_tagsView, addTagToFilter); | | |||
703 | } | | |||
704 | | ||||
705 | // Payees tab | | |||
706 | if (m_ui->m_emptyPayeesButton->isChecked()) { | | |||
707 | m_filter.addPayee(QString()); | | |||
708 | | ||||
709 | } else if (!allItemsSelected(m_ui->m_payeesView)) { | | |||
710 | scanCheckListItems(m_ui->m_payeesView, addPayeeToFilter); | | |||
711 | } | | |||
712 | | ||||
713 | // Details tab | | |||
714 | if (m_ui->m_typeBox->currentIndex() != 0) | | |||
715 | m_filter.addType(m_ui->m_typeBox->currentIndex()); | | |||
716 | | ||||
717 | if (m_ui->m_stateBox->currentIndex() != 0) | | |||
718 | m_filter.addState(m_ui->m_stateBox->currentIndex()); | | |||
719 | | ||||
720 | if (m_ui->m_validityBox->currentIndex() != 0) | | |||
721 | m_filter.addValidity(m_ui->m_validityBox->currentIndex()); | | |||
722 | | ||||
723 | if (m_ui->m_nrButton->isChecked() && !m_ui->m_nrEdit->text().isEmpty()) | | |||
724 | m_filter.setNumberFilter(m_ui->m_nrEdit->text(), m_ui->m_nrEdit->text()); | | |||
725 | | ||||
726 | if (m_ui->m_nrRangeButton->isChecked() | | |||
727 | && (!m_ui->m_nrFromEdit->text().isEmpty() || !m_ui->m_nrToEdit->text().isEmpty())) { | | |||
728 | m_filter.setNumberFilter(m_ui->m_nrFromEdit->text(), m_ui->m_nrToEdit->text()); | | |||
729 | } | | |||
730 | } | | |||
731 | | ||||
732 | void KFindTransactionDlg::slotSearch() | 314 | void KFindTransactionDlg::slotSearch() | ||
733 | { | 315 | { | ||
316 | Q_D(KFindTransactionDlg); | ||||
734 | // perform the search only if the button is enabled | 317 | // perform the search only if the button is enabled | ||
735 | if (!m_ui->buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) | 318 | if (!d->ui->buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) | ||
736 | return; | 319 | return; | ||
737 | 320 | | |||
738 | // setup the filter from the dialog widgets | 321 | // setup the filter from the dialog widgets | ||
739 | setupFilter(); | 322 | d->setupFilter(); | ||
740 | 323 | | |||
741 | // filter is setup, now fill the register | 324 | // filter is setup, now fill the register | ||
742 | slotRefreshView(); | 325 | slotRefreshView(); | ||
743 | 326 | | |||
744 | m_ui->m_register->setFocus(); | 327 | d->ui->m_register->setFocus(); | ||
745 | } | 328 | } | ||
746 | 329 | | |||
747 | void KFindTransactionDlg::slotRefreshView() | 330 | void KFindTransactionDlg::slotRefreshView() | ||
748 | { | 331 | { | ||
749 | m_needReload = true; | 332 | Q_D(KFindTransactionDlg); | ||
333 | d->m_needReload = true; | ||||
750 | if (isVisible()) { | 334 | if (isVisible()) { | ||
751 | loadView(); | 335 | d->loadView(); | ||
752 | m_needReload = false; | 336 | d->m_needReload = false; | ||
753 | } | 337 | } | ||
754 | } | 338 | } | ||
755 | 339 | | |||
756 | void KFindTransactionDlg::showEvent(QShowEvent* event) | 340 | void KFindTransactionDlg::showEvent(QShowEvent* event) | ||
757 | { | 341 | { | ||
758 | if (m_needReload) { | 342 | Q_D(KFindTransactionDlg); | ||
759 | loadView(); | 343 | if (d->m_needReload) { | ||
760 | m_needReload = false; | 344 | d->loadView(); | ||
345 | d->m_needReload = false; | ||||
761 | } | 346 | } | ||
762 | QDialog::showEvent(event); | 347 | QDialog::showEvent(event); | ||
763 | } | 348 | } | ||
764 | 349 | | |||
765 | void KFindTransactionDlg::loadView() | | |||
766 | { | | |||
767 | // setup sort order | | |||
768 | m_ui->m_register->setSortOrder(KMyMoneyGlobalSettings::sortSearchView()); | | |||
769 | | ||||
770 | // clear out old data | | |||
771 | m_ui->m_register->clear(); | | |||
772 | | ||||
773 | // retrieve the list from the engine | | |||
774 | MyMoneyFile::instance()->transactionList(m_transactionList, m_filter); | | |||
775 | | ||||
776 | // create the elements for the register | | |||
777 | QList<QPair<MyMoneyTransaction, MyMoneySplit> >::const_iterator it; | | |||
778 | QMap<QString, int>uniqueMap; | | |||
779 | MyMoneyMoney deposit, payment; | | |||
780 | | ||||
781 | int splitCount = 0; | | |||
782 | for (it = m_transactionList.constBegin(); it != m_transactionList.constEnd(); ++it) { | | |||
783 | const MyMoneySplit& split = (*it).second; | | |||
784 | MyMoneyAccount acc = MyMoneyFile::instance()->account(split.accountId()); | | |||
785 | ++splitCount; | | |||
786 | uniqueMap[(*it).first.id()]++; | | |||
787 | | ||||
788 | KMyMoneyRegister::Register::transactionFactory(m_ui->m_register, (*it).first, (*it).second, uniqueMap[(*it).first.id()]); | | |||
789 | { // debug stuff | | |||
790 | if (split.shares().isNegative()) { | | |||
791 | payment += split.shares().abs(); | | |||
792 | } else { | | |||
793 | deposit += split.shares().abs(); | | |||
794 | } | | |||
795 | } | | |||
796 | } | | |||
797 | | ||||
798 | // add the group markers | | |||
799 | m_ui->m_register->addGroupMarkers(); | | |||
800 | | ||||
801 | // sort the transactions according to the sort setting | | |||
802 | m_ui->m_register->sortItems(); | | |||
803 | | ||||
804 | // remove trailing and adjacent markers | | |||
805 | m_ui->m_register->removeUnwantedGroupMarkers(); | | |||
806 | | ||||
807 | // turn on the ledger lens for the register | | |||
808 | m_ui->m_register->setLedgerLensForced(); | | |||
809 | | ||||
810 | m_ui->m_register->updateRegister(true); | | |||
811 | | ||||
812 | m_ui->m_register->setFocusToTop(); | | |||
813 | m_ui->m_register->selectItem(m_ui->m_register->focusItem()); | | |||
814 | | ||||
815 | #ifdef KMM_DEBUG | | |||
816 | m_ui->m_foundText->setText(i18np("Found %1 matching transaction (D %2 / P %3 = %4)", | | |||
817 | "Found %1 matching transactions (D %2 / P %3 = %4)", splitCount, deposit.formatMoney("", 2), payment.formatMoney("", 2), (deposit - payment).formatMoney("", 2))); | | |||
818 | #else | | |||
819 | m_ui->m_foundText->setText(i18np("Found %1 matching transaction", "Found %1 matching transactions", splitCount)); | | |||
820 | #endif | | |||
821 | | ||||
822 | m_ui->m_tabWidget->setTabEnabled(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage), true); | | |||
823 | m_ui->m_tabWidget->setCurrentIndex(m_ui->m_tabWidget->indexOf(m_ui->m_resultPage)); | | |||
824 | | ||||
825 | QTimer::singleShot(10, this, SLOT(slotRightSize())); | | |||
826 | } | | |||
827 | | ||||
828 | void KFindTransactionDlg::slotRightSize() | 350 | void KFindTransactionDlg::slotRightSize() | ||
829 | { | 351 | { | ||
830 | m_ui->m_register->update(); | 352 | Q_D(KFindTransactionDlg); | ||
353 | d->ui->m_register->update(); | ||||
831 | } | 354 | } | ||
832 | 355 | | |||
833 | void KFindTransactionDlg::resizeEvent(QResizeEvent* ev) | 356 | void KFindTransactionDlg::resizeEvent(QResizeEvent* ev) | ||
834 | { | 357 | { | ||
358 | Q_D(KFindTransactionDlg); | ||||
835 | // Columns | 359 | // Columns | ||
836 | // 1 = Date | 360 | // 1 = Date | ||
837 | // 2 = Account | 361 | // 2 = Account | ||
Context not available. | |||||
843 | // don't forget the resizer | 367 | // don't forget the resizer | ||
844 | QDialog::resizeEvent(ev); | 368 | QDialog::resizeEvent(ev); | ||
845 | 369 | | |||
846 | if (!m_ui->m_register->isVisible()) | 370 | if (!d->ui->m_register->isVisible()) | ||
847 | return; | 371 | return; | ||
848 | 372 | | |||
849 | // resize the register | 373 | // resize the register | ||
850 | int w = m_ui->m_register->contentsRect().width(); | 374 | int w = d->ui->m_register->contentsRect().width(); | ||
851 | 375 | | |||
852 | int m_debitWidth = 80; | 376 | int m_debitWidth = 80; | ||
853 | int m_creditWidth = 80; | 377 | int m_creditWidth = 80; | ||
854 | 378 | | |||
855 | m_ui->m_register->adjustColumn(1); | 379 | d->ui->m_register->adjustColumn(1); | ||
856 | m_ui->m_register->adjustColumn(2); | 380 | d->ui->m_register->adjustColumn(2); | ||
857 | m_ui->m_register->adjustColumn(5); | 381 | d->ui->m_register->adjustColumn(5); | ||
858 | 382 | | |||
859 | m_ui->m_register->setColumnWidth(6, m_debitWidth); | 383 | d->ui->m_register->setColumnWidth(6, m_debitWidth); | ||
860 | m_ui->m_register->setColumnWidth(7, m_creditWidth); | 384 | d->ui->m_register->setColumnWidth(7, m_creditWidth); | ||
861 | 385 | | |||
862 | for (int i = 0; i < m_ui->m_register->columnCount(); ++i) { | 386 | for (auto i = 0; i < d->ui->m_register->columnCount(); ++i) { | ||
863 | switch (i) { | 387 | switch (i) { | ||
864 | case 4: // skip the one, we want to set | 388 | case 4: // skip the one, we want to set | ||
865 | break; | 389 | break; | ||
866 | default: | 390 | default: | ||
867 | w -= m_ui->m_register->columnWidth(i); | 391 | w -= d->ui->m_register->columnWidth(i); | ||
868 | break; | 392 | break; | ||
869 | } | 393 | } | ||
870 | } | 394 | } | ||
871 | 395 | | |||
872 | m_ui->m_register->setColumnWidth(4, w); | 396 | d->ui->m_register->setColumnWidth(4, w); | ||
873 | } | 397 | } | ||
874 | 398 | | |||
875 | 399 | | |||
876 | void KFindTransactionDlg::slotSelectTransaction() | 400 | void KFindTransactionDlg::slotSelectTransaction() | ||
877 | { | 401 | { | ||
878 | QList<KMyMoneyRegister::RegisterItem*> list = m_ui->m_register->selectedItems(); | 402 | Q_D(KFindTransactionDlg); | ||
403 | auto list = d->ui->m_register->selectedItems(); | ||||
879 | if (!list.isEmpty()) { | 404 | if (!list.isEmpty()) { | ||
880 | KMyMoneyRegister::Transaction* t = dynamic_cast<KMyMoneyRegister::Transaction*>(list[0]); | 405 | KMyMoneyRegister::Transaction* t = dynamic_cast<KMyMoneyRegister::Transaction*>(list[0]); | ||
881 | if (t) { | 406 | if (t) { | ||
Context not available. | |||||
887 | 412 | | |||
888 | bool KFindTransactionDlg::eventFilter(QObject* o, QEvent* e) | 413 | bool KFindTransactionDlg::eventFilter(QObject* o, QEvent* e) | ||
889 | { | 414 | { | ||
890 | bool rc = false; | 415 | Q_D(KFindTransactionDlg); | ||
416 | auto rc = false; | ||||
891 | 417 | | |||
892 | if (o->isWidgetType()) { | 418 | if (o->isWidgetType()) { | ||
893 | if (e->type() == QEvent::KeyPress) { | 419 | if (e->type() == QEvent::KeyPress) { | ||
894 | const QWidget* w = dynamic_cast<const QWidget*>(o); | 420 | const QWidget* w = dynamic_cast<const QWidget*>(o); | ||
895 | QKeyEvent *k = static_cast<QKeyEvent *>(e); | 421 | QKeyEvent *k = static_cast<QKeyEvent *>(e); | ||
896 | if (w == m_ui->m_register) { | 422 | if (w == d->ui->m_register) { | ||
897 | switch (k->key()) { | 423 | switch (k->key()) { | ||
898 | default: | 424 | default: | ||
899 | break; | 425 | break; | ||
Context not available. | |||||
912 | 438 | | |||
913 | void KFindTransactionDlg::slotShowHelp() | 439 | void KFindTransactionDlg::slotShowHelp() | ||
914 | { | 440 | { | ||
915 | QString anchor = m_helpAnchor[m_ui->m_criteriaTab->currentWidget()]; | 441 | Q_D(KFindTransactionDlg); | ||
442 | auto anchor = d->m_helpAnchor[d->ui->m_criteriaTab->currentWidget()]; | ||||
916 | if (anchor.isEmpty()) | 443 | if (anchor.isEmpty()) | ||
917 | anchor = QString("details.search"); | 444 | anchor = QString("details.search"); | ||
918 | 445 | | |||
Context not available. |