Fraxinus  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
QString qstring_cast(const T &val)
virtual bool setValue(const QString &value)
set the data value.
virtual QString getValue() const
get the data value.
boost::shared_ptr< class TrackingService > TrackingServicePtr
virtual QString getDisplayName() const
name of data entity. Used for display to user.
virtual QStringList getValueRange() const
virtual QString getHelp() const
return a descriptive help string for the data, used for example as a tool tip.
virtual QString convertInternal2Display(QString internal)
range of value. Use if data is constrained to a set.
StringPropertySelectTool(TrackingServicePtr trackingService)
void changed()
emit when the underlying data value is changed: The user interface will be updated.
std::map< QString, ToolPtr > ToolMap
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr