FlightGear next
DialogStateController.cxx
Go to the documentation of this file.
1// Copyright (C) 2020 James Turner <james@flightgear.org>
2//
3// This program is free software; you can redistribute it and/or
4// modify it under the terms of the GNU General Public License as
5// published by the Free Software Foundation; either version 2 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17#include "config.h"
18
20
21#include <QDebug>
22
23void DialogStateController::add(QString key, QJSValue cb)
24{
25 bool wasEmpty = m_changes.isEmpty();
26 if (!cb.isCallable()) {
27 qWarning() << "tried to insert non-callable into state key:" << key;
28 return;
29 }
30
31 m_changes.insert(key, cb);
32
33 if (wasEmpty) {
34 emit canApplyChanged(true);
35 }
36}
37
39{
40 auto it = m_changes.begin();
41 for (; it != m_changes.end(); ++it) {
42 QJSValueList args;
43 args.append(QJSValue(it.key()));
44 it.value().call(args);
45 }
46}
47
49{
50 m_changes.clear();
51 emit canApplyChanged(false);
52}
53
57
59{
60 if (m_canRestoreDefaults == canRestoreDefaults)
61 return;
62
63 m_canRestoreDefaults = canRestoreDefaults;
64 emit canRestoreDefaultsChanged(m_canRestoreDefaults);
65}
void canApplyChanged(bool canApply)
void setCanRestoreDefaults(bool canRestoreDefaults)
Q_INVOKABLE void add(QString key, QJSValue cb)
void canRestoreDefaultsChanged(bool canRestoreDefaults)