diff --git a/src/IntervalFilterAllWithTags.cpp b/src/IntervalFilterAllWithTags.cpp index 19621d8f..89a77de0 100644 --- a/src/IntervalFilterAllWithTags.cpp +++ b/src/IntervalFilterAllWithTags.cpp @@ -27,18 +27,59 @@ #include #include -IntervalFilterAllWithTags::IntervalFilterAllWithTags (std::set tags): _tags (std::move(tags)) +IntervalFilterAllWithTags::IntervalFilterAllWithTags (std::set tags, const bool complexFiltering): _tags (std::move(tags)), _complexFiltering (complexFiltering) {} bool IntervalFilterAllWithTags::accepts (const Interval& interval) { - for (auto& tag : _tags) - { - if (! interval.hasTag (tag)) + if (_complexFiltering) { + // TODO: WIP, This does not fully implement boolean logic. + // Check if OR exists. + bool isOr = false; + for (auto& tag : _tags) { - return false; + if (tag == "OR") + { + isOr = true; + break; + } } + + for (auto& tag : _tags) + { + // Process negation + bool isNegative = tag[0] == '-'; + std::string tagName = isNegative ? tag.substr(1) : tag; + bool hasTag = interval.hasTag(tagName); + if (isNegative) hasTag = !hasTag; + + // Return true at the first sign of a tag, if we're using OR logic. + if (isOr && hasTag) + { + return true; + } + + // Return false at the first sign of miss, if we're using AND logic. + if (!isOr && !hasTag) + { + return false; + } + } + + // OR logic : Nothing triggered the match, so this interval does not match. + // AND logic: Nothing triggered the miss, so this interval matches. + return isOr ? false : true; } + else { + // Old filtering AND logic + for (auto& tag : _tags) + { + if (! interval.hasTag (tag)) + { + return false; + } + } - return true; + return true; + } } diff --git a/src/IntervalFilterAllWithTags.h b/src/IntervalFilterAllWithTags.h index 9e204113..8418dd30 100644 --- a/src/IntervalFilterAllWithTags.h +++ b/src/IntervalFilterAllWithTags.h @@ -35,12 +35,13 @@ class IntervalFilterAllWithTags : public IntervalFilter { public: - explicit IntervalFilterAllWithTags(std::set ); + explicit IntervalFilterAllWithTags(std::set , const bool complexFiltering); bool accepts (const Interval&) final; private: const std::set _tags {}; + const bool _complexFiltering {}; }; #endif //INCLUDED_INTERVALFILTERTAGSET diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 2fcc7f6f..cf322122 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -100,7 +100,7 @@ int renderChart ( // Load the data. auto filtering = IntervalFilterAndGroup ({ new IntervalFilterAllInRange ({ filter.start, filter.end }), - new IntervalFilterAllWithTags (filter.tags()) + new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) }); auto tracked = getTracked (database, rules, filtering); diff --git a/src/commands/CmdContinue.cpp b/src/commands/CmdContinue.cpp index ba8dac52..5836a8b5 100644 --- a/src/commands/CmdContinue.cpp +++ b/src/commands/CmdContinue.cpp @@ -77,7 +77,7 @@ int CmdContinue ( } else if (!filter.tags ().empty ()) { - auto filtering = IntervalFilterAllWithTags (filter.tags()); + auto filtering = IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")); auto tracked = getTracked (database, rules, filtering); if (tracked.empty()) diff --git a/src/commands/CmdExport.cpp b/src/commands/CmdExport.cpp index b1e3d088..e702bd18 100644 --- a/src/commands/CmdExport.cpp +++ b/src/commands/CmdExport.cpp @@ -41,7 +41,7 @@ int CmdExport ( auto filtering = IntervalFilterAndGroup ({ new IntervalFilterAllInRange ({ filter.start, filter.end }), - new IntervalFilterAllWithTags (filter.tags()) + new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) }); auto tracked = getTracked (database, rules, filtering); diff --git a/src/commands/CmdReport.cpp b/src/commands/CmdReport.cpp index 7f811024..d16a9218 100644 --- a/src/commands/CmdReport.cpp +++ b/src/commands/CmdReport.cpp @@ -96,7 +96,7 @@ int CmdReport ( auto filter = cli.getFilter (); auto filtering = IntervalFilterAndGroup ({ new IntervalFilterAllInRange ({ filter.start, filter.end }), - new IntervalFilterAllWithTags (filter.tags ()) + new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) }); auto tracked = getTracked (database, rules, filtering); diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index 6f795b0a..e5e6de0a 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -53,7 +53,7 @@ int CmdSummary ( // Load the data. auto filtering = IntervalFilterAndGroup ({ new IntervalFilterAllInRange ({ filter.start, filter.end }), - new IntervalFilterAllWithTags (filter.tags()) + new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) }); auto tracked = getTracked (database, rules, filtering); diff --git a/src/commands/CmdTags.cpp b/src/commands/CmdTags.cpp index 47d45b99..c7536ec3 100644 --- a/src/commands/CmdTags.cpp +++ b/src/commands/CmdTags.cpp @@ -47,7 +47,7 @@ int CmdTags ( auto filter = cli.getFilter (); auto filtering = IntervalFilterAndGroup ({ new IntervalFilterAllInRange ({ filter.start, filter.end }), - new IntervalFilterAllWithTags (filter.tags ()) + new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) }); // Generate a unique, ordered list of tags. diff --git a/src/dom.cpp b/src/dom.cpp index 689971a3..a6bd58f3 100644 --- a/src/dom.cpp +++ b/src/dom.cpp @@ -112,7 +112,7 @@ bool domGet ( { auto filtering = IntervalFilterAndGroup ({ new IntervalFilterAllInRange ({ filter.start, filter.end }), - new IntervalFilterAllWithTags (filter.tags()) + new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) }); auto tracked = getTracked (database, rules, filtering);