• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm/lib

  • sources
  • kde-4.14
  • kdepim
  • kalarm
  • lib
buttongroup.cpp
Go to the documentation of this file.
1 /*
2  * buttongroup.cpp - QButtonGroup with an extra signal
3  * Program: kalarm
4  * Copyright © 2002,2004,2005,2008 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 #include "kalarm.h"
21 
22 #include "buttongroup.h"
23 #include <QAbstractButton>
24 
25 
26 ButtonGroup::ButtonGroup(QObject* parent)
27  : QButtonGroup(parent)
28 {
29  connect(this, SIGNAL(buttonClicked(QAbstractButton*)), SIGNAL(buttonSet(QAbstractButton*)));
30 }
31 
32 /******************************************************************************
33  * Inserts a button into the group.
34  */
35 void ButtonGroup::addButton(QAbstractButton* button)
36 {
37  QButtonGroup::addButton(button);
38  connect(button, SIGNAL(toggled(bool)), SLOT(slotButtonToggled(bool)));
39 }
40 
41 /******************************************************************************
42  * Inserts a button into the group.
43  */
44 void ButtonGroup::addButton(QAbstractButton* button, int id)
45 {
46  addButton(button);
47  mIds[id] = button;
48 }
49 
50 /******************************************************************************
51  * Returns the ID of the specified button.
52  * Reply = -1 if not found.
53  */
54 int ButtonGroup::id(QAbstractButton* button) const
55 {
56  for (QMap<int, QAbstractButton*>::ConstIterator it = mIds.constBegin(); it != mIds.constEnd(); ++it)
57  if (it.value() == button)
58  return it.key();
59  return -1;
60 }
61 
62 /******************************************************************************
63  * Returns the button with the specified ID.
64  */
65 QAbstractButton* ButtonGroup::find(int id) const
66 {
67  QMap<int, QAbstractButton*>::ConstIterator it = mIds.find(id);
68  if (it == mIds.constEnd())
69  return 0;
70  return it.value();
71 }
72 
73 /******************************************************************************
74  * Returns the ID of the currently selected button.
75  */
76 int ButtonGroup::selectedId() const
77 {
78  return id(checkedButton());
79 }
80 
81 /******************************************************************************
82  * Returns the ID of the currently selected button.
83  */
84 void ButtonGroup::setButton(int id)
85 {
86  QAbstractButton* button = find(id);
87  if (button)
88  button->setChecked(true);
89 }
90 
91 /******************************************************************************
92  * Called when one of the member buttons is toggled.
93  */
94 void ButtonGroup::slotButtonToggled(bool)
95 {
96  emit buttonSet(checkedButton());
97 }
98 #include "moc_buttongroup.cpp"
99 // vim: et sw=4:
buttongroup.h
QButtonGroup::addButton
void addButton(QAbstractButton *button)
QButtonGroup::buttonClicked
void buttonClicked(QAbstractButton *button)
QMap::constBegin
const_iterator constBegin() const
QMap
ButtonGroup::ButtonGroup
ButtonGroup(QObject *parent)
Constructor.
Definition: buttongroup.cpp:26
QButtonGroup::button
QAbstractButton * button(int id) const
ButtonGroup::id
int id(QAbstractButton *button) const
Returns the identifier of the specified button.
Definition: buttongroup.cpp:54
QButtonGroup
QObject
QMap::constEnd
const_iterator constEnd() const
ButtonGroup::selectedId
int selectedId() const
Returns the id of the selected button.
Definition: buttongroup.cpp:76
ButtonGroup::addButton
void addButton(QAbstractButton *button)
Adds a button to the group.
Definition: buttongroup.cpp:35
ButtonGroup::find
QAbstractButton * find(int id) const
Returns the button with the specified identifier id.
Definition: buttongroup.cpp:65
QAbstractButton::setChecked
void setChecked(bool)
QAbstractButton
ButtonGroup::buttonSet
void buttonSet(QAbstractButton *button)
Signal emitted whenever whenever any button in the group changes state, for whatever reason...
ButtonGroup::setButton
void setButton(int id)
Checks the button with the specified ID.
Definition: buttongroup.cpp:84
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QButtonGroup::checkedButton
QAbstractButton * checkedButton() const
QMap::find
iterator find(const Key &key)
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:35:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal