FlightGear next
QmlRadioButtonHelper.hxx
Go to the documentation of this file.
1// QmlRadioButtonHelper.hxx - helper for QtQuick radio button impl
2//
3// Written by James Turner, started April 2018.
4//
5// Copyright (C) 2015 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#ifndef QMLRADIOBUTTONHELPER_HXX
22#define QMLRADIOBUTTONHELPER_HXX
23
24#include <QObject>
25#include <QtQml>
26
28
29class QmlRadioButtonGroupAttached : public QObject
30{
31 Q_OBJECT
32
33 Q_PROPERTY(QmlRadioButtonGroup* group READ group WRITE setGroup NOTIFY groupChanged)
34 Q_PROPERTY(bool isSelected READ isSelected NOTIFY isSelectedChanged)
35public:
36 QmlRadioButtonGroupAttached(QObject* pr = nullptr);
37
39 bool isSelected() const;
40
41public slots:
43
44signals:
47
48private:
49 void onGroupSelectionChanged();
50
51 QmlRadioButtonGroup* m_group = nullptr;
52};
53
54class QmlRadioButtonGroup : public QObject
55{
56 Q_OBJECT
57
58 Q_PROPERTY(QObject* selected READ selected WRITE setSelected NOTIFY selectedChanged)
59public:
60 explicit QmlRadioButtonGroup(QObject *parent = nullptr);
61
63
64 QObject* selected() const;
65
66signals:
67 void selectedChanged(QObject* selected);
68
69public slots:
70 void setSelected(QObject* selected);
71
72private:
73 QObject* m_selected = nullptr;
74};
75
76QML_DECLARE_TYPEINFO(QmlRadioButtonGroup, QML_HAS_ATTACHED_PROPERTIES)
77
78#endif // QMLRADIOBUTTONHELPER_HXX
void setGroup(QmlRadioButtonGroup *group)
void groupChanged(QmlRadioButtonGroup *group)
void isSelectedChanged(bool isSelected)
QmlRadioButtonGroupAttached(QObject *pr=nullptr)
void setSelected(QObject *selected)
static QmlRadioButtonGroupAttached * qmlAttachedProperties(QObject *)
QmlRadioButtonGroup(QObject *parent=nullptr)
void selectedChanged(QObject *selected)