1 // ============================================================================= |
|
2 // CheckBoxGroup |
|
3 // ============================================================================= |
|
4 class CheckBoxGroup : public QGroupBox { |
|
5 Q_OBJECT |
|
6 |
|
7 public: |
|
8 CheckBoxGroup (const char* label, Qt::Orientation orient = Qt::Horizontal, QWidget* parent = null); |
|
9 |
|
10 void addCheckBox (const char* label, int key, bool checked = false); |
|
11 vector<int> checkedValues () const; |
|
12 QCheckBox* getCheckBox (int key); |
|
13 bool buttonChecked (int key); |
|
14 |
|
15 signals: |
|
16 void selectionChanged (); |
|
17 |
|
18 private: |
|
19 QBoxLayout* m_layout; |
|
20 std::map<int, QCheckBox*> m_vals; |
|
21 |
|
22 private slots: |
|
23 void buttonChanged (); |
|
24 }; |
|
25 |
|
26 CheckBoxGroup::CheckBoxGroup (const char* label, Qt::Orientation orient, QWidget* parent) : QGroupBox (parent) { |
|
27 m_layout = new QBoxLayout (makeDirection (orient)); |
|
28 setTitle (label); |
|
29 setLayout (m_layout); |
|
30 } |
|
31 |
|
32 void CheckBoxGroup::addCheckBox (const char* label, int key, bool checked) { |
|
33 if (m_vals.find (key) != m_vals.end ()) |
|
34 return; |
|
35 |
|
36 QCheckBox* box = new QCheckBox (label); |
|
37 box->setChecked (checked); |
|
38 |
|
39 m_vals[key] = box; |
|
40 m_layout->addWidget (box); |
|
41 |
|
42 connect (box, SIGNAL (stateChanged (int)), this, SLOT (buttonChanged ())); |
|
43 } |
|
44 |
|
45 vector<int> CheckBoxGroup::checkedValues () const { |
|
46 vector<int> vals; |
|
47 |
|
48 for (const auto& kv : m_vals) |
|
49 if (kv.second->isChecked ()) |
|
50 vals << kv.first; |
|
51 |
|
52 return vals; |
|
53 } |
|
54 |
|
55 QCheckBox* CheckBoxGroup::getCheckBox (int key) { |
|
56 return m_vals[key]; |
|
57 } |
|
58 |
|
59 void CheckBoxGroup::buttonChanged () { |
|
60 emit selectionChanged (); |
|
61 } |
|
62 |
|
63 bool CheckBoxGroup::buttonChecked (int key) { |
|
64 return m_vals[key]->isChecked (); |
|
65 } |
|
66 |
|
67 CheckBoxGroup* makeAxesBox() { |
|
68 CheckBoxGroup* cbg_axes = new CheckBoxGroup ("Axes", Qt::Horizontal); |
|
69 cbg_axes->addCheckBox ("X", X); |
|
70 cbg_axes->addCheckBox ("Y", Y); |
|
71 cbg_axes->addCheckBox ("Z", Z); |
|
72 return cbg_axes; |
|
73 } |
|