Commit f642c191 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Add exact payee name match option

The current 'Match on payees name' option works on a partial match
of the name. In some scenarios, an exact match is expected. The
new option allows to select that on a per payee basis.

The default for new payees entered through the GUI is not changed.
It remains 'No matching'. The default for new payees created during
statement import is the new 'Match exact name' option.

Also, the radio button based selection has been changed to a combobox.

GUI:
CCBUG: 374352
parent bbefd9f1
......@@ -906,12 +906,18 @@ void MyMoneyStatementReader::processTransactionEntry(const MyMoneyStatement::Tra
bool ignoreCase;
QStringList keys;
QStringList::const_iterator it_s;
switch ((*it_p).matchData(ignoreCase, keys)) {
const MyMoneyPayee::payeeMatchType matchType = (*it_p).matchData(ignoreCase, keys);
switch (matchType) {
case MyMoneyPayee::matchDisabled:
break;
case MyMoneyPayee::matchName:
case MyMoneyPayee::matchNameExact:
keys << QString("%1").arg(QRegExp::escape((*it_p).name()));
if(matchType == MyMoneyPayee::matchNameExact) {
keys.clear();
keys << QString("^%1$").arg(QRegExp::escape((*it_p).name()));
}
// tricky fall through here
case MyMoneyPayee::matchKey:
......
......@@ -196,8 +196,11 @@ MyMoneyPayee::payeeMatchType MyMoneyPayee::matchData(bool& ignorecase, QStringLi
if (m_matchingEnabled) {
type = m_usingMatchKey ? matchKey : matchName;
if (type == matchKey)
if (type == matchKey) {
keys = m_matchKey.split(';');
} else if (m_matchKey.compare(QLatin1String("^$")) == 0) {
type = matchNameExact;
}
}
return type;
......@@ -223,6 +226,8 @@ void MyMoneyPayee::setMatchData(payeeMatchType type, bool ignorecase, const QStr
QRegExp validKeyRegExp("[^ ]");
QStringList filteredKeys = keys.filter(validKeyRegExp);
m_matchKey = filteredKeys.join(";");
} else if(type == matchNameExact) {
m_matchKey = QLatin1String("^$");
}
}
}
......
......@@ -83,7 +83,8 @@ public:
typedef enum {
matchDisabled = 0,
matchName,
matchKey
matchKey,
matchNameExact
} payeeMatchType;
MyMoneyPayee();
......
......@@ -193,3 +193,16 @@ void MyMoneyPayeeTest::testMatchKeyAllowSpaceAtEnd()
QVERIFY(ignoreCase == false);
QVERIFY(keys == QLatin1String("payee "));
}
void MyMoneyPayeeTest::testMatchNameExact()
{
MyMoneyPayee payee;
QString keys;
bool ignoreCase;
payee.setMatchData(MyMoneyPayee::matchNameExact, false, keys);
keys = QLatin1String("payee ");
QCOMPARE(payee.matchData(ignoreCase, keys), MyMoneyPayee::matchNameExact);
QCOMPARE(ignoreCase, false);
QVERIFY(keys.isEmpty());
}
......@@ -30,6 +30,7 @@ private slots:
void testMatchKeyDisallowMultipleSpace();
void testMatchKeyAllowSpaceAtStart();
void testMatchKeyAllowSpaceAtEnd();
void testMatchNameExact();
};
#endif
......@@ -96,9 +96,10 @@ KPayeesView::KPayeesView(QWidget *parent) :
m_filterProxyModel->sort(0);
comboDefaultCategory->setModel(m_filterProxyModel);
m_matchType->setId(radioNoMatch, 0);
m_matchType->setId(radioNameMatch, 1);
m_matchType->setId(radioKeyMatch, 2);
matchTypeCombo->addItem(i18nc("@item No matching", "No matching"), MyMoneyPayee::matchDisabled);
matchTypeCombo->addItem(i18nc("@item Match Payees name partially", "Match Payees name (partial)"), MyMoneyPayee::matchName);
matchTypeCombo->addItem(i18nc("@item Match Payees name exactly", "Match Payees name (exact)"), MyMoneyPayee::matchNameExact);
matchTypeCombo->addItem(i18nc("@item Search match in list", "Match on a name listed below"), MyMoneyPayee::matchKey);
// create the searchline widget
// and insert it into the existing layout
......@@ -149,7 +150,7 @@ KPayeesView::KPayeesView(QWidget *parent) :
KGuiItem::assign(m_updateButton, updateButtonItem);
m_updateButton->setEnabled(false);
radioNoMatch->setChecked(true);
matchTypeCombo->setCurrentIndex(0);
checkMatchIgnoreCase->setEnabled(false);
......@@ -187,9 +188,7 @@ KPayeesView::KPayeesView(QWidget *parent) :
connect(notesEdit, SIGNAL(textChanged()), this, SLOT(slotPayeeDataChanged()));
connect(matchKeyEditList, SIGNAL(changed()), this, SLOT(slotKeyListChanged()));
connect(radioNoMatch, SIGNAL(toggled(bool)), this, SLOT(slotPayeeDataChanged()));
connect(radioNameMatch, SIGNAL(toggled(bool)), this, SLOT(slotPayeeDataChanged()));
connect(radioKeyMatch, SIGNAL(toggled(bool)), this, SLOT(slotPayeeDataChanged()));
connect(matchTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(slotPayeeDataChanged()));
connect(checkMatchIgnoreCase, SIGNAL(toggled(bool)), this, SLOT(slotPayeeDataChanged()));
connect(checkEnableDefaultCategory, SIGNAL(toggled(bool)), this, SLOT(slotPayeeDataChanged()));
......@@ -448,7 +447,7 @@ void KPayeesView::slotSelectPayee()
bool ignorecase = false;
MyMoneyPayee::payeeMatchType type = m_payee.matchData(ignorecase, keys);
m_matchType->button(static_cast<int>(type))->setChecked(true);
matchTypeCombo->setCurrentIndex(matchTypeCombo->findData(type));
matchKeyEditList->clear();
matchKeyEditList->insertStringList(keys);
checkMatchIgnoreCase->setChecked(ignorecase);
......@@ -573,7 +572,7 @@ void KPayeesView::slotKeyListChanged()
QStringList keys;
m_payee.matchData(ignorecase, keys);
if (m_matchType->checkedId() == MyMoneyPayee::matchKey) {
if (matchTypeCombo->currentData().toUInt() == MyMoneyPayee::matchKey) {
rc |= (keys != matchKeyEditList->items());
}
setDirty(rc);
......@@ -601,19 +600,19 @@ void KPayeesView::slotPayeeDataChanged()
QStringList keys;
MyMoneyPayee::payeeMatchType type = m_payee.matchData(ignorecase, keys);
rc |= (static_cast<int>(type) != m_matchType->checkedId());
rc |= (static_cast<int>(type) != matchTypeCombo->currentData().toUInt());
checkMatchIgnoreCase->setEnabled(false);
matchKeyEditList->setEnabled(false);
if (m_matchType->checkedId() != MyMoneyPayee::matchDisabled) {
if (matchTypeCombo->currentData().toUInt() != MyMoneyPayee::matchDisabled) {
checkMatchIgnoreCase->setEnabled(true);
// if we turn matching on, we default to 'ignore case'
// TODO maybe make the default a user option
if (type == MyMoneyPayee::matchDisabled && m_matchType->checkedId() != MyMoneyPayee::matchDisabled)
if (type == MyMoneyPayee::matchDisabled && matchTypeCombo->currentData().toUInt() != MyMoneyPayee::matchDisabled)
checkMatchIgnoreCase->setChecked(true);
rc |= (ignorecase != checkMatchIgnoreCase->isChecked());
if (m_matchType->checkedId() == MyMoneyPayee::matchKey) {
if (matchTypeCombo->currentData().toUInt() == MyMoneyPayee::matchKey) {
matchKeyEditList->setEnabled(true);
rc |= (keys != matchKeyEditList->items());
}
......@@ -653,7 +652,7 @@ void KPayeesView::slotUpdatePayee()
m_payee.setTelephone(telephoneEdit->text());
m_payee.setEmail(emailEdit->text());
m_payee.setNotes(notesEdit->toPlainText());
m_payee.setMatchData(static_cast<MyMoneyPayee::payeeMatchType>(m_matchType->checkedId()), checkMatchIgnoreCase->isChecked(), matchKeyEditList->items());
m_payee.setMatchData(static_cast<MyMoneyPayee::payeeMatchType>(matchTypeCombo->currentData().toUInt()), checkMatchIgnoreCase->isChecked(), matchKeyEditList->items());
m_payee.setDefaultAccountId();
m_payee.resetPayeeIdentifiers(payeeIdentifiers->identifiers());
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment