Unity 8
unitymenumodelstack.h
1 /*
2  * Copyright 2013 Canonical Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authors:
17  * Nick Dedekind <nick.dedekind@canonical.com>
18  */
19 
20 #ifndef UNITYMENUMODELSTACK_H
21 #define UNITYMENUMODELSTACK_H
22 
23 #include "unityindicatorsglobal.h"
24 
25 #include <QObject>
26 #include <QList>
27 
28 class UnityMenuModelEntry;
29 class UnityMenuModel;
30 
31 // A LIFO queue for storing the current submenu of a UnityMenuModel.
32 // The root menu model is set as the head, and each subsiquent submenu that is
33 // opened can be pushed onto the queue.
34 // The tail is set to the last item on the queue
35 // Popping the queue will remove the last entry, and the tail be updated to the last item.
36 class UNITYINDICATORS_EXPORT UnityMenuModelStack : public QObject
37 {
38  Q_OBJECT
39  Q_PROPERTY(UnityMenuModel* head READ head WRITE setHead NOTIFY headChanged)
40  Q_PROPERTY(UnityMenuModel* tail READ tail NOTIFY tailChanged)
41  Q_PROPERTY(int count READ count NOTIFY countChanged)
42 public:
43  UnityMenuModelStack(QObject*parent=nullptr);
44  ~UnityMenuModelStack();
45 
46  UnityMenuModel* head() const;
47  void setHead(UnityMenuModel* model);
48 
49  UnityMenuModel* tail() const;
50 
51  int count() const;
52 
53  Q_INVOKABLE void push(UnityMenuModel* model, int menuIndex);
54  Q_INVOKABLE UnityMenuModel* pop();
55 
56 Q_SIGNALS:
57  void headChanged(UnityMenuModel* head);
58  void tailChanged(UnityMenuModel* tail);
59  void countChanged(int count);
60 
61 private Q_SLOTS:
62  void onRemove();
63 
64 private:
65  QList<UnityMenuModelEntry*> m_menuModels;
66 };
67 
68 #endif // UNITYMENUMODELSTACK_H