Fraxinus  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
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
void changed()
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
ManageClippersWidget(VisServicesPtr services, QWidget *parent)
void setClipper(InteractiveClipperPtr clipper)
Composite widget for string selection.
boost::shared_ptr< class Clippers > ClippersPtr
QDomElement getElement()
return the current element
void addTab(BaseWidget *newTab, QString newTabName)
Interface for making widgets with a hierarchy of tabs.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
ClippingPropertiesWidget(VisServicesPtr services, QWidget *parent)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
StringPropertyPtr mClipperSelector
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
Widget for managing clippers.
InteractiveClipperPtr mCurrentClipper
Helper class for xml files used to store ssc/cx data.
Namespace for all CustusX production code.