some more refactoring

This commit is contained in:
fourtf
2020-02-23 17:45:59 +01:00
parent e1838154ff
commit 4a5dc80bc6
12 changed files with 62 additions and 75 deletions
+21 -18
View File
@@ -115,30 +115,33 @@ public:
this->itemsChanged_();
}
// compatability
[[deprecated]] int insertItem(const T &item, int proposedIndex = -1,
void *caller = nullptr)
{
return this->insert(item, proposedIndex, caller);
}
[[deprecated]] int appendItem(const T &item, void *caller = nullptr)
{
return this->append(item, caller);
}
[[deprecated]] void removeItem(int index, void *caller = nullptr)
{
this->removeAt(index, caller);
}
[[deprecated]] const std::vector<T> &getVector() const
const std::vector<T> &raw() const
{
assertInGuiThread();
return this->items_;
}
// compatability
[[deprecated("use insert")]] int insertItem(const T &item,
int proposedIndex = -1,
void *caller = nullptr)
{
return this->insert(item, proposedIndex, caller);
}
[[deprecated("use append")]] int appendItem(const T &item,
void *caller = nullptr)
{
return this->append(item, caller);
}
[[deprecated("use removeAt")]] void removeItem(int index,
void *caller = nullptr)
{
this->removeAt(index, caller);
}
[[deprecated]] std::vector<T> cloneVector()
{
return *this->readOnly();
+4 -4
View File
@@ -52,7 +52,7 @@ public:
};
int i = 0;
for (const TVectorItem &item : vec->getVector())
for (const TVectorItem &item : vec->raw())
{
SignalVectorItemArgs<TVectorItem> args{item, i++, 0};
@@ -272,15 +272,15 @@ public:
int from = data->data("chatterino_row_id").toInt();
int to = parent.row();
if (from < 0 || from > this->vector_->getVector().size() ||
to < 0 || to > this->vector_->getVector().size())
if (from < 0 || from > this->vector_->raw().size() ||
to < 0 || to > this->vector_->raw().size())
{
return false;
}
if (from != to)
{
auto item = this->vector_->getVector()[from];
auto item = this->vector_->raw()[from];
this->vector_->removeItem(from);
this->vector_->insertItem(item, to);
}
@@ -16,7 +16,7 @@ AccountController::AccountController()
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
if (args.caller != this)
{
auto &accs = this->twitch.accounts.getVector();
auto &accs = this->twitch.accounts.raw();
auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end());
@@ -212,7 +212,7 @@ void CommandController::initialize(Settings &, Paths &paths)
// Update the setting when the vector of commands has been updated (most
// likely from the settings dialog)
this->items_.delayedItemsChanged.connect([this] { //
this->commandsSetting_->setValue(this->items_.getVector());
this->commandsSetting_->setValue(this->items_.raw());
});
// Load commands from commands.json
@@ -12,38 +12,30 @@ HighlightController::HighlightController()
{
}
template <typename T>
inline void persist(SignalVector<T> &vec, const std::string &name)
{
auto setting = std::make_unique<ChatterinoSetting<std::vector<T>>>(name);
for (auto &&item : setting->getValue())
vec.append(item);
vec.delayedItemsChanged.connect([setting = setting.get(), vec = &vec] {
setting->setValue(vec->raw());
});
// TODO
setting.release();
}
void HighlightController::initialize(Settings &settings, Paths &paths)
{
assert(!this->initialized_);
this->initialized_ = true;
for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue())
{
this->phrases.appendItem(phrase);
}
this->phrases.delayedItemsChanged.connect([this] { //
this->highlightsSetting_.setValue(this->phrases.getVector());
});
for (const HighlightBlacklistUser &blacklistedUser :
this->blacklistSetting_.getValue())
{
this->blacklistedUsers.appendItem(blacklistedUser);
}
this->blacklistedUsers.delayedItemsChanged.connect([this] {
this->blacklistSetting_.setValue(this->blacklistedUsers.getVector());
});
for (const HighlightPhrase &user : this->userSetting_.getValue())
{
this->highlightedUsers.appendItem(user);
}
this->highlightedUsers.delayedItemsChanged.connect([this] { //
this->userSetting_.setValue(this->highlightedUsers.getVector());
});
persist(this->phrases, "/highlighting/highlights");
persist(this->blacklistedUsers, "/highlighting/blacklist");
persist(this->highlightedUsers, "/highlighting/users");
}
HighlightModel *HighlightController::createModel(QObject *parent)
@@ -40,13 +40,6 @@ public:
private:
bool initialized_ = false;
ChatterinoSetting<std::vector<HighlightPhrase>> highlightsSetting_ = {
"/highlighting/highlights"};
ChatterinoSetting<std::vector<HighlightBlacklistUser>> blacklistSetting_ = {
"/highlighting/blacklist"};
ChatterinoSetting<std::vector<HighlightPhrase>> userSetting_ = {
"/highlighting/users"};
};
} // namespace chatterino
+1 -1
View File
@@ -18,7 +18,7 @@ void IgnoreController::initialize(Settings &, Paths &)
}
this->phrases.delayedItemsChanged.connect([this] { //
this->ignoresSetting_.setValue(this->phrases.getVector());
this->ignoresSetting_.setValue(this->phrases.raw());
});
}
@@ -27,7 +27,7 @@ void ModerationActions::initialize(Settings &settings, Paths &paths)
}
this->items.delayedItemsChanged.connect([this] { //
this->setting_->setValue(this->items.getVector());
this->setting_->setValue(this->items.raw());
});
}
@@ -31,7 +31,7 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] { //
this->twitchSetting_.setValue(
this->channelMap[Platform::Twitch].getVector());
this->channelMap[Platform::Twitch].raw());
});
/*
for (const QString &channelName : this->mixerSetting_.getValue()) {
@@ -88,9 +88,9 @@ void NotificationController::removeChannelNotification(
const QString &channelName, Platform p)
{
for (std::vector<int>::size_type i = 0;
i != channelMap[p].getVector().size(); i++)
i != channelMap[p].raw().size(); i++)
{
if (channelMap[p].getVector()[i].toLower() == channelName.toLower())
if (channelMap[p].raw()[i].toLower() == channelName.toLower())
{
channelMap[p].removeItem(i);
i--;
@@ -128,14 +128,14 @@ NotificationModel *NotificationController::createModel(QObject *parent,
void NotificationController::fetchFakeChannels()
{
for (std::vector<int>::size_type i = 0;
i != channelMap[Platform::Twitch].getVector().size(); i++)
i != channelMap[Platform::Twitch].raw().size(); i++)
{
auto chan = getApp()->twitch.server->getChannelOrEmpty(
channelMap[Platform::Twitch].getVector()[i]);
channelMap[Platform::Twitch].raw()[i]);
if (chan->isEmpty())
{
getFakeTwitchChannelLiveStatus(
channelMap[Platform::Twitch].getVector()[i]);
channelMap[Platform::Twitch].raw()[i]);
}
}
}
+3 -3
View File
@@ -12,7 +12,7 @@ void PingController::initialize(Settings &settings, Paths &paths)
}
this->channelVector.delayedItemsChanged.connect([this] { //
this->pingSetting_.setValue(this->channelVector.getVector());
this->pingSetting_.setValue(this->channelVector.raw());
});
}
@@ -43,9 +43,9 @@ void PingController::muteChannel(const QString &channelName)
void PingController::unmuteChannel(const QString &channelName)
{
for (std::vector<int>::size_type i = 0;
i != channelVector.getVector().size(); i++)
i != channelVector.raw().size(); i++)
{
if (channelVector.getVector()[i].toLower() == channelName.toLower())
if (channelVector.raw()[i].toLower() == channelName.toLower())
{
channelVector.removeItem(i);
i--;
+3 -4
View File
@@ -160,13 +160,12 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
view->getTableView(), &QTableView::doubleClicked,
[](const QModelIndex &index) {
auto editor = new IrcConnectionEditor(
Irc::instance()
.connections.getVector()[size_t(index.row())]);
Irc::instance().connections.raw()[size_t(index.row())]);
if (editor->exec() == QDialog::Accepted)
{
auto data = editor->data();
auto &&conns = Irc::instance().connections.getVector();
auto &&conns = Irc::instance().connections.raw();
int i = 0;
for (auto &&conn : conns)
{
@@ -348,7 +347,7 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
->currentIndex()
.row();
auto &&vector = Irc::instance().connections.getVector();
auto &&vector = Irc::instance().connections.raw();
if (row >= 0 && row < int(vector.size()))
{
+2 -2
View File
@@ -343,7 +343,7 @@ void UserInfoPopup::installEvents()
else
{
const auto &vector =
getApp()->highlights->blacklistedUsers.getVector();
getApp()->highlights->blacklistedUsers.raw();
for (int i = 0; i < vector.size(); i++)
{
@@ -456,7 +456,7 @@ void UserInfoPopup::updateUserData()
// get ignoreHighlights state
bool isIgnoringHighlights = false;
const auto &vector = getApp()->highlights->blacklistedUsers.getVector();
const auto &vector = getApp()->highlights->blacklistedUsers.raw();
for (int i = 0; i < vector.size(); i++)
{
if (this->userName_ == vector[i].getPattern())