File indexing completed on 2024-11-24 04:42:24
0001 /* 0002 * buttongroup.h - QButtonGroup with an extra signal, and button IDs 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2002, 2004, 2005, 2008 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 #pragma once 0009 0010 #include <QButtonGroup> 0011 #include <QMap> 0012 class QAbstractButton; 0013 0014 0015 /** 0016 * @short A QButtonGroup with signal on new selection, and button IDs. 0017 * 0018 * The ButtonGroup class provides an enhanced version of the QButtonGroup class. 0019 * 0020 * It emits an additional signal, buttonSet(QAbstractButton*), whenever any of its 0021 * buttons changes state, for whatever reason, including programmatic control. (The 0022 * QButtonGroup class only emits signals when buttons are clicked on by the user.) 0023 * 0024 * It allows buttons to have associated ID numbers, which can be used to access the 0025 * buttons. 0026 * 0027 * @author David Jarvie <djarvie@kde.org> 0028 */ 0029 class ButtonGroup : public QButtonGroup 0030 { 0031 Q_OBJECT 0032 public: 0033 /** Constructor. 0034 * @param parent The parent object of this widget 0035 */ 0036 explicit ButtonGroup(QObject* parent = nullptr); 0037 /** Adds a button to the group. 0038 * The button is not given an ID. 0039 * This overrides the addButton() method of QButtonGroup. 0040 * @param button The button to insert 0041 */ 0042 void addButton(QAbstractButton* button); 0043 /** Adds a button with a specified ID to the group. 0044 * @param button The button to insert 0045 * @param id Button ID 0046 */ 0047 void addButton(QAbstractButton* button, int id); 0048 /** Returns the identifier of the specified button. 0049 * @return ID, or -1 if the button was not found 0050 */ 0051 int id(QAbstractButton* button) const; 0052 /** Returns the button with the specified identifier @p id. 0053 * @return button, or 0 if the button was not found 0054 */ 0055 QAbstractButton* find(int id) const; 0056 /** Returns the id of the selected button. 0057 * @return button if exactly one is selected, or -1 otherwise 0058 */ 0059 int selectedId() const; 0060 /** Checks the button with the specified ID. 0061 * @param id Button ID 0062 */ 0063 void setButton(int id); 0064 Q_SIGNALS: 0065 /** Signal emitted whenever any button in the group changes state, 0066 * for whatever reason. 0067 * @param button The button which is now selected 0068 */ 0069 void buttonSet(QAbstractButton* button); 0070 0071 private Q_SLOTS: 0072 void slotButtonToggled(bool); 0073 0074 private: 0075 QMap<int, QAbstractButton*> mIds; 0076 }; 0077 0078 // vim: et sw=4: