NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxStringPropertySelectTool.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 
14 #include "cxTrackingService.h"
15 #include "cxTypeConversions.h"
16 
17 namespace cx
18 {
19 
20 //---------------------------------------------------------
21 //---------------------------------------------------------
22 //---------------------------------------------------------
23 
25  mProvideActiveTool(false),
26  mActiveToolSelected(false),
27  mActiveToolName("<Active Tool>")
28 {
29  mTrackingService = trackingService;
30  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &Property::changed);
31  mValueName = "Select a tool";
32  mHelp = mValueName;
33 }
34 
36 {
37  mHelp = help;
38 }
39 
41 {
42  mValueName = name;
43 }
44 
46 {
47  return mValueName;
48 }
49 
50 bool StringPropertySelectTool::setValue(const QString& value)
51 {
52  if(value == mActiveToolName)
53  {
54  mTool.reset(); //Don't remember last tool when active tool is selected
55  bool emitChange = false;
56  if(!mActiveToolSelected)
57  emitChange = true;
58  mActiveToolSelected = true;
59  if(emitChange)
60  emit changed();
61  return true;
62  }
63  else
64  mActiveToolSelected = false;
65 
66  if(mTool && value==mTool->getUid())
67  return false;
68  ToolPtr temp = mTrackingService->getTool(value);
69  if(!temp)
70  return false;
71 
72  mTool = temp;
73  emit changed();
74  return true;
75 }
76 
78 {
79  if(mActiveToolSelected)
80  return mActiveToolName;
81  if(!mTool)
82  return "<no tool>";
83  return mTool->getUid();
84 }
85 
87 {
88  return mHelp;
89 }
90 
92 {
93  if(mActiveToolSelected)
94  return mTrackingService->getActiveTool();
95  return mTool;
96 }
97 
99 {
100  return mActiveToolSelected;
101 }
102 
104 {
105  TrackingService::ToolMap tools = mTrackingService->getTools();
106 
107  QStringList retval;
108 
109  if(mProvideActiveTool)
110  retval << mActiveToolName;
111 
112  for (TrackingService::ToolMap::iterator iter=tools.begin(); iter!=tools.end(); ++iter)
113  retval << iter->second->getUid();
114  return retval;
115 }
116 
118 {
119  if(internal == mActiveToolName)
120  return mActiveToolName;
121  ToolPtr tool = mTrackingService->getTool(internal);
122  if (!tool)
123  {
124  return "<no tool>";
125  }
126  return qstring_cast(tool->getName());
127 }
128 
130 {
131  mProvideActiveTool = on;
132 }
133 
135 {
136  mActiveToolSelected = true;
137 }
138 
139 } // namespace cx
cx::StringPropertySelectTool::setHelp
void setHelp(QString help)
Definition: cxStringPropertySelectTool.cpp:35
cx::StringPropertySelectTool::StringPropertySelectTool
StringPropertySelectTool(TrackingServicePtr trackingService)
Definition: cxStringPropertySelectTool.cpp:24
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::StringPropertySelectTool::setValue
virtual bool setValue(const QString &value)
set the data value.
Definition: cxStringPropertySelectTool.cpp:50
cx::StringPropertySelectTool::setValueName
void setValueName(QString name)
Definition: cxStringPropertySelectTool.cpp:40
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::StringPropertySelectTool::getHelp
virtual QString getHelp() const
Definition: cxStringPropertySelectTool.cpp:86
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::StringPropertySelectTool::getTool
ToolPtr getTool() const
Definition: cxStringPropertySelectTool.cpp:91
cx::StringPropertySelectTool::isActiveToolSelected
bool isActiveToolSelected() const
Definition: cxStringPropertySelectTool.cpp:98
cx::StringPropertySelectTool::setActiveTool
void setActiveTool()
Definition: cxStringPropertySelectTool.cpp:134
cxStringPropertySelectTool.h
cx::StringPropertySelectTool::getDisplayName
virtual QString getDisplayName() const
name of data entity. Used for display to user.
Definition: cxStringPropertySelectTool.cpp:45
cx::TrackingServicePtr
boost::shared_ptr< class TrackingService > TrackingServicePtr
Definition: cxToolFilterWidget.h:27
cx::StringPropertySelectTool::getValueRange
virtual QStringList getValueRange() const
Definition: cxStringPropertySelectTool.cpp:103
cxTypeConversions.h
cx::TrackingService::stateChanged
void stateChanged()
cx::StringPropertySelectTool::convertInternal2Display
virtual QString convertInternal2Display(QString internal)
Definition: cxStringPropertySelectTool.cpp:117
cx::StringPropertySelectTool::provideActiveTool
void provideActiveTool(bool on)
Definition: cxStringPropertySelectTool.cpp:129
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cxTrackingService.h
cx::StringPropertySelectTool::getValue
virtual QString getValue() const
get the data value.
Definition: cxStringPropertySelectTool.cpp:77
cx::TrackingService::ToolMap
std::map< QString, ToolPtr > ToolMap
Definition: cxTrackingService.h:54