Fraxinus  18.10
An IGT application
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) 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 
12 
13 /*
14  * sscHelperWidgets.cpp
15  *
16  * Created on: May 18, 2010
17  * Author: christiana
18  */
19 #include "cxHelperWidgets.h"
20 
21 #include <iostream>
22 #include "boost/shared_ptr.hpp"
23 #include "cxDoubleWidgets.h"
25 #include "cxCheckBoxWidget.h"
26 #include "cxColorSelectWidget.h"
27 #include "cxTypeConversions.h"
29 #include "cxDoubleSpanSlider.h"
30 #include "cxFilenameWidget.h"
32 #include "cxDataSelectWidget.h"
34 #include "cxFilePathProperty.h"
35 
36 namespace cx
37 {
38 
39 QWidget* createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
40 {
41  QWidget* retval = NULL;
42 
43  //make cx widgets
44  SelectDataStringPropertyBasePtr dsda = boost::dynamic_pointer_cast<SelectDataStringPropertyBase>(data);
45  if (dsda)
46  {
47  retval = new DataSelectWidget(viewService, patientModelService, parent, dsda, gridLayout, row);
48  return retval;
49  }
50  if(retval != NULL)
51  return retval;
52 
53  retval = sscCreateDataWidget(parent, data, gridLayout, row);
54  return retval;
55 }
56 
57 QWidget* sscCreateDataWidget(QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
58 {
59  FilePathPropertyPtr fp = boost::dynamic_pointer_cast<FilePathProperty>(data);
60  if (fp)
61  {
62  return new FilenameWidget(parent, fp, gridLayout, row);
63  }
64 
65  StringPropertyBasePtr str = boost::dynamic_pointer_cast<StringPropertyBase>(data);
66  if (str)
67  {
68 // if (str->getGuiRepresentation()==StringPropertyBase::grFILENAME)
69 // return new FilenameWidget(parent, str, gridLayout, row);
70  if (str->getAllowOnlyValuesInRange())
71  return new LabeledComboBoxWidget(parent, str, gridLayout, row);
72  else
73  return new LabeledLineEditWidget(parent, str, gridLayout, row);
74  }
75 
76  DoublePropertyBasePtr dbl = boost::dynamic_pointer_cast<DoublePropertyBase>(data);
77  if (dbl)
78  {
80  switch(gui)
81  {
83  return new SpinBoxAndSliderGroupWidget(parent, dbl, gridLayout, row);
84  break;
86  return new SpinBoxGroupWidget(parent, dbl, gridLayout, row);
87  break;
89  return new SpinBoxAndDialGroupWidget(parent, dbl, gridLayout, row);
90  }
91  }
92 
93  BoolPropertyBasePtr bl = boost::dynamic_pointer_cast<BoolPropertyBase>(data);
94  if (bl)
95  {
96  return new CheckBoxWidget(parent, bl, gridLayout, row);
97  }
98 
99  ColorPropertyBasePtr cl = boost::dynamic_pointer_cast<ColorPropertyBase>(data);
100  if (cl)
101  {
102  return new ColorSelectWidget(parent, cl, gridLayout, row);
103  }
104  DoublePairPropertyBasePtr doublepair = boost::dynamic_pointer_cast<DoublePairPropertyBase>(data);
105  if (doublepair)
106  {
107  return new SliderRangeGroupWidget(parent, doublepair, gridLayout, row);
108  }
109 
110  std::cout << "Failed to create Data Widget for " << (data ? data->getDisplayName() : "NULL") << std::endl;
111 
112  return NULL;
113 }
114 
115 QWidget* addDummyMargin(QWidget* widget)
116 {
117  QHBoxLayout* topLayout = new QHBoxLayout;
118  topLayout->setContentsMargins(1,0,0,0);
119  widget->setLayout(topLayout);
120  return widget;
121 }
122 
123 QHBoxLayout* mergeWidgetsIntoHBoxLayout(QWidget* first, QWidget* second)
124 {
125  QHBoxLayout* hackLayout = new QHBoxLayout;
126  hackLayout->setMargin(0);
127  hackLayout->setSpacing(0);
128 
129  if (first)
130  hackLayout->addWidget(first);
131  if (second)
132  hackLayout->addWidget(second);
133 
134  return hackLayout;
135 }
136 
137 }
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.
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.
Namespace for all CustusX production code.