Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/dialogs/kcurrencyeditdlg.cpp
Context not available. | |||||
85 | return QStyledItemDelegate::createEditor(parent, option, index); | 85 | return QStyledItemDelegate::createEditor(parent, option, index); | ||
---|---|---|---|---|---|
86 | } | 86 | } | ||
87 | 87 | | |||
88 | KCurrencyEditDlg::KCurrencyEditDlg(QWidget *parent) : ui(new Ui::KCurrencyEditDlg) | 88 | class KCurrencyEditDlgPrivate | ||
89 | { | 89 | { | ||
90 | Q_UNUSED(parent); | 90 | Q_DISABLE_COPY(KCurrencyEditDlgPrivate) | ||
91 | ui->setupUi(this); | 91 | Q_DECLARE_PUBLIC(KCurrencyEditDlg) | ||
92 | m_searchWidget = new KTreeWidgetSearchLineWidget(this, ui->m_currencyList); | 92 | | ||
93 | m_searchWidget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); | 93 | public: | ||
94 | m_searchWidget->setFocus(); | 94 | KCurrencyEditDlgPrivate(KCurrencyEditDlg *qq) : | ||
95 | ui->verticalLayout->insertWidget(0, m_searchWidget); | 95 | q_ptr(qq), | ||
96 | ui->m_currencyList->setItemDelegate(new KCurrencyEditDelegate(ui->m_currencyList)); | 96 | ui(new Ui::KCurrencyEditDlg) | ||
97 | ui->m_closeButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogClose])); | 97 | { | ||
98 | ui->m_editCurrencyButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentEdit])); | 98 | } | ||
99 | ui->m_selectBaseCurrencyButton->setIcon(QIcon::fromTheme(g_Icons[Icon::KMyMoney])); | 99 | | ||
100 | 100 | ~KCurrencyEditDlgPrivate() | |||
101 | connect(ui->m_currencyList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotOpenContextMenu(QPoint))); | 101 | { | ||
102 | connect(MyMoneyFile::instance(), SIGNAL(dataChanged()), this, SLOT(slotLoadCurrencies())); | 102 | delete ui; | ||
103 | connect(ui->m_currencyList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateCurrency(QTreeWidgetItem*))); | 103 | } | ||
104 | connect(ui->m_currencyList, SIGNAL(itemSelectionChanged()), this, SLOT(slotItemSelectionChanged())); | 104 | | ||
105 | 105 | enum removalModeE :int { RemoveSelected, RemoveUnused }; | |||
106 | connect(ui->m_selectBaseCurrencyButton, SIGNAL(clicked()), this, SLOT(slotSelectBaseCurrency())); | 106 | | ||
107 | connect(ui->m_addCurrencyButton, SIGNAL(clicked()), this, SLOT(slotAddCurrency())); | 107 | void removeCurrency(const removalModeE& mode) | ||
108 | connect(ui->m_removeCurrencyButton, SIGNAL(clicked()), this, SLOT(slotRemoveCurrency())); | 108 | { | ||
109 | connect(ui->m_editCurrencyButton, SIGNAL(clicked()), this, SLOT(slotEditCurrency())); | 109 | Q_Q(KCurrencyEditDlg); | ||
110 | connect(ui->m_removeUnusedCurrencyButton, SIGNAL(clicked()), this, SLOT(slotRemoveUnusedCurrency())); | 110 | auto file = MyMoneyFile::instance(); | ||
111 | MyMoneyFileTransaction ft; | ||||
112 | QBitArray skip((int)eStorage::Reference::Count); | ||||
113 | skip.fill(false); // check reference to all... | ||||
114 | skip.setBit((int)eStorage::Reference::Price); // ...except price | ||||
115 | | ||||
116 | QTreeWidgetItemIterator it (ui->m_currencyList); // iterate over whole tree | ||||
117 | if (mode == RemoveUnused) { | ||||
118 | while (*it) { | ||||
119 | MyMoneySecurity currency = (*it)->data(0, Qt::UserRole).value<MyMoneySecurity>(); | ||||
120 | if (file->baseCurrency() != currency && !file->isReferenced(currency, skip)) | ||||
121 | KMyMoneyUtils::deleteSecurity(currency, q); | ||||
122 | ++it; | ||||
123 | } | ||||
124 | } else if (mode == RemoveSelected) { | ||||
125 | QList<QTreeWidgetItem*> currencyRows = ui->m_currencyList->selectedItems(); | ||||
126 | foreach(auto currencyRow, currencyRows) { | ||||
127 | MyMoneySecurity currency = currencyRow->data(0, Qt::UserRole).value<MyMoneySecurity>(); | ||||
128 | if (file->baseCurrency() != currency && !file->isReferenced(currency, skip)) | ||||
129 | KMyMoneyUtils::deleteSecurity(currency, q); | ||||
130 | } | ||||
131 | } | ||||
132 | ft.commit(); | ||||
133 | ui->m_removeUnusedCurrencyButton->setDisabled(file->currencyList().count() <= 1); | ||||
134 | } | ||||
135 | | ||||
136 | KCurrencyEditDlg *q_ptr; | ||||
137 | Ui::KCurrencyEditDlg *ui; | ||||
138 | | ||||
139 | KAvailableCurrencyDlg *m_availableCurrencyDlg; | ||||
140 | KCurrencyEditorDlg *m_currencyEditorDlg; | ||||
141 | MyMoneySecurity m_currency; | ||||
142 | /** | ||||
143 | * Search widget for the list | ||||
144 | */ | ||||
145 | KTreeWidgetSearchLineWidget* m_searchWidget; | ||||
146 | }; | ||||
147 | | ||||
148 | KCurrencyEditDlg::KCurrencyEditDlg(QWidget *parent) : | ||||
149 | QDialog(parent), | ||||
150 | d_ptr(new KCurrencyEditDlgPrivate(this)) | ||||
151 | { | ||||
152 | Q_D(KCurrencyEditDlg); | ||||
153 | d->ui->setupUi(this); | ||||
154 | d->m_searchWidget = new KTreeWidgetSearchLineWidget(this, d->ui->m_currencyList); | ||||
155 | d->m_searchWidget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); | ||||
156 | d->m_searchWidget->setFocus(); | ||||
157 | d->ui->verticalLayout->insertWidget(0, d->m_searchWidget); | ||||
158 | d->ui->m_currencyList->setItemDelegate(new KCurrencyEditDelegate(d->ui->m_currencyList)); | ||||
159 | d->ui->m_closeButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogClose])); | ||||
160 | d->ui->m_editCurrencyButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DocumentEdit])); | ||||
161 | d->ui->m_selectBaseCurrencyButton->setIcon(QIcon::fromTheme(g_Icons[Icon::KMyMoney])); | ||||
162 | | ||||
163 | connect(d->ui->m_currencyList, &QWidget::customContextMenuRequested, this, &KCurrencyEditDlg::slotOpenContextMenu); | ||||
164 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KCurrencyEditDlg::slotLoadCurrencies); | ||||
165 | connect(d->ui->m_currencyList, &QTreeWidget::itemChanged, this, static_cast<void (KCurrencyEditDlg::*)(QTreeWidgetItem *, int)>(&KCurrencyEditDlg::slotUpdateCurrency)); | ||||
166 | connect(d->ui->m_currencyList, &QTreeWidget::itemSelectionChanged, this, &KCurrencyEditDlg::slotItemSelectionChanged); | ||||
167 | | ||||
168 | connect(d->ui->m_selectBaseCurrencyButton, &QAbstractButton::clicked, this, &KCurrencyEditDlg::slotSelectBaseCurrency); | ||||
169 | connect(d->ui->m_addCurrencyButton, &QAbstractButton::clicked, this, &KCurrencyEditDlg::slotAddCurrency); | ||||
170 | connect(d->ui->m_removeCurrencyButton, &QAbstractButton::clicked, this, &KCurrencyEditDlg::slotRemoveCurrency); | ||||
171 | connect(d->ui->m_editCurrencyButton, &QAbstractButton::clicked, this, &KCurrencyEditDlg::slotEditCurrency); | ||||
172 | connect(d->ui->m_removeUnusedCurrencyButton, &QAbstractButton::clicked, this, &KCurrencyEditDlg::slotRemoveUnusedCurrency); | ||||
111 | 173 | | |||
112 | QTimer::singleShot(10, this, SLOT(timerDone())); | 174 | QTimer::singleShot(10, this, SLOT(timerDone())); | ||
113 | } | 175 | } | ||
114 | 176 | | |||
115 | void KCurrencyEditDlg::timerDone() | 177 | void KCurrencyEditDlg::timerDone() | ||
116 | { | 178 | { | ||
179 | Q_D(KCurrencyEditDlg); | ||||
117 | slotLoadCurrencies(); | 180 | slotLoadCurrencies(); | ||
118 | 181 | | |||
119 | //resize the column widths | 182 | //resize the column widths | ||
120 | for (int i = 0; i < 3; ++i) | 183 | for (auto i = 0; i < 3; ++i) | ||
121 | ui->m_currencyList->resizeColumnToContents(i); | 184 | d->ui->m_currencyList->resizeColumnToContents(i); | ||
122 | 185 | | |||
123 | if (!m_currency.id().isEmpty()) { | 186 | if (!d->m_currency.id().isEmpty()) { | ||
124 | QTreeWidgetItemIterator it(ui->m_currencyList); | 187 | QTreeWidgetItemIterator it(d->ui->m_currencyList); | ||
125 | QTreeWidgetItem* q; | 188 | QTreeWidgetItem* q; | ||
126 | while ((q = *it) != 0) { | 189 | while ((q = *it) != 0) { | ||
127 | if (q->text(1) == m_currency.id()) { | 190 | if (q->text(1) == d->m_currency.id()) { | ||
128 | ui->m_currencyList->scrollToItem(q); | 191 | d->ui->m_currencyList->scrollToItem(q); | ||
129 | break; | 192 | break; | ||
130 | } | 193 | } | ||
131 | ++it; | 194 | ++it; | ||
Context not available. | |||||
135 | 198 | | |||
136 | KCurrencyEditDlg::~KCurrencyEditDlg() | 199 | KCurrencyEditDlg::~KCurrencyEditDlg() | ||
137 | { | 200 | { | ||
201 | Q_D(KCurrencyEditDlg); | ||||
202 | delete d; | ||||
138 | } | 203 | } | ||
139 | 204 | | |||
140 | void KCurrencyEditDlg::slotLoadCurrencies() | 205 | void KCurrencyEditDlg::slotLoadCurrencies() | ||
141 | { | 206 | { | ||
142 | disconnect(ui->m_currencyList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(slotSelectCurrency(QTreeWidgetItem*))); | 207 | Q_D(KCurrencyEditDlg); | ||
143 | disconnect(ui->m_currencyList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateCurrency(QTreeWidgetItem*))); | 208 | disconnect(d->ui->m_currencyList, &QTreeWidget::currentItemChanged, this, static_cast<void (KCurrencyEditDlg::*)(QTreeWidgetItem *, QTreeWidgetItem *)>(&KCurrencyEditDlg::slotSelectCurrency)); | ||
209 | disconnect(d->ui->m_currencyList, &QTreeWidget::itemChanged, this, static_cast<void (KCurrencyEditDlg::*)(QTreeWidgetItem *, int)>(&KCurrencyEditDlg::slotUpdateCurrency)); | ||||
144 | QList<MyMoneySecurity> list = MyMoneyFile::instance()->currencyList(); | 210 | QList<MyMoneySecurity> list = MyMoneyFile::instance()->currencyList(); | ||
145 | QList<MyMoneySecurity>::ConstIterator it; | 211 | QList<MyMoneySecurity>::ConstIterator it; | ||
146 | QTreeWidgetItem *first = 0; | 212 | QTreeWidgetItem *first = 0; | ||
Context not available. | |||||
161 | mask.clear(); | 227 | mask.clear(); | ||
162 | empty.setMask(mask); | 228 | empty.setMask(mask); | ||
163 | 229 | | |||
164 | ui->m_currencyList->clear(); | 230 | d->ui->m_currencyList->clear(); | ||
165 | for (it = list.constBegin(); it != list.constEnd(); ++it) { | 231 | for (it = list.constBegin(); it != list.constEnd(); ++it) { | ||
166 | QTreeWidgetItem *p = new QTreeWidgetItem(ui->m_currencyList); | 232 | QTreeWidgetItem *p = new QTreeWidgetItem(d->ui->m_currencyList); | ||
167 | p->setText(0, (*it).name()); | 233 | p->setText(0, (*it).name()); | ||
168 | p->setData(0, Qt::UserRole, QVariant::fromValue(*it)); | 234 | p->setData(0, Qt::UserRole, QVariant::fromValue(*it)); | ||
169 | p->setFlags(p->flags() | Qt::ItemIsEditable); | 235 | p->setFlags(p->flags() | Qt::ItemIsEditable); | ||
Context not available. | |||||
172 | 238 | | |||
173 | if ((*it).id() == baseCurrency) { | 239 | if ((*it).id() == baseCurrency) { | ||
174 | p->setData(0, Qt::DecorationRole, QIcon::fromTheme(g_Icons[Icon::KMyMoney])); | 240 | p->setData(0, Qt::DecorationRole, QIcon::fromTheme(g_Icons[Icon::KMyMoney])); | ||
175 | if (m_currency.id().isEmpty()) | 241 | if (d->m_currency.id().isEmpty()) | ||
176 | first = p; | 242 | first = p; | ||
177 | } else { | 243 | } else { | ||
178 | p->setData(0, Qt::DecorationRole, empty); | 244 | p->setData(0, Qt::DecorationRole, empty); | ||
179 | } | 245 | } | ||
180 | 246 | | |||
181 | // if we had a previously selected | 247 | // if we had a previously selected | ||
182 | if (!m_currency.id().isEmpty()) { | 248 | if (!d->m_currency.id().isEmpty()) { | ||
183 | if (m_currency.id() == p->text(1)) | 249 | if (d->m_currency.id() == p->text(1)) | ||
184 | first = p; | 250 | first = p; | ||
185 | } else if ((*it).id() == localCurrency && !first) | 251 | } else if ((*it).id() == localCurrency && !first) | ||
186 | first = p; | 252 | first = p; | ||
187 | } | 253 | } | ||
188 | ui->m_removeUnusedCurrencyButton->setDisabled(list.count() <= 1); | 254 | d->ui->m_removeUnusedCurrencyButton->setDisabled(list.count() <= 1); | ||
189 | ui->m_currencyList->sortItems(0, Qt::AscendingOrder); | 255 | d->ui->m_currencyList->sortItems(0, Qt::AscendingOrder); | ||
190 | 256 | | |||
191 | connect(ui->m_currencyList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(slotSelectCurrency(QTreeWidgetItem*))); | 257 | connect(d->ui->m_currencyList, &QTreeWidget::currentItemChanged, this, static_cast<void (KCurrencyEditDlg::*)(QTreeWidgetItem *, QTreeWidgetItem *)>(&KCurrencyEditDlg::slotSelectCurrency)); | ||
192 | connect(ui->m_currencyList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotUpdateCurrency(QTreeWidgetItem*))); | 258 | connect(d->ui->m_currencyList, &QTreeWidget::itemChanged, this, static_cast<void (KCurrencyEditDlg::*)(QTreeWidgetItem *, int)>(&KCurrencyEditDlg::slotUpdateCurrency)); | ||
193 | 259 | | |||
194 | if (first == 0) | 260 | if (first == 0) | ||
195 | first = ui->m_currencyList->invisibleRootItem()->child(0); | 261 | first = d->ui->m_currencyList->invisibleRootItem()->child(0); | ||
196 | if (first != 0) { | 262 | if (first != 0) { | ||
197 | ui->m_currencyList->setCurrentItem(first); | 263 | d->ui->m_currencyList->setCurrentItem(first); | ||
198 | ui->m_currencyList->scrollToItem(first); | 264 | d->ui->m_currencyList->scrollToItem(first); | ||
199 | } | 265 | } | ||
200 | 266 | | |||
201 | slotSelectCurrency(first); | 267 | slotSelectCurrency(first); | ||
202 | } | 268 | } | ||
203 | 269 | | |||
204 | void KCurrencyEditDlg::slotUpdateCurrency(QTreeWidgetItem* item) | 270 | void KCurrencyEditDlg::slotUpdateCurrency(QTreeWidgetItem* citem, int) | ||
271 | { | ||||
272 | slotUpdateCurrency(citem, nullptr); | ||||
273 | } | ||||
274 | | ||||
275 | void KCurrencyEditDlg::slotUpdateCurrency(QTreeWidgetItem* citem, QTreeWidgetItem *pitem) | ||||
205 | { | 276 | { | ||
277 | Q_D(KCurrencyEditDlg); | ||||
278 | Q_UNUSED(pitem) | ||||
206 | //if there is no current item selected, exit | 279 | //if there is no current item selected, exit | ||
207 | if (!ui->m_currencyList->currentItem() || item != ui->m_currencyList->currentItem()) | 280 | if (!d->ui->m_currencyList->currentItem() || citem != d->ui->m_currencyList->currentItem()) | ||
208 | return; | 281 | return; | ||
209 | 282 | | |||
210 | //verify that the stored currency id is not empty and the edited fields are not empty either | 283 | //verify that the stored currency id is not empty and the edited fields are not empty either | ||
211 | if (!m_currency.id().isEmpty() | 284 | if (!d->m_currency.id().isEmpty() | ||
212 | && !ui->m_currencyList->currentItem()->text(2).isEmpty() | 285 | && !d->ui->m_currencyList->currentItem()->text(2).isEmpty() | ||
213 | && !ui->m_currencyList->currentItem()->text(0).isEmpty()) { | 286 | && !d->ui->m_currencyList->currentItem()->text(0).isEmpty()) { | ||
214 | //check that either the name or the id have changed | 287 | //check that either the name or the id have changed | ||
215 | if (ui->m_currencyList->currentItem()->text(2) != m_currency.tradingSymbol() | 288 | if (d->ui->m_currencyList->currentItem()->text(2) != d->m_currency.tradingSymbol() | ||
216 | || ui->m_currencyList->currentItem()->text(0) != m_currency.name()) { | 289 | || d->ui->m_currencyList->currentItem()->text(0) != d->m_currency.name()) { | ||
217 | //update the name and the id | 290 | //update the name and the id | ||
218 | m_currency.setName(ui->m_currencyList->currentItem()->text(0)); | 291 | d->m_currency.setName(d->ui->m_currencyList->currentItem()->text(0)); | ||
219 | m_currency.setTradingSymbol(ui->m_currencyList->currentItem()->text(2)); | 292 | d->m_currency.setTradingSymbol(d->ui->m_currencyList->currentItem()->text(2)); | ||
220 | 293 | | |||
221 | emit updateCurrency(m_currency.id(), m_currency.name(), m_currency.tradingSymbol()); | 294 | emit updateCurrency(d->m_currency.id(), d->m_currency.name(), d->m_currency.tradingSymbol()); | ||
222 | } | 295 | } | ||
223 | } | 296 | } | ||
224 | } | 297 | } | ||
225 | 298 | | |||
226 | void KCurrencyEditDlg::slotSelectCurrency(const QString& id) | 299 | void KCurrencyEditDlg::slotSelectCurrency(const QString& id) | ||
227 | { | 300 | { | ||
228 | QTreeWidgetItemIterator it(ui->m_currencyList); | 301 | Q_D(KCurrencyEditDlg); | ||
302 | QTreeWidgetItemIterator it(d->ui->m_currencyList); | ||||
229 | 303 | | |||
230 | while (*it) { | 304 | while (*it) { | ||
231 | if ((*it)->text(1) == id) { | 305 | if ((*it)->text(1) == id) { | ||
232 | ui->m_currencyList->blockSignals(true); | 306 | d->ui->m_currencyList->blockSignals(true); | ||
233 | slotSelectCurrency(*it); | 307 | slotSelectCurrency(*it); | ||
234 | ui->m_currencyList->setCurrentItem(*it); | 308 | d->ui->m_currencyList->setCurrentItem(*it); | ||
235 | ui->m_currencyList->scrollToItem(*it); | 309 | d->ui->m_currencyList->scrollToItem(*it); | ||
236 | ui->m_currencyList->blockSignals(false); | 310 | d->ui->m_currencyList->blockSignals(false); | ||
237 | break; | 311 | break; | ||
238 | } | 312 | } | ||
239 | ++it; | 313 | ++it; | ||
240 | } | 314 | } | ||
241 | } | 315 | } | ||
242 | 316 | | |||
317 | void KCurrencyEditDlg::slotSelectCurrency(QTreeWidgetItem *citem, QTreeWidgetItem *pitem) | ||||
318 | { | ||||
319 | Q_UNUSED(pitem) | ||||
320 | slotSelectCurrency(citem); | ||||
321 | } | ||||
322 | | ||||
243 | void KCurrencyEditDlg::slotSelectCurrency(QTreeWidgetItem *item) | 323 | void KCurrencyEditDlg::slotSelectCurrency(QTreeWidgetItem *item) | ||
244 | { | 324 | { | ||
245 | MyMoneyFile* file = MyMoneyFile::instance(); | 325 | Q_D(KCurrencyEditDlg); | ||
326 | auto file = MyMoneyFile::instance(); | ||||
246 | QString baseId; | 327 | QString baseId; | ||
247 | try { | 328 | try { | ||
248 | baseId = MyMoneyFile::instance()->baseCurrency().id(); | 329 | baseId = MyMoneyFile::instance()->baseCurrency().id(); | ||
Context not available. | |||||
251 | 332 | | |||
252 | if (item) { | 333 | if (item) { | ||
253 | try { | 334 | try { | ||
254 | m_currency = file->security(item->text(1)); | 335 | d->m_currency = file->security(item->text(1)); | ||
255 | 336 | | |||
256 | } catch (const MyMoneyException &) { | 337 | } catch (const MyMoneyException &) { | ||
257 | m_currency = MyMoneySecurity(); | 338 | d->m_currency = MyMoneySecurity(); | ||
258 | } | 339 | } | ||
259 | 340 | | |||
260 | QBitArray skip((int)eStorage::Reference::Count); | 341 | QBitArray skip((int)eStorage::Reference::Count); | ||
261 | skip.fill(false); | 342 | skip.fill(false); | ||
262 | skip.setBit((int)eStorage::Reference::Price); | 343 | skip.setBit((int)eStorage::Reference::Price); | ||
263 | 344 | | |||
264 | const bool rc1 = m_currency.id() == baseId; | 345 | const bool rc1 = d->m_currency.id() == baseId; | ||
265 | const bool rc2 = file->isReferenced(m_currency, skip); | 346 | const bool rc2 = file->isReferenced(d->m_currency, skip); | ||
266 | const int count = ui->m_currencyList->selectedItems().count(); | 347 | const int count = d->ui->m_currencyList->selectedItems().count(); | ||
267 | 348 | | |||
268 | ui->m_selectBaseCurrencyButton->setDisabled(rc1 || count != 1); | 349 | d->ui->m_selectBaseCurrencyButton->setDisabled(rc1 || count != 1); | ||
269 | ui->m_editCurrencyButton->setDisabled(count != 1); | 350 | d->ui->m_editCurrencyButton->setDisabled(count != 1); | ||
270 | ui->m_removeCurrencyButton->setDisabled((rc1 || rc2) && count <= 1); | 351 | d->ui->m_removeCurrencyButton->setDisabled((rc1 || rc2) && count <= 1); | ||
271 | emit selectObject(m_currency); | 352 | emit selectObject(d->m_currency); | ||
272 | } | 353 | } | ||
273 | } | 354 | } | ||
274 | 355 | | |||
275 | void KCurrencyEditDlg::slotItemSelectionChanged() | 356 | void KCurrencyEditDlg::slotItemSelectionChanged() | ||
276 | { | 357 | { | ||
277 | int count = ui->m_currencyList->selectedItems().count(); | 358 | Q_D(KCurrencyEditDlg); | ||
278 | if (!ui->m_selectBaseCurrencyButton->isEnabled() && count == 1) | 359 | int count = d->ui->m_currencyList->selectedItems().count(); | ||
279 | slotSelectCurrency(ui->m_currencyList->currentItem()); | 360 | if (!d->ui->m_selectBaseCurrencyButton->isEnabled() && count == 1) | ||
361 | slotSelectCurrency(d->ui->m_currencyList->currentItem()); | ||||
280 | if (count > 1) | 362 | if (count > 1) | ||
281 | ui->m_removeCurrencyButton->setEnabled(true); | 363 | d->ui->m_removeCurrencyButton->setEnabled(true); | ||
282 | } | 364 | } | ||
283 | 365 | | |||
284 | void KCurrencyEditDlg::slotStartRename() | 366 | void KCurrencyEditDlg::slotStartRename() | ||
285 | { | 367 | { | ||
286 | QTreeWidgetItemIterator it_l(ui->m_currencyList, QTreeWidgetItemIterator::Selected); | 368 | Q_D(KCurrencyEditDlg); | ||
369 | QTreeWidgetItemIterator it_l(d->ui->m_currencyList, QTreeWidgetItemIterator::Selected); | ||||
287 | QTreeWidgetItem* it_v; | 370 | QTreeWidgetItem* it_v; | ||
288 | if ((it_v = *it_l) != 0) { | 371 | if ((it_v = *it_l) != 0) { | ||
289 | ui->m_currencyList->editItem(it_v, 0); | 372 | d->ui->m_currencyList->editItem(it_v, 0); | ||
290 | } | 373 | } | ||
291 | } | 374 | } | ||
292 | 375 | | |||
293 | void KCurrencyEditDlg::slotOpenContextMenu(const QPoint& p) | 376 | void KCurrencyEditDlg::slotOpenContextMenu(const QPoint& p) | ||
294 | { | 377 | { | ||
295 | QTreeWidgetItem* item = ui->m_currencyList->itemAt(p); | 378 | Q_D(KCurrencyEditDlg); | ||
379 | QTreeWidgetItem* item = d->ui->m_currencyList->itemAt(p); | ||||
296 | if (item) | 380 | if (item) | ||
297 | emit openContextMenu(item->data(0, Qt::UserRole).value<MyMoneySecurity>()); | 381 | emit openContextMenu(item->data(0, Qt::UserRole).value<MyMoneySecurity>()); | ||
298 | } | 382 | } | ||
299 | 383 | | |||
300 | void KCurrencyEditDlg::slotSelectBaseCurrency() | 384 | void KCurrencyEditDlg::slotSelectBaseCurrency() | ||
301 | { | 385 | { | ||
302 | if (!m_currency.id().isEmpty()) { | 386 | Q_D(KCurrencyEditDlg); | ||
303 | QTreeWidgetItem* p = ui->m_currencyList->currentItem(); | 387 | if (!d->m_currency.id().isEmpty()) { | ||
304 | emit selectBaseCurrency(m_currency); | 388 | QTreeWidgetItem* p = d->ui->m_currencyList->currentItem(); | ||
389 | emit selectBaseCurrency(d->m_currency); | ||||
305 | // in case the dataChanged() signal was not sent out (nested FileTransaction) | 390 | // in case the dataChanged() signal was not sent out (nested FileTransaction) | ||
306 | // we update the list manually | 391 | // we update the list manually | ||
307 | if (p == ui->m_currencyList->currentItem()) | 392 | if (p == d->ui->m_currencyList->currentItem()) | ||
308 | slotLoadCurrencies(); | 393 | slotLoadCurrencies(); | ||
309 | } | 394 | } | ||
310 | } | 395 | } | ||
311 | 396 | | |||
312 | void KCurrencyEditDlg::slotAddCurrency() | 397 | void KCurrencyEditDlg::slotAddCurrency() | ||
313 | { | 398 | { | ||
314 | m_availableCurrencyDlg = new KAvailableCurrencyDlg; // create new dialog for selecting currencies to add | 399 | Q_D(KCurrencyEditDlg); | ||
315 | if (m_availableCurrencyDlg->exec() != QDialog::Rejected) { | 400 | d->m_availableCurrencyDlg = new KAvailableCurrencyDlg; // create new dialog for selecting currencies to add | ||
316 | MyMoneyFile* file = MyMoneyFile::instance(); | 401 | if (d->m_availableCurrencyDlg->exec() != QDialog::Rejected) { | ||
402 | auto file = MyMoneyFile::instance(); | ||||
317 | QMap<MyMoneySecurity, MyMoneyPrice> ancientCurrencies = file->ancientCurrencies(); | 403 | QMap<MyMoneySecurity, MyMoneyPrice> ancientCurrencies = file->ancientCurrencies(); | ||
318 | MyMoneyFileTransaction ft; | 404 | MyMoneyFileTransaction ft; | ||
319 | QList<QTreeWidgetItem *> currencyRows = m_availableCurrencyDlg->ui->m_currencyList->selectedItems(); // get selected currencies from new dialog | 405 | QList<QTreeWidgetItem *> currencyRows = d->m_availableCurrencyDlg->ui->m_currencyList->selectedItems(); // get selected currencies from new dialog | ||
320 | foreach (auto currencyRow, currencyRows) { | 406 | foreach (auto currencyRow, currencyRows) { | ||
321 | MyMoneySecurity currency = currencyRow->data(0, Qt::UserRole).value<MyMoneySecurity>(); | 407 | MyMoneySecurity currency = currencyRow->data(0, Qt::UserRole).value<MyMoneySecurity>(); | ||
322 | file->addCurrency(currency); | 408 | file->addCurrency(currency); | ||
Context not available. | |||||
324 | file->addPrice(ancientCurrencies[currency]); // ...we want to add last known exchange rate as well | 410 | file->addPrice(ancientCurrencies[currency]); // ...we want to add last known exchange rate as well | ||
325 | } | 411 | } | ||
326 | ft.commit(); | 412 | ft.commit(); | ||
327 | ui->m_removeUnusedCurrencyButton->setDisabled(file->currencyList().count() <= 1); | 413 | d->ui->m_removeUnusedCurrencyButton->setDisabled(file->currencyList().count() <= 1); | ||
328 | } | | |||
329 | delete m_availableCurrencyDlg; | | |||
330 | } | | |||
331 | | ||||
332 | void KCurrencyEditDlg::removeCurrency(const removalModeE& mode) | | |||
333 | { | | |||
334 | MyMoneyFile* file = MyMoneyFile::instance(); | | |||
335 | MyMoneyFileTransaction ft; | | |||
336 | QBitArray skip((int)eStorage::Reference::Count); | | |||
337 | skip.fill(false); // check reference to all... | | |||
338 | skip.setBit((int)eStorage::Reference::Price); // ...except price | | |||
339 | | ||||
340 | QTreeWidgetItemIterator it (ui->m_currencyList); // iterate over whole tree | | |||
341 | if (mode == RemoveUnused) { | | |||
342 | while (*it) { | | |||
343 | MyMoneySecurity currency = (*it)->data(0, Qt::UserRole).value<MyMoneySecurity>(); | | |||
344 | if (file->baseCurrency() != currency && !file->isReferenced(currency, skip)) | | |||
345 | KMyMoneyUtils::deleteSecurity(currency, this); | | |||
346 | ++it; | | |||
347 | } | | |||
348 | } else if (mode == RemoveSelected) { | | |||
349 | QList<QTreeWidgetItem*> currencyRows = ui->m_currencyList->selectedItems(); | | |||
350 | foreach(auto currencyRow, currencyRows) { | | |||
351 | MyMoneySecurity currency = currencyRow->data(0, Qt::UserRole).value<MyMoneySecurity>(); | | |||
352 | if (file->baseCurrency() != currency && !file->isReferenced(currency, skip)) | | |||
353 | KMyMoneyUtils::deleteSecurity(currency, this); | | |||
354 | } | | |||
355 | } | 414 | } | ||
356 | ft.commit(); | 415 | delete d->m_availableCurrencyDlg; | ||
357 | ui->m_removeUnusedCurrencyButton->setDisabled(file->currencyList().count() <= 1); | | |||
358 | } | 416 | } | ||
359 | 417 | | |||
360 | void KCurrencyEditDlg::slotRemoveCurrency() | 418 | void KCurrencyEditDlg::slotRemoveCurrency() | ||
361 | { | 419 | { | ||
362 | removeCurrency(RemoveSelected); | 420 | Q_D(KCurrencyEditDlg); | ||
421 | d->removeCurrency(KCurrencyEditDlgPrivate::RemoveSelected); | ||||
363 | } | 422 | } | ||
364 | 423 | | |||
365 | void KCurrencyEditDlg::slotRemoveUnusedCurrency() | 424 | void KCurrencyEditDlg::slotRemoveUnusedCurrency() | ||
366 | { | 425 | { | ||
367 | removeCurrency(RemoveUnused); | 426 | Q_D(KCurrencyEditDlg); | ||
427 | d->removeCurrency(KCurrencyEditDlgPrivate::RemoveUnused); | ||||
368 | } | 428 | } | ||
369 | 429 | | |||
370 | void KCurrencyEditDlg::slotEditCurrency() | 430 | void KCurrencyEditDlg::slotEditCurrency() | ||
371 | { | 431 | { | ||
372 | MyMoneySecurity currency = ui->m_currencyList->currentItem()->data(0, Qt::UserRole).value<MyMoneySecurity>(); | 432 | Q_D(KCurrencyEditDlg); | ||
373 | m_currencyEditorDlg = new KCurrencyEditorDlg(currency); // create new dialog for editing currency | 433 | MyMoneySecurity currency = d->ui->m_currencyList->currentItem()->data(0, Qt::UserRole).value<MyMoneySecurity>(); | ||
374 | if (m_currencyEditorDlg->exec() != QDialog::Rejected) { | 434 | d->m_currencyEditorDlg = new KCurrencyEditorDlg(currency); // create new dialog for editing currency | ||
375 | MyMoneyFile* file = MyMoneyFile::instance(); | 435 | if (d->m_currencyEditorDlg->exec() != QDialog::Rejected) { | ||
436 | auto file = MyMoneyFile::instance(); | ||||
376 | MyMoneyFileTransaction ft; | 437 | MyMoneyFileTransaction ft; | ||
377 | currency.setPricePrecision(m_currencyEditorDlg->ui->m_pricePrecision->value()); | 438 | currency.setPricePrecision(d->m_currencyEditorDlg->ui->m_pricePrecision->value()); | ||
378 | try { | 439 | try { | ||
379 | file->modifyCurrency(currency); | 440 | file->modifyCurrency(currency); | ||
380 | ft.commit(); | 441 | ft.commit(); | ||
Context not available. | |||||
382 | qDebug("%s", qPrintable(e.what())); | 443 | qDebug("%s", qPrintable(e.what())); | ||
383 | } | 444 | } | ||
384 | } | 445 | } | ||
385 | delete m_currencyEditorDlg; | 446 | delete d->m_currencyEditorDlg; | ||
386 | } | 447 | } | ||
Context not available. |