NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxManageClippersWidget.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 "cxManageClippersWidget.h"
13 #include <QPushButton>
15 #include "cxInteractiveClipper.h"
16 #include "cxVisServices.h"
17 #include "cxLogger.h"
18 #include "cxProfile.h"
19 #include "cxClippers.h"
20 #include "cxClipperWidget.h"
21 #include "cxViewService.h"
23 
24 namespace cx
25 {
26 
28  TabbedWidget(parent, "ClippingPropertiesWidget", "Clipping Properties")
29 {
30  this->setToolTip("Clipping properties");
31 
32  this->addTab(new ManageClippersWidget(services, this), "Edit clippers");
33 }
34 
36  BaseWidget(parent, "ManageClippersWidget", "Manage Clippers"),
37  mServices(services),
38  mClipperWidget(new ClipperWidget(services, this))
39 {
40  this->setupUI();
41  connect(getClippers().get(), &Clippers::changed, this, &ManageClippersWidget::clippersChanged);
42 
43 }
44 
46 {
47  return mServices->view()->getClippers();
48 }
49 
51 {
52  XmlOptionFile mOptions = profile()->getXmlSettings().descend("clippers");
53 
54  QStringList range = getClippers()->getClipperNames();
55  mClipperSelector = StringProperty::initialize("clipperSelector", "Clipper", "Select clipper", "", range, mOptions.getElement());
57  this->clippersChanged();
58 }
59 
61 {
63  LabeledComboBoxWidget* clipperSelectorBox = new LabeledComboBoxWidget(this, mClipperSelector);
64 
65  QPushButton* newClipperButton = new QPushButton("Create clipper", this);
66  newClipperButton->setToolTip("Create new clipper based on currently selected");
67  newClipperButton->setEnabled(false);//TODO: Disabled for now
68 
69  mLayout = new QVBoxLayout(this);
70  mLayout->addWidget(newClipperButton);
71  mLayout->addWidget(clipperSelectorBox);
72 
73  connect(newClipperButton, &QPushButton::clicked, this, &ManageClippersWidget::newClipperButtonClicked);
74 
75 
76  mLayout->addWidget(mClipperWidget);
77 
78  mLayout->addStretch();
79 }
80 
81 void ManageClippersWidget::clippersChanged()
82 {
83  mClipperSelector->setValueRange(getClippers()->getClipperNames());
84 
85  QStringList range = mClipperSelector->getValueRange();
86  if(!range.contains(mClipperSelector->getValue()))
87  {
88  if(range.isEmpty())
89  mClipperSelector->setValue("");
90  else
91  mClipperSelector->setValue(range.first());
92  }
93 }
94 
96 {
97  QString clipperName = mClipperSelector->getValue();
98  if(clipperName.isEmpty())
99  return;
100 
101  mCurrentClipper = getClippers()->getClipper(clipperName);
103 }
104 
106 {
108  QString nameBase = getNameBaseOfCurrentClipper();
109  QString clipperName = nameBase;
110 
111  int i = 2;
112  while(getClippers()->exists(clipperName))
113  clipperName = nameBase + QString(" %1").arg(i++);
114 
115  getClippers()->add(clipperName, interactiveClipper);
116 
117  QStringList range = mClipperSelector->getValueRange();
118  range << clipperName;
119  mClipperSelector->setValueRange(range);
120  mClipperSelector->setValue(clipperName);
121 }
122 
124 {
125  QString nameBase = mClipperSelector->getValue();
126  nameBase.remove(QRegExp(" [0-9]{1,2}$"));
127 
128  return nameBase;
129 }
130 
131 } //cx
cx::LabeledComboBoxWidget
Composite widget for string selection.
Definition: cxLabeledComboBoxWidget.h:36
cx::ClipperWidget
Definition: cxClipperWidget.h:32
cx::ClipperWidget::setClipper
void setClipper(InteractiveClipperPtr clipper)
Definition: cxClipperWidget.cpp:207
cx::XmlOptionFile
Helper class for xml files used to store ssc/cx data.
Definition: cxXmlOptionItem.h:78
cx::ManageClippersWidget::mClipperWidget
ClipperWidget * mClipperWidget
Definition: cxManageClippersWidget.h:60
cx::InteractiveClipper
Definition: cxInteractiveClipper.h:38
cxLogger.h
cxClipperWidget.h
cx::ManageClippersWidget::initClipperSelector
void initClipperSelector()
Definition: cxManageClippersWidget.cpp:50
cx::TabbedWidget::addTab
void addTab(BaseWidget *newTab, QString newTabName)
Definition: cxTabbedWidget.cpp:37
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxManageClippersWidget.h
cx::BaseWidget
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cxLabeledComboBoxWidget.h
cx::ClippingPropertiesWidget::ClippingPropertiesWidget
ClippingPropertiesWidget(VisServicesPtr services, QWidget *parent)
Definition: cxManageClippersWidget.cpp:27
cx::ManageClippersWidget
Widget for managing clippers.
Definition: cxManageClippersWidget.h:48
cx::ClippersPtr
boost::shared_ptr< class Clippers > ClippersPtr
Definition: cxForwardDeclarations.h:153
cx::Clippers::changed
void changed()
cx::TabbedWidget
Interface for making widgets with a hierarchy of tabs.
Definition: cxTabbedWidget.h:34
cxInteractiveClipper.h
cx::ManageClippersWidget::mLayout
QVBoxLayout * mLayout
Definition: cxManageClippersWidget.h:56
cxProfile.h
cxViewService.h
cx::XmlOptionFile::getElement
QDomElement getElement()
return the current element
Definition: cxXmlOptionItem.cpp:365
cx::ManageClippersWidget::mCurrentClipper
InteractiveClipperPtr mCurrentClipper
Definition: cxManageClippersWidget.h:59
cx::ManageClippersWidget::getClippers
ClippersPtr getClippers()
Definition: cxManageClippersWidget.cpp:45
cx::profile
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
cx::ManageClippersWidget::ManageClippersWidget
ManageClippersWidget(VisServicesPtr services, QWidget *parent)
Definition: cxManageClippersWidget.cpp:35
cx::ManageClippersWidget::mServices
VisServicesPtr mServices
Definition: cxManageClippersWidget.h:55
cx::ManageClippersWidget::clipperChanged
void clipperChanged()
Definition: cxManageClippersWidget.cpp:95
cx::ManageClippersWidget::mClipperSelector
StringPropertyPtr mClipperSelector
Definition: cxManageClippersWidget.h:57
cxSelectClippersForDataWidget.h
cx::InteractiveClipperPtr
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
Definition: cxForwardDeclarations.h:157
cx::ManageClippersWidget::getNameBaseOfCurrentClipper
QString getNameBaseOfCurrentClipper()
Definition: cxManageClippersWidget.cpp:123
cx::StringProperty::initialize
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
Definition: cxStringProperty.cpp:29
cx::ManageClippersWidget::setupUI
void setupUI()
Definition: cxManageClippersWidget.cpp:60
cx::ManageClippersWidget::newClipperButtonClicked
void newClipperButtonClicked()
Definition: cxManageClippersWidget.cpp:105
cxClippers.h
cxVisServices.h