Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
34 
35 #include "cxTrackingService.h"
36 #include "cxTypeConversions.h"
37 
38 namespace cx
39 {
40 
41 //---------------------------------------------------------
42 //---------------------------------------------------------
43 //---------------------------------------------------------
44 
46  mProvideActiveTool(false),
47  mActiveToolSelected(false),
48  mActiveToolName("<Active Tool>")
49 {
50  mTrackingService = trackingService;
51  connect(mTrackingService.get(), &TrackingService::stateChanged, this, &Property::changed);
52  mValueName = "Select a tool";
53  mHelp = mValueName;
54 }
55 
57 {
58  mHelp = help;
59 }
60 
62 {
63  mValueName = name;
64 }
65 
67 {
68  return mValueName;
69 }
70 
71 bool StringPropertySelectTool::setValue(const QString& value)
72 {
73  if(value == mActiveToolName)
74  {
75  mActiveToolSelected = true;
76  return true;
77  }
78  else
79  mActiveToolSelected = false;
80 
81  if(mTool && value==mTool->getUid())
82  return false;
83  ToolPtr temp = mTrackingService->getTool(value);
84  if(!temp)
85  return false;
86 
87  mTool = temp;
88  emit changed();
89  return true;
90 }
91 
93 {
94  if(mActiveToolSelected)
95  return mActiveToolName;
96  if(!mTool)
97  return "<no tool>";
98  return mTool->getUid();
99 }
100 
102 {
103  return mHelp;
104 }
105 
107 {
108  if(mActiveToolSelected)
109  return mTrackingService->getActiveTool();
110  return mTool;
111 }
112 
114 {
115  TrackingService::ToolMap tools = mTrackingService->getTools();
116 
117  QStringList retval;
118 
119  if(mProvideActiveTool)
120  retval << mActiveToolName;
121 
122  for (TrackingService::ToolMap::iterator iter=tools.begin(); iter!=tools.end(); ++iter)
123  retval << iter->second->getUid();
124  return retval;
125 }
126 
128 {
129  if(internal == mActiveToolName)
130  return mActiveToolName;
131  ToolPtr tool = mTrackingService->getTool(internal);
132  if (!tool)
133  {
134  return "<no tool>";
135  }
136  return qstring_cast(tool->getName());
137 }
138 
140 {
141  mProvideActiveTool = on;
142 }
143 
145 {
146  mActiveToolSelected = true;
147 }
148 
149 } // 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
cxLogicManager_EXPORT TrackingServicePtr trackingService()
boost::shared_ptr< class Tool > ToolPtr