Commit 0b8ebec1 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Implement persistence of validity filter

BUG: 403825
FIXED-IN: 5.0.4
parent e052f183
/*
* Copyright 2003-2018 Thomas Baumgart <tbaumgart@kde.org>
* Copyright 2003-2019 Thomas Baumgart <tbaumgart@kde.org>
* Copyright 2004 Ace Jones <acejones@users.sourceforge.net>
* Copyright 2008-2010 Alvaro Soliverez <asoliverez@gmail.com>
* Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
......@@ -762,6 +762,21 @@ bool MyMoneyTransactionFilter::states(QList<int>& list) const
return result;
}
bool MyMoneyTransactionFilter::validities(QList<int>& list) const
{
Q_D(const MyMoneyTransactionFilter);
auto result = d->m_filterSet.singleFilter.validityFilter;
if (result) {
QHashIterator<int, QString> it_validity(d->m_validity);
while (it_validity.hasNext()) {
it_validity.next();
list += it_validity.key();
}
}
return result;
}
bool MyMoneyTransactionFilter::firstType(int&i) const
{
Q_D(const MyMoneyTransactionFilter);
......@@ -792,6 +807,21 @@ bool MyMoneyTransactionFilter::firstState(int&i) const
return result;
}
bool MyMoneyTransactionFilter::firstValidity(int&i) const
{
Q_D(const MyMoneyTransactionFilter);
auto result = d->m_filterSet.singleFilter.validityFilter;
if (result) {
QHashIterator<int, QString> it_validity(d->m_validity);
if (it_validity.hasNext()) {
it_validity.next();
i = it_validity.key();
}
}
return result;
}
bool MyMoneyTransactionFilter::textFilter(QRegExp& exp) const
{
Q_D(const MyMoneyTransactionFilter);
......
/*
* Copyright 2003-2018 Thomas Baumgart <tbaumgart@kde.org>
* Copyright 2003-2019 Thomas Baumgart <tbaumgart@kde.org>
* Copyright 2004 Ace Jones <acejones@users.sourceforge.net>
* Copyright 2008-2010 Alvaro Soliverez <asoliverez@gmail.com>
* Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
......@@ -471,6 +471,18 @@ public:
bool firstState(int& i) const;
bool states(QList<int>& list) const;
/**
* This method returns whether a validity filter has been set,
* and if so, it returns the first validity in the filter.
*
* @param i reference to int to replace with first validity filter, untouched otherwise
* @return return true if a validity filter has been set
*/
bool firstValidity(int& i) const;
bool validities(QList<int>& list) const;
/**
* This method returns whether a text filter has been set,
* and if so, it returns the text filter.
......
......@@ -3,6 +3,7 @@
* Copyright 2006 Darren Gould <darren_gould@gmx.de>
* Copyright 2007-2010 Alvaro Soliverez <asoliverez@gmail.com>
* Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
* Copyright 2019 Thomas Baumgart <tbaumgart@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -54,7 +55,8 @@ namespace Element {
Amount,
Dates,
Category,
AccountGroup
AccountGroup,
Validity
};
enum class Budget {
......@@ -85,6 +87,7 @@ namespace Attribute {
SettlementPeriod, ShowSTLTCapitalGains, TermsSeparator,
Pattern, CaseSensitive, RegEx, InvertText, State,
From, To,
Validity,
// insert new entries above this line
LastAttribute
};
......@@ -134,7 +137,8 @@ namespace MyMoneyXmlContentHandler2 {
{Element::Report::Amount, QStringLiteral("AMOUNT")},
{Element::Report::Dates, QStringLiteral("DATES")},
{Element::Report::Category, QStringLiteral("CATEGORY")},
{Element::Report::AccountGroup, QStringLiteral("ACCOUNTGROUP")}
{Element::Report::AccountGroup, QStringLiteral("ACCOUNTGROUP")},
{Element::Report::Validity, QStringLiteral("VALIDITY")}
};
return elementNames.value(elementID);
}
......@@ -196,7 +200,8 @@ namespace MyMoneyXmlContentHandler2 {
{Attribute::Report::InvertText, QStringLiteral("inverttext")},
{Attribute::Report::State, QStringLiteral("state")},
{Attribute::Report::From, QStringLiteral("from")},
{Attribute::Report::To, QStringLiteral("to")}
{Attribute::Report::To, QStringLiteral("to")},
{Attribute::Report::Validity, QStringLiteral("validity")}
};
return attributeNames.value(attributeID);
}
......@@ -417,6 +422,26 @@ namespace MyMoneyXmlContentHandler2 {
return stateAttributeLUT().key(text, 5);
}
QHash<int, QString> validityAttributeLUT()
{
static const QHash<int, QString> lut {
{0, QStringLiteral("any")},
{1, QStringLiteral("valid")},
{2, QStringLiteral("invalid")},
};
return lut;
}
QString validityAttributeToString(int textID)
{
return validityAttributeLUT().value(textID);
}
int stringToValidityAttribute(const QString &text)
{
return validityAttributeLUT().key(text, 0);
}
QHash<eMyMoney::TransactionFilter::Date, QString> dateLockLUT()
{
static const QHash<eMyMoney::TransactionFilter::Date, QString> lut {
......@@ -782,6 +807,11 @@ namespace MyMoneyXmlContentHandler2 {
if (state != -1)
report.addState(state);
}
if (elementName(Element::Report::Validity) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Validity))) {
const auto validity = stringToValidityAttribute(c.attribute(attributeName(Attribute::Report::Validity)));
if (validity != -1)
report.addValidity(validity);
}
if (elementName(Element::Report::Number) == c.tagName())
report.setNumberFilter(c.attribute(attributeName(Attribute::Report::From)), c.attribute(attributeName(Attribute::Report::To)));
if (elementName(Element::Report::Amount) == c.tagName())
......@@ -973,6 +1003,20 @@ namespace MyMoneyXmlContentHandler2 {
++it_state;
}
}
QList<int> validitylist;
if (report.validities(validitylist) && ! validitylist.empty()) {
// iterate over payees, and add each one
QList<int>::const_iterator it_validity = validitylist.constBegin();
while (it_validity != validitylist.constEnd()) {
QDomElement p = document.createElement(elementName(Element::Report::Validity));
p.setAttribute(attributeName(Attribute::Report::Validity), validityAttributeToString(*it_validity));
el.appendChild(p);
++it_validity;
}
}
//
// Number Filter
//
......
/*
* Copyright 2002-2018 Thomas Baumgart <tbaumgart@kde.org>
* Copyright 2002-2019 Thomas Baumgart <tbaumgart@kde.org>
* Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
*
* This program is free software; you can redistribute it and/or
......@@ -391,6 +391,10 @@ void KTransactionFilter::resetFilter(MyMoneyReport& rep)
if (rep.firstState(state))
d->ui->m_stateBox->setCurrentIndex(state);
int validity;
if (rep.firstValidity(validity))
d->ui->m_validityBox->setCurrentIndex(validity);
//
// Number Filter
//
......
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