forked from PLLUG-Community-C-Qt-Roadmap/CPPQT-MenuForCafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuiterator.cpp
More file actions
42 lines (34 loc) · 932 Bytes
/
Copy pathmenuiterator.cpp
File metadata and controls
42 lines (34 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "menuiterator.h"
#include "helpervisitor.h"
#include "core/menusection.h"
#include <iostream>
MenuIterator::MenuIterator(AbstractMenuItem *menu)
: mChildrenVisitor{std::make_unique<HelperVisitor>()}
{
auto childrenForTraversal = [this](MenuSection *item)
{
if (!item)
{
return;
}
for (int index = 0; index < item->size(); ++index)
{
auto next = item->at(index);
std::cout << next->name() << std::endl;
this->mItemsStack.push(next);
}
};
mChildrenVisitor->setMenuSectionHandler(childrenForTraversal);
menu->apply(mChildrenVisitor.get());
}
bool MenuIterator::hasNext() const
{
return !mItemsStack.empty();
}
AbstractMenuItem *MenuIterator::next()
{
AbstractMenuItem *nextItem = mItemsStack.top();
mItemsStack.pop();
nextItem->apply(mChildrenVisitor.get());
return nextItem;
}