Remove Unnecessary Includes in Headers (#4275)
* refactor: remove unnecessary includes in headers * fix: formatting * chore: changelog * fix: scrollbar * fix: suggestions and old appbase remains * fix: suggestion * fix: missing Qt forward declarations * fix: another qt include * fix: includes for precompiled-headers=off * Add missing `<memory>` includes * Add missing `#pragma once` * Fix tests Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "FilterModel.hpp"
|
||||
#include "controllers/filters/FilterModel.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/filters/FilterRecord.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/StandardItemHelper.hpp"
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/SignalVectorModel.hpp"
|
||||
#include "controllers/filters/FilterRecord.hpp"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class FilterRecord;
|
||||
using FilterRecordPtr = std::shared_ptr<FilterRecord>;
|
||||
|
||||
class FilterModel : public SignalVectorModel<FilterRecordPtr>
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "controllers/filters/FilterRecord.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
FilterRecord::FilterRecord(const QString &name, const QString &filter)
|
||||
: name_(name)
|
||||
, filter_(filter)
|
||||
, id_(QUuid::createUuid())
|
||||
, parser_(std::make_unique<filterparser::FilterParser>(filter))
|
||||
{
|
||||
}
|
||||
|
||||
FilterRecord::FilterRecord(const QString &name, const QString &filter,
|
||||
const QUuid &id)
|
||||
: name_(name)
|
||||
, filter_(filter)
|
||||
, id_(id)
|
||||
, parser_(std::make_unique<filterparser::FilterParser>(filter))
|
||||
{
|
||||
}
|
||||
|
||||
const QString &FilterRecord::getName() const
|
||||
{
|
||||
return this->name_;
|
||||
}
|
||||
|
||||
const QString &FilterRecord::getFilter() const
|
||||
{
|
||||
return this->filter_;
|
||||
}
|
||||
|
||||
const QUuid &FilterRecord::getId() const
|
||||
{
|
||||
return this->id_;
|
||||
}
|
||||
|
||||
bool FilterRecord::valid() const
|
||||
{
|
||||
return this->parser_->valid();
|
||||
}
|
||||
|
||||
bool FilterRecord::filter(const filterparser::ContextMap &context) const
|
||||
{
|
||||
return this->parser_->execute(context);
|
||||
}
|
||||
|
||||
bool FilterRecord::operator==(const FilterRecord &other) const
|
||||
{
|
||||
return std::tie(this->name_, this->filter_, this->id_) ==
|
||||
std::tie(other.name_, other.filter_, other.id_);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "controllers/filters/parser/FilterParser.hpp"
|
||||
#include "controllers/filters/parser/Types.hpp"
|
||||
#include "util/RapidjsonHelpers.hpp"
|
||||
#include "util/RapidJsonSerializeQString.hpp"
|
||||
|
||||
@@ -17,52 +16,21 @@ namespace chatterino {
|
||||
class FilterRecord
|
||||
{
|
||||
public:
|
||||
bool operator==(const FilterRecord &other) const
|
||||
{
|
||||
return std::tie(this->name_, this->filter_, this->id_) ==
|
||||
std::tie(other.name_, other.filter_, other.id_);
|
||||
}
|
||||
FilterRecord(const QString &name, const QString &filter);
|
||||
|
||||
FilterRecord(const QString &name, const QString &filter)
|
||||
: name_(name)
|
||||
, filter_(filter)
|
||||
, id_(QUuid::createUuid())
|
||||
, parser_(std::make_unique<filterparser::FilterParser>(filter))
|
||||
{
|
||||
}
|
||||
FilterRecord(const QString &name, const QString &filter, const QUuid &id);
|
||||
|
||||
FilterRecord(const QString &name, const QString &filter, const QUuid &id)
|
||||
: name_(name)
|
||||
, filter_(filter)
|
||||
, id_(id)
|
||||
, parser_(std::make_unique<filterparser::FilterParser>(filter))
|
||||
{
|
||||
}
|
||||
const QString &getName() const;
|
||||
|
||||
const QString &getName() const
|
||||
{
|
||||
return this->name_;
|
||||
}
|
||||
const QString &getFilter() const;
|
||||
|
||||
const QString &getFilter() const
|
||||
{
|
||||
return this->filter_;
|
||||
}
|
||||
const QUuid &getId() const;
|
||||
|
||||
const QUuid &getId() const
|
||||
{
|
||||
return this->id_;
|
||||
}
|
||||
bool valid() const;
|
||||
|
||||
bool valid() const
|
||||
{
|
||||
return this->parser_->valid();
|
||||
}
|
||||
bool filter(const filterparser::ContextMap &context) const;
|
||||
|
||||
bool filter(const filterparser::ContextMap &context) const
|
||||
{
|
||||
return this->parser_->execute(context);
|
||||
}
|
||||
bool operator==(const FilterRecord &other) const;
|
||||
|
||||
private:
|
||||
QString name_;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "controllers/filters/FilterSet.hpp"
|
||||
|
||||
#include "controllers/filters/FilterRecord.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
FilterSet::FilterSet()
|
||||
{
|
||||
this->listener_ =
|
||||
getCSettings().filterRecords.delayedItemsChanged.connect([this] {
|
||||
this->reloadFilters();
|
||||
});
|
||||
}
|
||||
|
||||
FilterSet::FilterSet(const QList<QUuid> &filterIds)
|
||||
{
|
||||
auto filters = getCSettings().filterRecords.readOnly();
|
||||
for (const auto &f : *filters)
|
||||
{
|
||||
if (filterIds.contains(f->getId()))
|
||||
this->filters_.insert(f->getId(), f);
|
||||
}
|
||||
|
||||
this->listener_ =
|
||||
getCSettings().filterRecords.delayedItemsChanged.connect([this] {
|
||||
this->reloadFilters();
|
||||
});
|
||||
}
|
||||
|
||||
FilterSet::~FilterSet()
|
||||
{
|
||||
this->listener_.disconnect();
|
||||
}
|
||||
|
||||
bool FilterSet::filter(const MessagePtr &m, ChannelPtr channel) const
|
||||
{
|
||||
if (this->filters_.size() == 0)
|
||||
return true;
|
||||
|
||||
filterparser::ContextMap context =
|
||||
filterparser::buildContextMap(m, channel.get());
|
||||
for (const auto &f : this->filters_.values())
|
||||
{
|
||||
if (!f->valid() || !f->filter(context))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const QList<QUuid> FilterSet::filterIds() const
|
||||
{
|
||||
return this->filters_.keys();
|
||||
}
|
||||
|
||||
void FilterSet::reloadFilters()
|
||||
{
|
||||
auto filters = getCSettings().filterRecords.readOnly();
|
||||
for (const auto &key : this->filters_.keys())
|
||||
{
|
||||
bool found = false;
|
||||
for (const auto &f : *filters)
|
||||
{
|
||||
if (f->getId() == key)
|
||||
{
|
||||
found = true;
|
||||
this->filters_.insert(key, f);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
this->filters_.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -1,86 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "controllers/filters/FilterRecord.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include <pajlada/signals.hpp>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QUuid>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class FilterRecord;
|
||||
using FilterRecordPtr = std::shared_ptr<FilterRecord>;
|
||||
struct Message;
|
||||
class Channel;
|
||||
using MessagePtr = std::shared_ptr<const Message>;
|
||||
using ChannelPtr = std::shared_ptr<Channel>;
|
||||
|
||||
class FilterSet
|
||||
{
|
||||
public:
|
||||
FilterSet()
|
||||
{
|
||||
this->listener_ =
|
||||
getCSettings().filterRecords.delayedItemsChanged.connect([this] {
|
||||
this->reloadFilters();
|
||||
});
|
||||
}
|
||||
FilterSet();
|
||||
FilterSet(const QList<QUuid> &filterIds);
|
||||
|
||||
FilterSet(const QList<QUuid> &filterIds)
|
||||
{
|
||||
auto filters = getCSettings().filterRecords.readOnly();
|
||||
for (const auto &f : *filters)
|
||||
{
|
||||
if (filterIds.contains(f->getId()))
|
||||
this->filters_.insert(f->getId(), f);
|
||||
}
|
||||
~FilterSet();
|
||||
|
||||
this->listener_ =
|
||||
getCSettings().filterRecords.delayedItemsChanged.connect([this] {
|
||||
this->reloadFilters();
|
||||
});
|
||||
}
|
||||
|
||||
~FilterSet()
|
||||
{
|
||||
this->listener_.disconnect();
|
||||
}
|
||||
|
||||
bool filter(const MessagePtr &m, ChannelPtr channel) const
|
||||
{
|
||||
if (this->filters_.size() == 0)
|
||||
return true;
|
||||
|
||||
filterparser::ContextMap context =
|
||||
filterparser::buildContextMap(m, channel.get());
|
||||
for (const auto &f : this->filters_.values())
|
||||
{
|
||||
if (!f->valid() || !f->filter(context))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const QList<QUuid> filterIds() const
|
||||
{
|
||||
return this->filters_.keys();
|
||||
}
|
||||
bool filter(const MessagePtr &m, ChannelPtr channel) const;
|
||||
const QList<QUuid> filterIds() const;
|
||||
|
||||
private:
|
||||
QMap<QUuid, FilterRecordPtr> filters_;
|
||||
pajlada::Signals::Connection listener_;
|
||||
|
||||
void reloadFilters()
|
||||
{
|
||||
auto filters = getCSettings().filterRecords.readOnly();
|
||||
for (const auto &key : this->filters_.keys())
|
||||
{
|
||||
bool found = false;
|
||||
for (const auto &f : *filters)
|
||||
{
|
||||
if (f->getId() == key)
|
||||
{
|
||||
found = true;
|
||||
this->filters_.insert(key, f);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
this->filters_.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
void reloadFilters();
|
||||
};
|
||||
|
||||
using FilterSetPtr = std::shared_ptr<FilterSet>;
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "Application.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "controllers/filters/parser/Types.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/twitch/TwitchBadge.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
|
||||
namespace filterparser {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/Message.hpp"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Message;
|
||||
|
||||
}
|
||||
|
||||
namespace filterparser {
|
||||
|
||||
using MessagePtr = std::shared_ptr<const chatterino::Message>;
|
||||
|
||||
Reference in New Issue
Block a user