NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxManageClippersWidget.h"
34 #include <QPushButton>
36 #include "cxInteractiveClipper.h"
37 #include "cxVisServices.h"
38 #include "cxLogger.h"
39 #include "cxProfile.h"
40 #include "cxClippers.h"
41 #include "cxClipperWidget.h"
42 #include "cxViewService.h"
44 
45 namespace cx
46 {
47 
49  TabbedWidget(parent, "ClippingPropertiesWidget", "Clipping Properties")
50 {
51  this->setToolTip("Clipping properties");
52 
53  this->addTab(new ManageClippersWidget(services, this), "Edit clippers");
54 }
55 
57  BaseWidget(parent, "ManageClippersWidget", "Manage Clippers"),
58  mServices(services),
59  mClipperWidget(new ClipperWidget(services, this))
60 {
61  this->setupUI();
62  connect(getClippers().get(), &Clippers::changed, this, &ManageClippersWidget::clippersChanged);
63 
64 }
65 
67 {
68  return mServices->view()->getClippers();
69 }
70 
72 {
73  XmlOptionFile mOptions = profile()->getXmlSettings().descend("clippers");
74 
75  QStringList range = getClippers()->getClipperNames();
76  mClipperSelector = StringProperty::initialize("clipperSelector", "Clipper", "Select clipper", "", range, mOptions.getElement());
78  this->clippersChanged();
79 }
80 
82 {
84  LabeledComboBoxWidget* clipperSelectorBox = new LabeledComboBoxWidget(this, mClipperSelector);
85 
86  QPushButton* newClipperButton = new QPushButton("Create clipper", this);
87  newClipperButton->setToolTip("Create new clipper based on currently selected");
88  newClipperButton->setEnabled(false);//TODO: Disabled for now
89 
90  mLayout = new QVBoxLayout(this);
91  mLayout->addWidget(newClipperButton);
92  mLayout->addWidget(clipperSelectorBox);
93 
94  connect(newClipperButton, &QPushButton::clicked, this, &ManageClippersWidget::newClipperButtonClicked);
95 
96 
97  mLayout->addWidget(mClipperWidget);
98 
99  mLayout->addStretch();
100 }
101 
102 void ManageClippersWidget::clippersChanged()
103 {
104  mClipperSelector->setValueRange(getClippers()->getClipperNames());
105 
106  QStringList range = mClipperSelector->getValueRange();
107  if(!range.contains(mClipperSelector->getValue()))
108  {
109  if(range.isEmpty())
110  mClipperSelector->setValue("");
111  else
112  mClipperSelector->setValue(range.first());
113  }
114 }
115 
117 {
118  QString clipperName = mClipperSelector->getValue();
119  if(clipperName.isEmpty())
120  return;
121 
122  mCurrentClipper = getClippers()->getClipper(clipperName);
124 }
125 
127 {
129  QString nameBase = getNameBaseOfCurrentClipper();
130  QString clipperName = nameBase;
131 
132  int i = 2;
133  while(getClippers()->exists(clipperName))
134  clipperName = nameBase + QString(" %1").arg(i++);
135 
136  getClippers()->add(clipperName, interactiveClipper);
137 
138  QStringList range = mClipperSelector->getValueRange();
139  range << clipperName;
140  mClipperSelector->setValueRange(range);
141  mClipperSelector->setValue(clipperName);
142 }
143 
145 {
146  QString nameBase = mClipperSelector->getValue();
147  nameBase.remove(QRegExp(" [0-9]{1,2}$"));
148 
149  return nameBase;
150 }
151 
152 } //cx
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:176
void changed()
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
ManageClippersWidget(VisServicesPtr services, QWidget *parent)
void setClipper(InteractiveClipperPtr clipper)
Composite widget for string selection.
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:108
StringPropertyPtr mClipperSelector
boost::shared_ptr< class InteractiveClipper > InteractiveClipperPtr
Widget for managing clippers.
boost::shared_ptr< class Clippers > ClippersPtr
InteractiveClipperPtr mCurrentClipper
Helper class for xml files used to store ssc/cx data.