refactored ModeratinActions

This commit is contained in:
fourtf 2020-02-23 20:10:47 +01:00
parent 8ae9abb250
commit df91ea44c4
4 changed files with 5 additions and 40 deletions

View file

@ -7,8 +7,6 @@
namespace chatterino {
class ModerationActions;
class ModerationActionModel : public SignalVectorModel<ModerationAction>
{
public:
@ -25,8 +23,6 @@ protected:
std::vector<QStandardItem *> &row) override;
friend class HighlightController;
friend class ModerationActions;
};
} // namespace chatterino

View file

@ -2,41 +2,18 @@
#include "Application.hpp"
#include "controllers/moderationactions/ModerationActionModel.hpp"
#include "singletons/Settings.hpp"
#include "util/PersistSignalVector.hpp"
#include <QRegularExpression>
namespace chatterino {
ModerationActions::ModerationActions()
{
}
void ModerationActions::initialize(Settings &settings, Paths &paths)
{
assert(!this->initialized_);
this->initialized_ = true;
this->setting_ =
std::make_unique<ChatterinoSetting<std::vector<ModerationAction>>>(
"/moderation/actions");
for (auto &val : this->setting_->getValue())
{
this->items.insert(val);
}
this->items.delayedItemsChanged.connect([this] { //
this->setting_->setValue(this->items.raw());
});
}
ModerationActionModel *ModerationActions::createModel(QObject *parent)
{
ModerationActionModel *model = new ModerationActionModel(parent);
model->initialize(&this->items);
return model;
persist(this->items, "/moderation/actions");
}
} // namespace chatterino

View file

@ -1,9 +1,7 @@
#pragma once
#include "common/Singleton.hpp"
#include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "controllers/moderationactions/ModerationAction.hpp"
namespace chatterino {
@ -11,21 +9,14 @@ namespace chatterino {
class Settings;
class Paths;
class ModerationActionModel;
class ModerationActions final : public Singleton
{
public:
ModerationActions();
virtual void initialize(Settings &settings, Paths &paths) override;
SignalVector<ModerationAction> items;
ModerationActionModel *createModel(QObject *parent);
private:
std::unique_ptr<ChatterinoSetting<std::vector<ModerationAction>>> setting_;
bool initialized_ = false;
};

View file

@ -174,7 +174,8 @@ ModerationPage::ModerationPage()
EditableModelView *view =
modMode
.emplace<EditableModelView>(
app->moderationActions->createModel(nullptr))
(new ModerationActionModel(nullptr))
->initialized(&app->moderationActions->items))
.getElement();
view->setTitles({"Actions"});