CustusX  18.04
An IGT application
cxSelectClippersForDataWidget.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 
13 #include "boost/bind.hpp"
14 #include <QTableWidget>
15 #include <QLabel>
16 #include <QCheckBox>
17 #include "cxVisServices.h"
18 #include "cxViewService.h"
19 #include "cxPatientModelService.h"
20 #include "cxClippers.h"
21 #include "cxLogger.h"
22 #include "cxInteractiveClipper.h"
23 #include "cxActiveData.h"
25 #include "cxDataSelectWidget.h"
26 
27 namespace cx
28 {
30  BaseWidget(parent, "select_clippers_for_image_widget", "Select Clippers")
31 {
32  StringPropertyActiveImagePtr activeImageProperty = StringPropertyActiveImage::New(services->patient());
33 
34  QVBoxLayout *mLayout = new QVBoxLayout(this);
35  mLayout->setMargin(0);
36 
37  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
38  selectClippersWidget->setActiveDataProperty(activeImageProperty);
39 
40  mLayout->addWidget(selectClippersWidget);
41 }
42 
44 
46  BaseWidget(parent, "select_clippers_for_mesh_widget", "Select Clippers")
47 {
48  StringPropertyActiveDataPtr activeMeshProperty = StringPropertyActiveData::New(services->patient(), "mesh");
49 
50  QVBoxLayout *mLayout = new QVBoxLayout(this);
51  mLayout->setMargin(0);
52 
53  SelectClippersForDataWidget *selectClippersWidget = new SelectClippersForDataWidget(services, this);
54  selectClippersWidget->setActiveDataProperty(activeMeshProperty);
55 
56  mLayout->addWidget(selectClippersWidget);
57 }
58 
60 
62  BaseWidget(parent, "select_clippers_for_data_widget", "Select Clippers"),
63  mServices(services),
64  mActiveDataProperty(StringPropertyActiveData::New(services->patient()))
65 {
66  this->initUI();
67 
68  ClippersPtr clippers = mServices->view()->getClippers();
69  connect(clippers.get(), &Clippers::changed, this, &SelectClippersForDataWidget::setModified);
71 }
72 
74 {
76  mActiveDataProperty = property;
77  connect(mActiveDataProperty.get(), &Property::changed, this, &SelectClippersForDataWidget::setModified);
78 }
79 
81 {
82  mClipperTableWidget = new QTableWidget(this);
83 
84  mHeading = new QLabel("Active clippers");
85 
86  mLayout = new QVBoxLayout(this);
87  mLayout->setMargin(0);
88  mLayout->addWidget(mHeading);
89  mLayout->addWidget(mClipperTableWidget);
90 
91  this->setupClipperSelectorUI();
93 }
94 
96 {
97  ClippersPtr clippers = mServices->view()->getClippers();
98  mClipperTableWidget->setColumnCount(3);
99  mClipperTableWidget->setRowCount(clippers->size());
100  QStringList horizontalHeaders;
101  horizontalHeaders << "Clip data" << "Clipper" << "Invert";
102  mClipperTableWidget->setHorizontalHeaderLabels(horizontalHeaders);
103 }
104 
106 {
107  ClippersPtr clippers = mServices->view()->getClippers();
108  QStringList clipperNames = clippers->getClipperNames();
109 
110  int row = 0;
111  for(int i = 0; i < clipperNames.size(); ++i)
112  {
113  QString clipperName = clipperNames.at(i);
114  this->createDataCheckBox(row, clipperName);
115 
116  QTableWidgetItem *descriptionItem = new QTableWidgetItem(clipperName);
117  mClipperTableWidget->setItem(row++, 1, descriptionItem);
118  }
119 }
120 
121 void SelectClippersForDataWidget::createDataCheckBox(int row, QString clipperName)
122 {
123  QCheckBox *dataCheckBox = this->createCheckBox(clipperName);
124  QCheckBox *invertCheckbox = this->createCheckBox(clipperName);
125  mClipperTableWidget->setCellWidget(row, 0, dataCheckBox);
126  mClipperTableWidget->setCellWidget(row, 2, invertCheckbox);
127 
128  boost::function<void()> func = boost::bind(&SelectClippersForDataWidget::clipDataClicked, this, dataCheckBox, clipperName);
129  connect(dataCheckBox, &QCheckBox::clicked, this, func);
130 
131  boost::function<void()> invertFunc = boost::bind(&SelectClippersForDataWidget::invertClicked, this, invertCheckbox, clipperName);
132  connect(invertCheckbox, &QCheckBox::clicked, this, invertFunc);
133 
134  this->updateCheckBoxesFromClipper(dataCheckBox, invertCheckbox, clipperName);
135 }
136 
137 void SelectClippersForDataWidget::updateCheckBoxesFromClipper(QCheckBox *dataCheckBox, QCheckBox *invertCheckBox, QString clipperName)
138 {
139  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
140  DataPtr activeData = mActiveDataProperty->getData();
141 
142  bool checkData = clipper->exists(activeData);
143  dataCheckBox->setChecked(checkData);
144 
145  bool checkInvert = clipper->getInvertPlane();
146  invertCheckBox->setChecked(checkInvert);
147 }
148 
149 QCheckBox *SelectClippersForDataWidget::createCheckBox(QString clipperName)
150 {
151  QCheckBox *checkbox = new QCheckBox();
152  checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
153  return checkbox;
154 }
155 
156 cx::InteractiveClipperPtr SelectClippersForDataWidget::getClipper(QString clipperName)
157 {
158  ClippersPtr clippers = mServices->view()->getClippers();
159  cx::InteractiveClipperPtr clipper = clippers->getClipper(clipperName);
160  return clipper;
161 }
162 
163 void SelectClippersForDataWidget::clipDataClicked(QCheckBox *checkBox, QString clipperName)
164 {
165  DataPtr activeData = mActiveDataProperty->getData();
166  cx::InteractiveClipperPtr clipper = this->getClipper(clipperName);
167  bool checked = checkBox->isChecked();
168 
169  if(checked)
170  clipper->addData(activeData);
171  else
172  clipper->removeData(activeData);
173 }
174 
175 void SelectClippersForDataWidget::invertClicked(QCheckBox *checkBox, QString clipperName)
176 {
177  bool checked = checkBox->isChecked();
178  this->getClipper(clipperName)->invertPlane(checked);
179 }
180 
182 {
184 }
185 
186 
187 }//cx
188 
void changed()
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
boost::shared_ptr< class StringPropertyActiveImage > StringPropertyActiveImagePtr
Turn clippers on/off for a spesific data structure.
SelectClippersForMeshWidget(VisServicesPtr services, QWidget *parent)
SelectClippersForImageWidget(VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class Clippers > ClippersPtr
SelectDataStringPropertyBasePtr mActiveDataProperty
void invertClicked(QCheckBox *checkBox, QString clipperName)
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
static StringPropertyActiveImagePtr New(PatientModelServicePtr patientModelService)
void setActiveDataProperty(SelectDataStringPropertyBasePtr property)
void clipDataClicked(QCheckBox *checkBox, QString clipperName)
void changed()
emit when the underlying data value is changed: The user interface will be updated.
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
static StringPropertyActiveDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
SelectClippersForDataWidget(VisServicesPtr services, QWidget *parent)
boost::shared_ptr< class StringPropertyActiveData > StringPropertyActiveDataPtr
Namespace for all CustusX production code.