mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
renamed files SignalVector -> SimpleSignalVector and SingalVector2 -> SignalVector
This commit is contained in:
parent
c3c2b934ba
commit
6013591730
|
@ -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 \
|
||||
|
|
|
@ -1,34 +1,125 @@
|
|||
#pragma once
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QTimer>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename TValue>
|
||||
class SignalVector
|
||||
template <typename TVectorItem>
|
||||
struct SignalVectorItemArgs {
|
||||
const TVectorItem &item;
|
||||
int index;
|
||||
void *caller;
|
||||
};
|
||||
|
||||
template <typename TVectorItem>
|
||||
class ReadOnlySignalVector : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
SignalVector &operator=(std::vector<TValue> &other)
|
||||
ReadOnlySignalVector()
|
||||
{
|
||||
this->data = other;
|
||||
QObject::connect(&this->itemsChangedTimer, &QTimer::timeout,
|
||||
[this] { this->delayedItemsChanged.invoke(); });
|
||||
this->itemsChangedTimer.setInterval(100);
|
||||
this->itemsChangedTimer.setSingleShot(true);
|
||||
}
|
||||
virtual ~ReadOnlySignalVector() = default;
|
||||
|
||||
this->updated.invoke();
|
||||
pajlada::Signals::Signal<SignalVectorItemArgs<TVectorItem>> itemInserted;
|
||||
pajlada::Signals::Signal<SignalVectorItemArgs<TVectorItem>> itemRemoved;
|
||||
pajlada::Signals::NoArgSignal delayedItemsChanged;
|
||||
|
||||
return *this;
|
||||
const std::vector<TVectorItem> &getVector() const
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
return this->vector;
|
||||
}
|
||||
|
||||
operator std::vector<TValue> &()
|
||||
void invokeDelayedItemsChanged()
|
||||
{
|
||||
return this->data;
|
||||
assertInGuiThread();
|
||||
|
||||
if (!this->itemsChangedTimer.isActive()) {
|
||||
itemsChangedTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
pajlada::Signals::NoArgSignal updated;
|
||||
protected:
|
||||
std::vector<TVectorItem> vector;
|
||||
QTimer itemsChangedTimer;
|
||||
};
|
||||
|
||||
private:
|
||||
std::vector<TValue> data;
|
||||
template <typename TVectorItem>
|
||||
class BaseSignalVector : public ReadOnlySignalVector<TVectorItem>
|
||||
{
|
||||
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<TVectorItem> 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 <typename TVectorItem>
|
||||
class UnsortedSignalVector : public BaseSignalVector<TVectorItem>
|
||||
{
|
||||
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<TVectorItem> args{item, index, caller};
|
||||
this->itemInserted.invoke(args);
|
||||
this->invokeDelayedItemsChanged();
|
||||
return index;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TVectorItem, typename Compare>
|
||||
class SortedSignalVector : public BaseSignalVector<TVectorItem>
|
||||
{
|
||||
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<TVectorItem> args{item, index, caller};
|
||||
this->itemInserted.invoke(args);
|
||||
this->invokeDelayedItemsChanged();
|
||||
return index;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QStandardItemModel>
|
||||
#include <QTimer>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename TVectorItem>
|
||||
struct SignalVectorItemArgs {
|
||||
const TVectorItem &item;
|
||||
int index;
|
||||
void *caller;
|
||||
};
|
||||
|
||||
template <typename TVectorItem>
|
||||
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<SignalVectorItemArgs<TVectorItem>> itemInserted;
|
||||
pajlada::Signals::Signal<SignalVectorItemArgs<TVectorItem>> itemRemoved;
|
||||
pajlada::Signals::NoArgSignal delayedItemsChanged;
|
||||
|
||||
const std::vector<TVectorItem> &getVector() const
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
return this->vector;
|
||||
}
|
||||
|
||||
void invokeDelayedItemsChanged()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
if (!this->itemsChangedTimer.isActive()) {
|
||||
itemsChangedTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<TVectorItem> vector;
|
||||
QTimer itemsChangedTimer;
|
||||
};
|
||||
|
||||
template <typename TVectorItem>
|
||||
class BaseSignalVector : public ReadOnlySignalVector<TVectorItem>
|
||||
{
|
||||
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<TVectorItem> 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 <typename TVectorItem>
|
||||
class UnsortedSignalVector : public BaseSignalVector<TVectorItem>
|
||||
{
|
||||
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<TVectorItem> args{item, index, caller};
|
||||
this->itemInserted.invoke(args);
|
||||
this->invokeDelayedItemsChanged();
|
||||
return index;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TVectorItem, typename Compare>
|
||||
class SortedSignalVector : public BaseSignalVector<TVectorItem>
|
||||
{
|
||||
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<TVectorItem> args{item, index, caller};
|
||||
this->itemInserted.invoke(args);
|
||||
this->invokeDelayedItemsChanged();
|
||||
return index;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QStandardItem>
|
||||
|
|
34
src/common/SimpleSignalVector.hpp
Normal file
34
src/common/SimpleSignalVector.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename TValue>
|
||||
class SignalVector
|
||||
{
|
||||
public:
|
||||
SignalVector &operator=(std::vector<TValue> &other)
|
||||
{
|
||||
this->data = other;
|
||||
|
||||
this->updated.invoke();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::vector<TValue> &()
|
||||
{
|
||||
return this->data;
|
||||
}
|
||||
|
||||
pajlada::Signals::NoArgSignal updated;
|
||||
|
||||
private:
|
||||
std::vector<TValue> data;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "controllers/accounts/Account.hpp"
|
||||
#include "providers/twitch/TwitchAccountManager.hpp"
|
||||
#include "util/SharedPtrElementLess.hpp"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "controllers/commands/Command.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "controllers/ignores/IgnorePhrase.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "controllers/moderationactions/ModerationAction.hpp"
|
||||
#include "common/ChatterinoSetting.hpp"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "controllers/taggedusers/TaggedUser.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/SimpleSignalVector.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
#include <map>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/SimpleSignalVector.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
#include <QMap>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/SimpleSignalVector.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
#include <map>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/SignalVector2.hpp"
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
#include "util/SharedPtrElementLess.hpp"
|
||||
|
||||
|
|
Loading…
Reference in a new issue