3 #include <QStandardItemModel> 5 #include <boost/noncopyable.hpp> 6 #include <pajlada/signals/signal.hpp> 25 pajlada::Signals::Signal<SignalVectorItemEvent<T>>
itemRemoved;
29 : readOnly_(new
std::vector<T>())
31 QObject::connect(&this->itemsChangedTimer_, &QTimer::timeout, [
this] {
32 this->delayedItemsChanged.invoke();
34 this->itemsChangedTimer_.setInterval(100);
35 this->itemsChangedTimer_.setSingleShot(
true);
41 this->itemCompare_ = std::move(compare);
46 return bool(this->itemCompare_);
50 std::shared_ptr<const std::vector<T>>
readOnly()
52 return this->readOnly_;
71 auto it = std::lower_bound(this->items_.begin(), this->items_.end(),
72 item, this->itemCompare_);
73 index = it - this->items_.begin();
74 this->items_.insert(it, item);
80 index = this->items_.size();
84 assert(
index >= 0 && index <= this->items_.size());
87 this->items_.insert(this->items_.begin() +
index,
item);
91 this->itemInserted.invoke(args);
92 this->itemsChanged_();
107 return this->insert(item, -1,
caller);
113 assert(index >= 0 && index <
int(this->items_.size()));
116 this->items_.erase(this->items_.begin() +
index);
119 this->itemRemoved.invoke(args);
121 this->itemsChanged_();
124 const std::vector<T> &
raw()
const 133 return *this->readOnly();
140 return this->items_.begin();
146 return this->items_.end();
149 decltype(
auto) operator[](
size_t index)
152 return this->items[
index];
158 return this->items_.empty();
165 if (!this->itemsChangedTimer_.isActive())
167 this->itemsChangedTimer_.start();
171 this->readOnly_ = std::make_shared<const std::vector<T>>(this->items_);
174 std::vector<T> items_;
175 std::shared_ptr<const std::vector<T>> readOnly_;
176 QTimer itemsChangedTimer_;
177 std::function<bool(const T &, const T &)> itemCompare_;
Definition: SignalVector.hpp:21
int index
Definition: SignalVector.hpp:16
pajlada::Signals::Signal< SignalVectorItemEvent< T > > itemInserted
Definition: SignalVector.hpp:24
Definition: SeventvEventAPISubscription.hpp:67
pajlada::Signals::Signal< SignalVectorItemEvent< T > > itemRemoved
Definition: SignalVector.hpp:25
Definition: Application.cpp:48
SignalVector(std::function< bool(const T &, const T &)> &&compare)
Definition: SignalVector.hpp:38
pajlada::Signals::NoArgSignal delayedItemsChanged
Definition: SignalVector.hpp:26
void removeAt(int index, void *caller=nullptr)
Definition: SignalVector.hpp:110
auto begin() const
Definition: SignalVector.hpp:137
const std::vector< T > & raw() const
Definition: SignalVector.hpp:124
void * caller
Definition: SignalVector.hpp:17
SignalVector()
Definition: SignalVector.hpp:28
std::shared_ptr< const std::vector< T > > readOnly()
A read-only version of the vector which can be used concurrently.
Definition: SignalVector.hpp:50
int append(const T &item, void *caller=nullptr)
Definition: SignalVector.hpp:104
std::vector< T > cloneVector()
Definition: SignalVector.hpp:131
Definition: SignalVector.hpp:14
auto end() const
Definition: SignalVector.hpp:143
const T & item
Definition: SignalVector.hpp:15
auto empty()
Definition: SignalVector.hpp:155
bool isSorted() const
Definition: SignalVector.hpp:44
int insert(const T &item, int index=-1, void *caller=nullptr)
Definition: SignalVector.hpp:65