FlightGear next
StackController.cxx
Go to the documentation of this file.
1// StackController.cxx - manage a stack of QML items
2//
3// Written by James Turner, started February 2019
4//
5// Copyright (C) 2019 James Turner <james@flightgear.org>
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License as
9// published by the Free Software Foundation; either version 2 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21#include "StackController.hxx"
22
26
28{
29 if (m_stack.empty())
30 return {};
31 return m_stack.front();
32}
33
35{
36 if (m_stack.empty())
37 return {};
38 return m_titles.front();
39}
40
42{
43 if (m_titles.size() < 2)
44 return {};
45 return m_titles.at(1);
46}
47
49{
50 return (m_stack.size() > 1);
51}
52
53void StackController::push(QUrl page, QString title)
54{
55 m_stack.push_front(page);
56 m_titles.push_front(title);
57 emit currentPageChanged();
58}
59
61{
62 if (m_stack.empty())
63 return;
64 m_stack.pop_front();
65 m_titles.pop_front();
66 emit currentPageChanged();
67}
68
69void StackController::replace(QUrl url, QString title)
70{
71 m_stack.clear();
72 m_stack.push_back(url);
73 m_titles.clear();
74 m_titles.push_back(title);
75
76 emit currentPageChanged();
77}
Q_INVOKABLE void replace(QUrl url, QString title)
Q_INVOKABLE void pop()
Q_INVOKABLE void push(QUrl page, QString title)
void currentPageChanged()