From 6013591730ba9a924bc05e1ad1f0e232489ba643 Mon Sep 17 00:00:00 2001 From: fourtf Date: Thu, 28 Jun 2018 20:25:37 +0200 Subject: [PATCH] renamed files SignalVector -> SimpleSignalVector and SingalVector2 -> SignalVector --- chatterino.pro | 6 +- src/common/SignalVector.hpp | 159 ++++++++++++++---- src/common/SignalVector2.hpp | 125 -------------- src/common/SignalVectorModel.hpp | 2 +- src/common/SimpleSignalVector.hpp | 34 ++++ .../accounts/AccountController.hpp | 2 +- .../commands/CommandController.cpp | 2 +- .../commands/CommandController.hpp | 2 +- .../highlights/HighlightController.hpp | 2 +- src/controllers/ignores/IgnoreController.hpp | 2 +- .../moderationactions/ModerationActions.hpp | 2 +- .../taggedusers/TaggedUsersController.hpp | 2 +- src/providers/bttv/BttvEmotes.hpp | 2 +- src/providers/emoji/Emojis.hpp | 2 +- src/providers/ffz/FfzEmotes.hpp | 2 +- src/providers/twitch/TwitchAccountManager.hpp | 2 +- 16 files changed, 174 insertions(+), 174 deletions(-) delete mode 100644 src/common/SignalVector2.hpp create mode 100644 src/common/SimpleSignalVector.hpp diff --git a/chatterino.pro b/chatterino.pro index d30b3e07b..555149197 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -242,8 +242,6 @@ HEADERS += \ src/common/Property.hpp \ src/common/ProviderId.hpp \ src/common/SerializeCustom.hpp \ - src/common/SignalVector.hpp \ - src/common/SignalVector2.hpp \ src/common/SignalVectorModel.hpp \ src/common/UrlFetch.hpp \ src/common/Version.hpp \ @@ -392,7 +390,9 @@ HEADERS += \ src/singletons/Settings.hpp \ src/singletons/Updates.hpp \ src/singletons/NativeMessaging.hpp \ - src/singletons/Theme.hpp + src/singletons/Theme.hpp \ + src/common/SimpleSignalVector.hpp \ + src/common/SignalVector.hpp RESOURCES += \ resources/resources.qrc \ diff --git a/src/common/SignalVector.hpp b/src/common/SignalVector.hpp index 9d39867a9..f479cd85b 100644 --- a/src/common/SignalVector.hpp +++ b/src/common/SignalVector.hpp @@ -1,34 +1,125 @@ -#pragma once - -#include - -#include -#include - -namespace chatterino { - -template -class SignalVector -{ -public: - SignalVector &operator=(std::vector &other) - { - this->data = other; - - this->updated.invoke(); - - return *this; - } - - operator std::vector &() - { - return this->data; - } - - pajlada::Signals::NoArgSignal updated; - -private: - std::vector data; -}; - -} // namespace chatterino +#pragma once + +#include +#include +#include +#include +#include + +#include "debug/AssertInGuiThread.hpp" + +namespace chatterino { + +template +struct SignalVectorItemArgs { + const TVectorItem &item; + int index; + void *caller; +}; + +template +class ReadOnlySignalVector : boost::noncopyable +{ +public: + ReadOnlySignalVector() + { + QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, + [this] { this->delayedItemsChanged.invoke(); }); + this->itemsChangedTimer.setInterval(100); + this->itemsChangedTimer.setSingleShot(true); + } + virtual ~ReadOnlySignalVector() = default; + + pajlada::Signals::Signal> itemInserted; + pajlada::Signals::Signal> itemRemoved; + pajlada::Signals::NoArgSignal delayedItemsChanged; + + const std::vector &getVector() const + { + assertInGuiThread(); + + return this->vector; + } + + void invokeDelayedItemsChanged() + { + assertInGuiThread(); + + if (!this->itemsChangedTimer.isActive()) { + itemsChangedTimer.start(); + } + } + +protected: + std::vector vector; + QTimer itemsChangedTimer; +}; + +template +class BaseSignalVector : public ReadOnlySignalVector +{ +public: + // returns the actual index of the inserted item + virtual int insertItem(const TVectorItem &item, int proposedIndex = -1, void *caller = 0) = 0; + + void removeItem(int index, void *caller = 0) + { + assertInGuiThread(); + assert(index >= 0 && index < this->vector.size()); + + TVectorItem item = this->vector[index]; + this->vector.erase(this->vector.begin() + index); + SignalVectorItemArgs args{item, index, caller}; + this->itemRemoved.invoke(args); + + this->invokeDelayedItemsChanged(); + } + + int appendItem(const TVectorItem &item, void *caller = 0) + { + return this->insertItem(item, -1, caller); + } +}; + +template +class UnsortedSignalVector : public BaseSignalVector +{ +public: + virtual int insertItem(const TVectorItem &item, int index = -1, void *caller = 0) override + { + assertInGuiThread(); + if (index == -1) { + index = this->vector.size(); + } else { + assert(index >= 0 && index <= this->vector.size()); + } + + this->vector.insert(this->vector.begin() + index, item); + + SignalVectorItemArgs args{item, index, caller}; + this->itemInserted.invoke(args); + this->invokeDelayedItemsChanged(); + return index; + } +}; + +template +class SortedSignalVector : public BaseSignalVector +{ +public: + virtual int insertItem(const TVectorItem &item, int = -1, void *caller = nullptr) override + { + assertInGuiThread(); + + auto it = std::lower_bound(this->vector.begin(), this->vector.end(), item, Compare{}); + int index = it - this->vector.begin(); + this->vector.insert(it, item); + + SignalVectorItemArgs args{item, index, caller}; + this->itemInserted.invoke(args); + this->invokeDelayedItemsChanged(); + return index; + } +}; + +} // namespace chatterino diff --git a/src/common/SignalVector2.hpp b/src/common/SignalVector2.hpp deleted file mode 100644 index f479cd85b..000000000 --- a/src/common/SignalVector2.hpp +++ /dev/null @@ -1,125 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "debug/AssertInGuiThread.hpp" - -namespace chatterino { - -template -struct SignalVectorItemArgs { - const TVectorItem &item; - int index; - void *caller; -}; - -template -class ReadOnlySignalVector : boost::noncopyable -{ -public: - ReadOnlySignalVector() - { - QObject::connect(&this->itemsChangedTimer, &QTimer::timeout, - [this] { this->delayedItemsChanged.invoke(); }); - this->itemsChangedTimer.setInterval(100); - this->itemsChangedTimer.setSingleShot(true); - } - virtual ~ReadOnlySignalVector() = default; - - pajlada::Signals::Signal> itemInserted; - pajlada::Signals::Signal> itemRemoved; - pajlada::Signals::NoArgSignal delayedItemsChanged; - - const std::vector &getVector() const - { - assertInGuiThread(); - - return this->vector; - } - - void invokeDelayedItemsChanged() - { - assertInGuiThread(); - - if (!this->itemsChangedTimer.isActive()) { - itemsChangedTimer.start(); - } - } - -protected: - std::vector vector; - QTimer itemsChangedTimer; -}; - -template -class BaseSignalVector : public ReadOnlySignalVector -{ -public: - // returns the actual index of the inserted item - virtual int insertItem(const TVectorItem &item, int proposedIndex = -1, void *caller = 0) = 0; - - void removeItem(int index, void *caller = 0) - { - assertInGuiThread(); - assert(index >= 0 && index < this->vector.size()); - - TVectorItem item = this->vector[index]; - this->vector.erase(this->vector.begin() + index); - SignalVectorItemArgs args{item, index, caller}; - this->itemRemoved.invoke(args); - - this->invokeDelayedItemsChanged(); - } - - int appendItem(const TVectorItem &item, void *caller = 0) - { - return this->insertItem(item, -1, caller); - } -}; - -template -class UnsortedSignalVector : public BaseSignalVector -{ -public: - virtual int insertItem(const TVectorItem &item, int index = -1, void *caller = 0) override - { - assertInGuiThread(); - if (index == -1) { - index = this->vector.size(); - } else { - assert(index >= 0 && index <= this->vector.size()); - } - - this->vector.insert(this->vector.begin() + index, item); - - SignalVectorItemArgs args{item, index, caller}; - this->itemInserted.invoke(args); - this->invokeDelayedItemsChanged(); - return index; - } -}; - -template -class SortedSignalVector : public BaseSignalVector -{ -public: - virtual int insertItem(const TVectorItem &item, int = -1, void *caller = nullptr) override - { - assertInGuiThread(); - - auto it = std::lower_bound(this->vector.begin(), this->vector.end(), item, Compare{}); - int index = it - this->vector.begin(); - this->vector.insert(it, item); - - SignalVectorItemArgs args{item, index, caller}; - this->itemInserted.invoke(args); - this->invokeDelayedItemsChanged(); - return index; - } -}; - -} // namespace chatterino diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index 6b664548a..a91835947 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include #include diff --git a/src/common/SimpleSignalVector.hpp b/src/common/SimpleSignalVector.hpp new file mode 100644 index 000000000..9d39867a9 --- /dev/null +++ b/src/common/SimpleSignalVector.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include + +#include +#include + +namespace chatterino { + +template +class SignalVector +{ +public: + SignalVector &operator=(std::vector &other) + { + this->data = other; + + this->updated.invoke(); + + return *this; + } + + operator std::vector &() + { + return this->data; + } + + pajlada::Signals::NoArgSignal updated; + +private: + std::vector data; +}; + +} // namespace chatterino diff --git a/src/controllers/accounts/AccountController.hpp b/src/controllers/accounts/AccountController.hpp index cce426e27..4e16caaa3 100644 --- a/src/controllers/accounts/AccountController.hpp +++ b/src/controllers/accounts/AccountController.hpp @@ -2,7 +2,7 @@ #include -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/accounts/Account.hpp" #include "providers/twitch/TwitchAccountManager.hpp" #include "util/SharedPtrElementLess.hpp" diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 7a60733b3..e6f12c52e 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -1,7 +1,7 @@ #include "CommandController.hpp" #include "Application.hpp" -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/commands/Command.hpp" #include "controllers/commands/CommandModel.hpp" diff --git a/src/controllers/commands/CommandController.hpp b/src/controllers/commands/CommandController.hpp index 60e5cba5a..58f0c91e7 100644 --- a/src/controllers/commands/CommandController.hpp +++ b/src/controllers/commands/CommandController.hpp @@ -4,7 +4,7 @@ #include #include -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/commands/Command.hpp" namespace chatterino { diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index 4e8dfb6e2..2fcaa3fff 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/highlights/HighlightPhrase.hpp" #include "messages/Message.hpp" #include "singletons/Settings.hpp" diff --git a/src/controllers/ignores/IgnoreController.hpp b/src/controllers/ignores/IgnoreController.hpp index 37ab7e3e7..59623160d 100644 --- a/src/controllers/ignores/IgnoreController.hpp +++ b/src/controllers/ignores/IgnoreController.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/ignores/IgnorePhrase.hpp" #include "singletons/Settings.hpp" diff --git a/src/controllers/moderationactions/ModerationActions.hpp b/src/controllers/moderationactions/ModerationActions.hpp index 6f58ae137..823f97bad 100644 --- a/src/controllers/moderationactions/ModerationActions.hpp +++ b/src/controllers/moderationactions/ModerationActions.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/moderationactions/ModerationAction.hpp" #include "common/ChatterinoSetting.hpp" diff --git a/src/controllers/taggedusers/TaggedUsersController.hpp b/src/controllers/taggedusers/TaggedUsersController.hpp index b9e9c21ca..b09cea72b 100644 --- a/src/controllers/taggedusers/TaggedUsersController.hpp +++ b/src/controllers/taggedusers/TaggedUsersController.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "controllers/taggedusers/TaggedUser.hpp" namespace chatterino { diff --git a/src/providers/bttv/BttvEmotes.hpp b/src/providers/bttv/BttvEmotes.hpp index 2df25aa5d..4f831e26f 100644 --- a/src/providers/bttv/BttvEmotes.hpp +++ b/src/providers/bttv/BttvEmotes.hpp @@ -1,7 +1,7 @@ #pragma once #include "common/Emotemap.hpp" -#include "common/SignalVector.hpp" +#include "common/SimpleSignalVector.hpp" #include "util/ConcurrentMap.hpp" #include diff --git a/src/providers/emoji/Emojis.hpp b/src/providers/emoji/Emojis.hpp index 814a11251..8d76179f7 100644 --- a/src/providers/emoji/Emojis.hpp +++ b/src/providers/emoji/Emojis.hpp @@ -1,7 +1,7 @@ #pragma once #include "common/Emotemap.hpp" -#include "common/SignalVector.hpp" +#include "common/SimpleSignalVector.hpp" #include "util/ConcurrentMap.hpp" #include diff --git a/src/providers/ffz/FfzEmotes.hpp b/src/providers/ffz/FfzEmotes.hpp index 90caeb207..5dc1fe856 100644 --- a/src/providers/ffz/FfzEmotes.hpp +++ b/src/providers/ffz/FfzEmotes.hpp @@ -1,7 +1,7 @@ #pragma once #include "common/Emotemap.hpp" -#include "common/SignalVector.hpp" +#include "common/SimpleSignalVector.hpp" #include "util/ConcurrentMap.hpp" #include diff --git a/src/providers/twitch/TwitchAccountManager.hpp b/src/providers/twitch/TwitchAccountManager.hpp index 3b09bf13a..e9bbfd943 100644 --- a/src/providers/twitch/TwitchAccountManager.hpp +++ b/src/providers/twitch/TwitchAccountManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "common/SignalVector2.hpp" +#include "common/SignalVector.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "util/SharedPtrElementLess.hpp"