NorMIT-nav  22.09
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 #include "cxFilePreviewProperty.h"
36 #include "cxFilePreviewWidget.h"
37 #include "cxLogger.h"
38 
39 namespace cx
40 {
41 QWidget* createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
42 {
43  QWidget* retval = NULL;
44 
45  //make cx widgets
46  SelectDataStringPropertyBasePtr dsda = boost::dynamic_pointer_cast<SelectDataStringPropertyBase>(data);
47  if (dsda)
48  {
49  retval = new DataSelectWidget(viewService, patientModelService, parent, dsda, gridLayout, row);
50  return retval;
51  }
52  if(retval != NULL)
53  return retval;
54 
55  retval = sscCreateDataWidget(parent, data, gridLayout, row);
56  return retval;
57 }
58 
59 QWidget* sscCreateDataWidget(QWidget* parent, PropertyPtr data, QGridLayout* gridLayout, int row)
60 {
61  FilePathPropertyPtr fp = boost::dynamic_pointer_cast<FilePathProperty>(data);
62  if (fp)
63  {
64  return new FilenameWidget(parent, fp, gridLayout, row);
65  }
66 
67  StringPropertyBasePtr str = boost::dynamic_pointer_cast<StringPropertyBase>(data);
68  if (str)
69  {
70  // if (str->getGuiRepresentation()==StringPropertyBase::grFILENAME)
71  // return new FilenameWidget(parent, str, gridLayout, row);
72  if (str->getAllowOnlyValuesInRange())
73  return new LabeledComboBoxWidget(parent, str, gridLayout, row);
74  else
75  return new LabeledLineEditWidget(parent, str, gridLayout, row);
76  }
77 
78  DoublePropertyBasePtr dbl = boost::dynamic_pointer_cast<DoublePropertyBase>(data);
79  if (dbl)
80  {
81  DoublePropertyBase::GuiRepresentation gui = dbl->getGuiRepresentation();
82  switch(gui)
83  {
85  return new SpinBoxAndSliderGroupWidget(parent, dbl, gridLayout, row);
86  break;
88  return new SpinBoxGroupWidget(parent, dbl, gridLayout, row);
89  break;
91  return new SpinBoxAndDialGroupWidget(parent, dbl, gridLayout, row);
92  }
93  }
94 
95  BoolPropertyBasePtr bl = boost::dynamic_pointer_cast<BoolPropertyBase>(data);
96  if (bl)
97  {
98  return new CheckBoxWidget(parent, bl, gridLayout, row);
99  }
100 
101  ColorPropertyBasePtr cl = boost::dynamic_pointer_cast<ColorPropertyBase>(data);
102  if (cl)
103  {
104  return new ColorSelectWidget(parent, cl, gridLayout, row);
105  }
106  DoublePairPropertyBasePtr doublepair = boost::dynamic_pointer_cast<DoublePairPropertyBase>(data);
107  if (doublepair)
108  {
109  return new SliderRangeGroupWidget(parent, doublepair, gridLayout, row);
110  }
111 
112  FilePreviewPropertyPtr filePreview = boost::dynamic_pointer_cast<FilePreviewProperty>(data);
113  if (filePreview)
114  {
115  return new FilePreviewWidget(parent, filePreview, gridLayout, row);
116  }
117 
118  std::cout << "Failed to create Data Widget for " << (data ? data->getDisplayName() : "NULL") << std::endl;
119 
120  return NULL;
121 }
122 
123 QWidget* addDummyMargin(QWidget* widget)
124 {
125  QHBoxLayout* topLayout = new QHBoxLayout;
126  topLayout->setContentsMargins(1,0,0,0);
127  widget->setLayout(topLayout);
128  return widget;
129 }
130 
131 QHBoxLayout* mergeWidgetsIntoHBoxLayout(QWidget* first, QWidget* second)
132 {
133  QHBoxLayout* hackLayout = new QHBoxLayout;
134  hackLayout->setMargin(0);
135  hackLayout->setSpacing(0);
136 
137  if (first)
138  hackLayout->addWidget(first);
139  if (second)
140  hackLayout->addWidget(second);
141 
142  return hackLayout;
143 }
144 
145 }
cx::LabeledComboBoxWidget
Composite widget for string selection.
Definition: cxLabeledComboBoxWidget.h:36
cx::DoublePairPropertyBasePtr
boost::shared_ptr< DoublePairPropertyBase > DoublePairPropertyBasePtr
Definition: cxDoublePairPropertyBase.h:86
cx::createDataWidget
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Definition: cxHelperWidgets.cpp:41
cx::FilePreviewPropertyPtr
boost::shared_ptr< class FilePreviewProperty > FilePreviewPropertyPtr
Definition: cxForwardDeclarations.h:147
cxLogger.h
cx::addDummyMargin
QWidget * addDummyMargin(QWidget *widget)
Definition: cxHelperWidgets.cpp:123
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxCheckBoxWidget.h
cx::mergeWidgetsIntoHBoxLayout
QHBoxLayout * mergeWidgetsIntoHBoxLayout(QWidget *first, QWidget *second)
Definition: cxHelperWidgets.cpp:131
cxFilePathProperty.h
cxLabeledComboBoxWidget.h
cx::DoublePropertyBase::GuiRepresentation
GuiRepresentation
Definition: cxDoublePropertyBase.h:78
cx::DoublePropertyBase::grSLIDER
@ grSLIDER
Definition: cxDoublePropertyBase.h:81
cxFilePreviewProperty.h
cxHelperWidgets.h
cx::PropertyPtr
boost::shared_ptr< class Property > PropertyPtr
Definition: cxLocalServerStreamerServer.h:25
cxColorSelectWidget.h
cx::FilePathPropertyPtr
boost::shared_ptr< class FilePathProperty > FilePathPropertyPtr
Definition: cxPlusConnectWidget.h:28
cx::DoublePropertyBase::grDIAL
@ grDIAL
Definition: cxDoublePropertyBase.h:82
cx::ColorSelectWidget
Widget for the ColorPropertyBase.
Definition: cxColorSelectWidget.h:33
cx::CheckBoxWidget
Widget for the BoolPropertyBase.
Definition: cxCheckBoxWidget.h:41
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::ViewServicePtr
boost::shared_ptr< class ViewService > ViewServicePtr
Definition: cxLogicManager.h:28
cxTypeConversions.h
cx::SpinBoxGroupWidget
Composite widget for scalar data manipulation.
Definition: cxDoubleWidgets.h:189
cx::LabeledLineEditWidget
Composite widget for string edit.
Definition: cxLabeledLineEditWidget.h:35
cx::BoolPropertyBasePtr
boost::shared_ptr< class BoolPropertyBase > BoolPropertyBasePtr
Definition: cxImageFileStreamerService.h:22
cxFilenameWidget.h
cx::ColorPropertyBasePtr
boost::shared_ptr< class ColorPropertyBase > ColorPropertyBasePtr
Definition: cxForwardDeclarations.h:139
cx::SpinBoxAndSliderGroupWidget
Composite widget for scalar data manipulation.
Definition: cxDoubleWidgets.h:205
cx::FilePreviewWidget
View a xml document.
Definition: cxFilePreviewWidget.h:37
cxDataSelectWidget.h
cxDoubleWidgets.h
cxLabeledLineEditWidget.h
cx::sscCreateDataWidget
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Definition: cxHelperWidgets.cpp:59
cx::DoublePropertyBasePtr
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
Definition: cxIGTLinkStreamerService.h:21
cx::StringPropertyBasePtr
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
Definition: cxIGTLinkStreamerService.h:20
cxSelectDataStringProperty.h
cx::DataSelectWidget
Definition: cxDataSelectWidget.h:38
cx::DoublePropertyBase::grSPINBOX
@ grSPINBOX
Definition: cxDoublePropertyBase.h:80
cx::SliderRangeGroupWidget
Definition: cxDoubleSpanSlider.h:101
cxFilePreviewWidget.h
cx::SpinBoxAndDialGroupWidget
Composite widget for scalar data manipulation.
Definition: cxDoubleWidgets.h:222
cx::SelectDataStringPropertyBasePtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
Definition: cxMeshGlyphsWidget.h:26
cx::FilenameWidget
Composite widget for filename edit.
Definition: cxFilenameWidget.h:35
cxDoubleSpanSlider.h