CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxHelperWidgets.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 
33 
34 /*
35  * sscHelperWidgets.cpp
36  *
37  * Created on: May 18, 2010
38  * Author: christiana
39  */
40 #include "cxHelperWidgets.h"
41 
42 #include <iostream>
43 #include "boost/shared_ptr.hpp"
44 #include "cxDoubleWidgets.h"
46 #include "cxCheckBoxWidget.h"
47 #include "cxColorSelectWidget.h"
48 #include "cxTypeConversions.h"
50 #include "cxDoubleSpanSlider.h"
51 #include "cxFilenameWidget.h"
53 #include "cxDataSelectWidget.h"
55 #include "cxFilePathProperty.h"
56 
57 namespace cx
58 {
59 
60 QWidget* createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
61 {
62  QWidget* retval = NULL;
63 
64  //make cx widgets
65  SelectDataStringPropertyBasePtr dsda = boost::dynamic_pointer_cast<SelectDataStringPropertyBase>(data);
66  if (dsda)
67  {
68  retval = new DataSelectWidget(viewService, patientModelService, parent, dsda, gridLayout, row);
69  return retval;
70  }
71  if(retval != NULL)
72  return retval;
73 
74  retval = sscCreateDataWidget(parent, data, gridLayout, row);
75  return retval;
76 }
77 
78 QWidget* sscCreateDataWidget(QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
79 {
80  FilePathPropertyPtr fp = boost::dynamic_pointer_cast<FilePathProperty>(data);
81  if (fp)
82  {
83  return new FilenameWidget(parent, fp, gridLayout, row);
84  }
85 
86  StringPropertyBasePtr str = boost::dynamic_pointer_cast<StringPropertyBase>(data);
87  if (str)
88  {
89 // if (str->getGuiRepresentation()==StringPropertyBase::grFILENAME)
90 // return new FilenameWidget(parent, str, gridLayout, row);
91  if (str->getAllowOnlyValuesInRange())
92  return new LabeledComboBoxWidget(parent, str, gridLayout, row);
93  else
94  return new LabeledLineEditWidget(parent, str, gridLayout, row);
95  }
96 
97  DoublePropertyBasePtr dbl = boost::dynamic_pointer_cast<DoublePropertyBase>(data);
98  if (dbl)
99  {
101  switch(gui)
102  {
104  return new SpinBoxAndSliderGroupWidget(parent, dbl, gridLayout, row);
105  break;
107  return new SpinBoxGroupWidget(parent, dbl, gridLayout, row);
108  break;
110  return new SpinBoxAndDialGroupWidget(parent, dbl, gridLayout, row);
111  }
112  }
113 
114  BoolPropertyBasePtr bl = boost::dynamic_pointer_cast<BoolPropertyBase>(data);
115  if (bl)
116  {
117  return new CheckBoxWidget(parent, bl, gridLayout, row);
118  }
119 
120  ColorPropertyBasePtr cl = boost::dynamic_pointer_cast<ColorPropertyBase>(data);
121  if (cl)
122  {
123  return new ColorSelectWidget(parent, cl, gridLayout, row);
124  }
125  DoublePairPropertyBasePtr doublepair = boost::dynamic_pointer_cast<DoublePairPropertyBase>(data);
126  if (doublepair)
127  {
128  return new SliderRangeGroupWidget(parent, doublepair, gridLayout, row);
129  }
130 
131  std::cout << "Failed to create Data Widget for " << (data ? data->getDisplayName() : "NULL") << std::endl;
132 
133  return NULL;
134 }
135 
136 QWidget* addDummyMargin(QWidget* widget)
137 {
138  QHBoxLayout* topLayout = new QHBoxLayout;
139  topLayout->setContentsMargins(1,0,0,0);
140  widget->setLayout(topLayout);
141  return widget;
142 }
143 
144 QHBoxLayout* mergeWidgetsIntoHBoxLayout(QWidget* first, QWidget* second)
145 {
146  QHBoxLayout* hackLayout = new QHBoxLayout;
147  hackLayout->setMargin(0);
148  hackLayout->setSpacing(0);
149 
150  if (first)
151  hackLayout->addWidget(first);
152  if (second)
153  hackLayout->addWidget(second);
154 
155  return hackLayout;
156 }
157 
158 }
QWidget * addDummyMargin(QWidget *widget)
virtual GuiRepresentation getGuiRepresentation()
Widget for the BoolPropertyBase.
Composite widget for filename edit.
boost::shared_ptr< class ViewService > ViewServicePtr
Widget for the ColorPropertyBase.
Composite widget for string selection.
boost::shared_ptr< DoublePairPropertyBase > DoublePairPropertyBasePtr
Composite widget for string edit.
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
QHBoxLayout * mergeWidgetsIntoHBoxLayout(QWidget *first, QWidget *second)
Abstract interface for interaction with internal string-valued data.
Composite widget for scalar data manipulation.
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
boost::shared_ptr< class Property > PropertyPtr
boost::shared_ptr< class BoolPropertyBase > BoolPropertyBasePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
Composite widget for scalar data manipulation.
cxLogicManager_EXPORT ViewServicePtr viewService()
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
boost::shared_ptr< class ColorPropertyBase > ColorPropertyBasePtr
Abstract interface for interaction with internal data structure: A pair of doubles.
boost::shared_ptr< class FilePathProperty > FilePathPropertyPtr
Composite widget for scalar data manipulation.