CustusX  18.04-rc1
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  mActiveToolSelected = true;
55  return true;
56  }
57  else
58  mActiveToolSelected = false;
59 
60  if(mTool && value==mTool->getUid())
61  return false;
62  ToolPtr temp = mTrackingService->getTool(value);
63  if(!temp)
64  return false;
65 
66  mTool = temp;
67  emit changed();
68  return true;
69 }
70 
72 {
73  if(mActiveToolSelected)
74  return mActiveToolName;
75  if(!mTool)
76  return "<no tool>";
77  return mTool->getUid();
78 }
79 
81 {
82  return mHelp;
83 }
84 
86 {
87  if(mActiveToolSelected)
88  return mTrackingService->getActiveTool();
89  return mTool;
90 }
91 
93 {
94  TrackingService::ToolMap tools = mTrackingService->getTools();
95 
96  QStringList retval;
97 
98  if(mProvideActiveTool)
99  retval << mActiveToolName;
100 
101  for (TrackingService::ToolMap::iterator iter=tools.begin(); iter!=tools.end(); ++iter)
102  retval << iter->second->getUid();
103  return retval;
104 }
105 
107 {
108  if(internal == mActiveToolName)
109  return mActiveToolName;
110  ToolPtr tool = mTrackingService->getTool(internal);
111  if (!tool)
112  {
113  return "<no tool>";
114  }
115  return qstring_cast(tool->getName());
116 }
117 
119 {
120  mProvideActiveTool = on;
121 }
122 
124 {
125  mActiveToolSelected = true;
126 }
127 
128 } // 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