CustusX  15.3.4-beta
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 
56 namespace cx
57 {
58 
59 QWidget* createDataWidget(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
60 {
61  QWidget* retval = NULL;
62 
63  //make cx widgets
64  SelectDataStringPropertyBasePtr dsda = boost::dynamic_pointer_cast<SelectDataStringPropertyBase>(data);
65  if (dsda)
66  {
67  retval = new DataSelectWidget(visualizationService, patientModelService, parent, dsda, gridLayout, row);
68  return retval;
69  }
70  if(retval != NULL)
71  return retval;
72 
73  retval = sscCreateDataWidget(parent, data, gridLayout, row);
74  return retval;
75 }
76 
77 QWidget* sscCreateDataWidget(QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
78 {
79  StringPropertyBasePtr str = boost::dynamic_pointer_cast<StringPropertyBase>(data);
80  if (str)
81  {
82  if (str->getGuiRepresentation()==StringPropertyBase::grFILENAME)
83  return new FilenameWidget(parent, str, gridLayout, row);
84  else if (str->getAllowOnlyValuesInRange())
85  return new LabeledComboBoxWidget(parent, str, gridLayout, row);
86  else
87  return new LabeledLineEditWidget(parent, str, gridLayout, row);
88  }
89 
90  DoublePropertyBasePtr dbl = boost::dynamic_pointer_cast<DoublePropertyBase>(data);
91  if (dbl)
92  {
94  switch(gui)
95  {
97  return new SpinBoxAndSliderGroupWidget(parent, dbl, gridLayout, row);
98  break;
100  return new SpinBoxGroupWidget(parent, dbl, gridLayout, row);
101  break;
103  return new SpinBoxAndDialGroupWidget(parent, dbl, gridLayout, row);
104  }
105  }
106 
107  BoolPropertyBasePtr bl = boost::dynamic_pointer_cast<BoolPropertyBase>(data);
108  if (bl)
109  {
110  return new CheckBoxWidget(parent, bl, gridLayout, row);
111  }
112 
113  ColorPropertyBasePtr cl = boost::dynamic_pointer_cast<ColorPropertyBase>(data);
114  if (cl)
115  {
116  return new ColorSelectWidget(parent, cl, gridLayout, row);
117  }
118  DoublePairPropertyBasePtr doublepair = boost::dynamic_pointer_cast<DoublePairPropertyBase>(data);
119  if (doublepair)
120  {
121  return new SliderRangeGroupWidget(parent, doublepair, gridLayout, row);
122  }
123 
124  std::cout << "Failed to create Data Widget for " << (data ? data->getDisplayName() : "NULL") << std::endl;
125 
126  return NULL;
127 }
128 
129 QWidget* addDummyMargin(QWidget* widget)
130 {
131  QHBoxLayout* topLayout = new QHBoxLayout;
132  topLayout->setContentsMargins(1,0,0,0);
133  widget->setLayout(topLayout);
134  return widget;
135 }
136 
137 QHBoxLayout* mergeWidgetsIntoHBoxLayout(QWidget* first, QWidget* second)
138 {
139  QHBoxLayout* hackLayout = new QHBoxLayout;
140  hackLayout->setMargin(0);
141  hackLayout->setSpacing(0);
142 
143  if (first)
144  hackLayout->addWidget(first);
145  if (second)
146  hackLayout->addWidget(second);
147 
148  return hackLayout;
149 }
150 
151 }
QWidget * addDummyMargin(QWidget *widget)
virtual GuiRepresentation getGuiRepresentation()
Widget for the BoolPropertyBase.
QWidget * createDataWidget(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Composite widget for filename edit.
Widget for the ColorPropertyBase.
Composite widget for string selection.
boost::shared_ptr< DoublePairPropertyBase > DoublePairPropertyBasePtr
Composite widget for string edit.
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 VisualizationService > VisualizationServicePtr
Definition: cxRegServices.h:43
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.
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.
Composite widget for scalar data manipulation.
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr