Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/views/payeeidentifierselectiondelegate.cpp
Show All 16 Lines | |||||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "payeeidentifierselectiondelegate.h" | 19 | #include "payeeidentifierselectiondelegate.h" | ||
20 | 20 | | |||
21 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
22 | 22 | | |||
23 | #include "payeeidentifier/payeeidentifierloader.h" | 23 | #include "payeeidentifier/payeeidentifierloader.h" | ||
24 | #include "models/payeeidentifiercontainermodel.h" | 24 | #include "models/payeeidentifiercontainermodel.h" | ||
25 | #include "payeeidentifier/ibanbic/ibanbic.h" | ||||
26 | #include "payeeidentifier/nationalaccount/nationalaccount.h" | ||||
25 | 27 | | |||
26 | 28 | | |||
27 | payeeIdentifierTypeSelectionWidget::payeeIdentifierTypeSelectionWidget(QWidget* parent) | 29 | payeeIdentifierTypeSelectionWidget::payeeIdentifierTypeSelectionWidget(QWidget* parent) | ||
28 | : QComboBox(parent) | 30 | : QComboBox(parent) | ||
29 | { | 31 | { | ||
30 | connect(this, SIGNAL(activated(int)), this, SLOT(itemSelected(int))); | 32 | connect(this, SIGNAL(activated(int)), this, SLOT(itemSelected(int))); | ||
31 | } | 33 | } | ||
32 | 34 | | |||
Show All 16 Lines | 49 | { | |||
49 | Q_UNUSED(index); | 51 | Q_UNUSED(index); | ||
50 | 52 | | |||
51 | payeeIdentifierTypeSelectionWidget* comboBox = new payeeIdentifierTypeSelectionWidget(parent); | 53 | payeeIdentifierTypeSelectionWidget* comboBox = new payeeIdentifierTypeSelectionWidget(parent); | ||
52 | comboBox->setFrame(false); | 54 | comboBox->setFrame(false); | ||
53 | connect(comboBox, SIGNAL(commitData(QWidget*)), this, SIGNAL(commitData(QWidget*))); | 55 | connect(comboBox, SIGNAL(commitData(QWidget*)), this, SIGNAL(commitData(QWidget*))); | ||
54 | 56 | | |||
55 | comboBox->addItem(i18n("Please select the account number type")); | 57 | comboBox->addItem(i18n("Please select the account number type")); | ||
56 | payeeIdentifierLoader *const loader = payeeIdentifierLoader::instance(); | 58 | payeeIdentifierLoader *const loader = payeeIdentifierLoader::instance(); | ||
57 | QStringList pidids = loader->availableDelegates(); | 59 | | ||
58 | Q_FOREACH(QString pidid, pidids) { | 60 | for (const auto &pidid : loader->availableDelegates()) { | ||
59 | comboBox->addItem(loader->translatedDelegateName(pidid), QVariant(pidid)); | 61 | QString delegateName; | ||
62 | if (pidid == payeeIdentifiers::ibanBic::staticPayeeIdentifierIid()) | ||||
63 | delegateName = i18n("IBAN and BIC"); | ||||
64 | else if (pidid == payeeIdentifiers::nationalAccount::staticPayeeIdentifierIid()) | ||||
65 | delegateName = i18n("National Account Number"); | ||||
66 | comboBox->addItem(delegateName, QVariant(pidid)); | ||||
60 | } | 67 | } | ||
68 | | ||||
61 | return comboBox; | 69 | return comboBox; | ||
62 | } | 70 | } | ||
63 | 71 | | |||
64 | void payeeIdentifierSelectionDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const | 72 | void payeeIdentifierSelectionDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const | ||
65 | { | 73 | { | ||
66 | QComboBox *const comboBox = qobject_cast<QComboBox*>(editor); | 74 | QComboBox *const comboBox = qobject_cast<QComboBox*>(editor); | ||
67 | const QString selectedPidType = comboBox->model()->data(comboBox->model()->index(comboBox->currentIndex(), 0), Qt::UserRole).toString(); | 75 | const QString selectedPidType = comboBox->model()->data(comboBox->model()->index(comboBox->currentIndex(), 0), Qt::UserRole).toString(); | ||
68 | payeeIdentifier orig = model->data(index, payeeIdentifierContainerModel::payeeIdentifier).value<payeeIdentifier>(); | 76 | payeeIdentifier orig = model->data(index, payeeIdentifierContainerModel::payeeIdentifier).value<payeeIdentifier>(); | ||
69 | payeeIdentifier ident(orig.id(), payeeIdentifierLoader::instance()->createPayeeIdentifier(selectedPidType)); | 77 | | ||
78 | payeeIdentifier ident; | ||||
79 | if (selectedPidType == payeeIdentifiers::ibanBic::staticPayeeIdentifierIid()) | ||||
80 | ident = payeeIdentifier(orig.id(), new payeeIdentifiers::ibanBic()); | ||||
81 | else if (selectedPidType == payeeIdentifiers::nationalAccount::staticPayeeIdentifierIid()) | ||||
82 | ident = payeeIdentifier(orig.id(), new payeeIdentifiers::nationalAccount()); | ||||
83 | | ||||
70 | model->setData(index, QVariant::fromValue<payeeIdentifier>(ident), payeeIdentifierContainerModel::payeeIdentifier); | 84 | model->setData(index, QVariant::fromValue<payeeIdentifier>(ident), payeeIdentifierContainerModel::payeeIdentifier); | ||
71 | } | 85 | } | ||
72 | 86 | | |||
73 | void payeeIdentifierSelectionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& /*index*/) const | 87 | void payeeIdentifierSelectionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& /*index*/) const | ||
74 | { | 88 | { | ||
75 | editor->setGeometry(option.rect); | 89 | editor->setGeometry(option.rect); | ||
76 | } | 90 | } | ||
77 | 91 | | |||
78 | QSize payeeIdentifierSelectionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const | 92 | QSize payeeIdentifierSelectionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const | ||
79 | { | 93 | { | ||
80 | return QStyledItemDelegate::sizeHint(option, index); | 94 | return QStyledItemDelegate::sizeHint(option, index); | ||
81 | } | 95 | } |