CustusX  22.04-rc5
An IGT application
cxToolProperty.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 "cxToolProperty.h"
13 
14 #include "cxTypeConversions.h"
15 #include "cxTrackingService.h"
16 #include "cxTool.h"
17 
18 namespace cx
19 {
20 
21 
23 {
24  mTrackingService = trackingService;
25  connect(mTrackingService.get(), SIGNAL(activeToolChanged(const QString&)), this, SIGNAL(changed()));
26  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &StringPropertyActiveTool::changed);
27 }
28 
30 {
31  return "Active Tool";
32 }
33 
34 bool StringPropertyActiveTool::setValue(const QString& value)
35 {
36  ToolPtr newTool = mTrackingService->getTool(value);
37  if (!newTool)
38  return false;
39  if(newTool == mTrackingService->getActiveTool())
40  return false;
41  mTrackingService->setActiveTool(newTool->getUid());
42  return true;
43 }
44 
46 {
47  if (!mTrackingService->getActiveTool())
48  return "";
49  return qstring_cast(mTrackingService->getActiveTool()->getUid());
50 }
51 
53 {
54  return "select the active tool";
55 }
56 
58 {
59  TrackingService::ToolMap tools = mTrackingService->getTools();
60 
61  QStringList retval;
62  for (TrackingService::ToolMap::iterator iter=tools.begin(); iter!=tools.end(); ++iter)
63  retval << iter->second->getUid();
64  return retval;
65 }
66 
68 {
69  ToolPtr tool = mTrackingService->getTool(internal);
70  if (!tool)
71  return "<no tool>";
72  return qstring_cast(tool->getName());
73 }
74 
75 //--------------------------------------------------------
76 //--------------------------------------------------------
77 //--------------------------------------------------------
78 
80 {
81  mTrackingService = trackingService;
82  connect(mTrackingService.get(), &TrackingService::activeToolChanged, this, &StringPropertyActiveProbeConfiguration::activeToolChanged);
83  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &StringPropertyActiveProbeConfiguration::activeToolChanged);
84  this->activeToolChanged();
85 }
86 
87 void StringPropertyActiveProbeConfiguration::activeToolChanged()
88 {
89  // ignore tool changes to something non-probeish.
90  // This gives the user a chance to use the widget without having to show the probe.
91  ToolPtr newTool = mTrackingService->getFirstProbe();
92  if (!newTool || !newTool->getProbe())
93  return;
94 
95  if (mTool)
96  disconnect(mTool->getProbe().get(), &Probe::sectorChanged, this, &StringPropertyActiveProbeConfiguration::changed);
97 
98  mTool = newTool;
99 
100  if (mTool)
101  connect(mTool->getProbe().get(), &Probe::sectorChanged, this, &StringPropertyActiveProbeConfiguration::changed);
102 
103  emit changed();
104 }
105 
107 {
108  return "Probe Config";
109 }
110 
112 {
113  if (!mTool)
114  return false;
115  mTool->getProbe()->applyNewConfigurationWithId(value);
116  return true;
117 }
118 
120 {
121  if (!mTool)
122  return "";
123  return mTool->getProbe()->getConfigId();
124 }
125 
127 {
128  return "Select a probe configuration for the active probe.";
129 }
130 
132 {
133  if (!mTool)
134  return QStringList();
135  return mTool->getProbe()->getConfigIdList();
136 }
137 
139 {
140  if (!mTool)
141  return "<no tool>";
142  return mTool->getProbe()->getConfigName(internal);
143 }
144 
145 
146 }
StringPropertyActiveTool(TrackingServicePtr trackingService)
QString qstring_cast(const T &val)
virtual QStringList getValueRange() const
virtual QString getValue() const
get the data value.
virtual QStringList getValueRange() const
boost::shared_ptr< class TrackingService > TrackingServicePtr
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual bool setValue(const QString &value)
set the data value.
virtual bool setValue(const QString &value)
set the data value.
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
void activeToolChanged(const QString &uId)
void sectorChanged()
< Return a ProbeSectorPtr for the given uid. Use &#39;active&#39; to get the default.
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
std::map< QString, ToolPtr > ToolMap
StringPropertyActiveProbeConfiguration(TrackingServicePtr trackingService)
virtual QString getValue() const
get the data value.
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr