-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrolgroup.cpp
More file actions
91 lines (70 loc) · 2.72 KB
/
controlgroup.cpp
File metadata and controls
91 lines (70 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
For the header file ...
class ControlGroup : public QWidget
{
Q_OBJECT
public:
explicit ControlGroup( Twidget *tw, QWidget *parent=0 )
{
init(tw, parent);
}
ControlGroup(){};
~ControlGroup(){};
QList<QRadioButton*> widgetList;
void init( Twidget *tw, QWidget *parent);
Twidget* getTwidget() {return m_tw;}
private:
Twidget *m_tw;
QWidget *m_parent;
};
#ifndef CONTROLGROUP_CPP
#define CONTROLGROUP_CPP
#include "controlgroup.h"
////template <typename T>
////void ControlGroup<T>::init( Twidget *tw, QWidget *parent )
void ControlGroup::init( Twidget *tw, QWidget *parent )
{
m_tw = tw;
m_parent = parent;
// See if the caller wants a QButtonGroup. That would make these buttons
// mutually exclusive.
// The QButtonGroup emits a signal with the ID of the checked button for
// each button that is checked in an exclusive group.
//
if(tw->grouped)
tw->buttonGroup = new QButtonGroup(parent);
else
tw->mapper = new QSignalMapper(parent);
for (int index = 0; index < tw->objCount; index++)
{
////T *object = new T(parent);
QRadioButton *object = new QRadioButton(parent);
// Layout the objects according to the Table Configuration given by
// the "topology" field in the Twidget struct.
//
int x = tw->geometry.x() + ((index % tw->topology.x()) * tw->geometry.width())
+ ((index % tw->topology.x()) * tw->geometry.height());
int y = tw->geometry.y() + ((index % tw->topology.y()) * tw->geometry.height())
+ ((index % tw->topology.x()) * tw->geometry.width());
////widgetList.append((T *)object);
widgetList.append((QRadioButton *)object);
object->setObjectName(QString(tw->objName % QString::number(index)));
object->setText(QString(tw->objText[index]));
object->setGeometry(x, y, tw->geometry.width(), tw->geometry.height());
// If the buttons are grouped, the buttonGroup will notify the mapper.
// In this case, the mapper only needs to be programmed at the end of
// this loop.
// If they are not grouped, the buttons themselves must notify the
// mapper, and the mapper must be programmed to recognize each button
// in the group.
//
if(tw->grouped)
tw->buttonGroup->addButton(object, index);
else
{
connect(object, SIGNAL(clicked()), tw->mapper, SLOT(map()));
tw->mapper->setMapping(object, index);
}
//tw->labelList.append(new QLabel(parent));
}
}
#endif