29 using ItemAction = std::function<void(
const T& item,
int index)>;
41 , _action(std::move(action))
52 T
currentItem()
const {
return _currentIndex >= 0 && _currentIndex < _items.size()
53 ? _items[_currentIndex] : T(); }
70 void _processNextItem()
75 while (_currentIndex < _items.size() && _filter && !_filter(_items[_currentIndex], _currentIndex)) {
79 if (_currentIndex >= _items.size()) {
87 _action(_items[_currentIndex], _currentIndex);
92 QMetaObject::invokeMethod(
this, &LoopState::_processNextItem, Qt::QueuedConnection);
98 int _currentIndex = -1;
99 int _processedCount = 0;
void onEnter() override
Override to perform actions on state entry.
void setFilter(ItemPredicate filter)
Set a predicate to filter items (only items where predicate returns true are processed)
std::function< bool(const T &item, int index)> ItemPredicate
int currentIndex() const
Get the current index being processed.
T currentItem() const
Get the current item being processed.
int totalItems() const
Get the total number of items.
int processedCount() const
Get the number of items processed so far.
LoopState(const QString &stateName, QState *parent, const QList< T > &items, ItemAction action)
std::function< void(const T &item, int index)> ItemAction
QString stateName() const