Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxSelectionGroupBox.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxSelectionGroupBox.h"
13 
14 #include <QComboBox>
15 #include <QButtonGroup>
16 #include <QVBoxLayout>
17 #include <QHBoxLayout>
18 #include <QGridLayout>
19 #include <QCheckBox>
20 
21 namespace cx
22 {
23 SelectionGroupBox::SelectionGroupBox(QString title, QStringList selectionList, Qt::Orientation orientation, bool exclusive, QWidget* parent) :
24  QGroupBox(parent),
25  mSelectionList(selectionList),
26  mButtonGroup(new QButtonGroup(parent))
27 {
28  if (orientation==Qt::Vertical)
29  mLayout = new QVBoxLayout(this);
30  else
31  mLayout = new QHBoxLayout(this);
32 
33  this->setTitle(title);
34 
35  this->populate(exclusive);
36 }
37 
39 {}
40 
42 {
43  QStringList retval;
44  QList<QAbstractButton*> applicationButtonList = mButtonGroup->buttons();
45  foreach(QAbstractButton* button, applicationButtonList)
46  {
47  if(button->isChecked())
48  retval << button->text();
49  }
50  return retval;
51 }
52 
53 void SelectionGroupBox::setSelected(QStringList selectedlist)
54 {
55  this->filter(selectedlist);
56 }
57 
59 {
60  QList<QAbstractButton*> applicationButtonList = mButtonGroup->buttons();
61  foreach(QAbstractButton* button, applicationButtonList)
62  {
63  button->setEnabled(value);
64  }
65 }
66 
67 void SelectionGroupBox::populate(bool exclusive)
68 {
69  mButtonGroup->setExclusive(exclusive);
70  foreach(QString string, mSelectionList)
71  {
72  if(string.isEmpty())
73  continue;
74 
75  string = string.toLower();
76  string[0] = string[0].toUpper();
77 
78  QCheckBox* box = new QCheckBox(string);
79  mButtonGroup->addButton(box);
80  mLayout->addWidget(box);
81 
82  //need to tell the outside world that the state of a button changed
83  connect(box, SIGNAL(stateChanged(int)), this, SIGNAL(selectionChanged()));
84  connect(box, SIGNAL(clicked(bool)), this, SIGNAL(userClicked()));
85  }
86 // mLayout->addStretch();
87  QHBoxLayout* hbox = dynamic_cast<QHBoxLayout*>(mLayout);
88  if (hbox)
89  hbox->addStretch();
90 }
91 
92 void SelectionGroupBox::filter(QStringList filter)
93 {
94  bool exclusive = mButtonGroup->exclusive();
95 
96  mButtonGroup->setExclusive(false);
97  QList<QAbstractButton*> applicationButtonList = mButtonGroup->buttons();
98  foreach(QAbstractButton* button, applicationButtonList)
99  {
100  bool on = filter.contains(button->text(), Qt::CaseInsensitive);
101  button->setChecked(on);
102  }
103  mButtonGroup->setExclusive(exclusive);
104 }
105 }//namespace cx
106 
void setEnabledButtons(bool value)
enables or disables all buttons
virtual QStringList getSelected()
get a list of selected button text
void userClicked()
emitted when a user has clicked a button inside the groupbox
virtual void setSelected(QStringList selectedlist)
set the selected buttons
void selectionChanged()
emitted when the selection of application changed
SelectionGroupBox(QString title, QStringList selectionList, Qt::Orientation orientation, bool exclusive=false, QWidget *parent=NULL)
Namespace for all CustusX production code.